From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 01/31] target/arm: Implement MSR/MRS access to NS banked registers
Date: Thu, 21 Sep 2017 17:41:09 +0100 [thread overview]
Message-ID: <1506012099-13605-2-git-send-email-peter.maydell@linaro.org> (raw)
In-Reply-To: <1506012099-13605-1-git-send-email-peter.maydell@linaro.org>
In v8M the MSR and MRS instructions have extra register value
encodings to allow secure code to access the non-secure banked
version of various special registers.
(We don't implement the MSPLIM_NS or PSPLIM_NS aliases, because
we don't currently implement the stack limit registers at all.)
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-id: 1505240046-11454-2-git-send-email-peter.maydell@linaro.org
---
target/arm/helper.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 110 insertions(+)
diff --git a/target/arm/helper.c b/target/arm/helper.c
index 4f41841..f4f2a87 100644
--- a/target/arm/helper.c
+++ b/target/arm/helper.c
@@ -8892,12 +8892,68 @@ uint32_t HELPER(v7m_mrs)(CPUARMState *env, uint32_t reg)
break;
case 20: /* CONTROL */
return env->v7m.control[env->v7m.secure];
+ case 0x94: /* CONTROL_NS */
+ /* We have to handle this here because unprivileged Secure code
+ * can read the NS CONTROL register.
+ */
+ if (!env->v7m.secure) {
+ return 0;
+ }
+ return env->v7m.control[M_REG_NS];
}
if (el == 0) {
return 0; /* unprivileged reads others as zero */
}
+ if (arm_feature(env, ARM_FEATURE_M_SECURITY)) {
+ switch (reg) {
+ case 0x88: /* MSP_NS */
+ if (!env->v7m.secure) {
+ return 0;
+ }
+ return env->v7m.other_ss_msp;
+ case 0x89: /* PSP_NS */
+ if (!env->v7m.secure) {
+ return 0;
+ }
+ return env->v7m.other_ss_psp;
+ case 0x90: /* PRIMASK_NS */
+ if (!env->v7m.secure) {
+ return 0;
+ }
+ return env->v7m.primask[M_REG_NS];
+ case 0x91: /* BASEPRI_NS */
+ if (!env->v7m.secure) {
+ return 0;
+ }
+ return env->v7m.basepri[M_REG_NS];
+ case 0x93: /* FAULTMASK_NS */
+ if (!env->v7m.secure) {
+ return 0;
+ }
+ return env->v7m.faultmask[M_REG_NS];
+ case 0x98: /* SP_NS */
+ {
+ /* This gives the non-secure SP selected based on whether we're
+ * currently in handler mode or not, using the NS CONTROL.SPSEL.
+ */
+ bool spsel = env->v7m.control[M_REG_NS] & R_V7M_CONTROL_SPSEL_MASK;
+
+ if (!env->v7m.secure) {
+ return 0;
+ }
+ if (!arm_v7m_is_handler_mode(env) && spsel) {
+ return env->v7m.other_ss_psp;
+ } else {
+ return env->v7m.other_ss_msp;
+ }
+ }
+ default:
+ break;
+ }
+ }
+
switch (reg) {
case 8: /* MSP */
return (env->v7m.control[env->v7m.secure] & R_V7M_CONTROL_SPSEL_MASK) ?
@@ -8936,6 +8992,60 @@ void HELPER(v7m_msr)(CPUARMState *env, uint32_t maskreg, uint32_t val)
return;
}
+ if (arm_feature(env, ARM_FEATURE_M_SECURITY)) {
+ switch (reg) {
+ case 0x88: /* MSP_NS */
+ if (!env->v7m.secure) {
+ return;
+ }
+ env->v7m.other_ss_msp = val;
+ return;
+ case 0x89: /* PSP_NS */
+ if (!env->v7m.secure) {
+ return;
+ }
+ env->v7m.other_ss_psp = val;
+ return;
+ case 0x90: /* PRIMASK_NS */
+ if (!env->v7m.secure) {
+ return;
+ }
+ env->v7m.primask[M_REG_NS] = val & 1;
+ return;
+ case 0x91: /* BASEPRI_NS */
+ if (!env->v7m.secure) {
+ return;
+ }
+ env->v7m.basepri[M_REG_NS] = val & 0xff;
+ return;
+ case 0x93: /* FAULTMASK_NS */
+ if (!env->v7m.secure) {
+ return;
+ }
+ env->v7m.faultmask[M_REG_NS] = val & 1;
+ return;
+ case 0x98: /* SP_NS */
+ {
+ /* This gives the non-secure SP selected based on whether we're
+ * currently in handler mode or not, using the NS CONTROL.SPSEL.
+ */
+ bool spsel = env->v7m.control[M_REG_NS] & R_V7M_CONTROL_SPSEL_MASK;
+
+ if (!env->v7m.secure) {
+ return;
+ }
+ if (!arm_v7m_is_handler_mode(env) && spsel) {
+ env->v7m.other_ss_psp = val;
+ } else {
+ env->v7m.other_ss_msp = val;
+ }
+ return;
+ }
+ default:
+ break;
+ }
+ }
+
switch (reg) {
case 0 ... 7: /* xPSR sub-fields */
/* only APSR is actually writable */
--
2.7.4
next prev parent reply other threads:[~2017-09-21 16:41 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-21 16:41 [Qemu-devel] [PULL 00/31] target-arm queue Peter Maydell
2017-09-21 16:41 ` Peter Maydell [this message]
2017-09-21 16:41 ` [Qemu-devel] [PULL 02/31] nvic: Add banked exception states Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 03/31] nvic: Add cached vectpending_is_s_banked state Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 04/31] nvic: Add cached vectpending_prio state Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 05/31] nvic: Implement AIRCR changes for v8M Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 06/31] nvic: Make ICSR.RETTOBASE handle banked exceptions Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 07/31] nvic: Implement NVIC_ITNS<n> registers Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 08/31] nvic: Handle banked exceptions in nvic_recompute_state() Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 09/31] nvic: Make set_pending and clear_pending take a secure parameter Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 10/31] nvic: Make SHPR registers banked Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 11/31] nvic: Compare group priority for escalation to HF Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 12/31] nvic: In escalation to HardFault, support HF not being priority -1 Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 13/31] nvic: Implement v8M changes to fixed priority exceptions Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 14/31] nvic: Disable the non-secure HardFault if AIRCR.BFHFNMINS is clear Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 15/31] nvic: Handle v8M changes in nvic_exec_prio() Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 16/31] target/arm: Handle banking in negative-execution-priority check in cpu_mmu_index() Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 17/31] nvic: Make ICSR banked for v8M Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 18/31] nvic: Make SHCSR " Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 19/31] nvic: Support banked exceptions in acknowledge and complete Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 20/31] target/arm: Remove out of date ARM ARM section references in A64 decoder Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 21/31] hw/arm/palm.c: Don't use old_mmio for static_ops Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 22/31] hw/gpio/omap_gpio.c: Don't use old_mmio Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 23/31] hw/timer/omap_synctimer.c: " Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 24/31] hw/timer/omap_gptimer: " Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 25/31] hw/i2c/omap_i2c.c: " Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 26/31] hw/arm/omap2.c: " Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 27/31] msf2: Add Smartfusion2 System timer Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 28/31] msf2: Microsemi Smartfusion2 System Register block Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 29/31] msf2: Add Smartfusion2 SPI controller Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 30/31] msf2: Add Smartfusion2 SoC Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 31/31] msf2: Add Emcraft's Smartfusion2 SOM kit Peter Maydell
2017-09-21 17:28 ` [Qemu-devel] [PULL 00/31] target-arm queue Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1506012099-13605-2-git-send-email-peter.maydell@linaro.org \
--to=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).