From patchwork Fri Oct 6 15:59:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 115083 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp1984198qgn; Fri, 6 Oct 2017 09:29:28 -0700 (PDT) X-Google-Smtp-Source: AOwi7QCO5FNtPASETHt94Rs29/c9JqWtM9OyxnOPA/uTVNL8XAXfvw2Q2xxTEComZrP6SJeb/lmJ X-Received: by 10.55.176.132 with SMTP id z126mr30575195qke.133.1507307368362; Fri, 06 Oct 2017 09:29:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507307368; cv=none; d=google.com; s=arc-20160816; b=Me0LttYBPSDMsFpIXv/c+tvoX1eBZvDz5eIBP3OlY0Am1c7yhIEX5Gr39nktlZk5Og j2VdfTQpq1heu2m1GOTExbbQPtFGSYcnwZTMFoWMQpFm9hVwtIlehFiwuvI4zSQHiWVQ 8OCoGM9o9IagOVG/O/5mD2Y5zyz0pmr1TwsWrAwWAootVt2tUKUypLLVlJLvpzqnMGle /tBJ9cYDG8WuRhDenq509JHdjZqi52bYQRM2aFBLedv4LyL2wn+/xLG90bQntm2Cfmxk 21YqzHzeTTYAXIDrlshmAZ/Bfl5U6G7oJWjr7KhLE4EOoLlT+dW5HVR/9wmrBjvH0Bj6 r2jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:arc-authentication-results; bh=04Y4RGUOjFI/6oHl4yK/zYWTa2ZhfvBMzX1sPOCjCKw=; b=Z2AHvltIOXuiPO4ihT0FfxnaeNBIfJZBVOUH0vXIyyJknjVFduKBM2I7Fz2xBD3H6k fM0jxMc1i/waI3FsvVTYWPCm2KMz0dtPoZHjDxcpfU6a9Sh+N8oE0cVD67hGyuMLMUkm KkjDFo2iDH6Q9fuXPUzI8Hrs2zYC/UcL3tk/aM+4cKfpugJHkOqOOHt38srhAlPsEe3g Pj+ABNGXdZqzHiDQ4pM8UU/uHtFeDGti0IdG1o+dIBLBatUiK5un/GS8bxZ+JhuuQFlY wQ6P2tBQ1p2tK/uxqExxExwf1qd8N7fQOgE9DhsD4acFl3eBLffySjWw4DK18MyVSFUu s8JA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 208.118.235.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. [208.118.235.17]) by mx.google.com with ESMTPS id 12si1519328qkf.383.2017.10.06.09.29.28 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 06 Oct 2017 09:29:28 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 208.118.235.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 ([::1]:45791 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e0VV9-0005bs-SY for patch@linaro.org; Fri, 06 Oct 2017 12:29:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58143) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e0V1m-0004F6-IP for qemu-devel@nongnu.org; Fri, 06 Oct 2017 11:59:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e0V1k-0007p2-8S for qemu-devel@nongnu.org; Fri, 06 Oct 2017 11:59:06 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:37714) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e0V1j-0007js-VZ for qemu-devel@nongnu.org; Fri, 06 Oct 2017 11:59:04 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1e0V1c-0002uS-DR for qemu-devel@nongnu.org; Fri, 06 Oct 2017 16:58:56 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 6 Oct 2017 16:59:33 +0100 Message-Id: <1507305585-20608-9-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1507305585-20608-1-git-send-email-peter.maydell@linaro.org> References: <1507305585-20608-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PULL 08/20] target/arm: Restore SPSEL to correct CONTROL register on exception return 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" On exception return for v8M, the SPSEL bit in the EXC_RETURN magic value should be restored to the SPSEL bit in the CONTROL register banked specified by the EXC_RETURN.ES bit. Add write_v7m_control_spsel_for_secstate() which behaves like write_v7m_control_spsel() but allows the caller to specify which CONTROL bank to use, reimplement write_v7m_control_spsel() in terms of it, and use it in exception return. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-id: 1506092407-26985-6-git-send-email-peter.maydell@linaro.org --- target/arm/helper.c | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) -- 2.7.4 diff --git a/target/arm/helper.c b/target/arm/helper.c index b82fc9f..1bab86c 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -6059,28 +6059,42 @@ static bool v7m_using_psp(CPUARMState *env) env->v7m.control[env->v7m.secure] & R_V7M_CONTROL_SPSEL_MASK; } -/* Write to v7M CONTROL.SPSEL bit. This may change the current - * stack pointer between Main and Process stack pointers. +/* Write to v7M CONTROL.SPSEL bit for the specified security bank. + * This may change the current stack pointer between Main and Process + * stack pointers if it is done for the CONTROL register for the current + * security state. */ -static void write_v7m_control_spsel(CPUARMState *env, bool new_spsel) +static void write_v7m_control_spsel_for_secstate(CPUARMState *env, + bool new_spsel, + bool secstate) { - uint32_t tmp; - bool new_is_psp, old_is_psp = v7m_using_psp(env); + bool old_is_psp = v7m_using_psp(env); - env->v7m.control[env->v7m.secure] = - deposit32(env->v7m.control[env->v7m.secure], + env->v7m.control[secstate] = + deposit32(env->v7m.control[secstate], R_V7M_CONTROL_SPSEL_SHIFT, R_V7M_CONTROL_SPSEL_LENGTH, new_spsel); - new_is_psp = v7m_using_psp(env); + if (secstate == env->v7m.secure) { + bool new_is_psp = v7m_using_psp(env); + uint32_t tmp; - if (old_is_psp != new_is_psp) { - tmp = env->v7m.other_sp; - env->v7m.other_sp = env->regs[13]; - env->regs[13] = tmp; + if (old_is_psp != new_is_psp) { + tmp = env->v7m.other_sp; + env->v7m.other_sp = env->regs[13]; + env->regs[13] = tmp; + } } } +/* Write to v7M CONTROL.SPSEL bit. This may change the current + * stack pointer between Main and Process stack pointers. + */ +static void write_v7m_control_spsel(CPUARMState *env, bool new_spsel) +{ + write_v7m_control_spsel_for_secstate(env, new_spsel, env->v7m.secure); +} + void write_v7m_exception(CPUARMState *env, uint32_t new_exc) { /* Write a new value to v7m.exception, thus transitioning into or out @@ -6379,7 +6393,7 @@ static void do_v7m_exception_exit(ARMCPU *cpu) * Handler mode (and will be until we write the new XPSR.Interrupt * field) this does not switch around the current stack pointer. */ - write_v7m_control_spsel(env, return_to_sp_process); + write_v7m_control_spsel_for_secstate(env, return_to_sp_process, exc_secure); switch_v7m_security_state(env, return_to_secure);