1kinit();2kvminit();3procinit();4trapinithart();5plicinit();6virtio_disk_init();7userinit();8scheduler();page?page?page?page?slot 0slot 1slot 2PID 1CPUmodekernelsatpnonestvecnone/init1
The parts the kernel builds: free pages, page table, process table, interrupts, diskKernel main() on its card, and the CPU with its mode, satp and stvec registersTokens: a build token per line, pages leaving the free list, process 1 moving onto the CPUBack left: xv6's kernel main(), one line per part. Around it: the free page list, the kernel page table, the process table, interrupts, the disk, and the CPU with its mode, satp and stvec registers. Front left: process 1, faint until it exists. Each line builds its part: pages go on the free list, the page table and trap handler are installed in satp and stvec, slots are cleared, interrupts and the disk are readied. userinit fills slot 0 with process 1, the scheduler runs it, it loads /init from the disk, and the CPU drops to user mode. The card is xv6's main(), the small teaching kernel used in MIT 6.1810, cut to one line per part. Each line stands for one or two real calls (kvminit and kvminithart, for example), kept in their real order; the console is set up first and is not shown.

Starting alone

  1. A boot loader has copied the kernel into memory and jumped to it. The CPU is in kernel mode, running one thing: the kernel's main(). No free-memory list, trap table or process exists yet. Each line of main() builds one.

Building the parts

The first process

What happens

;; step 1/11 · power-on
xv6's main() on the first CPU (abridged):

 1  kinit();             // free page list
 2  kvminit();           // kernel page table
 3  procinit();          // process table
 4  trapinithart();      // trap table
 5  plicinit();          // interrupts
 6  virtio_disk_init();  // disk driver
 7  userinit();          // process 1
 8  scheduler();         // run it

mode     kernel (the machine starts in kernel mode)
exists   only the kernel code itself

The card is xv6's main(), the small teaching kernel used in MIT 6.1810, cut to one line per part. Each line stands for one or two real calls (kvminit and kvminithart, for example), kept in their real order; the console is set up first and is not shown. The figure draws four pages and three process-table slots. A real machine has many thousands of pages, and xv6 has 64 slots. The disk driver and other parts take pages from the list too; the drawing shows only the kernel page table and process 1.