2019-09-25 09:56:41 +00:00
|
|
|
# Tutorial 01 - Wait Forever
|
|
|
|
|
|
|
|
## tl;dr
|
|
|
|
|
2019-10-21 19:39:09 +00:00
|
|
|
Project skeleton is set up; Code just halts all CPU cores executing the kernel code.
|
2019-09-25 09:56:41 +00:00
|
|
|
|
|
|
|
- Toolchain: `cargo xbuild` tools (`xrustc`, `xclippy`) and the
|
2019-10-10 17:46:05 +00:00
|
|
|
`aarch64-unknown-none-softfloat` target are used for building `AArch64`
|
|
|
|
bare-metal code.
|
2019-09-25 09:56:41 +00:00
|
|
|
- `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.
|
2019-10-10 17:46:05 +00:00
|
|
|
- Code is organized into `kernel`, `arch` and `BSP` (Board Support Package)
|
|
|
|
parts.
|
|
|
|
- Conditional compilation includes respective `arch` and `BSP` according to
|
|
|
|
user-supplied arguments.
|
2019-09-25 09:56:41 +00:00
|
|
|
- Custom `link.ld` linker script.
|
|
|
|
- Load address at `0x80_000`
|
|
|
|
- Only `.text` section.
|
|
|
|
- `main.rs`: Important [inner attributes]:
|
|
|
|
- `#![no_std]`, `#![no_main]`
|
|
|
|
- Assembly `_start()` function that executes `wfe` (Wait For Event), halting all
|
|
|
|
cores that are executing `_start()`.
|
|
|
|
- We (have to) define a `#[panic_handler]` function.
|
2019-10-12 07:06:34 +00:00
|
|
|
- Just waits infinitely for a cpu event.
|
2019-09-25 09:56:41 +00:00
|
|
|
|
|
|
|
[inner attributes]: https://doc.rust-lang.org/reference/attributes.html
|
2019-10-21 19:39:09 +00:00
|
|
|
|
|
|
|
### Give it a try
|
|
|
|
|
|
|
|
In the project folder, invoke QEMU and observe the CPU core spinning on `wfe`:
|
|
|
|
```console
|
|
|
|
make qemu
|
|
|
|
[...]
|
|
|
|
IN:
|
|
|
|
0x00080000: d503205f wfe
|
|
|
|
0x00080004: 17ffffff b #0x80000
|
|
|
|
```
|