Skip to contentSkip to conversation

target-arm queue

GIT PULL New Peter Maydell 2 participants 5 messages Jan 5, 2012 – Jan 7, 2012

lore
Share & tools
lore
#0 lore raw

Pending target-arm patches; not very many, but seems better to commit them now, since there might be further trustzone related patches that would have to sit on top of these. Please pull.

The following changes since commit c47f3223658119219bbe0b8d09da733d1c06e76f:

Merge remote-tracking branch 'pmaydell/arm-devs.for-upstream' into staging (2012-01-04 10:06:25 -0600)

are available in the git repository at:

git://git.linaro.org/people/pmaydell/qemu-arm.git target-arm.for-upstream

Mark Langsdorf (1):
arm: add dummy A9-specific cp15 registers

Peter Maydell (2):
target-arm: Don't use cpu_single_env in bank_number()
target-arm: Ignore attempts to set invalid modes in CPSR

 target-arm/cpu.h     |    6 +++-
 target-arm/helper.c  |   90 ++++++++++++++++++++++++++++++++++++++++++++++----
 target-arm/machine.c |    6 +++
 3 files changed, 94 insertions(+), 8 deletions(-)
#1 lore raw

PATCH 1/3 target-arm: Don't use cpu_single_env in bank_number()

Avoid using cpu_single_env in bank_number() -- if we were called via the gdb stub reading or writing the CPSR then it is NULL and we will segfault if we take the cpu_abort().

---
 target-arm/helper.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
target-arm/helper.c +6 -6
index 65f4fbf..5b994d5 100644
@@ -642,7 +642,7 @@ uint32_t HELPER(get_r13_banked)(CPUState *env, uint32_t mode)
 extern int semihosting_enabled;
 
 /* Map CPU modes onto saved register banks.  */
-static inline int bank_number (int mode)
+static inline int bank_number(CPUState *env, int mode)
 {
     switch (mode) {
     case ARM_CPU_MODE_USR:
@@ -659,7 +659,7 @@ static inline int bank_number (int mode)
     case ARM_CPU_MODE_FIQ:
         return 5;
     }
-    cpu_abort(cpu_single_env, "Bad mode %x\n", mode);
+    cpu_abort(env, "Bad mode %x\n", mode);
     return -1;
 }
 
@@ -680,12 +680,12 @@ void switch_mode(CPUState *env, int mode)
         memcpy (env->regs + 8, env->fiq_regs, 5 * sizeof(uint32_t));
     }
 
-    i = bank_number(old_mode);
+    i = bank_number(env, old_mode);
     env->banked_r13[i] = env->regs[13];
     env->banked_r14[i] = env->regs[14];
     env->banked_spsr[i] = env->spsr;
 
-    i = bank_number(mode);
+    i = bank_number(env, mode);
     env->regs[13] = env->banked_r13[i];
     env->regs[14] = env->banked_r14[i];
     env->spsr = env->banked_spsr[i];
@@ -2125,7 +2125,7 @@ void HELPER(set_r13_banked)(CPUState *env, uint32_t mode, uint32_t val)
     if ((env->uncached_cpsr & CPSR_M) == mode) {
         env->regs[13] = val;
     } else {
-        env->banked_r13[bank_number(mode)] = val;
+        env->banked_r13[bank_number(env, mode)] = val;
     }
 }
 
@@ -2134,7 +2134,7 @@ uint32_t HELPER(get_r13_banked)(CPUState *env, uint32_t mode)
     if ((env->uncached_cpsr & CPSR_M) == mode) {
         return env->regs[13];
     } else {
-        return env->banked_r13[bank_number(mode)];
+        return env->banked_r13[bank_number(env, mode)];
     }
 }
 
Signature · 1 line
1.7.1
#2 lore raw

PATCH 2/3 target-arm: Ignore attempts to set invalid modes in CPSR

In reply to Peter Maydell

Ignore attempts to set the CPSR mode field to an invalid value. This is UNPREDICTABLE, but we should not cpu_abort() for things a malicious guest (or a confused user on the gdbstub interface) can provoke.

---
 target-arm/helper.c |   30 +++++++++++++++++++++++++++++-
 1 files changed, 29 insertions(+), 1 deletions(-)
target-arm/helper.c +29 -1
index 5b994d5..261d547 100644
@@ -463,6 +463,26 @@ void cpu_arm_close(CPUARMState *env)
     g_free(env);
 }
 
+static int bad_mode_switch(CPUState *env, int mode)
+{
+    /* Return true if it is not valid for us to switch to
+     * this CPU mode (ie all the UNPREDICTABLE cases in
+     * the ARM ARM CPSRWriteByInstr pseudocode).
+     */
+    switch (mode) {
+    case ARM_CPU_MODE_USR:
+    case ARM_CPU_MODE_SYS:
+    case ARM_CPU_MODE_SVC:
+    case ARM_CPU_MODE_ABT:
+    case ARM_CPU_MODE_UND:
+    case ARM_CPU_MODE_IRQ:
+    case ARM_CPU_MODE_FIQ:
+        return 0;
+    default:
+        return 1;
+    }
+}
+
 uint32_t cpsr_read(CPUARMState *env)
 {
     int ZF;
@@ -499,7 +519,15 @@ void cpsr_write(CPUARMState *env, uint32_t val, uint32_t mask)
     }
 
     if ((env->uncached_cpsr ^ val) & mask & CPSR_M) {
-        switch_mode(env, val & CPSR_M);
+        if (bad_mode_switch(env, val & CPSR_M)) {
+            /* Attempt to switch to an invalid mode: this is UNPREDICTABLE.
+             * We choose to ignore the attempt and leave the CPSR M field
+             * untouched.
+             */
+            mask &= ~CPSR_M;
+        } else {
+            switch_mode(env, val & CPSR_M);
+        }
     }
     mask &= ~CACHED_CPSR_BITS;
     env->uncached_cpsr = (env->uncached_cpsr & ~mask) | (val & mask);
Signature · 1 line
1.7.1
#3 lore raw

PATCH 3/3 arm: add dummy A9-specific cp15 registers

In reply to Peter Maydell

From: Mark Langsdorf <[email protected]>

Add dummy register support for the cp15, CRn=c15 registers.

config_base_register and power_control_register currently default to 0, but may have improved support after the QOM CPU patches are finished.

---
 target-arm/cpu.h     |    6 +++++-
 target-arm/helper.c  |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 target-arm/machine.c |    6 ++++++
 3 files changed, 59 insertions(+), 1 deletions(-)
target-arm/cpu.h +5 -1
index c4d742f..26b4981 100644
@@ -149,6 +149,10 @@ typedef struct CPUARMState {
         uint32_t c15_i_max; /* Maximum D-cache dirty line index.  */
         uint32_t c15_i_min; /* Minimum D-cache dirty line index.  */
         uint32_t c15_threadid; /* TI debugger thread-ID.  */
+        uint32_t c15_config_base_address; /* SCU base address.  */
+        uint32_t c15_diagnostic; /* diagnostic register */
+        uint32_t c15_power_diagnostic;
+        uint32_t c15_power_control; /* power control */
     } cp15;
 
     struct {
@@ -448,7 +452,7 @@ void cpu_arm_set_cp_io(CPUARMState *env, int cpnum,
 #define cpu_signal_handler cpu_arm_signal_handler
 #define cpu_list arm_cpu_list
 
-#define CPU_SAVE_VERSION 4
+#define CPU_SAVE_VERSION 5
 
 /* MMU modes definitions */
 #define MMU_MODE0_SUFFIX _kernel
target-arm/helper.c +48 -0

60 lines not on this page · raw message

target-arm/machine.c +6 -0
index aaee9b9..8984775 100644
@@ -56,6 +56,9 @@ void cpu_save(QEMUFile *f, void *opaque)
     qemu_put_be32(f, env->cp15.c13_tls2);
     qemu_put_be32(f, env->cp15.c13_tls3);
     qemu_put_be32(f, env->cp15.c15_cpar);
+    qemu_put_be32(f, env->cp15.c15_power_control);
+    qemu_put_be32(f, env->cp15.c15_diagnostic);
+    qemu_put_be32(f, env->cp15.c15_power_diagnostic);
 
     qemu_put_be32(f, env->features);
 
@@ -170,6 +173,9 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id)
     env->cp15.c13_tls2 = qemu_get_be32(f);
     env->cp15.c13_tls3 = qemu_get_be32(f);
     env->cp15.c15_cpar = qemu_get_be32(f);
+    env->cp15.c15_power_control = qemu_get_be32(f);
+    env->cp15.c15_diagnostic = qemu_get_be32(f);
+    env->cp15.c15_power_diagnostic = qemu_get_be32(f);
 
     env->features = qemu_get_be32(f);
 
Signature · 1 line
1.7.1
#4 lore raw
In reply to Peter Maydell
Quoted 15 lines · Peter Maydell

Pending target-arm patches; not very many, but seems better to commit them now, since there might be further trustzone related patches that would have to sit on top of these. Please pull.

The following changes since commit c47f3223658119219bbe0b8d09da733d1c06e76f:

Merge remote-tracking branch 'pmaydell/arm-devs.for-upstream' into staging (2012-01-04 10:06:25 -0600)

are available in the git repository at:

git://git.linaro.org/people/pmaydell/qemu-arm.git target-arm.for-upstream

Mark Langsdorf (1):
arm: add dummy A9-specific cp15 registers

Quoted 10 lines

Peter Maydell (2):
target-arm: Don't use cpu_single_env in bank_number()
target-arm: Ignore attempts to set invalid modes in CPSR

 target-arm/cpu.h     |    6 +++-
 target-arm/helper.c  |   90 ++++++++++++++++++++++++++++++++++++++++++++++----
 target-arm/machine.c |    6 +++
 3 files changed, 94 insertions(+), 8 deletions(-)

Thanks, pulled.

Signature · 2 lines
Aurelien Jarno	                        GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net