3.2 KiB
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 | chapters/01-freestanding |
running a chapter
you need:
rustup(each chapter pins its toolchain inrust-toolchain.toml)justnasmand GNUld(binutils)qemu-system-x86_64grub-mkrescue/grub2-mkrescue, withxorriso+mtools
# 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:
cargo install just
then, in a chapter:
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 typicallyx86_64for now
- note:
kernel/src/: architecture-neutral code
testing
tests sit next to the code they test, declared with test!:
#[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?
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 file for details.