0

I tried this recipe : How to run a bare metal ELF file on QEMU? to run bare metal AArch64 executables on QEMU (and it worked). I'd like to do the same for 64-bit SPARCv9 executables (preferably starting from C/C++, not assembly) - I tried the examples in this link : Run SPARC assembly in QEMU, but that one runs in user-mode Linux, does syscall translation to the host system, etc.

Example :

int main(int argc, char **argv) {
  volatile int a = 11, b = 13, c = 7, d = 5; 
  return a + b - c - d;
} 

How do I run this example as a bare metal Sparcv9 executable AND connect gdb to it ?

Any of the available 64-bit boards in qemu/hw/sparc64/ would be fine. Thank you.

ihi
  • 107
  • 1
  • 9
  • In addition to my answer, I just thought I'd recommend using [renode](https://renode.io/) as an alternative to qemu. While not as high performance, it is a modern alternative, that has first-class support for emulating custom peripherals, which is often half the difficulty in bare-metal emulation. – silvergasp Aug 01 '22 at 20:17
  • That's a slightly weird thing to want to run as a bare metal executable, because it starts at main() and returns a value from it, which is to say it's assuming a libc runtime and is not really 'bare metal'. – Peter Maydell Aug 01 '22 at 21:28
  • In the `AArch64` example I posted, the program writes couple of characters to the board's UART. I'd like to achieve the same, but didn't want to specialize the question to a specific `SPARC` dev board. – ihi Aug 01 '22 at 23:13
  • One of the key characteristics of "bare metal" is that it is generally specific to a particular bit of hardware... – Peter Maydell Aug 02 '22 at 11:59

2 Answers2

0

I believe what you are after is the qemu-system-sparc64 command. Just something to note is that the general form for bare-metal emulation is qemu-system-{ARCH} and the general command for user mode emulation is qemu-{ARCH}.

An example from the qemu docs.

qemu-system-sparc64 \
  -drive file=hd.qcow2,if=none,id=hd \
  -device virtio-blk-pci,bus=pciB,drive=hd,bootindex=0

As for building your own c/c++ bare-metal executables, that's a relatively broad topic, but I'd recommend starting with GCC and newlib-nano (for libc).

silvergasp
  • 1,517
  • 12
  • 23
  • From the `AArch64` link I posted - it looks like there are 2-3 very simple steps to do to run a bare metal executable on `ARM`. I am expecting an answer along the same lines ? – ihi Aug 01 '22 at 20:19
  • It seems that you are looking for a very specific type of answer. How do you feel about updating your question to specify *exactly* what you are after? – silvergasp Aug 01 '22 at 20:55
  • Thank you for the suggestion - added a very small example + exactly what I need. Thanks again. – ihi Aug 01 '22 at 21:05
0

Basically it's similar to running an AArch64 bare-metal ELF:

qemu-system-sparc64 -nographic -kernel test64.elf -serial mon:stdio -s

or

qemu-system-sparc64 -nographic -bios test64.elf -serial mon:stdio -s

Both -kernel and -bios options in sun4u emulation may load ELF files, the difference is that in the first example the hardware is initialized by OpenBIOS, and in the second example you are running in a PROM right after the cold start. The -s option will make QEMU listen for an incoming connection from gdb on TCP port 1234.

In the second example you probably also would like to add the -S option in oder to make QEMU not to start the execution of your ELF file until you tell it to from gdb. In gdb you do the following:

(gdb) set architecture sparc:v9
The target architecture is assumed to be sparc:v9
(gdb)  target remote localhost:1234