diff --git a/README.adoc b/README.adoc index d156368..3f1cdad 100644 --- a/README.adoc +++ b/README.adoc @@ -13170,7 +13170,11 @@ The C standard library infrastructure is implemented in the common userland / ba ==== 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. +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: + +* link:userland/arch/x86_64/freestanding/[] +* link:userland/arch/arm/freestanding/[] +* link: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. <>. @@ -13185,6 +13189,14 @@ In order to GDB step debug those executables, you will want to use `--no-continu You are now left on the very first instruction of our tiny executable! +===== nostartfiles programs + +Assembly examples under `nostartfiles` directories can use the standard library, but they don't use the pre-`main` boilerplate and start directly at our explicitly given `_start`: + +* link:userland/arch/aarch64/freestanding/[] + +I'm not sure how much stdlib functionality is supposed to work without the pre-main stuff, but I guess we'll just have to find out! + === GCC inline assembly Examples under `arch//c/` directories show to how use inline assembly from higher level languages such as C: diff --git a/path_properties.py b/path_properties.py index 9ed29e7..7f130be 100644 --- a/path_properties.py +++ b/path_properties.py @@ -260,6 +260,7 @@ gnu_extension_properties = { 'cc_pedantic': False, 'cxx_std': 'gnu++17' } +# https://github.com/cirosantilli/linux-kernel-module-cheat#freestanding-programs freestanding_properties = { 'baremetal': False, 'cc_flags': [ @@ -269,6 +270,13 @@ freestanding_properties = { ], 'extra_objs_lkmc_common': False, } +# https://github.com/cirosantilli/linux-kernel-module-cheat#nostartfiles-programs +nostartfiles_properties = { + 'baremetal': False, + 'cc_flags': [ + '-nostartfiles', LF, + ], +} # See: https://cirosantilli.com/linux-kernel-module-cheat#path-properties path_properties_tuples = ( PathProperties.default_properties, @@ -405,6 +413,7 @@ path_properties_tuples = ( 'freestanding': freestanding_properties, 'lkmc_assert_eq_fail.S': {'signal_received': signal.Signals.SIGABRT}, 'lkmc_assert_memcmp_fail.S': {'signal_received': signal.Signals.SIGABRT}, + 'nostartfiles': nostartfiles_properties, 'udf.S': { 'signal_generated_by_os': True, 'signal_received': signal.Signals.SIGILL, diff --git a/userland/arch/aarch64/freestanding/README.adoc b/userland/arch/aarch64/freestanding/README.adoc new file mode 100644 index 0000000..ff42a8a --- /dev/null +++ b/userland/arch/aarch64/freestanding/README.adoc @@ -0,0 +1 @@ +https://github.com/cirosantilli/linux-kernel-module-cheat#freestanding-programs diff --git a/userland/arch/aarch64/nostartfiles/README.adoc b/userland/arch/aarch64/nostartfiles/README.adoc new file mode 100644 index 0000000..2a2f030 --- /dev/null +++ b/userland/arch/aarch64/nostartfiles/README.adoc @@ -0,0 +1 @@ +https://github.com/cirosantilli/linux-kernel-module-cheat#nostartfiles-programs diff --git a/userland/arch/aarch64/nostartfiles/build b/userland/arch/aarch64/nostartfiles/build new file mode 120000 index 0000000..ab18017 --- /dev/null +++ b/userland/arch/aarch64/nostartfiles/build @@ -0,0 +1 @@ +../build \ No newline at end of file diff --git a/userland/arch/aarch64/nostartfiles/exit.S b/userland/arch/aarch64/nostartfiles/exit.S new file mode 100644 index 0000000..d02fe28 --- /dev/null +++ b/userland/arch/aarch64/nostartfiles/exit.S @@ -0,0 +1,4 @@ +.global _start +_start: + mov x0, 0 + bl exit diff --git a/userland/arch/aarch64/nostartfiles/test b/userland/arch/aarch64/nostartfiles/test new file mode 120000 index 0000000..419df4f --- /dev/null +++ b/userland/arch/aarch64/nostartfiles/test @@ -0,0 +1 @@ +../test \ No newline at end of file diff --git a/userland/arch/arm/freestanding/README.adoc b/userland/arch/arm/freestanding/README.adoc new file mode 100644 index 0000000..ff42a8a --- /dev/null +++ b/userland/arch/arm/freestanding/README.adoc @@ -0,0 +1 @@ +https://github.com/cirosantilli/linux-kernel-module-cheat#freestanding-programs diff --git a/userland/arch/x86_64/freestanding/README.adoc b/userland/arch/x86_64/freestanding/README.adoc new file mode 100644 index 0000000..ff42a8a --- /dev/null +++ b/userland/arch/x86_64/freestanding/README.adoc @@ -0,0 +1 @@ +https://github.com/cirosantilli/linux-kernel-module-cheat#freestanding-programs