From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38714) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YEgvQ-0005jn-0E for qemu-devel@nongnu.org; Fri, 23 Jan 2015 11:17:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YEgvK-00035Y-V5 for qemu-devel@nongnu.org; Fri, 23 Jan 2015 11:17:35 -0500 Received: from mail-pa0-f46.google.com ([209.85.220.46]:60384) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YEgvK-00035U-Pw for qemu-devel@nongnu.org; Fri, 23 Jan 2015 11:17:30 -0500 Received: by mail-pa0-f46.google.com with SMTP id lj1so4884907pab.5 for ; Fri, 23 Jan 2015 08:17:30 -0800 (PST) From: Greg Bellows Date: Fri, 23 Jan 2015 10:17:14 -0600 Message-Id: <1422029835-4696-4-git-send-email-greg.bellows@linaro.org> In-Reply-To: <1422029835-4696-1-git-send-email-greg.bellows@linaro.org> References: <1422029835-4696-1-git-send-email-greg.bellows@linaro.org> Subject: [Qemu-devel] [PATCH V2 3/4] target-arm: Change reset to highest available EL List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: Greg Bellows Update to arm_cpu_reset() to reset into the highest available exception level based on the set ARM features. Signed-off-by: Greg Bellows --- v1 -> v2 - Added Linux boot into secure EL1 - Added reset to EL2 if enabled - Removed extraneous SCR.NS reset - Fixed incorrect feature check --- hw/arm/boot.c | 22 ++++++++++++++++++++-- target-arm/cpu.c | 9 ++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/hw/arm/boot.c b/hw/arm/boot.c index 52ebd8b..a48d1b2 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -463,8 +463,26 @@ static void do_cpu_reset(void *opaque) * (SCR.NS = 0), we change that here if non-secure boot has been * requested. */ - if (arm_feature(env, ARM_FEATURE_EL3) && !info->secure_boot) { - env->cp15.scr_el3 |= SCR_NS; + if (arm_feature(env, ARM_FEATURE_EL3)) { + /* AArch64 is defined to come out of reset into EL3 if enabled. + * If we are booting Linux then we need to adjust our EL as + * Linux expects us to be in EL2 or EL1. AArch32 resets into + * SVC, which Linux expects, so no privilege/exception level to + * adjust. + */ + if (env->aarch64) { + if (arm_feature(env, ARM_FEATURE_EL2)) { + env->pstate = PSTATE_MODE_EL2h; + } else { + env->pstate = PSTATE_MODE_EL1h; + } + } + + /* Set to non-secure if not a secure boot */ + if (!info->secure_boot) { + /* Linux expects non-secure state */ + env->cp15.scr_el3 |= SCR_NS; + } } if (CPU(cpu) == first_cpu) { diff --git a/target-arm/cpu.c b/target-arm/cpu.c index 285947f..f43e2de 100644 --- a/target-arm/cpu.c +++ b/target-arm/cpu.c @@ -113,7 +113,14 @@ static void arm_cpu_reset(CPUState *s) /* and to the FP/Neon instructions */ env->cp15.c1_coproc = deposit64(env->cp15.c1_coproc, 20, 2, 3); #else - env->pstate = PSTATE_MODE_EL1h; + /* Reset into the highest available EL */ + if (arm_feature(env, ARM_FEATURE_EL3)) { + env->pstate = PSTATE_MODE_EL3h; + } else if (arm_feature(env, ARM_FEATURE_EL2)) { + env->pstate = PSTATE_MODE_EL2h; + } else { + env->pstate = PSTATE_MODE_EL1h; + } env->pc = cpu->rvbar; #endif } else { -- 1.8.3.2