From patchwork Tue Jan 8 22:31:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 155022 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp39617jaa; Tue, 8 Jan 2019 14:44:03 -0800 (PST) X-Google-Smtp-Source: ALg8bN5xzjacVhVMNbWgJSmV77QUIKFmr+sJuUcPrGnnE+4WRzy56io7JChiQqve3rx1BqVuCXjq X-Received: by 2002:a1c:5f8a:: with SMTP id t132mr3316308wmb.40.1546987443145; Tue, 08 Jan 2019 14:44:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546987443; cv=none; d=google.com; s=arc-20160816; b=NKheYnMS9rmso7mIwyXxr0AQFgWS65CB9N7dSvbLk3pSkS/fnqdmn/7W/zsDdOEEkd t1xHR0qZdc08F6m8z6SMDXgrmclC4AK+UiOntfbgBxDLAfiSqsi30gAlpckLHW5rarPl jn/vAsYKvUMHYN6ARJY427rAifum04V39q2j5VlyNSpX72rmaqLluGXQh7jXAYXS3sKk w5D5I9iwkhP63crbufSPbo7Xj24aXbenW/LBycTbUYZzz6bLdP4n2Y7aqlB0BDRDeHU9 rITTvhtueOnMY4AIuJEVuO7Vd0NOuriU2l9MCxTzkVK3JbvJElKk+PcTBRIUuSWY0Cwg w8Aw== 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=/zabiqBD3w7s8c81oBx5z5thZaUzr5Ml+9EbpNixrdM=; b=zznKWvXdtIiSs5N6QbPEyX3p5CUok99oDIhlkJgOWuOQaSPVLzKVMKxU4FeotkS819 uAai7tBppxvJ1KGGwbm89TcjxzzzogWOe+V8Er+IXUhOhp6dIkORCXl3IRrh4Dmk/5mS ItshX5wbAmXHj41AZotm6TiquUYbKXHz2aobqm+vQAzfjxH2+XP5JQWmdMSL6a4RN1d/ 8QNDHC21nNRsKNMhdxJ/9YzCXWvRW1DMvoYzDYcmVuqZSwL4ob2/5sgQqqMofgTYvm0P ZJq3O0MVG7rOQlYbkvcHsjKIt9XqOK+aUy/CXZG+pP4oKa/8fY8e5fYoEKmf7FvqiO4h Gs4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=d7XNEfIv; 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 t203si7841531wmb.136.2019.01.08.14.44.02 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 08 Jan 2019 14:44:03 -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=d7XNEfIv; 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]:42489 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gh06L-0001oo-UE for patch@linaro.org; Tue, 08 Jan 2019 17:44:01 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52729) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ggzv7-0000Ce-A6 for qemu-devel@nongnu.org; Tue, 08 Jan 2019 17:32:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ggzv4-0004m8-TL for qemu-devel@nongnu.org; Tue, 08 Jan 2019 17:32:25 -0500 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:33301) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ggzv4-0004hY-EJ for qemu-devel@nongnu.org; Tue, 08 Jan 2019 17:32:22 -0500 Received: by mail-pg1-x541.google.com with SMTP id z11so2375961pgu.0 for ; Tue, 08 Jan 2019 14:32:19 -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=/zabiqBD3w7s8c81oBx5z5thZaUzr5Ml+9EbpNixrdM=; b=d7XNEfIv6/yYZfm2/6ExFE2XJdzZsGWCDY3nnJr153uZI+97A5w1Ti3UADl9FaVMrW bh6bI1x+aZPsBKn7zwTsOaCDsvxV7IWjvhts7t2SY80et7X6pCXxdFo9HEW+j+F4R+8R ElzQwxh9xRoyFKamu86LvZUCCDTGaGlrnFJwA= 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=/zabiqBD3w7s8c81oBx5z5thZaUzr5Ml+9EbpNixrdM=; b=gKXPv38l4NnjcQ0v+KueCVja4xRs5YBlvpFoPwYl7eqhJuwYZwZT6t5LMeYQEmQ3/Q +nXOIYVxd27NLP9LszS38Y6kES9ctnEy5R2VUUZ2ucYwo9mALkQ7OVD57dUDO5R1yR7d D9snvmngLFVnQvwSdxe+4T5bCWUApwSDFY+gyyj3FfDALwUbU4GlCjPuZ0oaT/08EeIe sII2bXzKab56yvS1PGWyASHIWD6QHSoE/byMlUA5KPw7PfpHpLBJlU0Yas5nz3YNhRNY KaQbyvjByvnvQXTdgBeAcF3jMl8++QZMaweJJsyxYnNFYzvbZ7zdA90b8W3Wdv7/xnTI Ud0g== X-Gm-Message-State: AJcUuke3mQoeRz5WhI41n9H3ut5bqx/l3nl/mhIdKnn/PEv/8DewAHss VnP6xJuAKCQDQowKaLSJKTMJB28ssaU= X-Received: by 2002:a62:47d9:: with SMTP id p86mr3431638pfi.95.1546986738053; Tue, 08 Jan 2019 14:32:18 -0800 (PST) Received: from cloudburst.lan (2001-44b8-2176-c800-8cc6-2630-7d99-5ef1.static.ipv6.internode.on.net. [2001:44b8:2176:c800:8cc6:2630:7d99:5ef1]) by smtp.gmail.com with ESMTPSA id w128sm100686177pfw.79.2019.01.08.14.32.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Jan 2019 14:32:17 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 9 Jan 2019 08:31:14 +1000 Message-Id: <20190108223129.5570-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190108223129.5570-1-richard.henderson@linaro.org> References: <20190108223129.5570-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::541 Subject: [Qemu-devel] [PATCH v3 16/31] target/arm: Introduce arm_mmu_idx 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" The pattern ARMMMUIdx mmu_idx = core_to_arm_mmu_idx(env, cpu_mmu_index(env, false)); is computing the full ARMMMUIdx, stripping off the ARM bits, and then putting them back. Avoid the extra two steps with the appropriate helper function. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson ---- v2: Move arm_mmu_idx declaration to internals.h. --- target/arm/cpu.h | 9 ++++++++- target/arm/internals.h | 8 ++++++++ target/arm/helper.c | 27 ++++++++++++++++----------- 3 files changed, 32 insertions(+), 12 deletions(-) -- 2.17.2 diff --git a/target/arm/cpu.h b/target/arm/cpu.h index eb83a71b67..c1d511f274 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -2749,7 +2749,14 @@ ARMMMUIdx arm_v7m_mmu_idx_for_secstate_and_priv(CPUARMState *env, /* Return the MMU index for a v7M CPU in the specified security state */ ARMMMUIdx arm_v7m_mmu_idx_for_secstate(CPUARMState *env, bool secstate); -/* Determine the current mmu_idx to use for normal loads/stores */ +/** + * cpu_mmu_index: + * @env: The cpu environment + * @ifetch: True for code access, false for data access. + * + * Return the core mmu index for the current translation regime. + * This function is used by generic TCG code paths. + */ int cpu_mmu_index(CPUARMState *env, bool ifetch); /* Indexes used when registering address spaces with cpu_address_space_init */ diff --git a/target/arm/internals.h b/target/arm/internals.h index 0ed20c03cc..89f3b122a4 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -919,4 +919,12 @@ void arm_cpu_update_virq(ARMCPU *cpu); */ void arm_cpu_update_vfiq(ARMCPU *cpu); +/** + * arm_mmu_idx: + * @env: The cpu environment + * + * Return the full ARMMMUIdx for the current translation regime. + */ +ARMMMUIdx arm_mmu_idx(CPUARMState *env); + #endif diff --git a/target/arm/helper.c b/target/arm/helper.c index 56d0b60b74..ba6733c4f1 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -7117,7 +7117,7 @@ static bool v7m_push_callee_stack(ARMCPU *cpu, uint32_t lr, bool dotailchain, limit = env->v7m.msplim[M_REG_S]; } } else { - mmu_idx = core_to_arm_mmu_idx(env, cpu_mmu_index(env, false)); + mmu_idx = arm_mmu_idx(env); frame_sp_p = &env->regs[13]; limit = v7m_sp_limit(env); } @@ -7298,7 +7298,7 @@ static bool v7m_push_stack(ARMCPU *cpu) CPUARMState *env = &cpu->env; uint32_t xpsr = xpsr_read(env); uint32_t frameptr = env->regs[13]; - ARMMMUIdx mmu_idx = core_to_arm_mmu_idx(env, cpu_mmu_index(env, false)); + ARMMMUIdx mmu_idx = arm_mmu_idx(env); /* Align stack pointer if the guest wants that */ if ((frameptr & 4) && @@ -11073,7 +11073,7 @@ hwaddr arm_cpu_get_phys_page_attrs_debug(CPUState *cs, vaddr addr, int prot; bool ret; ARMMMUFaultInfo fi = {}; - ARMMMUIdx mmu_idx = core_to_arm_mmu_idx(env, cpu_mmu_index(env, false)); + ARMMMUIdx mmu_idx = arm_mmu_idx(env); *attrs = (MemTxAttrs) {}; @@ -12977,26 +12977,31 @@ ARMMMUIdx arm_v7m_mmu_idx_for_secstate(CPUARMState *env, bool secstate) return arm_v7m_mmu_idx_for_secstate_and_priv(env, secstate, priv); } -int cpu_mmu_index(CPUARMState *env, bool ifetch) +ARMMMUIdx arm_mmu_idx(CPUARMState *env) { - int el = arm_current_el(env); + int el; if (arm_feature(env, ARM_FEATURE_M)) { - ARMMMUIdx mmu_idx = arm_v7m_mmu_idx_for_secstate(env, env->v7m.secure); - - return arm_to_core_mmu_idx(mmu_idx); + return arm_v7m_mmu_idx_for_secstate(env, env->v7m.secure); } + el = arm_current_el(env); if (el < 2 && arm_is_secure_below_el3(env)) { - return arm_to_core_mmu_idx(ARMMMUIdx_S1SE0 + el); + return ARMMMUIdx_S1SE0 + el; + } else { + return ARMMMUIdx_S12NSE0 + el; } - return el; +} + +int cpu_mmu_index(CPUARMState *env, bool ifetch) +{ + return arm_to_core_mmu_idx(arm_mmu_idx(env)); } void cpu_get_tb_cpu_state(CPUARMState *env, target_ulong *pc, target_ulong *cs_base, uint32_t *pflags) { - ARMMMUIdx mmu_idx = core_to_arm_mmu_idx(env, cpu_mmu_index(env, false)); + ARMMMUIdx mmu_idx = arm_mmu_idx(env); int current_el = arm_current_el(env); int fp_el = fp_exception_el(env, current_el); uint32_t flags = 0;