Received: from eggs.gnu.org ([2001:4830:134:3::10]:34356) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WkvQf-0000TE-4d for qemu-devel@nongnu.org; Thu, 15 May 2014 09:10:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WkvQa-0002oN-UB for qemu-devel@nongnu.org; Thu, 15 May 2014 09:10:33 -0400 Received: from edge10.ethz.ch ([82.130.75.186]:55434) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WkvQa-0002oD-LN for qemu-devel@nongnu.org; Thu, 15 May 2014 09:10:28 -0400 From: "Aggeler Fabian" Date: Thu, 15 May 2014 13:10:26 +0000 Message-ID: <082155EB-6147-4E42-BF71-E0F2ABE75DD1@ethz.ch> References: <1399997768-32014-1-git-send-email-aggelerf@ethz.ch> <1399997768-32014-20-git-send-email-aggelerf@ethz.ch> In-Reply-To: Content-Language: en-US Content-Type: text/plain; charset="Windows-1252" Content-ID: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH v2 19/23] target-arm: maintain common bits of banked CP registers List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Greg Bellows Cc: "Edgar E. Iglesias" , Sergey Fedorov , QEMU Developers , Peter Maydell On 14 May 2014, at 23:20, Greg Bellows > wrote: On 13 May 2014 11:16, Fabian Aggeler > wrote: Some of SCTRL bits are common for secure and non-secure state. Translation table base masks are updated on NS-bit switch as well as on TTBCR writes. Signed-off-by: Sergey Fedorov > Signed-off-by: Fabian Aggeler > --- target-arm/cpu.h | 10 ++++++++++ target-arm/helper.c | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/target-arm/cpu.h b/target-arm/cpu.h index c20c44a..7893004 100644 --- a/target-arm/cpu.h +++ b/target-arm/cpu.h @@ -425,6 +425,14 @@ int arm_cpu_handle_mmu_fault(CPUState *cpu, vaddr addr= ess, int rw, #define SCTLR_AFE (1U << 29) #define SCTLR_TE (1U << 30) +/* Bitmask for banked bits (Security Extensions) */ +#define SCTLR_BANKED (SCTLR_TE | SCTLR_AFE | SCTLR_TRE | SCTLR_EE | \ + SCTLR_VE | SCTLR_HA | SCTLR_UWXN | SCTLR_WXN | SCTLR_V | \ + SCTLR_I | SCTLR_Z | SCTLR_SW | SCTLR_CP15BEN | SCTLR_C | \ + SCTLR_A | SCTLR_M) +/* Treat bits that are not explicitly banked as common */ +#define SCTLR_COMMON (~SCTLR_BANKED) + #define CPSR_M (0x1fU) #define CPSR_T (1U << 5) #define CPSR_F (1U << 6) @@ -662,6 +670,8 @@ static inline int arm_feature(CPUARMState *env, int fea= ture) return (env->features & (1ULL << feature)) !=3D 0; } +#define SCR_NS (1U << 0) + /* Return true if the processor is in secure state */ static inline bool arm_is_secure(CPUARMState *env) { diff --git a/target-arm/helper.c b/target-arm/helper.c index c76a86b..618fd31 100644 --- a/target-arm/helper.c +++ b/target-arm/helper.c @@ -2165,12 +2165,49 @@ static void sctlr_write(CPUARMState *env, const ARM= CPRegInfo *ri, } raw_write(env, ri, value); + + if (!arm_el_is_aa64(env, 3)) { + /* Aarch32 has some bits that are common to secure (mapped to + * SCTLR_EL3) and non-secure instances of the SCTLR. */ + + env->cp15.c1_sys_el1 &=3D SCTLR_BANKED | + (arm_current_sctlr(env) & SCTLR_COMMON); + env->cp15.c1_sys_el3 &=3D SCTLR_BANKED | + (arm_current_sctlr(env) & SCTLR_COMMON); + } + /* ??? Lots of these bits are not implemented. */ /* This may enable/disable the MMU, so do a TLB flush. */ tlb_flush(CPU(cpu), 1); } #ifndef CONFIG_USER_ONLY +static void scr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t v= alue) +{ + if (!arm_el_is_aa64(env, 3) && + (value & SCR_NS) !=3D (env->cp15.c1_scr & SCR_NS)) { + /* If EL3 is using Aarch32 switching NS-bit may make the CPU use a + * different instance (secure or non-secure) when accessing CP + * registers. + * Common bits of otherwise banked registers need to by synchroniz= ed + * at this point. + */ + env->cp15.c1_sys_el1 &=3D SCTLR_BANKED | + (arm_current_sctlr(env) & SCTLR_COMMON); + env->cp15.c1_sys_el3 &=3D SCTLR_BANKED | + (arm_current_sctlr(env) & SCTLR_COMMON); I must be missing something, if the common bits are sync'd across the banks= in sctlr_write(), why do we need to do it here? Right, should not be needed. I=92ll remove it. + } + + env->cp15.c1_scr =3D value; + + /* After possible switch, calculate c2_mask and c2_base_mask again for= the + * instance which is now active (secure or non-secure). + */ + int maskshift =3D extract32(A32_BANKED_REG_GET(env, c2_control), 0, 3)= ; + env->cp15.c2_mask =3D ~(((uint32_t)0xffffffffu) >> maskshift); + env->cp15.c2_base_mask =3D ~((uint32_t)0x3fffu >> maskshift); As mentioned elsewhere, does it make sense to bank the c2_mask fields so th= ey stay in sync with c2_control? Presumably we would not need to do these = updates in this case. Good idea, I will bank them and remove this bit. + +} static void nsacr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value) @@ -2183,7 +2220,7 @@ static const ARMCPRegInfo tz_cp_reginfo[] =3D { #ifndef CONFIG_USER_ONLY { .name =3D "SCR", .cp =3D 15, .crn =3D 1, .crm =3D 1, .opc1 =3D 0, .o= pc2 =3D 0, .access =3D PL3_RW, .fieldoffset =3D offsetof(CPUARMState, cp15.c1_s= cr), - .resetvalue =3D 0, }, + .resetvalue =3D 0, .writefn =3D scr_write }, { .name =3D "SCR_EL3", .state =3D ARM_CP_STATE_AA64, .opc0 =3D 3, .crn =3D 6, .crm =3D 1, .opc1 =3D 0, .opc2 =3D 0, .access =3D PL3_RW, .fieldoffset =3D offsetof(CPUARMState, cp15.c1_s= cr), -- 1.8.3.2