indicogniBuild a VMM

Build · Rust · Apple Silicon

Build a VMM from scratch.

Write a virtual machine monitor in Rust on top of Apple's Hypervisor.framework, then boot Linux on it. No QEMU underneath: every exit, device and interrupt is code you wrote and can read.

Needs a Mac 12 parts · 26 chapters written Runs in browser 35 labs built · 24 primers

What you'll build

The whole picture Four layers, top to bottom. 1. The guest: Linux, U-Boot then FreeBSD, or a test guest. It believes it runs on a QEMU virt board. 2. The macvmm process, one macOS process that sandboxes itself. It holds the command line (crates/macvmm), the VMM library (crates/vmm: vCPU threads, devices, virtio, loaders and the device tree) and the FFI bindings (crates/hvf). Beside it, on the host, are the input files (kernel, initramfs, disk image), which macvmm reads, and the terminal, which carries the serial console both ways. 3. Hypervisor.framework and the macOS kernel, called through the FFI bindings: the stage-2 memory map, vCPUs, the in-kernel GIC interrupt controller and the virtual timer. 4. The Apple Silicon CPU, which runs the guest's instructions directly, at full speed. macvmm: one macOS process, sandboxedHypervisor.framework + macOS kernelThe guestLinux, U-Boot then FreeBSD, or a testguest. It believes it runs on a QEMUvirt board.Command linecrates/macvmmVMM librarycrates/vmmvCPU threads, devices, virtio,loaders and the device treeFFI bindingscrates/hvfHost fileskernel,initramfs,disk imageTerminalthe serialconsoleStage-2 memoryvCPUsIn-kernel GICVirtual timerApple Silicon CPUruns the guest's instructionsdirectly, at full speed
macvmm is one macOS process between the guest and Hypervisor.framework, and the guest's code runs directly on the CPU.
The heart of a VMM: run, exit, emulate, resume A loop of five steps. 1. macvmm calls hv_vcpu_run and the guest runs at full speed. 2. Exit: the guest touched a device address or made a hypercall, so the CPU stops it and hv_vcpu_run returns. 3. macvmm decodes the syndrome register, ESR_EL2, which says why the guest stopped. 4. A device model, or the PSCI code for a hypercall, emulates the access. 5. macvmm advances the program counter to the next instruction (after a hypercall the CPU has already done this), then calls hv_vcpu_run again. Measured on 2026-11-22 on an Apple M5 Pro with scripts/run-linux.sh --cpus 4 --stats, booting Linux to a shell and powering it off: 35,271 exits in total, the same in each of 4 runs. 35,235 were device accesses (MMIO data aborts), 25 were hypercalls and 11 were other kinds. There were no timer or WFI exits, because the in-kernel GIC handles those inside Hypervisor.framework. hv_vcpu_runthe guest runs atfull speedExitdevice accessor hypercallDecode the ESRwhy it stoppedEmulatea device modelor PSCI answersAdvance the PCto the nextinstructionMeasured: one Linux run, 4 vCPUs35,271 exits in total.35,235 were device accesses (MMIO),25 were hypercalls, 11 other kinds.No timer or WFI exits at all:the in-kernel GIC handles those.
When the guest touches a device, the CPU stops it, and your code decodes why, emulates the device and runs the guest again.

Take the visual tour

What you need

  • Needs a Mac

    A Mac with Apple Silicon (Apple M1 or later) on macOS 15 or later, with Xcode command-line tools and Rust, for the chapters that run your VMM. Tested only on macOS 27.2 on an M5 Pro; older ones are expected to work. The code is on GitHub, and chapter 00 shows how to get it.

  • Runs in a browser

    Reading, the primers and the labs need only a browser. Labs run entirely on your machine; nothing is uploaded.

  • You should know

    Some Rust or C, what a process and a memory address are, and a terminal. No virtualization or ARM background needed: Part 0 starts from zero.

How it works

  • Real code

    Every block of reference VMM code, headed by its file path and line numbers, is pulled from the repository when the site is built, never pasted, so it cannot drift.

  • Predict, then reveal

    Each chapter asks you to commit to a guess before it shows the answer, and breaks things on purpose so you see why they work.

  • A test you run

    Every chapter ends with a checkpoint: one command and the exact output you should see. Every block labelled Terminal is a captured run, and its footer says where it came from.

Curriculum

Part 0What a virtual machine is, and where ours sits
  1. 00Two kernels, one Mac: what a virtual machine isNeeds a Mac Runs in browser ~3.5 h
  2. 01Where our VMM sits: Hypervisor.framework and a hand-written FFINeeds a Mac Runs in browser ~4 h
Part IThe bare machine, first VM exit
  1. 02An exception, one level up: your first VM exitNeeds a Mac Runs in browser ~5.5 h
  2. 03A guest of your own, and what an exit costsNeeds a Mac Runs in browser ~3.5 h
Part IIMemory
  1. 04Guest memory: the only safe access is a copyNeeds a Mac Runs in browser ~3.5 h
  2. 05Two stages, one map: holes in stage 2 on purposeNeeds a Mac Runs in browser ~3.5 h
Part IIIA CPU that runs: registers, exits, sysregs
  1. 06vCPU state: registers, PSTATE and resetNeeds a Mac Runs in browser ~2 h
  2. 07The exit loop: decoding syndromes and emulating MMIONeeds a Mac Runs in browser ~4 h
  3. 08System registers, injection, hypercalls and PSCINeeds a Mac Runs in browser ~4.5 h
Part IVDevices: MMIO, PL011, DTB
  1. 09A device is a state machine: the bus, PL011 and PL031Needs a Mac Runs in browser ~4 h
  2. 10The Device Tree: the VMM's promise to the guestNeeds a Mac Runs in browser ~4.5 h
Part VInterrupts and time
  1. 11Getting the CPU back: the timer and a bare interruptNeeds a Mac Runs in browser ~4.5 h
  2. 12Why an interrupt controller, and why in the kernelNeeds a Mac Runs in browser ~4.5 h
Part VIBooting Linux
  1. 13Loading kernels: arm64 Image, initramfs and ELFNeeds a Mac Runs in browser ~4.5 h
  2. 14Booting Linux to a shellNeeds a Mac Runs in browser ~5 h
Part VIIVirtio
  1. 15Rings and a doorbell: the virtio-mmio transportNeeds a Mac Runs in browser ~4.5 h
  2. 16Split virtqueues: shared memory with an adversaryNeeds a Mac Runs in browser ~6.5 h
  3. 17virtio-rng (worked) and virtio-console (faded)Needs a Mac ~4.5 h
  4. 18virtio-blk: a root filesystem that persistsNeeds a Mac Runs in browser ~5.5 h
  5. 19virtio-net without a networking entitlementNeeds a Mac Runs in browser ~6 h
Part VIIISMP
  1. 20SMP: many vCPUs, many threadsNeeds a Mac Runs in browser ~6 h
Part IXFirmware and FreeBSD
  1. 21Firmware: a stricter guest (U-Boot, flash, ISV=0)Needs a Mac Runs in browser ~8 h
  2. 22FreeBSD through U-Boot EFINeeds a Mac ~6 h Optional chapter
Part XmacOS guests
  1. 23macOS guests, the high road: Virtualization.frameworkNeeds a Mac ~3 h
  2. 24macOS guests, the low road: vmapple and AVPBooter (capstone)Needs a Mac Runs in browser ~10 h Stretch goal
Part XIProductization
  1. 25Hardening: threat model, fuzzing and sandboxingNeeds a Mac Runs in browser ~6 h
  2. 26Snapshots: save, restore, resume (planned)Needs a Mac Runs in browser ~6 h Planned
  3. 27Debugging and performance: gdbstub, exit profiling (planned)Needs a Mac Runs in browser ~7 h Planned

Honesty note. The macOS-guest chapters are research chapters: they state what was and was not observed on a real Mac, and nothing more. Chapters marked "planned" are not written yet.