xv6, line by line

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

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

  1. Makefile — How the kernel, the user programs and the disk image are built. annotated
  2. kernel/kernel.ld — Where in memory each part of the kernel is placed. annotated
  3. kernel/entry.S — The first instructions every CPU runs. annotated
  4. kernel/start.c — Machine mode setup, then the switch to supervisor mode. annotated
  5. kernel/main.c — Initializes every kernel subsystem and starts the first process. annotated
  6. kernel/memlayout.h — The physical and virtual memory map. annotated
  7. kernel/vm.c — Page tables: how virtual addresses become physical ones. annotated
  8. kernel/proc.c — Processes, the scheduler, fork/exit/wait. annotated
  9. kernel/trampoline.S — The bridge between user space and the kernel. annotated
  10. kernel/trap.c — Handling system calls, interrupts and faults. annotated
  11. kernel/syscall.c — Dispatching a system call to its handler. annotated
  12. kernel/fs.c — The file system: inodes, directories, path names. annotated

The kernel

FileLanguageLines
kernel/bio.c annotatedC153
kernel/buf.h annotatedC header11
kernel/console.c annotatedC203
kernel/defs.h annotatedC header186
kernel/elf.h annotatedC header42
kernel/entry.S annotatedRISC-V assembly21
kernel/exec.c annotatedC176
kernel/fcntl.h annotatedC header5
kernel/file.c annotatedC179
kernel/file.h annotatedC header40
kernel/fs.c annotatedC741
kernel/fs.h annotatedC header61
kernel/kalloc.c annotatedC82
kernel/kernel.ld annotatedlinker script45
kernel/kernelvec.S annotatedRISC-V assembly64
kernel/log.c annotatedC261
kernel/main.c annotatedC45
kernel/memlayout.h annotatedC header63
kernel/param.h annotatedC header14
kernel/pipe.c annotatedC143
kernel/plic.c annotatedC47
kernel/printk.c annotatedC152
kernel/proc.c annotatedC703
kernel/proc.h annotatedC header104
kernel/riscv.h annotatedC header417
kernel/sleeplock.c annotatedC55
kernel/sleeplock.h annotatedC header9
kernel/spinlock.c annotatedC116
kernel/spinlock.h annotatedC header8
kernel/start.c annotatedC66
kernel/stat.h annotatedC header11
kernel/string.c annotatedC106
kernel/swtch.S annotatedRISC-V assembly42
kernel/syscall.c annotatedC151
kernel/syscall.h annotatedC header23
kernel/sysfile.c annotatedC530
kernel/sysproc.c annotatedC112
kernel/trampoline.S annotatedRISC-V assembly153
kernel/trap.c annotatedC220
kernel/types.h annotatedC header10
kernel/uart.c annotatedC155
kernel/virtio.h annotatedC header99
kernel/virtio_disk.c annotatedC333
kernel/vm.c annotatedC491
kernel/vm.h annotatedC header2

User programs and library

FileLanguageLines
user/cat.c annotatedC43
user/dorphan.c annotatedC35
user/echo.c annotatedC19
user/forktest.c annotatedC56
user/forphan.c annotatedC40
user/grep.c annotatedC108
user/grind.c annotatedC351
user/init.c annotatedC54
user/kill.c annotatedC17
user/ln.c annotatedC15
user/logstress.c annotatedC48
user/ls.c annotatedC88
user/mkdir.c annotatedC23
user/printf.c annotatedC135
user/rm.c annotatedC23
user/sh.c annotatedC499
user/stressfs.c annotatedC50
user/sync.c annotatedC10
user/ulib.c annotatedC162
user/umalloc.c annotatedC90
user/user.h annotatedC header50
user/user.ld annotatedlinker script39
user/usertests.c annotatedC3538
user/usys.S gen annotatedRISC-V assembly112
user/usys.pl annotatedPerl45
user/wc.c annotatedC55
user/zombie.c annotatedC14

mkfs: builds the disk image

FileLanguageLines
mkfs/mkfs.c annotatedC307

Build and project files

FileLanguageLines
.gdbinit.tmpl-riscv annotatedGDB script6
Makefile annotatedMakefile204
README annotatedtext48
test-xv6.py annotatedPython224
.clang-format annotatedtext10
.dir-locals.el annotatedEmacs Lisp4
.editorconfig annotatedtext22
.gitignore annotatedtext12
LICENSE annotatedtext24

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.