From patchwork Mon Feb 4 13:21:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 157409 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3913290jaa; Mon, 4 Feb 2019 05:24:51 -0800 (PST) X-Google-Smtp-Source: ALg8bN6F6F1g4bkY6X+tzv2hw+HAbHV1U+ODXKSBpTl6FSblmqh0i8AEtEqccHsnYMQYaDlRV9UX X-Received: by 2002:a81:83c1:: with SMTP id t184mr48392135ywf.117.1549286691668; Mon, 04 Feb 2019 05:24:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549286691; cv=none; d=google.com; s=arc-20160816; b=ekqnTPYAMahadqcOeSSs/yS0OvyHSDn0y0n55RhD1GNJYfT8448NvHsk6ah1mHDVBT d9IhaRqUSXjRfUFVJAWQ4hKPcx0q/Cxl3dZUsBq7Ms0si3IDqFKwaD/rX0C8nuYT9ZzR /nbiYw8rV2qaUZB+sUGaSFwY+yGbTUOEn46Z6XHcqjjV52sBT1P/KVJYDs39/F8CdpMd euPzSxZYielKQTut6HjaUaDVqujiPl+lxHAFwqssLFdzJZb7qPrLIApbgtow4HLJIpbz 3pkCVQOB1gsDKwurH+MCdIMT7lGuVcjGMQRR1WZVC/Rjs21OIop3vXad/PrUM2vEKtyK VEHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=jys3zZetk/4aZpt2Z4tdApTnslMweo+0rFVX+0Gfq4E=; b=K6k0bTm/sNnIHEnIounQ54ujdpeOub6W645jLoxkG+T6xxv5tJVSgGCQX71Jizqd29 JkCVv478OxVr9zoSpuJteTn/kpklSycttK6Gbx5pfc8f6eKIcvR3z+jIeUhYgdxc0oO9 Of5Vxq0T2XdjvbEgR07NcwBp2qoLMgYw0xkDqGB9HIHiyMssP8s9E9JfrW/d4WEM2wLK aoHyGYbfmmcCLxbZeFECwQ6p0Bjav2bJkOsVSfAjZGxKOqHiTGPMvWdrx3mt/0ZXpstD ZoWsf5SgGM2041LvpREpJyvOq4/67lDU0mbYzDbL6hKrNPYvGm0k/YcYpwVoBPNE4ECg 9drQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=D7Y91JhO; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id j23si37665ybg.317.2019.02.04.05.24.51 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 04 Feb 2019 05:24:51 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=D7Y91JhO; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:42712 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqeF1-0002KU-5D for patch@linaro.org; Mon, 04 Feb 2019 08:24:51 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51512) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqeC0-00011N-V2 for qemu-devel@nongnu.org; Mon, 04 Feb 2019 08:21:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqeBy-0006Ut-25 for qemu-devel@nongnu.org; Mon, 04 Feb 2019 08:21:44 -0500 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:44256) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gqeBx-0006Pt-Mt for qemu-devel@nongnu.org; Mon, 04 Feb 2019 08:21:41 -0500 Received: by mail-wr1-x441.google.com with SMTP id z5so14305426wrt.11 for ; Mon, 04 Feb 2019 05:21:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=jys3zZetk/4aZpt2Z4tdApTnslMweo+0rFVX+0Gfq4E=; b=D7Y91JhOF+bZHYWoZ8FYh5hrxaozGoxFTEyqa7YzTWNzkikbhPIHz/GLaVgeiN80Qr xQvQUrESKxxf02+EsMvx4FrrUMbosBQHZRmOZJ869kil8lP8LbODoegaEKlEXVny655q HUQ5vePGuQVJk0QIleTYoGmc04TDEPFThnHw8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=jys3zZetk/4aZpt2Z4tdApTnslMweo+0rFVX+0Gfq4E=; b=A7wzjvbLMaJbOrQMedLrANPDnAH/dhOHZfaNhIUro30tbcYjgcm2FjJ8qcssMuFXtL G6AG23q0Q4LKSiCXT74Cuto941EG9UeiLWJ9pQUPZrjKYN+xxLvETX+ZScOwSAAnQs3w y3n9JgaM6ko+gF4iVzUnKlyzK+f3pq+Nf1iUTfw3emiCaimOQGvNYhzpYMPuJLaXfaPY nSM/ZIJbnBcMncG/xDey7Et7DRAiSB3qh5Wr9JHyZ/dBQZlEV9mUhCu5yzDy4l5nCCt4 XTI+YTZk4hpDkyf9w7EZfZByVxdJt1XMr+Nm5S1oA3kHk4CLxUrWsM7yRZOgzI37cOLR DIoQ== X-Gm-Message-State: AJcUuke1cSyS+hc0K/QCaokEj2+v5suKnrpm5dALtvJUgCXw9qCyG3vD X5Kklat1/2CLMkp+12BVMPMBnXhJvACByg== X-Received: by 2002:adf:900f:: with SMTP id h15mr48985857wrh.18.1549286494237; Mon, 04 Feb 2019 05:21:34 -0800 (PST) Received: from cloudburst.twiddle.net (host81-133-38-158.in-addr.btopenworld.com. [81.133.38.158]) by smtp.gmail.com with ESMTPSA id l20sm30371534wrb.93.2019.02.04.05.21.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 04 Feb 2019 05:21:33 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 4 Feb 2019 13:21:23 +0000 Message-Id: <20190204132126.3255-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190204132126.3255-1-richard.henderson@linaro.org> References: <20190204132126.3255-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::441 Subject: [Qemu-devel] [PATCH v2 1/4] target/arm: Add TBFLAG_A64_TBID, split out gen_top_byte_ignore X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Split out gen_top_byte_ignore in preparation of handling these data accesses; the new tbflags field is not yet honored. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- v2: Re-add some commentary wrt TBI bits. --- target/arm/cpu.h | 1 + target/arm/translate.h | 3 +- target/arm/helper.c | 1 + target/arm/translate-a64.c | 72 +++++++++++++++++++------------------- 4 files changed, 40 insertions(+), 37 deletions(-) -- 2.17.2 diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 366ab97db3..029f6cd60c 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -3058,6 +3058,7 @@ FIELD(TBFLAG_A64, ZCR_LEN, 4, 4) FIELD(TBFLAG_A64, PAUTH_ACTIVE, 8, 1) FIELD(TBFLAG_A64, BT, 9, 1) FIELD(TBFLAG_A64, BTYPE, 10, 2) +FIELD(TBFLAG_A64, TBID, 12, 2) static inline bool bswap_code(bool sctlr_b) { diff --git a/target/arm/translate.h b/target/arm/translate.h index f73939d7b4..17748ddfb9 100644 --- a/target/arm/translate.h +++ b/target/arm/translate.h @@ -26,7 +26,8 @@ typedef struct DisasContext { int user; #endif ARMMMUIdx mmu_idx; /* MMU index to use for normal loads/stores */ - uint8_t tbii; /* TBI1|TBI0 for EL0/1 or TBI for EL2/3 */ + uint8_t tbii; /* TBI1|TBI0 for insns */ + uint8_t tbid; /* TBI1|TBI0 for data */ bool ns; /* Use non-secure CPREG bank on access */ int fp_excp_el; /* FP exception EL or 0 if enabled */ int sve_excp_el; /* SVE exception EL or 0 if enabled */ diff --git a/target/arm/helper.c b/target/arm/helper.c index be0ec7de2a..25d8ec38f8 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -13767,6 +13767,7 @@ void cpu_get_tb_cpu_state(CPUARMState *env, target_ulong *pc, } flags = FIELD_DP32(flags, TBFLAG_A64, TBII, tbii); + flags = FIELD_DP32(flags, TBFLAG_A64, TBID, tbid); } #endif diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index 37077138e3..0b4a09ca1c 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -284,10 +284,10 @@ void gen_a64_set_pc_im(uint64_t val) tcg_gen_movi_i64(cpu_pc, val); } -/* Load the PC from a generic TCG variable. +/* + * Handle Top Byte Ignore (TBI) bits. * - * If address tagging is enabled via the TCR TBI bits, then loading - * an address into the PC will clear out any tag in it: + * If address tagging is enabled via the TCR TBI bits: * + for EL2 and EL3 there is only one TBI bit, and if it is set * then the address is zero-extended, clearing bits [63:56] * + for EL0 and EL1, TBI0 controls addresses with bit 55 == 0 @@ -295,45 +295,44 @@ void gen_a64_set_pc_im(uint64_t val) * If the appropriate TBI bit is set for the address then * the address is sign-extended from bit 55 into bits [63:56] * - * We can avoid doing this for relative-branches, because the - * PC + offset can never overflow into the tag bits (assuming - * that virtual addresses are less than 56 bits wide, as they - * are currently), but we must handle it for branch-to-register. + * Here We have concatenated TBI{1,0} into tbi. */ -static void gen_a64_set_pc(DisasContext *s, TCGv_i64 src) +static void gen_top_byte_ignore(DisasContext *s, TCGv_i64 dst, + TCGv_i64 src, int tbi) { - /* Note that TBII is TBI1:TBI0. */ - int tbi = s->tbii; - - if (s->current_el <= 1) { - if (tbi != 0) { - /* Sign-extend from bit 55. */ - tcg_gen_sextract_i64(cpu_pc, src, 0, 56); - - if (tbi != 3) { - TCGv_i64 tcg_zero = tcg_const_i64(0); - - /* - * The two TBI bits differ. - * If tbi0, then !tbi1: only use the extension if positive. - * if !tbi0, then tbi1: only use the extension if negative. - */ - tcg_gen_movcond_i64(tbi == 1 ? TCG_COND_GE : TCG_COND_LT, - cpu_pc, cpu_pc, tcg_zero, cpu_pc, src); - tcg_temp_free_i64(tcg_zero); - } - return; - } + if (tbi == 0) { + /* Load unmodified address */ + tcg_gen_mov_i64(dst, src); + } else if (s->current_el >= 2) { + /* FIXME: ARMv8.1-VHE S2 translation regime. */ + /* Force tag byte to all zero */ + tcg_gen_extract_i64(dst, src, 0, 56); } else { - if (tbi != 0) { - /* Force tag byte to all zero */ - tcg_gen_extract_i64(cpu_pc, src, 0, 56); - return; + /* Sign-extend from bit 55. */ + tcg_gen_sextract_i64(dst, src, 0, 56); + + if (tbi != 3) { + TCGv_i64 tcg_zero = tcg_const_i64(0); + + /* + * The two TBI bits differ. + * If tbi0, then !tbi1: only use the extension if positive. + * if !tbi0, then tbi1: only use the extension if negative. + */ + tcg_gen_movcond_i64(tbi == 1 ? TCG_COND_GE : TCG_COND_LT, + dst, dst, tcg_zero, dst, src); + tcg_temp_free_i64(tcg_zero); } } +} - /* Load unmodified address */ - tcg_gen_mov_i64(cpu_pc, src); +static void gen_a64_set_pc(DisasContext *s, TCGv_i64 src) +{ + /* + * If address tagging is enabled for instructions via the TCR TBI bits, + * then loading an address into the PC will clear out any tag. + */ + gen_top_byte_ignore(s, cpu_pc, src, s->tbii); } typedef struct DisasCompare64 { @@ -14018,6 +14017,7 @@ static void aarch64_tr_init_disas_context(DisasContextBase *dcbase, core_mmu_idx = FIELD_EX32(tb_flags, TBFLAG_ANY, MMUIDX); dc->mmu_idx = core_to_arm_mmu_idx(env, core_mmu_idx); dc->tbii = FIELD_EX32(tb_flags, TBFLAG_A64, TBII); + dc->tbid = FIELD_EX32(tb_flags, TBFLAG_A64, TBID); dc->current_el = arm_mmu_idx_to_el(dc->mmu_idx); #if !defined(CONFIG_USER_ONLY) dc->user = (dc->current_el == 0);