xv6 book — Chapters 3 (Page tables) and 4 (Traps and system calls)
- The closest companion to
ccc's kernel. Free PDF. Read alongsidesrc/kernel/. Difficulty: Beginner-to-Intermediate.
Operating Systems: Three Easy Pieces — §6 ("Limited Direct Execution")
- The conceptual model of why kernel privilege exists. Free online. Difficulty: Beginner.
Advanced Programming in the UNIX Environment (APUE) — Stevens & Rago, Chapter 8
- Process API from the user side: fork, exec, wait, signals. The "what does the syscall look like to user programs" perspective. Difficulty: Intermediate.
RISC-V Privileged ISA — §3 (Trap mechanism), §4 (Sv32 paging)
- The mechanism
s_trap_entryandvm.zigimplement. Difficulty: Reference.
- The argument-passing rules for
_startand syscalls. Difficulty: Reference.
- xv6's
kmainanalog. Read side-by-side withccc/src/kernel/kmain.zig. Difficulty: Intermediate.
- 14-instruction context switch. Almost line-identical to
ccc's. Difficulty: Intermediate.
Linux: arch/riscv/kernel/entry.S
- Production-grade trap entry. Lots more bookkeeping than
ccc's — perf counters, ftrace, audit, etc. Difficulty: Advanced.
- Real M-mode firmware boot. What
boot.Sis, but for production hardware. Difficulty: Advanced.
- Page tables, traps, system calls, scheduling. Free videos. Pair with the xv6 book.
Stanford CS 140 ("OS Concepts")
- Pintos-based undergrad OS course. Different code but same concepts.
"How a system call works" — various authors
- Linux kernel docs on adding a syscall. Even if you don't end up patching Linux, the walk-through illuminates the kernel's view. Difficulty: Intermediate.
"The Cost of Context Switching"
- A classic blog post on real-hardware context-switch costs.
ccc's emulator hides these costs, but reading this gives perspective on what production OSes optimize. Difficulty: Intermediate.
zig build run -- --trace kernel.elf | head -200
- The cleanest way to see boot in action: every instruction from
0x80000000to the first user-modeaddi. The privilege column flips from[M]to[S]to[U]exactly where you'd expect.
- Diffs
ccc's--traceoutput forkernel.elfagainstqemu-system-riscv32. If a CSR write or trap routing differs from QEMU, this catches it. Requires QEMU.
Next: processes-fork-exec-wait — how the kernel manages multiple processes. We've shown one process; now we make N.