Skip to content

Commit b57cf38

Browse files
committed
baremetal: document the bootloaders
1 parent 8dd0141 commit b57cf38

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

README.adoc

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10217,12 +10217,10 @@ then on the second shell:
1021710217
./run-gdb --arch arm --baremetal interactive/prompt --no-continue
1021810218
....
1021910219

10220-
and now we are left at the very first executed instruction of our tiny bootloader: link:baremetal/lib/arm.S[]
10220+
and now we are left at the very first executed instruction of our tiny <<baremetal-bootloaders>>.
1022110221

1022210222
Then just use `stepi` to when jumping into main to go to the C code in link:baremetal/interactive/prompt.c[].
1022310223

10224-
The bootloader is used to put the hardware in its main operating mode before we run our main payload on it.
10225-
1022610224
You can also find executables that don't use the bootloader at all under `baremetal/arch/<arch>/no_bootloader/*.S`, e.g.:
1022710225

1022810226
....
@@ -10231,8 +10229,6 @@ You can also find executables that don't use the bootloader at all under `bareme
1023110229

1023210230
The cool thing about those examples is that you start at the very first instruction of your program, which gives more control.
1023310231

10234-
However, those examples tend to be less portable, so we use examples with the bootloader for the most part.
10235-
1023610232
Alternatively, skip directly to the C program main function with:
1023710233

1023810234
....
@@ -10253,6 +10249,33 @@ and on another shell:
1025310249

1025410250
`aarch64` GDB step debug is broken as mentioned at: <<gem5-gdb-step-debug-kernel-aarch64>>.
1025510251

10252+
=== Baremetal bootloaders
10253+
10254+
As can be seen from <<baremetal-gdb-step-debug>>, all examples under link:baremetal/[], with the exception of `baremetal/arch/<arch>/no_bootloader`, start from our tiny bootloaders:
10255+
10256+
* link:baremetal/lib/arm.S[]
10257+
* link:baremetal/lib/aarch64.S[]
10258+
10259+
Out simplistic bootloaders basically setup up just enough system state to allow calling:
10260+
10261+
* C functions such as `exit` from the assembly examples
10262+
* the `main` of C examples itself
10263+
10264+
The most important things that we setup in the bootloaders are:
10265+
10266+
* the stack pointer
10267+
* NEON: <<aarch64-baremetal-neon-setup>>
10268+
* TODO: we don't do this currently but maybe we should setup BSS
10269+
10270+
The C functions that become available as a result are:
10271+
10272+
* Newlib functions implemented at link:baremetal/lib/syscalls.c[]
10273+
* non-Newlib functions implemented at link:common.c[]
10274+
10275+
It is not possible to call those C functions from the examples that don't use a bootloader.
10276+
10277+
For this reason, we tend to create examples with bootloaders, as it is easier to write them portably.
10278+
1025610279
=== Semihosting
1025710280

1025810281
Semihosting is a publicly documented interface specified by ARM Holdings that allows us to do some magic operations very useful in development.
@@ -10512,7 +10535,7 @@ output:
1051210535

1051310536
==== ARM multicore
1051410537

10515-
TODO get working: CPU 1 not waking up:
10538+
TODO get working on QEMU, CPU 1 not waking up. gem5 works:
1051610539

1051710540
....
1051810541
./run --arch aarch64 --baremetal arch/aarch64/multicore --cpus 2
@@ -10524,6 +10547,14 @@ CPU 0 of this program enters a spinlock loop: it repeatedly checks if a given me
1052410547

1052510548
So, we need CPU 1 to come to the rescue to that memory address be `1`, otherwise CPU 0 will be stuck there forever.
1052610549

10550+
Don't believe me? Then try:
10551+
10552+
....
10553+
./run --arch aarch64 --baremetal arch/aarch64/multicore --cpus 1
10554+
....
10555+
10556+
and watch it hang forever.
10557+
1052710558
Bibliography:
1052810559

1052910560
* https://stackoverflow.com/questions/20055754/arm-start-wakeup-bringup-the-other-cpu-cores-aps-and-pass-execution-start-addre

0 commit comments

Comments
 (0)