rust-raspberrypi-OS-tutorials/01_wait_forever
Andre Richter 2432c0d283
Revert to assembly boot code
It is too risky to rely on the compiler to not insert any operations using the
stack.

Having a stack-setting call in Rust using the cortex-a crate as the first action
in a Rust-only _start() function does not work if you're subsequently using the
stack, because the compiler often inserts the operations to make room on the
stack to prepare a function call BEFORE the call to set the stack, which crashes
the boot process.

Hence, keep on using a small piece of assembly boot code throughout.
2021-03-20 09:41:43 +01:00
..
.vscode Run of prettier over whole repo 2020-09-25 21:24:56 +02:00
src Revert to assembly boot code 2021-03-20 09:41:43 +01:00
build.rs Add color and verbosity to Makefile 2021-03-12 23:44:10 +01:00
Cargo.lock Add code for tutorial 01 2019-10-27 23:09:35 +01:00
Cargo.toml Revert to assembly boot code 2021-03-20 09:41:43 +01:00
Makefile Overhaul linker script 2021-03-16 22:36:06 +01:00
README.CN.md Remove xbuild. Use upstream aarch64 rust-std 🎉 🦀 2020-04-07 23:17:48 +02:00
README.md Revert to assembly boot code 2021-03-20 09:41:43 +01:00

Tutorial 01 - Wait Forever

tl;dr

  • The project skeleton is set up.
  • A small piece of assembly code runs that just halts all CPU cores executing the kernel code.

Building

  • Makefile targets:
    • doc: Generate documentation.
    • qemu: Run the kernel in QEMU
    • clippy
    • clean
    • readelf: Inspect the ELF output.
    • objdump: Inspect the assembly.
    • nm: Inspect the symbols.

Code to look at

  • Custom link.ld linker script.
    • Load address at 0x8_0000
    • Only .text section.
  • main.rs: Important inner attributes:
    • #![no_std], #![no_main]
  • boot.s: Assembly _start() function that executes wfe (Wait For Event), halting all cores that are executing _start().
  • We (have to) define a #[panic_handler] function to make the compiler happy.
    • Make it unimplemented!() because it will be stripped out since it is not used.

Test it

In the project folder, invoke QEMU and observe the CPU core spinning on wfe:

$ make qemu
[...]
IN:
0x00080000:  d503205f  wfe
0x00080004:  17ffffff  b        #0x80000