# Linux Kernel Module Cheat
The perfect emulation setup to study and develop the <<linux-kernel>> v5.9.2, kernel modules, <<qemu-buildroot-setup,QEMU>>, <<gem5-buildroot-setup,gem5>> and x86_64, ARMv7 and ARMv8 <<userland-assembly,userland>> and <<baremetal-setup,baremetal>> assembly, <<c,ANSI C>>, <<cpp,C++>> and <<posix,POSIX>>. <<gdb>> and <<kgdb>> just work. Powered by <<about-the-qemu-buildroot-setup,Buildroot>> and <<about-the-baremetal-setup,crosstool-NG>>. Highly automated. Thoroughly documented. Automated <<test-this-repo,tests>>.

### 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` and `argv` 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.

- gem5 baremetal arm CLI args