Skip to contentSkip to conversation

Cortex m3 initialisation

Qemu-devel Benjamin Bagland 2 participants 2 messages Mar 14, 2010 – Apr 22, 2010

lore
Share & tools
lore
#0 lore raw

Hi,

I'm having an issue while trying to use the lm3s811 board emulation with qemu 0.12.3 or git. It works fine however with qemu-0.11.1.

The problem comes from hw/armv7m.c, around line 231, the initial PC and SP are set by reading from physical memory, however the rom data is not copied in physical memory until the reset later on in the initialisation (comes from commit 45a50b1668822c23afc I think). Since the initial PC is invalid, the cpu goes straight into UsageFault instead of going to the proper reset routine.

I've made a small patch to read from rom instead of physical memory, that fixes the issue with my test program but I'm not sure if it's the proper thing to do, or even if it works with other arm boards.

Rgds,
Benjamin

hw/armv7m.c +4 -2
index 034323d..674a8b4 100644
@@ -231,8 +231,10 @@ qemu_irq *armv7m_init(int flash_size, int sram_size,
        regular ROM image and perform the normal CPU reset sequence.
        Otherwise jump directly to the entry point.  */
     if (lowaddr == 0) {
-	env->regs[13] = ldl_phys(0);
-	pc = ldl_phys(4);
+        /* roms are not loaded in physical memory until reset */
+        uint32_t *rom = rom_ptr(0);
+        env->regs[13] = rom[0];
+        pc = rom[1];
     } else {
 	pc = entry;
     }
#1 lore raw
Quoted 12 lines · Benjamin Bagland

Hi,

I'm having an issue while trying to use the lm3s811 board emulation with qemu 0.12.3 or git. It works fine however with qemu-0.11.1.

The problem comes from hw/armv7m.c, around line 231, the initial PC and SP are set by reading from physical memory, however the rom data is not copied in physical memory until the reset later on in the initialisation (comes from commit 45a50b1668822c23afc I think). Since the initial PC is invalid, the cpu goes straight into UsageFault instead of going to the proper reset routine.

Quoted 3 lines

I've made a small patch to read from rom instead of physical memory, that fixes the issue with my test program but I'm not sure if it's the proper thing to do, or even if it works with other arm boards.

The patch seems to be generated on top of some code that is not in the repository, but in short, I think both loading the kernel, roms, and setting of pc and sp should be done only on reset. There's probably a bootloader somewhere that sets the pc and sp on real hw.

Cheers