From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43592) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X1tHE-0003Hv-EX for qemu-devel@nongnu.org; Tue, 01 Jul 2014 04:19:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X1tHA-0002Qj-7G for qemu-devel@nongnu.org; Tue, 01 Jul 2014 04:18:56 -0400 Received: from mail-yh0-x235.google.com ([2607:f8b0:4002:c01::235]:40214) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X1tHA-0002Qb-3F for qemu-devel@nongnu.org; Tue, 01 Jul 2014 04:18:52 -0400 Received: by mail-yh0-f53.google.com with SMTP id b6so5727102yha.12 for ; Tue, 01 Jul 2014 01:18:51 -0700 (PDT) Date: Tue, 1 Jul 2014 18:17:56 +1000 From: "Edgar E. Iglesias" Message-ID: <20140701081756.GJ13735@toto> References: <1404169773-20264-1-git-send-email-greg.bellows@linaro.org> <1404169773-20264-5-git-send-email-greg.bellows@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1404169773-20264-5-git-send-email-greg.bellows@linaro.org> Subject: Re: [Qemu-devel] [PATCH v4 04/33] target-arm: add arm_is_secure() function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: greg.bellows@linaro.org Cc: peter.maydell@linaro.org, peter.crosthwaite@xilinx.com, Sergey Fedorov , Fabian Aggeler , qemu-devel@nongnu.org, serge.fdrv@gmail.com, christoffer.dall@linaro.org On Mon, Jun 30, 2014 at 06:09:04PM -0500, greg.bellows@linaro.org wrote: > From: Fabian Aggeler > > arm_is_secure() function allows to determine CPU security state > if the CPU implements Security Extensions/EL3. > arm_is_secure_below_el3() returns true if CPU is in secure state > below EL3. > > Signed-off-by: Sergey Fedorov > Signed-off-by: Fabian Aggeler > Signed-off-by: Greg Bellows > --- > target-arm/cpu.h | 38 ++++++++++++++++++++++++++++++++++++++ > 1 file changed, 38 insertions(+) > > diff --git a/target-arm/cpu.h b/target-arm/cpu.h > index ffc51f2..aba077b 100644 > --- a/target-arm/cpu.h > +++ b/target-arm/cpu.h > @@ -726,6 +726,44 @@ static inline int arm_feature(CPUARMState *env, int feature) > return (env->features & (1ULL << feature)) != 0; > } > > + > +/* Return true if exception level below EL3 is in secure state */ > +static inline bool arm_is_secure_below_el3(CPUARMState *env) > +{ > +#if !defined(CONFIG_USER_ONLY) > + if (arm_feature(env, ARM_FEATURE_EL3)) { > + return !(env->cp15.scr_el3 & SCR_NS); > + } else if (arm_feature(env, ARM_FEATURE_EL2)) { > + return false; > + } else { > + /* IMPDEF: QEMU defaults to non-secure */ > + return false; > + } > +#else > + return false; > +#endif > +} Should we be #ifdefing the entire arm_is_secure_below_el3() as it is not called from user-only code? > + > +/* Return true if the processor is in secure state */ > +static inline bool arm_is_secure(CPUARMState *env) > +{ > +#if !defined(CONFIG_USER_ONLY) > + if (arm_feature(env, ARM_FEATURE_EL3)) { > + if (env->aarch64 && extract32(env->pstate, 2, 2) == 3) { > + /* CPU currently in Aarch64 state and EL3 */ > + return true; > + } else if (!env->aarch64 && > + (env->uncached_cpsr & CPSR_M) == ARM_CPU_MODE_MON) { > + /* CPU currently in Aarch32 state and monitor mode */ > + return true; > + } > + } > + return arm_is_secure_below_el3(env); > +#else > + return false; > +#endif > +} > + > /* Return true if the specified exception level is running in AArch64 state. */ > static inline bool arm_el_is_aa64(CPUARMState *env, int el) > { > -- > 1.8.3.2 >