In this post, we will emulate a baremetal program for Cortex-M on Ubuntu PC.
We will need
- QEMU emulator for ARM
Fortunately both of them are available through Ubuntu software repository.
Install them using the following command:
sudo apt install qemu-system-arm sudo apt install gdb-arm-none-eabi
We will use QEMU for emulation. GDB is used to control and inspect QEMU.
qemu-system-arm -monitor stdio -machine lm3s811evb -cpu cortex-m3 -s -S -kernel startup.elf
Access QEMU HMI monitor from terminal
-machine lm3s811evb -cpu cortex-m3
Start GDB server on
Don’t start execution. This is used so we can start and control execution from GDB
The executable file to execute
Launch GDB client
You should now be in GDB interactive console.
Connect to QEMU
Lets connect to GDB server hosted by QEMU from the GDB client
target remote localhost:1234 load
Run the program
<Ctrl-c> to stop execution.
In lines 13, 14 and 16, we update registers r1, r0 and r2 respectively. They should hold values 0x20000000, 10 and 10 respectively.
info reg r0 r1 r2
r0 0x20000000 536870912
r1 0xa 10
r2 0xa 10
We write value 10 to memory address 0x20000000. Lets check if that worked correctly:
0x20000000: 0x0000000a 0x00000000 0x00000000 0x00000000