From patchwork Thu Sep 7 13:28:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 111915 Delivered-To: patch@linaro.org Received: by 10.140.94.239 with SMTP id g102csp93457qge; Thu, 7 Sep 2017 06:28:45 -0700 (PDT) X-Google-Smtp-Source: ADKCNb63YlM6nwt0lk7vvubB9LqU8bqbLWVrrVsWPvCQrJINMbmJBoXSi7nDtiYDooG386fp8+bn X-Received: by 10.55.97.208 with SMTP id v199mr3466576qkb.165.1504790925407; Thu, 07 Sep 2017 06:28:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504790925; cv=none; d=google.com; s=arc-20160816; b=v2TaBYS4f7FZciiQ13qDQK2LvFBdVtia8lUxjzc1x90B8Q0egxkTAk+5JPFEqdzYmb NNCtnRitHNmOluwvZxbjOjK233Kdtf/+GJ+oe3bjPNsKGEKtb0fnhltA47AG3ek2u5bf dF852W/SU5gGZDxVaRUsamcOBok1dvr07U6jZ8vHX0AbhADtBGzV4Sehkir1r2WLU4Cb eSQ1IBRdAIvGVLUBdmbyRFS0EyoTLxqQt40tQJJPKdgM8OcumxITiOvR/d6LYHrE+PyX hv0EnYr3ctmiv3wzJLNYs+dQhJsLJbTWD7aKD1ElgIbLmG8imGTonWGrEsEObfZg3txs 80Zg== 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=fU790eCLUu+TPkShPCeSi9PARCbOfoDz6l7SRNPdoBM=; b=r4xbrx5Fpmo61o5qETZyS8//gOrLsCEt8KT1BllAUnQOeQ1KdodfrDZ3xuIq+VV0dz vibbtIvwraNEbKlWtJrFaXPgnmE7H74TX8oQEPN27l12z/1mBLA8Bmr/pmvY0DLx+j8U GyGkdaGh5XAHkn+MntNUxrvMqbIdjxeE2Pd4+J4T0B0/EPu+nICO4ZrIrIKNJzmSvCwi 9oNXuVd6ELF0Csdik3+etdcfQxZlE9CFsKAOO5pwMr/aivyH754f+spHt9WeLr71LYn5 WPBoceJEnOA/ycPv0/Vs4l7Tr0Ydfp2otlrb/V6vA1jOhycT4X5VsvC8AC2a+S0J6eiu 0Hew== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id s199si2836211qke.10.2017.09.07.06.28.45 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 07 Sep 2017 06:28:45 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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]:40494 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dpwrL-00010W-8M for patch@linaro.org; Thu, 07 Sep 2017 09:28:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56327) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dpwqx-0000zP-Tr for qemu-devel@nongnu.org; Thu, 07 Sep 2017 09:28:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dpwqs-0007aK-Rx for qemu-devel@nongnu.org; Thu, 07 Sep 2017 09:28:19 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:37186) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dpwqs-0007Xf-JK for qemu-devel@nongnu.org; Thu, 07 Sep 2017 09:28:14 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1dpwqr-0001az-6v for qemu-devel@nongnu.org; Thu, 07 Sep 2017 14:28:13 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 7 Sep 2017 14:28:07 +0100 Message-Id: <1504790904-17018-15-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504790904-17018-1-git-send-email-peter.maydell@linaro.org> References: <1504790904-17018-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 14/31] target/arm: Make PRIMASK register banked for v8M 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" Make the PRIMASK register banked if v8M security extensions are enabled. Note that we do not yet implement the functionality of the new AIRCR.PRIS bit (which allows the effect of the NS copy of PRIMASK to be restricted). Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-id: 1503414539-28762-8-git-send-email-peter.maydell@linaro.org --- target/arm/cpu.h | 2 +- hw/intc/armv7m_nvic.c | 2 +- target/arm/helper.c | 4 ++-- target/arm/machine.c | 9 +++++++-- 4 files changed, 11 insertions(+), 6 deletions(-) -- 2.7.4 diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 273abc3..26ec744 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -431,7 +431,7 @@ typedef struct CPUARMState { uint32_t bfar; /* BusFault Address */ unsigned mpu_ctrl; /* MPU_CTRL */ int exception; - uint32_t primask; + uint32_t primask[2]; uint32_t faultmask; uint32_t secure; /* Is CPU in Secure state? (not guest visible) */ } v7m; diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c index 2a41e5d..a654792 100644 --- a/hw/intc/armv7m_nvic.c +++ b/hw/intc/armv7m_nvic.c @@ -169,7 +169,7 @@ static inline int nvic_exec_prio(NVICState *s) if (env->v7m.faultmask) { running = -1; - } else if (env->v7m.primask) { + } else if (env->v7m.primask[env->v7m.secure]) { running = 0; } else if (env->v7m.basepri[env->v7m.secure] > 0) { running = env->v7m.basepri[env->v7m.secure] & nvic_gprio_mask(s); diff --git a/target/arm/helper.c b/target/arm/helper.c index 7007266..9a7ab96 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -8830,7 +8830,7 @@ uint32_t HELPER(v7m_mrs)(CPUARMState *env, uint32_t reg) return (env->v7m.control & R_V7M_CONTROL_SPSEL_MASK) ? env->regs[13] : env->v7m.other_sp; case 16: /* PRIMASK */ - return env->v7m.primask; + return env->v7m.primask[env->v7m.secure]; case 17: /* BASEPRI */ case 18: /* BASEPRI_MAX */ return env->v7m.basepri[env->v7m.secure]; @@ -8890,7 +8890,7 @@ void HELPER(v7m_msr)(CPUARMState *env, uint32_t maskreg, uint32_t val) } break; case 16: /* PRIMASK */ - env->v7m.primask = val & 1; + env->v7m.primask[env->v7m.secure] = val & 1; break; case 17: /* BASEPRI */ env->v7m.basepri[env->v7m.secure] = val & 0xff; diff --git a/target/arm/machine.c b/target/arm/machine.c index dbb432d..3c42bf5 100644 --- a/target/arm/machine.c +++ b/target/arm/machine.c @@ -103,7 +103,7 @@ static const VMStateDescription vmstate_m_faultmask_primask = { .minimum_version_id = 1, .fields = (VMStateField[]) { VMSTATE_UINT32(env.v7m.faultmask, ARMCPU), - VMSTATE_UINT32(env.v7m.primask, ARMCPU), + VMSTATE_UINT32(env.v7m.primask[M_REG_NS], ARMCPU), VMSTATE_END_OF_LIST() } }; @@ -251,6 +251,7 @@ static const VMStateDescription vmstate_m_security = { .fields = (VMStateField[]) { VMSTATE_UINT32(env.v7m.secure, ARMCPU), VMSTATE_UINT32(env.v7m.basepri[M_REG_S], ARMCPU), + VMSTATE_UINT32(env.v7m.primask[M_REG_S], ARMCPU), VMSTATE_END_OF_LIST() } }; @@ -271,9 +272,13 @@ static int get_cpsr(QEMUFile *f, void *opaque, size_t size, * differences are that the T bit is not in the same place, the * primask/faultmask info may be in the CPSR I and F bits, and * we do not want the mode bits. + * We know that this cleanup happened before v8M, so there + * is no complication with banked primask/faultmask. */ uint32_t newval = val; + assert(!arm_feature(env, ARM_FEATURE_M_SECURITY)); + newval &= (CPSR_NZCV | CPSR_Q | CPSR_IT | CPSR_GE); if (val & CPSR_T) { newval |= XPSR_T; @@ -287,7 +292,7 @@ static int get_cpsr(QEMUFile *f, void *opaque, size_t size, env->v7m.faultmask = 1; } if (val & CPSR_I) { - env->v7m.primask = 1; + env->v7m.primask[M_REG_NS] = 1; } val = newval; }