xv6, line by line
xv6 is a small, complete Unix-like operating system written at MIT for teaching. It runs on RISC-V. This site presents every file of it, so you can read the whole thing, from the Makefile to the scheduler, and follow any name to where it is defined and everywhere it is used.
How to read this site
- Hover over a highlighted name to see what it is and where it is defined.
- Click a name to jump to its definition. The Symbol panel lists every place the name is used, across C, assembly, linker scripts and the Makefile.
- Press / to search for any file, function, struct, macro or label.
- In an annotated file, click any line to read its notes in the side panel, or press Start reading and step through with j / k. Show notes inline puts the notes between the lines instead.
- Dotted underlines are glossary terms; the glossary lists them all.
- Your browser's Back button returns you to where you were.
Start with a guided tour
The 52 guided tours walk through the running system step by step, showing the machine state and what the other CPUs are doing. A good path for beginners:
Lost? Four questions locate you at any moment: which privilege mode, which stack, which page table, and which locks this CPU holds (with interrupts on or off). The concept pages explain each one, and every tour step shows all four.
Created byJyotiprakash MishraAuthor of RISC-V Architecture and XV6 (De Gruyter Brill, 2026), the book this site accompanies. Meet the creator →
A suggested reading order
Makefile— How the kernel, the user programs and the disk image are built. annotatedkernel/kernel.ld— Where in memory each part of the kernel is placed. annotatedkernel/entry.S— The first instructions every CPU runs. annotatedkernel/start.c— Machine mode setup, then the switch to supervisor mode. annotatedkernel/main.c— Initializes every kernel subsystem and starts the first process. annotatedkernel/memlayout.h— The physical and virtual memory map. annotatedkernel/vm.c— Page tables: how virtual addresses become physical ones. annotatedkernel/proc.c— Processes, the scheduler, fork/exit/wait. annotatedkernel/trampoline.S— The bridge between user space and the kernel. annotatedkernel/trap.c— Handling system calls, interrupts and faults. annotatedkernel/syscall.c— Dispatching a system call to its handler. annotatedkernel/fs.c— The file system: inodes, directories, path names. annotated
The kernel
| File | Language | Lines |
|---|---|---|
| kernel/bio.c annotated | C | 153 |
| kernel/buf.h annotated | C header | 11 |
| kernel/console.c annotated | C | 203 |
| kernel/defs.h annotated | C header | 186 |
| kernel/elf.h annotated | C header | 42 |
| kernel/entry.S annotated | RISC-V assembly | 21 |
| kernel/exec.c annotated | C | 176 |
| kernel/fcntl.h annotated | C header | 5 |
| kernel/file.c annotated | C | 179 |
| kernel/file.h annotated | C header | 40 |
| kernel/fs.c annotated | C | 741 |
| kernel/fs.h annotated | C header | 61 |
| kernel/kalloc.c annotated | C | 82 |
| kernel/kernel.ld annotated | linker script | 45 |
| kernel/kernelvec.S annotated | RISC-V assembly | 64 |
| kernel/log.c annotated | C | 261 |
| kernel/main.c annotated | C | 45 |
| kernel/memlayout.h annotated | C header | 63 |
| kernel/param.h annotated | C header | 14 |
| kernel/pipe.c annotated | C | 143 |
| kernel/plic.c annotated | C | 47 |
| kernel/printk.c annotated | C | 152 |
| kernel/proc.c annotated | C | 703 |
| kernel/proc.h annotated | C header | 104 |
| kernel/riscv.h annotated | C header | 417 |
| kernel/sleeplock.c annotated | C | 55 |
| kernel/sleeplock.h annotated | C header | 9 |
| kernel/spinlock.c annotated | C | 116 |
| kernel/spinlock.h annotated | C header | 8 |
| kernel/start.c annotated | C | 66 |
| kernel/stat.h annotated | C header | 11 |
| kernel/string.c annotated | C | 106 |
| kernel/swtch.S annotated | RISC-V assembly | 42 |
| kernel/syscall.c annotated | C | 151 |
| kernel/syscall.h annotated | C header | 23 |
| kernel/sysfile.c annotated | C | 530 |
| kernel/sysproc.c annotated | C | 112 |
| kernel/trampoline.S annotated | RISC-V assembly | 153 |
| kernel/trap.c annotated | C | 220 |
| kernel/types.h annotated | C header | 10 |
| kernel/uart.c annotated | C | 155 |
| kernel/virtio.h annotated | C header | 99 |
| kernel/virtio_disk.c annotated | C | 333 |
| kernel/vm.c annotated | C | 491 |
| kernel/vm.h annotated | C header | 2 |
User programs and library
| File | Language | Lines |
|---|---|---|
| user/cat.c annotated | C | 43 |
| user/dorphan.c annotated | C | 35 |
| user/echo.c annotated | C | 19 |
| user/forktest.c annotated | C | 56 |
| user/forphan.c annotated | C | 40 |
| user/grep.c annotated | C | 108 |
| user/grind.c annotated | C | 351 |
| user/init.c annotated | C | 54 |
| user/kill.c annotated | C | 17 |
| user/ln.c annotated | C | 15 |
| user/logstress.c annotated | C | 48 |
| user/ls.c annotated | C | 88 |
| user/mkdir.c annotated | C | 23 |
| user/printf.c annotated | C | 135 |
| user/rm.c annotated | C | 23 |
| user/sh.c annotated | C | 499 |
| user/stressfs.c annotated | C | 50 |
| user/sync.c annotated | C | 10 |
| user/ulib.c annotated | C | 162 |
| user/umalloc.c annotated | C | 90 |
| user/user.h annotated | C header | 50 |
| user/user.ld annotated | linker script | 39 |
| user/usertests.c annotated | C | 3538 |
| user/usys.S gen annotated | RISC-V assembly | 112 |
| user/usys.pl annotated | Perl | 45 |
| user/wc.c annotated | C | 55 |
| user/zombie.c annotated | C | 14 |
mkfs: builds the disk image
| File | Language | Lines |
|---|---|---|
| mkfs/mkfs.c annotated | C | 307 |
Build and project files
| File | Language | Lines |
|---|---|---|
| .gdbinit.tmpl-riscv annotated | GDB script | 6 |
| Makefile annotated | Makefile | 204 |
| README annotated | text | 48 |
| test-xv6.py annotated | Python | 224 |
| .clang-format annotated | text | 10 |
| .dir-locals.el annotated | Emacs Lisp | 4 |
| .editorconfig annotated | text | 22 |
| .gitignore annotated | text | 12 |
| LICENSE annotated | text | 24 |
83 files · 13,249 lines · 2,457 named symbols. Source: mit-pdos/xv6-riscv @ 06aad25 (MIT license).
© 2026 Jyotiprakash Mishra. Text, tours, questions and labs: CC BY-NC-SA 4.0; site software: GPL-3.0-or-later; xv6 itself: MIT. What covers what. Credit derived work as “xv6, line by line” by Jyotiprakash Mishra, https://xv6.jyotiprakash.org.