Skip to contentSkip to conversation

target/arm: Support EL0 v7m msr/mrs for CONFIG_USER_ONLY

PATCH In review Richard Henderson 2 participants 2 messages Nov 18, 2019 – Nov 19, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/arm: Support EL0 v7m msr/mrs for CONFIG_USER_ONLY

Simply moving the non-stub helper_v7m_mrs/msr outside of !CONFIG_USER_ONLY is not an option, because of all of the other system-mode helpers that are called.

But we can split out a few subroutines to handle the few EL0 accessible registers without duplicating code.

---
 target/arm/cpu.h      |   2 +
 target/arm/m_helper.c | 110 ++++++++++++++++++++++++++----------------
 2 files changed, 70 insertions(+), 42 deletions(-)
target/arm/cpu.h +2 -0
index e1a66a2d1c..81f5b5b75f 100644
@@ -1317,6 +1317,7 @@ static inline void xpsr_write(CPUARMState *env, uint32_t val, uint32_t mask)
     if (mask & XPSR_GE) {
         env->GE = (val & XPSR_GE) >> 16;
     }
+#ifndef CONFIG_USER_ONLY
     if (mask & XPSR_T) {
         env->thumb = ((val & XPSR_T) != 0);
     }
@@ -1332,6 +1333,7 @@ static inline void xpsr_write(CPUARMState *env, uint32_t val, uint32_t mask)
         /* Note that this only happens on exception exit */
         write_v7m_exception(env, val & XPSR_EXCP);
     }
+#endif
 }
 
 #define HCR_VM        (1ULL << 0)
target/arm/m_helper.c +68 -42

143 lines not on this page · raw message

Signature · 1 line
2.17.1
#1 lore raw
Quoted 8 lines · Richard Henderson

Simply moving the non-stub helper_v7m_mrs/msr outside of !CONFIG_USER_ONLY is not an option, because of all of the other system-mode helpers that are called.

But we can split out a few subroutines to handle the few EL0 accessible registers without duplicating code.

Quoted 8 lines
---
 target/arm/cpu.h      |   2 +
 target/arm/m_helper.c | 110 ++++++++++++++++++++++++++----------------
 2 files changed, 70 insertions(+), 42 deletions(-)

/* These should probably raise undefined insn exceptions. */

This comment is now wrong -- all the 'dummy version for user mode' helpers below it are either "known to never be called" or have a "works for user-mode" implementation, so we can just delete it.

Quoted 5 lines
target/arm/m_helper.c +2 -2
-void HELPER(v7m_msr)(CPUARMState *env, uint32_t reg, uint32_t val)
+void HELPER(v7m_msr)(CPUARMState *env, uint32_t maskreg, uint32_t val)
 {
-    ARMCPU *cpu = env_archcpu(env);
+    uint32_t mask = extract32(maskreg, 8, 4);

target/arm/m_helper.c line 95

Quoted 10 lines
target/arm/m_helper.c +8 -1
+    uint32_t reg = extract32(maskreg, 0, 8);
 
-    cpu_abort(CPU(cpu), "v7m_msr %d\n", reg);
+    switch (reg) {
+    case 0 ... 7: /* xPSR sub-fields */
+        v7m_msr_xpsr(env, mask, reg, val);
+        break;
+    case 20: /* CONTROL */
+        /* There are no sub-fields that are actually writable from EL0. */
+        break;

I feel like somebody's static analysis is probably going to complain if we don't have a default case here:
default:

        /* Writes to all other registers from EL0 are ignored */
        break;

Looks good otherwise, so I'll apply it to target-arm.next with those fixups.

thanks
-- PMM