Received: from eggs.gnu.org ([2001:4830:134:3::10]:51378) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WwnwH-0002bT-C9 for qemu-devel@nongnu.org; Tue, 17 Jun 2014 03:36:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WwnwC-00046k-AZ for qemu-devel@nongnu.org; Tue, 17 Jun 2014 03:36:17 -0400 Received: from edge10.ethz.ch ([82.130.75.186]:57594) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WwnwC-00046U-0p for qemu-devel@nongnu.org; Tue, 17 Jun 2014 03:36:12 -0400 From: "Aggeler Fabian" Date: Tue, 17 Jun 2014 07:36:09 +0000 Message-ID: References: <1402444514-19658-1-git-send-email-aggelerf@ethz.ch> <1402444514-19658-15-git-send-email-aggelerf@ethz.ch> In-Reply-To: Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-ID: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH v3 14/32] target-arm: Respect SCR.FW, SCR.AW and SCTLR.NMFI List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Greg Bellows Cc: Peter Maydell , Peter Crosthwaite , QEMU Developers , Sergey Fedorov , "Edgar E. Iglesias" , Christoffer Dall On 13 Jun 2014, at 00:43, Greg Bellows > wrote: On 10 June 2014 18:54, Fabian Aggeler > wrote: bits when modifying CPSR. Signed-off-by: Fabian Aggeler > --- target-arm/helper.c | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/target-arm/helper.c b/target-arm/helper.c index 2fbecfa..f6ff4aa 100644 --- a/target-arm/helper.c +++ b/target-arm/helper.c @@ -3091,9 +3091,6 @@ void cpsr_write(CPUARMState *env, uint32_t val, uint3= 2_t mask) env->GE =3D (val >> 16) & 0xf; } - env->daif &=3D ~(CPSR_AIF & mask); - env->daif |=3D val & CPSR_AIF & mask; - if ((env->uncached_cpsr ^ val) & mask & CPSR_M) { if (bad_mode_switch(env, val & CPSR_M)) { /* Attempt to switch to an invalid mode: this is UNPREDICTABLE= . @@ -3105,6 +3102,45 @@ void cpsr_write(CPUARMState *env, uint32_t val, uint= 32_t mask) switch_mode(env, val & CPSR_M); } } + + /* In an implementation that does not include Virtualization Extension= s + * the SCR.FW and SCR.AW bit control whether non-secur= e software is allowed + * to change the CPSR_F and CPSR_A bits respectively. + */ + if ((mask & CPSR_A) + && (val & CPSR_A) !=3D (env->uncached_cpsr & CPSR_A) + && arm_feature(env, ARM_FEATURE_EL3) + && !(env->cp15.scr_el3 & SCR_AW) && !arm_is_secure(env)) { + qemu_log_mask(LOG_GUEST_ERROR, "Ignoring attempt to switch CPSR_A = " + "flag from non-secure world with SCR.AW bi= t set\n"); + mask &=3D ~CPSR_A; Ignoring the write appears to only be valid in the case of ARMv7 (actually = says "early implementations of v7") but not v8. This is noted in the ARMv8= spec in the section "Effects of EL3 and EL2 on the CPSR.{A, F} bits". Acc= ording to this passage, the AW/FW bits only block the corresponding bits be= ing updated when the SPSR is copied to the CPSR. It sounds like they are d= istinguishing between this copy and a raw write. Yes, I missed that bit. Adding a !arm_feature(env, ARM_FEATURE_V8) conditio= n should help in that case. And then do the check as well when copying SPSR to CPSR. + } + + if ((mask & CPSR_F)) { + /* Pre ARMv8: Check whether non-maskable FIQ (NMFI) support is ena= bled. + * If this bit is set software is not allowed to mask FIQs, + * but is allowed to set CPSR_F to 0. + */ + if (!arm_feature(env, ARM_FEATURE_V8) && + (A32_BANKED_CURRENT_REG_GET(env, sctlr) & SCTLR_NMFI) && + (val & CPSR_F)) { + qemu_log_mask(LOG_GUEST_ERROR, "Ignoring attempt to enable CPS= R_F " + "flag (non-maskable FIQ [NMFI] support enabled)\n"); + mask &=3D ~CPSR_F; + } + + if ((val & CPSR_F) !=3D (env->uncached_cpsr & CPSR_F) + && arm_feature(env, ARM_FEATURE_EL3) + && !(env->cp15.scr_el3 & SCR_FW) && !arm_is_secure(env)) { + qemu_log_mask(LOG_GUEST_ERROR, "Ignoring attempt to switch CPS= R_F " + "flag from non-secure world with SCR.FW bit set\n"); + mask &=3D ~CPSR_F; + } + } + + env->daif &=3D ~(CPSR_AIF & mask); + env->daif |=3D val & CPSR_AIF & mask; + mask &=3D ~CACHED_CPSR_BITS; env->uncached_cpsr =3D (env->uncached_cpsr & ~mask) | (val & mask); } -- 1.8.3.2