From nobody Tue Nov 4 06:39:54 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1505241159859912.1403715570821; Tue, 12 Sep 2017 11:32:39 -0700 (PDT) Received: from localhost ([::1]:38046 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drpzD-0005Nl-0b for importer@patchew.org; Tue, 12 Sep 2017 14:32:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43595) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drph6-0003Xk-R8 for qemu-devel@nongnu.org; Tue, 12 Sep 2017 14:13:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1drph5-0006VV-TH for qemu-devel@nongnu.org; Tue, 12 Sep 2017 14:13:56 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:37316) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1drph2-0006QF-5A; Tue, 12 Sep 2017 14:13:52 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1drpgz-00019p-Lp; Tue, 12 Sep 2017 19:13:49 +0100 From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Date: Tue, 12 Sep 2017 19:14:02 +0100 Message-Id: <1505240046-11454-16-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1505240046-11454-1-git-send-email-peter.maydell@linaro.org> References: <1505240046-11454-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] [PATCH 15/19] nvic: Handle v8M changes in nvic_exec_prio() 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: , Cc: patches@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Update nvic_exec_prio() to support the v8M changes: * BASEPRI, FAULTMASK and PRIMASK are all banked * AIRCR.PRIS can affect NS priorities * AIRCR.BFHFNMINS affects FAULTMASK behaviour These changes mean that it's no longer possible to definitely say that if FAULTMASK is set it overrides PRIMASK, and if PRIMASK is set it overrides BASEPRI (since if PRIMASK_NS is set and AIRCR.PRIS is set then whether that 0x80 priority should take effect or the priority in BASEPRI_S depends on the value of BASEPRI_S, for instance). So we switch to the same approach used by the pseudocode of working through BASEPRI, PRIMASK and FAULTMASK and overriding the previous values if needed. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson --- hw/intc/armv7m_nvic.c | 51 ++++++++++++++++++++++++++++++++++++++++++-----= ---- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c index 91d2f33..b13327d 100644 --- a/hw/intc/armv7m_nvic.c +++ b/hw/intc/armv7m_nvic.c @@ -319,18 +319,51 @@ static void nvic_recompute_state(NVICState *s) static inline int nvic_exec_prio(NVICState *s) { CPUARMState *env =3D &s->cpu->env; - int running; + int running =3D NVIC_NOEXC_PRIO; =20 - if (env->v7m.faultmask[env->v7m.secure]) { - running =3D -1; - } else if (env->v7m.primask[env->v7m.secure]) { + if (env->v7m.basepri[M_REG_NS] > 0) { + running =3D exc_group_prio(s, env->v7m.basepri[M_REG_NS], M_REG_NS= ); + } + + if (env->v7m.basepri[M_REG_S] > 0) { + int basepri =3D exc_group_prio(s, env->v7m.basepri[M_REG_S], M_REG= _S); + if (running > basepri) { + running =3D basepri; + } + } + + if (env->v7m.primask[M_REG_NS]) { + if (env->v7m.aircr & R_V7M_AIRCR_PRIS_MASK) { + if (running > NVIC_NS_PRIO_LIMIT) { + running =3D NVIC_NS_PRIO_LIMIT; + } + } else { + running =3D 0; + } + } + + if (env->v7m.primask[M_REG_S]) { running =3D 0; - } else if (env->v7m.basepri[env->v7m.secure] > 0) { - running =3D env->v7m.basepri[env->v7m.secure] & - nvic_gprio_mask(s, env->v7m.secure); - } else { - running =3D NVIC_NOEXC_PRIO; /* lower than any possible priority */ } + + if (env->v7m.faultmask[M_REG_NS]) { + if (env->v7m.aircr & R_V7M_AIRCR_BFHFNMINS_MASK) { + running =3D -1; + } else { + if (env->v7m.aircr & R_V7M_AIRCR_PRIS_MASK) { + if (running > NVIC_NS_PRIO_LIMIT) { + running =3D NVIC_NS_PRIO_LIMIT; + } + } else { + running =3D 0; + } + } + } + + if (env->v7m.faultmask[M_REG_S]) { + running =3D (env->v7m.aircr & R_V7M_AIRCR_BFHFNMINS_MASK) ? -3 : -= 1; + } + /* consider priority of active handler */ return MIN(running, s->exception_prio); } --=20 2.7.4