From patchwork Mon Apr 19 20:22:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 424048 Delivered-To: patch@linaro.org Received: by 2002:a02:6a6f:0:0:0:0:0 with SMTP id m47csp3049629jaf; Mon, 19 Apr 2021 13:52:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyvNZ/sakIG51Lde5CcXZc5eW52ZP+KTZHvSdVvT6YqCJhIf5cofzsSXjJBYvWXv2ZljU2Y X-Received: by 2002:a92:c048:: with SMTP id o8mr19440359ilf.147.1618865542854; Mon, 19 Apr 2021 13:52:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618865542; cv=none; d=google.com; s=arc-20160816; b=U0rl9JLSjKuhrFeCkIiAGEZdzZ6eFAWeZkeSjTeFcUrQIO9TjKhqx9P/b01RUFcXft T0tcG2el0KJjceabcUML9CPurLpu19ectuU6ly2+do2zQAIqpzVFLIeCi89N44VAAeus 34dWZIsqP04LJ6tZ7hhlSFG+cgfuOJO0lwDD4ISZM8qCWpenDCRaT+OcGd55er+DPzE/ me4bJZiYiQC8lpNfDfdm4pMH6grpNcIUAh6Vh0T2NohQoUs/fIWFiIPCYhmbJKTu1cyC scNgqshzDF1lrn6m80VOjO/Gy9n4bm/nzz6XMS/tsUAw00xf5TwxD/CbyjBkQImzKaXE A8zg== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=nwgWduUVKAJ9bK9DS+BzsRqkrXPjkekV7O1Cx87RTkQ=; b=rK27CO6Y8WBp6/tMjPErBfkzzt9MlDbpNwGSryDdKvU8T+/xIs3sE75jLw8aixYsDA GURK4EtCZx9/d0Gj0RGf4fesA3m+7Aa3m2pJTz8omZLC1CYf5mgLYl/qQfwgZy0vZ4/0 tDckFPSSA8iVFWkAwLm/9dgfaEkDx8gN4IlJzGscTU6KzWspG3LE9xNTTQ2EKtwUEG94 yZUAhJgJecSvpq23TZE56rvQ6Wv63yoPn8hqnuZJPcDS8Z3JMVslkRQQAMF3hf6Gr6zS yXtw6P3hs0kJBcdrsf0HEKdB777dh6ajmZ2RGCkdEHDKGQiABIjsQgDF+e1lGPKeZHs8 FrRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=i6P1FA80; 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 q11si16838917ilo.71.2021.04.19.13.52.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 19 Apr 2021 13:52:22 -0700 (PDT) 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=i6P1FA80; 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 ([::1]:44452 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lYasX-0005pI-6G for patch@linaro.org; Mon, 19 Apr 2021 16:52:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33786) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYaQU-0007Ck-S5 for qemu-devel@nongnu.org; Mon, 19 Apr 2021 16:23:22 -0400 Received: from mail-qk1-x735.google.com ([2607:f8b0:4864:20::735]:42935) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lYaQS-0002Wz-PW for qemu-devel@nongnu.org; Mon, 19 Apr 2021 16:23:22 -0400 Received: by mail-qk1-x735.google.com with SMTP id z2so187463qkb.9 for ; Mon, 19 Apr 2021 13:23:20 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=nwgWduUVKAJ9bK9DS+BzsRqkrXPjkekV7O1Cx87RTkQ=; b=i6P1FA80+o0oiEIVxiVCy3q4IEsVfUpSja4+gEEbCSUJdM6mivcJAHgyPDrxNU2JZu RIuPQ0Byv4ZdGcNyQArsD08UsjRN89oQIgBVUIgvSnXxyrpQ2Hl+XvViBbhLnkV7Yqsq D2kCXD49R2pg6Mxq22ByL2DyhrO6CRfCniIeTF/362WTjE6u0jwhPaejnVrz1iqZrhfX KIlVgcV26bUUhnsT1pT+51KgkCN5oRRfIBDciJXITiPZChebKmFfy4MSVuGE/ztwpRR+ b1QzwbFG2uUbgPVoUS1BrFhod+noIAruz7bx6iWlI6QZK71ky07/gUbLXVRonLhWZZ5f CZwQ== 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:mime-version:content-transfer-encoding; bh=nwgWduUVKAJ9bK9DS+BzsRqkrXPjkekV7O1Cx87RTkQ=; b=YNeCk+GNKkdr0tljrRJmwMhysFmScXh0QAWBG9Uez4z+Om5u9rCvca3p9c/yB2iv/g X6bObgsqThTgKM5rCGCFqf+oEGC2XomrBcHxkMlHysXwLVGP1B2sUs5Z6An/uTp7zP0m rPGYx3+0McyuBUoSSw23YHgJI7pwJOJUPhsBwM/zblu4GLn0hEA598IuU5S3jdvAPyZ6 lI3AaHIx3BfMrFG5zBXbM3Z0U47XH9ONlwKxQs+X1PyPr2611223ORTAhcbwvfNhi/IZ GHnkfNcEKAzXwgtnuvjL6Hts2jvzI18jCNtfxgcofBOYbSqO10oyCcoFtxtPbOVFOeLW EQxw== X-Gm-Message-State: AOAM530tj99d5UiSO8Klgrsu9imIFy4888POsXaa1qb888hOYN9+m1FL OkbCxES4WkRg4lPkW+FZC7IlW9l7bRKQJwDx X-Received: by 2002:a05:620a:386:: with SMTP id q6mr1947891qkm.438.1618863799850; Mon, 19 Apr 2021 13:23:19 -0700 (PDT) Received: from localhost.localdomain ([2607:fb90:80c7:aba4:3594:91a:8889:c77a]) by smtp.gmail.com with ESMTPSA id c23sm10007835qtm.46.2021.04.19.13.23.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Apr 2021 13:23:19 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v5 10/31] target/arm: Add ALIGN_MEM to TBFLAG_ANY Date: Mon, 19 Apr 2021 13:22:36 -0700 Message-Id: <20210419202257.161730-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210419202257.161730-1-richard.henderson@linaro.org> References: <20210419202257.161730-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::735; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x735.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , qemu-arm@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Use this to signal when memory access alignment is required. This value comes from the CCR register for M-profile, and from the SCTLR register for A-profile. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- target/arm/cpu.h | 2 ++ target/arm/translate.h | 2 ++ target/arm/helper.c | 19 +++++++++++++++++-- target/arm/translate-a64.c | 1 + target/arm/translate.c | 7 +++---- 5 files changed, 25 insertions(+), 6 deletions(-) -- 2.25.1 diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 5e0131be1a..616b393253 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -3414,6 +3414,8 @@ FIELD(TBFLAG_ANY, MMUIDX, 4, 4) FIELD(TBFLAG_ANY, FPEXC_EL, 8, 2) /* For A-profile only, target EL for debug exceptions. */ FIELD(TBFLAG_ANY, DEBUG_TARGET_EL, 10, 2) +/* Memory operations require alignment: SCTLR_ELx.A or CCR.UNALIGN_TRP */ +FIELD(TBFLAG_ANY, ALIGN_MEM, 12, 1) /* * Bit usage when in AArch32 state, both A- and M-profile. diff --git a/target/arm/translate.h b/target/arm/translate.h index 50c2aba066..b185c14a03 100644 --- a/target/arm/translate.h +++ b/target/arm/translate.h @@ -87,6 +87,8 @@ typedef struct DisasContext { bool bt; /* True if any CP15 access is trapped by HSTR_EL2 */ bool hstr_active; + /* True if memory operations require alignment */ + bool align_mem; /* * >= 0, a copy of PSTATE.BTYPE, which will be 0 without v8.5-BTI. * < 0, set by the current instruction. diff --git a/target/arm/helper.c b/target/arm/helper.c index 8275eb2e65..cb542d4300 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -13018,6 +13018,12 @@ static CPUARMTBFlags rebuild_hflags_m32(CPUARMState *env, int fp_el, ARMMMUIdx mmu_idx) { CPUARMTBFlags flags = {}; + uint32_t ccr = env->v7m.ccr[env->v7m.secure]; + + /* Without HaveMainExt, CCR.UNALIGN_TRP is RES1. */ + if (ccr & R_V7M_CCR_UNALIGN_TRP_MASK) { + DP_TBFLAG_ANY(flags, ALIGN_MEM, 1); + } if (arm_v7m_is_handler_mode(env)) { DP_TBFLAG_M32(flags, HANDLER, 1); @@ -13030,7 +13036,7 @@ static CPUARMTBFlags rebuild_hflags_m32(CPUARMState *env, int fp_el, */ if (arm_feature(env, ARM_FEATURE_V8) && !((mmu_idx & ARM_MMU_IDX_M_NEGPRI) && - (env->v7m.ccr[env->v7m.secure] & R_V7M_CCR_STKOFHFNMIGN_MASK))) { + (ccr & R_V7M_CCR_STKOFHFNMIGN_MASK))) { DP_TBFLAG_M32(flags, STACKCHECK, 1); } @@ -13049,12 +13055,17 @@ static CPUARMTBFlags rebuild_hflags_a32(CPUARMState *env, int fp_el, ARMMMUIdx mmu_idx) { CPUARMTBFlags flags = rebuild_hflags_aprofile(env); + int el = arm_current_el(env); + + if (arm_sctlr(env, el) & SCTLR_A) { + DP_TBFLAG_ANY(flags, ALIGN_MEM, 1); + } if (arm_el_is_aa64(env, 1)) { DP_TBFLAG_A32(flags, VFPEN, 1); } - if (arm_current_el(env) < 2 && env->cp15.hstr_el2 && + if (el < 2 && env->cp15.hstr_el2 && (arm_hcr_el2_eff(env) & (HCR_E2H | HCR_TGE)) != (HCR_E2H | HCR_TGE)) { DP_TBFLAG_A32(flags, HSTR_ACTIVE, 1); } @@ -13099,6 +13110,10 @@ static CPUARMTBFlags rebuild_hflags_a64(CPUARMState *env, int el, int fp_el, sctlr = regime_sctlr(env, stage1); + if (sctlr & SCTLR_A) { + DP_TBFLAG_ANY(flags, ALIGN_MEM, 1); + } + if (arm_cpu_data_is_big_endian_a64(el, sctlr)) { DP_TBFLAG_ANY(flags, BE_DATA, 1); } diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index b32ff56666..92a62b1a75 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -14697,6 +14697,7 @@ static void aarch64_tr_init_disas_context(DisasContextBase *dcbase, dc->user = (dc->current_el == 0); #endif dc->fp_excp_el = EX_TBFLAG_ANY(tb_flags, FPEXC_EL); + dc->align_mem = EX_TBFLAG_ANY(tb_flags, ALIGN_MEM); dc->sve_excp_el = EX_TBFLAG_A64(tb_flags, SVEEXC_EL); dc->sve_len = (EX_TBFLAG_A64(tb_flags, ZCR_LEN) + 1) * 16; dc->pauth_active = EX_TBFLAG_A64(tb_flags, PAUTH_ACTIVE); diff --git a/target/arm/translate.c b/target/arm/translate.c index 418715fe13..e918c2e1a4 100644 --- a/target/arm/translate.c +++ b/target/arm/translate.c @@ -933,8 +933,7 @@ static void gen_aa32_ld_i32(DisasContext *s, TCGv_i32 val, TCGv_i32 a32, { TCGv addr; - if (arm_dc_feature(s, ARM_FEATURE_M) && - !arm_dc_feature(s, ARM_FEATURE_M_MAIN)) { + if (s->align_mem) { opc |= MO_ALIGN; } @@ -948,8 +947,7 @@ static void gen_aa32_st_i32(DisasContext *s, TCGv_i32 val, TCGv_i32 a32, { TCGv addr; - if (arm_dc_feature(s, ARM_FEATURE_M) && - !arm_dc_feature(s, ARM_FEATURE_M_MAIN)) { + if (s->align_mem) { opc |= MO_ALIGN; } @@ -8861,6 +8859,7 @@ static void arm_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) dc->user = (dc->current_el == 0); #endif dc->fp_excp_el = EX_TBFLAG_ANY(tb_flags, FPEXC_EL); + dc->align_mem = EX_TBFLAG_ANY(tb_flags, ALIGN_MEM); if (arm_feature(env, ARM_FEATURE_M)) { dc->vfp_enabled = 1;