81 lines
No EOL
3.2 KiB
Markdown
81 lines
No EOL
3.2 KiB
Markdown
# crossing the boundary
|
|
source code for *crossing the boundary*, a blog series about writing a kernel in Rust, from a freestanding binary all the way to userspace, hence the name.
|
|
|
|
each directory under `/chapters` is the **complete project as of the end of that chapter**. you can jump in anywhere: pick a chapter, `cd` into it, and `just run`.
|
|
|
|
| # | Chapter | Post | Code |
|
|
|----|------------------------|------------------------------|--------------------------------------------------------------------|
|
|
| 01 | freestanding | [read](http://fawn.rest/journal/crossing-the-boundary-1/) | [`chapters/01-freestanding`](chapters/01-freestanding) |
|
|
|
|
## running a chapter
|
|
you need:
|
|
|
|
- `rustup` (each chapter pins its toolchain in `rust-toolchain.toml`)
|
|
- [`just`](https://just.systems/)
|
|
- `nasm` and GNU `ld` (binutils)
|
|
- `qemu-system-x86_64`
|
|
- `grub-mkrescue`/`grub2-mkrescue`, with `xorriso` + `mtools`
|
|
|
|
```sh
|
|
# Fedora
|
|
sudo dnf install -y just nasm binutils qemu-system-x86 xorriso mtools grub2-tools-extra grub2-pc-modules
|
|
|
|
# Debian 13+ or Ubuntu 24.04+
|
|
sudo apt install -y just nasm binutils qemu-system-x86 xorriso mtools grub-pc-bin grub-common
|
|
```
|
|
|
|
you can also install just through cargo:
|
|
|
|
```sh
|
|
cargo install just
|
|
```
|
|
|
|
then, in a chapter:
|
|
|
|
```sh
|
|
just run # boot in QEMU; the serial console is in your terminal, and Ctrl+C quits
|
|
just test # boot the test kernel and report the results
|
|
just check # rustfmt and clippy
|
|
just # show available commands
|
|
```
|
|
|
|
## how a chapter is organized
|
|
each chapter is a cargo workspace:
|
|
|
|
- `kernel/src/arch/<arch>/`: architecture-specific code, including boot code (`boot/`: entry assembly, multiboot2 header, linker scriot)
|
|
- note: `<arch>` is typically `x86_64` for now
|
|
- `kernel/src/`: architecture-neutral code
|
|
|
|
## testing
|
|
tests sit next to the code they test, declared with `test!`:
|
|
|
|
```rust
|
|
#[cfg(feature = "test")]
|
|
mod tests {
|
|
crate::test! {
|
|
fn adds_up() {
|
|
assert_eq!(2 + 2, 4);
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
`just test` builds the kernel with `--features test`, which runs every collected test instead of the normal entry, and boots in QEMU. a panic fails the run. QEMU's `isa-debug-exit` device reports the result as QEMU's exit code.
|
|
|
|
## what changed between two chapters?
|
|
```sh
|
|
just diff 3 4
|
|
just diff 3 4 --stat
|
|
```
|
|
|
|
## author recipes
|
|
| recipe | purpose |
|
|
|---------------------------------|------------------------------------------------------------------|
|
|
| `just setup` | installs every chapter's pinned toolchain |
|
|
| `just check [n]` | rustfmt and clippy in every chapter (or just chapter `n`) |
|
|
| `just test [n]` | builds and tests every chapter (or just chapter `n`) |
|
|
| `just new-chapter <slug>` | copies the latest chapter to the next number |
|
|
| `just propagate <n> [commit]` | applies a fix made in chapter `n` to every later chapter |
|
|
|
|
## license
|
|
this project is licensed under the MIT License. see the [LICENSE](LICENSE) file for details. |