-
Notifications
You must be signed in to change notification settings - Fork 0
Debugging Baremetal Applications Using QEMU
Install all necessary prerequisites which are necessary for building QEMU: https://wiki.qemu.org/Hosts/Linux. Then prepare sources and a build directory:
git clone https://github.com/foss-for-synopsys-dwc-arc-processors/qemu
mkdir -p qemu/build
cd qemu/build
Configure QEMU (use your own --prefix
value):
../configure --target-list=arc-softmmu,arc64-softmmu,arc-linux-user,arc64-linux-user \
--enable-debug --enable-debug-tcg --prefix=/tools/qemu
Build an install:
make
make install
Configure your environment:
export QEMU_HOME="/tools/qemu"
export PATH="${QEMU_HOME}/bin:$PATH"
Consider a simple example code (save it as main.c
):
#include <stdio.h>
int main()
{
printf("Hello, World!\n");
return 0;
}
You need to use -specs=qemu.specs
to use input/output features and pass -serial stdio
to link
a virtual character device with host's stdio
:
$ arc-elf32-gcc -mcpu=archs -specs=qemu.specs main.c -o main.elf
$ qemu-system-arc -M arc-sim -cpu archs -monitor none -display none -nographic \
-no-reboot -serial stdio -kernel main.elf
Hello, World!
By default, QEMU creates a character device for arc-sim
board on hard coded 0x90000000
address.
A program built with -specs=qemu.specs
uses this address for all input/output operations.
However, if -semihosting
option is passed to QEMU, then it uses the same input/output interface
as nSIM with -on nsim_emt
option. It allows to use the same binary for running both
on QEMU and nSIM:
$ arc-elf32-gcc -mcpu=archs -specs=nsim.specs main.c -o main.elf
$ qemu-system-arc -M arc-sim -cpu archs -monitor none -display none -nographic \
-no-reboot -serial stdio -semihosting -kernel main.elf
Hello, World!