# Linux Kernel Module Cheat

#### 28.5.1. Freestanding programs

Unlike most our other assembly examples, which use the C standard library for portability, examples under `freestanding/` directories don’t link to the C standard library:

- userland/freestanding/: freestanding programs that work on any ISA

- userland/arch/x86_64/freestanding/

- userland/arch/arm/freestanding/

- userland/arch/aarch64/freestanding/

As a result, those examples cannot do IO portably, and so they make raw system calls and only be run on one given OS, e.g. Linux system calls.

Such executables are called freestanding because they don’t execute the glibc initialization code, but rather start directly on our custom hand written assembly.

In order to GDB step debug those executables, you will want to use `--no-continue`, e.g.:

    ./run --arch aarch64 --userland userland/arch/aarch64/freestanding/linux/hello.S --gdb-wait
    ./run-gdb --arch aarch64 --no-continue --userland userland/arch/aarch64/freestanding/linux/hello.S

or in one go with tmux:

    ./run \
      --arch aarch64 \
      --gdb-wait \
      --tmux-args=--no-continue \
      --userland userland/arch/aarch64/freestanding/linux/hello.S \
    ;

You are now left on the very first instruction of our tiny executable!

This is analogous to step debugging baremetal examples.

Related:

- https://stackoverflow.com/questions/4783404/is-main-really-start-of-a-c-program/64116561#64116561 "Is main() really start of a C++ program?"

- https://electronics.stackexchange.com/questions/258896/what-happens-before-main/404298#404298

- https://electronics.stackexchange.com/questions/55767/who-receives-the-value-returned-by-main, more microcontroller focused, should entitled "how to quit a program in microcontroller"

- https://stackoverflow.com/questions/53570678/what-happens-before-main-in-c "What happens before main in C++?"

- https://www.quora.com/What-is-happening-before-the-main-function-is-called-in-C++-programming

- https://stackoverflow.com/questions/2053029/how-exactly-does-attribute-constructor-work

- nostartfiles programs