2019-09-25 09:56:41 +00:00
|
|
|
# Tutorial 01 - Wait Forever
|
|
|
|
|
|
|
|
## tl;dr
|
|
|
|
|
2020-10-04 20:27:28 +00:00
|
|
|
- The project skeleton is set up.
|
|
|
|
- A small piece of assembly code runs that just halts all CPU cores executing the kernel code.
|
2019-09-25 09:56:41 +00:00
|
|
|
|
2020-03-28 12:27:39 +00:00
|
|
|
## Building
|
|
|
|
|
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.
|
2020-03-28 12:27:39 +00:00
|
|
|
|
|
|
|
## Code to look at
|
|
|
|
|
2022-04-19 09:26:00 +00:00
|
|
|
- `BSP`-specific `kernel.ld` linker script.
|
2020-09-30 19:51:31 +00:00
|
|
|
- Load address at `0x8_0000`
|
2019-09-25 09:56:41 +00:00
|
|
|
- Only `.text` section.
|
|
|
|
- `main.rs`: Important [inner attributes]:
|
|
|
|
- `#![no_std]`, `#![no_main]`
|
2021-03-20 08:41:43 +00:00
|
|
|
- `boot.s`: Assembly `_start()` function that executes `wfe` (Wait For Event), halting all cores
|
2021-01-23 21:43:59 +00:00
|
|
|
that are executing `_start()`.
|
2020-12-26 23:35:47 +00:00
|
|
|
- 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.
|
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
|
|
|
|
2019-12-30 23:00:09 +00:00
|
|
|
### Test it
|
2019-10-21 19:39:09 +00:00
|
|
|
|
|
|
|
In the project folder, invoke QEMU and observe the CPU core spinning on `wfe`:
|
2021-03-12 23:25:14 +00:00
|
|
|
|
2019-10-21 19:39:09 +00:00
|
|
|
```console
|
2020-03-28 12:27:39 +00:00
|
|
|
$ make qemu
|
2019-10-21 19:39:09 +00:00
|
|
|
[...]
|
2019-12-30 23:00:09 +00:00
|
|
|
IN:
|
|
|
|
0x00080000: d503205f wfe
|
2019-10-21 19:39:09 +00:00
|
|
|
0x00080004: 17ffffff b #0x80000
|
|
|
|
```
|