indicogniBuild a VMM

Reference

Reference card

The facts you look up while you work: the machine's memory map, macvmm's exit statuses, and where to find every term and primer.

The memory map

macvmm's board copies the memory map of QEMU's virt machine, so stock firmware and stock kernels run on it unmodified. One file, crates/vmm/src/arch/layout.rs, is the single source of truth: the device tree, the bus and the stage-2 mappings are all built from it. These are its base addresses (chapter 05 explains each one):

crates/vmm/src/arch/layout.rslines 103-122
pub const FLASH0_BASE: u64 = 0x0000_0000;pub const FLASH1_BASE: u64 = 0x0400_0000;pub const FLASH_BANK_SIZE: u64 = 0x0400_0000;/// Both flash banks: one read+execute `RomRegion` from `FLASH0_BASE` (chapter 21). Bank 1 must/// be readable because U-Boot `qemu_arm64` reads its environment memory-mapped from/// `CONFIG_ENV_ADDR = 0x0400_0000` before any driver probes.pub const FLASH_SIZE: u64 = 0x0800_0000;pub const GICD_BASE: u64 = 0x0800_0000;pub const GICD_SIZE: u64 = 0x0001_0000;pub const GIC_MSI_BASE: u64 = 0x0802_0000;pub const GICR_BASE: u64 = 0x080A_0000;pub const PL011_BASE: u64 = 0x0900_0000;pub const PL011_INTID: u32 = 33; // SPI 1pub const PL031_BASE: u64 = 0x0901_0000;pub const PL031_INTID: u32 = 34; // SPI 2pub const VIRTIO_MMIO_BASE: u64 = 0x0a00_0000;pub const TESTDEV_BASE: u64 = 0x0b00_0000;/// The never-populated hole that `guests/mmio-poke` stores into.pub const PROBE_HOLE_BASE: u64 = 0x0c00_0000;pub const RAM_BASE: u64 = 0x4000_0000;

And every region except RAM, with its kind and its interrupt where it has one:

crates/vmm/src/arch/layout.rslines 126-148
use RegionKind::*;/// Every region of the `virt` board except RAM, sorted by base (QEMU `hw/arm/virt.c`,/// `base_memmap[]`; one row per line).#[rustfmt::skip]pub const VIRT_REGIONS: &[Region] = &[    Region { name: "flash0",      base: FLASH0_BASE,      size: FLASH_BANK_SIZE, kind: Rom,       intid: None },    Region { name: "flash1",      base: FLASH1_BASE,      size: FLASH_BANK_SIZE, kind: Rom,       intid: None },    Region { name: "gicd",        base: GICD_BASE,        size: GICD_SIZE,       kind: GicDist,   intid: None },    Region { name: "gicv2-cpu",   base: 0x0801_0000,      size: 0x0001_0000,     kind: Reserved,  intid: None },    Region { name: "gic-v2m",     base: GIC_MSI_BASE,     size: 0x0001_0000,     kind: GicMsi,    intid: None },    Region { name: "gic-its",     base: 0x0808_0000,      size: 0x0002_0000,     kind: Reserved,  intid: None },    Region { name: "gicr",        base: GICR_BASE,        size: 0x00F6_0000,     kind: GicRedist, intid: None },    Region { name: "pl011",       base: PL011_BASE,       size: 0x1000,          kind: Mmio,      intid: Some(PL011_INTID) },    Region { name: "pl031",       base: PL031_BASE,       size: 0x1000,          kind: Mmio,      intid: Some(PL031_INTID) },    Region { name: "fw-cfg",      base: 0x0902_0000,      size: 0x18,            kind: Reserved,  intid: None },    Region { name: "pl061",       base: 0x0903_0000,      size: 0x1000,          kind: Reserved,  intid: Some(39) },    Region { name: "virtio-mmio", base: VIRTIO_MMIO_BASE, size: 0x4000,          kind: Mmio,      intid: None },    Region { name: "testdev",     base: TESTDEV_BASE,     size: 0x1000,          kind: Mmio,      intid: None },    Region { name: "probe-hole",  base: PROBE_HOLE_BASE,  size: 0x0200_0000,     kind: Reserved,  intid: None },    Region { name: "pcie-mmio",   base: 0x1000_0000,      size: 0x2eff_0000,     kind: Reserved,  intid: None },    Region { name: "pcie-pio",    base: 0x3eff_0000,      size: 0x0001_0000,     kind: Reserved,  intid: None },    Region { name: "pcie-ecam",   base: 0x3f00_0000,      size: 0x0100_0000,     kind: Reserved,  intid: None },];

Exit statuses

When macvmm stops, the reason becomes the process's exit status, so a script can tell a clean power-off from a timeout or a crash (chapter 03 meets the first ones):

crates/vmm/src/control.rslines 140-156
impl StopReason {    /// The process exit code: 0 clean power-off, 1 VMM or host failure, 2 bad configuration,    /// 3 fatal guest error, 4 reset, 5 timeout, 6 debug exit with a nonzero code, 130 user quit.    pub fn exit_code(&self) -> i32 {        match self {            StopReason::PowerOff | StopReason::DebugExit(0) => 0,            StopReason::Vmm(e) => e.exit_code(),            StopReason::GuestFatal(_) => 3,            StopReason::Reset => 4,            StopReason::Timeout => 5,            StopReason::DebugExit(_) => 6,            StopReason::UserQuit => 130,        }    }}

Words, primers and labs

  • The glossary defines every course term in one line and links the chapter or primer that teaches it.
  • The primers teach what the course uses but does not build: calling conventions, file formats, page tables, firmware.
  • The labs run in any browser and are also embedded in their chapters.

Primary sources

  • Arm Architecture Reference Manual for A-profile (DDI 0487): exception levels, ESR_EL2, stage-2 translation. The reading-arm-specs primer shows how to find your way in it.
  • Virtual I/O Device (virtio) Version 1.2, OASIS: the transport and the split virtqueue.
  • Devicetree Specification, release 0.4: the flattened device tree format.
  • Linux Documentation/arch/arm64/booting.rst: what a kernel expects when it starts; see the arm64 boot protocol primer.
  • Apple's Hypervisor.framework headers, in your SDK under System/Library/Frameworks/Hypervisor.framework/Headers/.