33.4. Baremetal command line arguments
QEMU and gem5 currently supports baremetal CLI arguments!
You can see them in action e.g. with:
./run --arch aarch64 --baremetal userland/c/command_line_arguments.c --cli-args 'aa bb cc' ./run --arch aarch64 --userland userland/c/command_line_arguments.c --cli-args 'aa bb cc'
both of which output the exact same thing:
aa bb cc
This is implemented by parsing the command line arguments and placing them into memory where the code will find them.
This works by:
-
fixing the
argc
andargv
addresses in memory in the Baremetal linker script -
the Baremetal bootloaders pass those addresses correctly to the call of
main
-
our Python scripts write the desired binary memory values to a file
-
QEMU loads those files into memory with
-device loader
: https://github.com/qemu/qemu/blob/60905286cb5150de854e08279bca7dfc4b549e91/docs/generic-loader.txt
It is worth noting that e.g. ARM has a Semihosting mechanism for loading CLI arguments through SYS_GET_CMDLINE
, but our mechanism works in principle for any ISA.