[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 04/23] target-arm: Fix resetting issues on ARMv7-M CP
From: |
Peter Maydell |
Subject: |
[Qemu-devel] [PULL 04/23] target-arm: Fix resetting issues on ARMv7-M CPUs |
Date: |
Fri, 12 Sep 2014 14:23:35 +0100 |
From: Martin Galvan <address@hidden>
When calling qemu_system_reset after startup on a Cortex-M
CPU, the initial values of PC, MSP and the Thumb bit weren't being set
correctly if the vector table was in ROM. In particular, since Thumb was 0, a
Usage Fault would arise immediately after trying to execute any instruction
on a Cortex-M.
Signed-off-by: Martin Galvan <address@hidden>
Message-id: address@hidden
[PMM: removed an incorrect comment]
Reviewed-by: Peter Maydell <address@hidden>
Signed-off-by: Peter Maydell <address@hidden>
---
target-arm/cpu.c | 32 ++++++++++++++++++++++----------
1 file changed, 22 insertions(+), 10 deletions(-)
diff --git a/target-arm/cpu.c b/target-arm/cpu.c
index 8199f32..29f7162 100644
--- a/target-arm/cpu.c
+++ b/target-arm/cpu.c
@@ -129,22 +129,34 @@ static void arm_cpu_reset(CPUState *s)
env->uncached_cpsr = ARM_CPU_MODE_SVC;
env->daif = PSTATE_D | PSTATE_A | PSTATE_I | PSTATE_F;
/* On ARMv7-M the CPSR_I is the value of the PRIMASK register, and is
- clear at reset. Initial SP and PC are loaded from ROM. */
+ * clear at reset. Initial SP and PC are loaded from ROM.
+ */
if (IS_M(env)) {
- uint32_t pc;
+ uint32_t initial_msp; /* Loaded from 0x0 */
+ uint32_t initial_pc; /* Loaded from 0x4 */
uint8_t *rom;
+
env->daif &= ~PSTATE_I;
rom = rom_ptr(0);
if (rom) {
- /* We should really use ldl_phys here, in case the guest
- modified flash and reset itself. However images
- loaded via -kernel have not been copied yet, so load the
- values directly from there. */
- env->regs[13] = ldl_p(rom) & 0xFFFFFFFC;
- pc = ldl_p(rom + 4);
- env->thumb = pc & 1;
- env->regs[15] = pc & ~1;
+ /* Address zero is covered by ROM which hasn't yet been
+ * copied into physical memory.
+ */
+ initial_msp = ldl_p(rom);
+ initial_pc = ldl_p(rom + 4);
+ } else {
+ /* Address zero not covered by a ROM blob, or the ROM blob
+ * is in non-modifiable memory and this is a second reset after
+ * it got copied into memory. In the latter case, rom_ptr
+ * will return a NULL pointer and we should use ldl_phys instead.
+ */
+ initial_msp = ldl_phys(s->as, 0);
+ initial_pc = ldl_phys(s->as, 4);
}
+
+ env->regs[13] = initial_msp & 0xFFFFFFFC;
+ env->regs[15] = initial_pc & ~1;
+ env->thumb = initial_pc & 1;
}
if (env->cp15.c1_sys & SCTLR_V) {
--
1.9.1
- [Qemu-devel] [PULL 19/23] hw/arm/virt: fix pl011 and pl031 irq flags, (continued)
- [Qemu-devel] [PULL 19/23] hw/arm/virt: fix pl011 and pl031 irq flags, Peter Maydell, 2014/09/12
- [Qemu-devel] [PULL 05/23] target-arm: Fix broken indentation in arm_cpu_reest(), Peter Maydell, 2014/09/12
- [Qemu-devel] [PULL 07/23] exec.c: Relax restrictions on watchpoint length and alignment, Peter Maydell, 2014/09/12
- [Qemu-devel] [PULL 06/23] hw/arm/virt: Provide flash devices for boot ROMs, Peter Maydell, 2014/09/12
- [Qemu-devel] [PULL 12/23] target-arm: Move extended_addresses_enabled() to internals.h, Peter Maydell, 2014/09/12
- [Qemu-devel] [PULL 20/23] hw/arm/boot: load DTB as a ROM image, Peter Maydell, 2014/09/12
- [Qemu-devel] [PULL 01/23] hw/arm/virt: add linux, stdout-path to /chosen DT node, Peter Maydell, 2014/09/12
- [Qemu-devel] [PULL 08/23] exec.c: Provide full set of dummy wp remove functions in user-mode, Peter Maydell, 2014/09/12
- [Qemu-devel] [PULL 21/23] hw/arm/boot: pass an address limit to and return size from load_dtb(), Peter Maydell, 2014/09/12
- [Qemu-devel] [PULL 03/23] pl061: implement input interrupt logic, Peter Maydell, 2014/09/12
- [Qemu-devel] [PULL 04/23] target-arm: Fix resetting issues on ARMv7-M CPUs,
Peter Maydell <=
- [Qemu-devel] [PULL 13/23] target-arm: Implement handling of fired watchpoints, Peter Maydell, 2014/09/12
- [Qemu-devel] [PULL 22/23] hw/arm/boot: load device tree to base of DRAM if no -kernel option was passed, Peter Maydell, 2014/09/12
- [Qemu-devel] [PULL 02/23] cpu-exec.c: Allow disabling of IRQs on ARM Cortex-M CPUs, Peter Maydell, 2014/09/12
- Re: [Qemu-devel] [PULL 00/23] target-arm queue, Peter Maydell, 2014/09/12