Chapter 24 · Part X
macOS guests, the low road: vmapple and AVPBooter (capstone)
Course progress: chapter 24 is 25 of the 26 chapters written so far (numbering starts at 00)
Warm-up: three questions from earlier chapters
Answer each one in your head or on paper before you open its answer. They change on each visit.
From chapter 21: Firmware: a stricter guest (U-Boot, flash, ISV=0)
U-Boot's word
0xa9010d22faults with ISV = 0 and the exit reports IPA0x12c678. Which accesses must the VMM perform, at which addresses, and which registers change afterwards?Show answer
Bits 31:30 are
10(8-byte elements), mode10(plain offset), L = 0 (store), imm7 = 2 (times 8 = 16), Rt2 = 3, Rn = 9, Rt = 2:stp x2, x3, [x9, #16]. Two 8-byte stores,x2at the exit IPA0x12c678andx3at0x12c680(exit IPA plus the element size). No register changes except the PC, which advances by 4: offset mode has no writeback. In flash, both stores are ignored.From chapter 21: Firmware: a stricter guest (U-Boot, flash, ISV=0)
A guest's
TCR_EL1saysT0SZ = 25with 4 KiB pages. How many address bits does a walk resolve, at which levels, and which level-1 entry does the virtual address0x8008_1828use?Show answer
64 - 25 = 39 bits. A 4 KiB page leaves 12 offset bits, and each level resolves 9 bits, so 27 bits need three levels: 1, 2 and 3. The level-1 index is VA bits 38:30,
0x80081828 >> 30 = 2.From chapter 21: Firmware: a stricter guest (U-Boot, flash, ISV=0)
Why is our stage-1 walker a loop of at most four table reads instead of "follow table descriptors until you reach a page"?
Show answer
The tables are guest memory, written by the guest, so they are hostile input. A descriptor can point at its own table, or tables can form a cycle; "until a page" would never end, and recursion would exhaust the stack. The architecture never needs more than four levels (0 to 3), so the walk stops after four reads whatever the tables say, and a table outside RAM is a refusal, not a read.
From chapter 21: Firmware: a stricter guest (U-Boot, flash, ISV=0)
ldp x0, x1, [x2]faults with ISV = 0 at exit IPA0x0b00_0ff8, the last 8 bytes of the 4 KiB test device window. What does the VMM do, and what does the guest see?Show answer
The second element would be at
0x0b00_1000, outside the test device's window, so the plan is refused before any access: a pair is emulated only inside one device. The VMM injects a synchronous external abort: the guest takes a data abort at its own level (EC0x25from EL1), DFSC0x10,FAR_EL1= the faulting virtual address,x0andx1unchanged, and the PC not advanced.From chapter 21: Firmware: a stricter guest (U-Boot, flash, ISV=0)
Give the PC,
x0and what RAM holds at the first instruction for a firmware boot and for a direct Linux boot, with 512 MiB of RAM on ourvirtmachine.Show answer
Firmware boot:
PC = 0x0(the firmware's first word in flash),x0 = 0x4000_0000, and RAM holds only the DTB, at its start. Direct boot:PC = 0x4020_0000(the kernel),x0 = 0x4000_0000, and RAM holds the DTB, the kernel and the initramfs. Both start at EL1h with interrupts masked (0x3c5).From chapter 21: Firmware: a stricter guest (U-Boot, flash, ISV=0)
Why is the firmware ROM kept out of the guest-memory API, and how does the ISV = 0 path still read U-Boot's instructions from it?
Show answer
Everything that writes guest memory on the guest's behalf (virtio devices doing DMA, loaders) goes through that API; keeping the ROM out of it means no guest request can ever change the firmware. The ISV = 0 path gets a separate, read-only hook: when the PC's IPA is not RAM, it asks the ROM for one aligned, bounds-checked 4-byte word.
From chapter 21: Firmware: a stricter guest (U-Boot, flash, ISV=0)
At the U-Boot prompt on the reference, you type
mw.l 0x4000000 0xdeadbeef, thenmd.l 0x4000000 1. What doesmdprint, and what appears on standard error?Show answer
04000000: 00000000. The store was a data abort on flash bank 1, answered by the write-ignore flash device, which logsflash: ignored 4-byte write of 0xdeadbeef at offset 0x0 (flash is read-only, write 1 to this bank). The offset is 0 because each bank has its own device.From chapter 21: Firmware: a stricter guest (U-Boot, flash, ISV=0)
The ISV = 0 path has decoded
str x1, [x2], and its own walk ofx2gives an IPA different from the exit's. Why not perform the store at the walked address?Show answer
The exit's IPA is where the guest really faulted, and the hardware checked permissions only for that access. Our walk reads the tables in memory after the fault, while the hardware used its TLB: another vCPU may have rewritten the instruction or the tables since, or this vCPU may have changed a descriptor without a
TLBI, so the walk can describe a different page the guest may not even be allowed to touch. The decoded address is only a cross-check: any disagreement is refused with an injected abort.From chapter 21: Firmware: a stricter guest (U-Boot, flash, ISV=0)
The VMM emulates
ldp x3, x4, [x5], #16on a device. In what order do the accesses and register writes happen, and what if the second read fails?Show answer
Both reads happen first, on the exit IPA and exit IPA plus 8. Only then are
x3andx4written, thenx5gets its old value plus 16, then the PC advances by 4. If either read fails, no register changes at all (the reference then applies the unhandled-MMIO policy, by default a fatal stop). For pairs this rarely arises, because the plan already refused any pair not wholly inside one device window.From chapter 12: Why an interrupt controller, and why in the kernel
A device tree node says
interrupts = <0 5 4>under a GICv3. Which INTID will the device's interrupt arrive as, and how is it triggered?Show answer
INTID 37. The first cell 0 means SPI (shared peripheral interrupt), and SPI n is INTID 32 + n, so SPI 5 is INTID 37. The third cell 4 means level-sensitive, active high.
From chapter 12: Why an interrupt controller, and why in the kernel
The
/timernode lists<1 11 4>for the virtual timer. Which INTID is that, and why is it not an SPI?Show answer
INTID 27. The first cell 1 means PPI (private peripheral interrupt), and PPI n is INTID 16 + n. Each CPU has its own timer, so its interrupt is private to that CPU and lives in that CPU's redistributor, not in the shared distributor.
From chapter 12: Why an interrupt controller, and why in the kernel
An interrupt handler reads
ICC_IAR1_EL1and gets 1023. What happened, and should it writeICC_EOIR1_EL1?Show answer
1023 is the spurious INTID: nothing was pending by the time the CPU asked (another CPU took it, or the line dropped). There is nothing to handle and nothing was made active, so the handler returns without an end-of-interrupt write.
From chapter 12: Why an interrupt controller, and why in the kernel
Your VMM calls
hv_gic_createright after creating vCPU 0. What comes back, and where must the call go instead?Show answer
An error,
HV_BUSYon our Mac (beforehv_vm_createit isHV_NO_DEVICE). The GIC must be created after the VM and before any vCPU, because each vCPU gets its own redistributor and CPU-interface state when it is created.From chapter 12: Why an interrupt controller, and why in the kernel
A UART model raises its level line when a byte arrives but never lowers it. The guest's handler reads the byte and writes EOI. What does the guest see next?
Show answer
The same interrupt again, at once, forever: at EOI the GIC sees the line still high and makes it pending again. The guest makes no progress (an interrupt storm). The device must lower the line when the cause is gone: the FIFO drained, the cause cleared in
ICR, or the source masked inIMSC.From chapter 12: Why an interrupt controller, and why in the kernel
GicSpi::newis asked to wire INTID 27 to a device. What does it answer, and why is refusing at machine build time better than lettinghv_gic_set_spifail later?Show answer
It refuses with
NotAnSpi: 27 is a PPI (the virtual timer), outside the SPI range 32..1020. Refusing at build time turns a wiring bug into a start-up error with a message; a later failure would happen on a path the guest triggers (every UART access) and could only be logged and ignored.From chapter 12: Why an interrupt controller, and why in the kernel
A 2-vCPU machine puts its redistributors at
0x080A_0000. How much space must the GIC node's secondregentry cover, and where does vCPU 1's redistributor start?Show answer
Two frames of 128 KiB (
0x2_0000), so0x4_0000bytes. The second frame starts at0x080C_0000; the frames follow the order in which the vCPUs were created, so the guest finds its own by reading each frame's affinity.From chapter 12: Why an interrupt controller, and why in the kernel
The chapter 11 timer guest made 10 VTIMER and 10 WFI exits for ten 100 ms sleeps. How many of each does the same workload make with the in-kernel GIC, and why?
Show answer
Zero of each. The kernel delivers the virtual timer's interrupt through its own GIC and handles WFI by parking the vCPU until an interrupt is pending, so neither event needs our VMM. What remains are the exits our devices cause, such as UART register accesses.
From chapter 12: Why an interrupt controller, and why in the kernel
A key arrives while the guest's only vCPU sleeps in WFI under the in-kernel GIC. Which thread raises the interrupt, and what does it call?
Show answer
The stdin reader thread: it pushes the byte into the UART model, which recomputes its level and calls
hv_gic_set_spi(33, true)through itsIrqLine. That call works from any thread and wakes the vCPU inside the kernel; no kick and no VM exit is needed.From chapter 05: Two stages, one map: holes in stage 2 on purpose
A guest stores a byte to
0x0900_0000, where its UART should be, but your VMM has mapped an ordinary page of RAM there. What does the guest see, and what does your VMM see?Show answer
The guest sees a store that worked: the byte sits in RAM, and a load from the same address returns it. Nothing is printed. Your VMM sees nothing at all: a mapped address never causes a VM exit, so the VMM never learns the store happened. A device register needs a stage-2 hole, so each access stops the guest.
From chapter 05: Two stages, one map: holes in stage 2 on purpose
With its MMU on, a guest stores to the virtual address
0x0b10_0000, which its own page tables translate to0x0b00_0000. Nothing is mapped at0x0b00_0000in stage 2. Which address does the VM exit report, and why that one?Show answer
0x0b00_0000, the IPA. Stage 2 is the stage that failed, and by then the hardware had already translated the virtual address through the guest's stage 1, so it records the IPA's page number (inHPFAR_EL2, with the offset fromFAR_EL2) and the VMM never has to read the guest's tables. The virtual address means something only inside the guest's current address space.From chapter 05: Two stages, one map: holes in stage 2 on purpose
A data-abort exit has the syndrome
0x93890046. Is it a load or a store, how wide, and what kind of fault?Show answer
The class is
0x93890046 >> 26 = 0x24, a data abort from the guest. Bit 6 (WnR) is 1, so a write. Bits 23:22 (SAS) are0b10, so1 << 2 = 4bytes. The low six bits (DFSC) are0x06: a translation fault at level 2, meaning stage 2 found no entry for the address.From chapter 05: Two stages, one map: holes in stage 2 on purpose
Your machine has 512 MiB of RAM from
0x4000_0000, so RAM ends at0x6000_0000. How many IPA bits does the address space need, and what doesipa_bits_needed(0x6000_0000)return?Show answer
31 bits would be enough:
1 << 30 = 0x4000_0000is too small,1 << 31 = 0x8000_0000covers0x6000_0000. The function returns 36, because it never asks for less than HVF's default size, so a small machine gets the same VM it would get without the setting.From chapter 05: Two stages, one map: holes in stage 2 on purpose
Where does virtio slot 5 live, and which INTID does it use?
Show answer
At
0x0a00_0000 + 5 × 0x200 = 0x0a00_0a00, with INTID48 + 5 = 53. QEMU'svirtboard wires slot i to shared interrupt line (SPI)16 + i, and SPIs are numbered from INTID 32, so slot i is INTID32 + 16 + i.From chapter 05: Two stages, one map: holes in stage 2 on purpose
A layout puts a trapped device window of
0x200bytes at0x0a00_0200and RAM at0x4000_0000. Which of the two must be 16 KiB-aligned, and why only that one?Show answer
Only RAM. A mapped region goes through
hv_vm_map, which works in whole 16 KiB host pages. A trapped window is never mapped: it is the absence of a mapping, so it can have any size and alignment.From chapter 05: Two stages, one map: holes in stage 2 on purpose
A guest stores to
0x10_0000_0000(1 << 36) in a VM with a 36-bit IPA space. What does the exit's DFSC say?Show answer
0x04: a translation fault at level 0. The address is outside the input range of the stage-2 tables, so the hardware does not look it up at all. We checked this on a real Mac; it is not an address-size fault.From chapter 05: Two stages, one map: holes in stage 2 on purpose
Your VMM hard-codes a 31-bit IPA space and you start a guest with
--mem 2G. What happens, and before or after the guest runs its first instruction?Show answer
Before: RAM from
0x4000_0000would end at0xC000_0000, past1 << 31 = 0x8000_0000, sohv_vm_maprefuses the RAM withHV_BAD_ARGUMENTand the VM never starts. The width of the map has to cover the layout, which is whatipa_bits_neededcomputes.From chapter 05: Two stages, one map: holes in stage 2 on purpose
Without a second translation stage, how would a VMM keep a guest from reaching host memory it does not own, and what would it cost?
Show answer
With shadow page tables: the VMM keeps its own tables that map guest virtual addresses straight to host memory, write-protects the guest's tables, and updates the shadow copy on every trapped write. Every guest page-table write becomes a VM exit, which is why hardware added stage 2.
Concepts you'll need
Chapters before this one: chapter 21, Firmware: a stricter guest (U-Boot, flash, ISV=0); chapter 23, macOS guests, the high road: Virtualization.framework.
- Core, taught here: the vmapple board, a second memory map beside
virt; the unknown-MMIO logger as a measuring instrument; the device-access trace, summarised by counts only; observed, inferred and unknown; a controlled-variable experiment on an undocumented machine; "load from the host, never copy"; the design record. - Core, from earlier: the exit trace,
--timeoutand--stats(chapters 03 and 11); the unhandled MMIO (memory-mapped I/O) policy (chapter 05); MMIO decode and ISV (instruction syndrome valid) (chapter 07); PSCI (power state coordination interface) and system reset (chapter 08); the in-kernel GICv3 and WFI (wait for interrupt) (chapter 12); firmware in a ROM, the ISV=0 path and architecture decision records (chapter 21); Virtualization.framework, its XPC helper and its entitlement, and a macOS bundle's machine identifier (chapter 23). - Primers (review):
codesign-entitlements(restricted entitlements);smccc(PSCI calls in a trace);reading-arm-specs(RAZ/WI). - Pointers: QEMU's
hw/vmapple/sources and vmapple documentation atv10.0.0; ParavirtualizedGraphics.framework; Apple's boot chain, in an Aside; the macOS software licence agreement, cited, never legal advice; the QEMU mailing-list patch series that reports the private CPU mode. - Forward definitions: none. The few new names (cfg, bdif, pvpanic, ECID (exclusive chip ID), iBoot, the private CPU mode) are defined where they first appear.
On your Mac, inside Virtualization.framework, sits a file of 335,096 bytes called AVPBooter.vmapple2.bin: AVPBooter, the boot ROM (read-only memory) a macOS virtual machine runs first. Point the virtual machine monitor (VMM) you built at it, and within half a millisecond it makes 34 accesses to device registers we never built. Then, for the remaining twenty seconds, it makes no VM exit at all, while one of your CPU cores runs flat out.
Is the ROM waiting for us to answer something, or has it given up? And how would you find out without reading a single one of its instructions, which, as you will see, you may not do?
Every row of chapter 00's problem ledger is closed for Linux and FreeBSD. This chapter goes beyond the ledger: real boot chains are stricter guests, and this one has no published contract at all. The deliverable is an honest trace and a design record, not a boot: macOS does not boot in macvmm, and nothing on this page says it does.
Objectives: by the end you can
- (Sitting A) Summarise, citing QEMU's
hw/vmapple/atv10.0.0, how QEMU's vmapple machine boots macOS on Hypervisor.framework: AVPBooter loaded from the host, its cfg, bdif, AES and graphics devices, and disks from a Virtualization.framework install. - (Sitting A) Sort claims about the macOS boot chain into observed, inferred and unknown, and state the rule that keeps our tracing within the licence.
- (Sitting B) Build macvmm with
experimental-vmapple, run AVPBooter, and summarise its device-access trace with counts only. - (Sitting B) Predict, then measure, how many distinct addresses AVPBooter touches when unknown reads return 0 and when they return all ones, explain why neither trace is "right", and narrow the experiment to one register of the next device the trace asks for (cfg).
- (Sitting B) Diagnose from the trace and
--statswhether stalled firmware is polling, waiting for an interrupt, or running without exits; then write a design record with stop criteria set in advance.
Before you start. From the repository root, run scripts/learner start 24 --level open; a capstone has no scaffold, so this copies only the journal to learner/journal/24.md. Sitting A is reading (about 3 hours); sitting B is at your Mac (7 hours or more).
Two roads to the same guest
Chapter 23 took the high road: Virtualization.framework (VZ) is built to boot macOS from a configuration you fill in (chapter 23's vz-mac does that, with an optional install), because Apple wrote the whole machine, including a helper process with a restricted entitlement, one only Apple's own code may hold. The low road is ours: an empty machine, every device by hand. The inventory you wrote at the end of chapter 23 is the list of what that road must supply; this chapter checks its first rows against a real trace.
Somebody has walked it: QEMU, the open-source machine emulator, has a board called vmapple that boots macOS on Hypervisor.framework, shipped in QEMU 10.0 in 2025. Its documentation is blunt: "newer versions than 12.x are currently NOT supported on the guest side".
Its workflow has three steps. First, install macOS 12 with a VZ-based tool and take the machine's identity number, the ECID: a 64-bit number held inside the bundle's machine identifier from chapter 23. QEMU needs it because its board hands it to the ROM in the cfg block below. QEMU's documentation never says "ECID": it calls the same value uuid, passes it as -M vmapple,uuid=, and pulls it out of the machine identifier with its script contrib/vmapple/uuid.sh. vz-mac has a subcommand that prints it, tools/vz-mac/run.sh ecid --bundle .cache/macvmm/macos-vm, which works only if you installed macOS in chapter 23. Second, strip the first 0x4000 bytes of the bundle's auxiliary storage image: VZ keeps 16 KiB of its own metadata at the front, which QEMU does not expect (vz-mac's trim-aux subcommand does this). Third, start QEMU with -bios pointing at AVPBooter.vmapple2.bin. Even QEMU needs Virtualization.framework to install macOS; only the later boots run on QEMU's own board.
QEMU is licensed under the GNU General Public License (GPL), so we read it for facts (addresses, sizes, field lists), never copying its code or prose. They come from hw/vmapple/vmapple.c, cfg.c, bdif.c and docs/system/arm/vmapple.rst at the tag v10.0.0, checked on 2026-11-20.
What the machine is, according to QEMU
QEMU's board is a table of regions, like our virt map from chapter 05, and none of it is where virt puts things. GIC is the Generic Interrupt Controller; UART, the serial port (universal asynchronous receiver-transmitter); SPI, a shared peripheral interrupt; RTC, a real-time clock; GPIO, general-purpose input/output pins:
| Region | Base | Size | What it is |
|---|---|---|---|
| firmware | 0x0010_0000 | 1 MiB | AVPBooter |
| cfg | 0x0040_0000 | 64 KiB | configuration block |
| GIC distributor | 0x1000_0000 | 64 KiB | interrupt controller (chapter 12) |
| GIC redistributors | 0x1001_0000 | 4 MiB | one frame per CPU |
| PL011 UART | 0x2001_0000 | 64 KiB | serial console, SPI 1 |
| PL031 RTC | 0x2005_0000 | 4 KiB | clock, SPI 2 |
| PL061 GPIO | 0x2006_0000 | 4 KiB | power button, SPI 5 |
| pvpanic | 0x2007_0000 | 2 bytes | written by a panicking guest |
| bdif | 0x3000_0000 | 2 MiB | "backdoor" disk interface |
| apple-gfx, IOSurface mapper | 0x3020_0000, 0x3021_0000 | 64 KiB each | graphics bridged to the host (an IOSurface is a macOS shared graphics buffer) |
| AES engine | 0x3022_0000, 0x3023_0000 | 16 KiB each | AES (Advanced Encryption Standard) cryptography |
| PCIe ECAM, MMIO window | 0x4000_0000, 0x5000_0000 | 256 MiB, about 512 MiB | PCI Express (PCIe): ECAM (Enhanced Configuration Access Mechanism, chapter 23's configuration window), then devices |
| RAM | 0x7000_0000 | as configured |
QEMU's vmapple map at v10.0.0. Notice 0x4000_0000: RAM on our virt board, PCI Express configuration space here.
So vmapple is a second board with its own map, not a variant of virt. The CPU side is familiar (chapters 08 and 20): PSCI over hvc, secondaries powered off. QEMU passes no device tree; that a later stage builds one for the kernel is inferred from how physical Macs boot, not shown.
The work is in the devices. cfg is a page the booter reads to learn about its machine: a version (2), the CPU count, the ECID, the RAM size, two "run the installer" flags, a random seed, network addresses, a serial "1234", a model "VM0001", a chip name "Apple M1 (Virtual)", and fields QEMU's own source names unk1 to unk10: its authors did not know every field either.
bdif (backdoor block interface) is how the booter reads disks before any driver exists. The guest writes, to a command register, the guest-physical address of a three-entry descriptor: where the sector number is, where to put the data, where to write a status byte. The device copies 512-byte sectors of the root or auxiliary disk into guest memory; QEMU's version only reads.
Security
In bdif the guest controls three addresses, a sector number and a length, all in memory a second virtual CPU (vCPU) can rewrite while the device works: chapter 16's virtqueue lesson with no ring around it. Copy the descriptor once, check every address with checked_add, cap the length, and write nothing until all of it checks out.
The rest arrives once a kernel runs: the AES engine, which the guest asks to encrypt or decrypt buffers (its built-in keys are Apple's; QEMU uses placeholders), PCI Express with virtio devices, and apple-gfx, which hands two register windows to ParavirtualizedGraphics.framework, Apple's library that draws a guest's display on the host with Metal, Apple's programming interface for the graphics processor (GPU).
vmapple map
Browse the vmapple board's memory map and device inventory, each row cited and tagged observed, inferred or unknown, and switch evidence off to see which claims rest on it.
Runs in browserOpen full page: vmapple mapLoading the lab. If nothing appears, your browser may have JavaScript turned off or the lab failed to load.
If the lab does not load, here is what it shows when it opens: the map above with each row tagged by its column (defined in the next section) and by what backs it, from QEMU's sources and the first probe of sitting B. The lab keeps sitting B's second run hidden until you ask for it.
row column seen in the reference runs source of the rowavpbooter 0x100000 observed first exit at pc=0x103478 QEMU vmapple.c, our runcfg 0x400000 observed 33 accesses, all unmodelled QEMU vmapple.c, cfg.c, our rungicd/gicr 0x10000000 observed (accepted) hv_gic_create accepts them QEMU vmapple.c, our runpl011 0x20010000 inferred no access seen QEMU vmapple.cpvpanic 0x20070000 observed 1 access QEMU vmapple.c, our runbdif 0x30000000 inferred no access seen QEMU vmapple.c, bdif.cpcie, aes, apple-gfx unknown never reached QEMU vmapple.cObserved, inferred, unknown
From here on every sentence you write about this machine goes into one of three columns. Observed: you ran it on your Mac and have the output. Inferred: it follows from observations plus a public source you can name. Unknown: nobody has shown it, or the only way to show it is closed to you. The skill is refusing to let a plausible sentence drift from the third column into the first.
Aside
Apple's Platform Security Guide describes how a physical Apple-silicon Mac boots: a boot ROM, then iBoot (Apple's boot loader, the stages after the boot ROM), then the kernelcache (the macOS kernel linked with its drivers), each checking the next one's signature. The guide is about hardware and never mentions AVPBooter: use it to generate hypotheses, and keep them inferred or unknown until a trace of yours moves them.
Here are the first claims, sorted:
| Claim | Column | Why |
|---|---|---|
AVPBooter.vmapple2.bin is 335,096 bytes | observed | ls -l |
| the CPU starts at its first byte, at exception level 1 (EL1), with the memory management unit (MMU) off | inferred | QEMU's board does this; our first exit lies inside the ROM |
| its first device access is to cfg | observed, on our board | the first probe below |
| it reads disks through bdif | inferred | QEMU documents it; sitting B tests whether our runs reach it |
| later stages are iBoot-family loaders that load a kernelcache | unknown | physical Macs suggest it; nothing here shows it |
| a modern macOS guest needs a private CPU mode (a CPU setting only Apple's own helper process may switch on) | observed in part, inferred in part | refused to us: observed by sitting B's probe; needed by guests: inferred from a named QEMU patch series, sitting B |
The line you do not cross
AVPBooter is Apple software, licensed to you with macOS. Read the licence at /System/Library/CoreServices/Setup Assistant.app/Contents/Resources/en.lproj/OSXSoftwareLicense.rtf; nothing here is legal advice. Section 2B(iii) permits up to two additional copies of macOS in virtual machines on each Apple computer you own or control that already runs it, for listed purposes. Section 2K says Apple boot ROM code and firmware may not be copied, modified or redistributed. Section 2N forbids copying, decompiling, reverse engineering or disassembling the software.
A VMM cannot avoid observing the code it runs: every exit shows a program counter (PC), an address, a size and a value. So macvmm draws its line:
- Loaded in place. The ROM is read from the system path at run time; no code path writes it to a file.
- Only device accesses, in two instruments. The logger prints the device-access trace: each access to an address with no device, as
(pc, ipa, size, direction, value), at most 256 per boot (the IPA, intermediate physical address, is chapter 05's guest-physical address). The optional exit trace (--trace exits:FILE) has one line per exit with the same fields, capped only by file size; it is your private file under.cache/. - No disassembly or decompilation of the ROM's instructions.
- No memory dumps. Once the ROM has copied itself or its data into guest RAM, a dump of that RAM is a copy of the ROM by another route.
- Not published: the per-access lines, the values written, guesses about what the code is for. This page shows counts and how runs ended; your trace stays in your workspace.
The two-copy limit becomes code too, as sitting B shows. Limiting concurrent runs to two is our conservative reading of section 2B(iii), not legal advice.
Before you stop, set yourself the sitting's exercise. Read, at tag v10.0.0, the memory map in hw/vmapple/vmapple.c, the field list in hw/vmapple/cfg.c and docs/system/arm/vmapple.rst. Start a draft of your design record (Your turn, at the end of the page) with five claims of your own about the machine, each with its column and its source. The Spec hunt's first item is a good sixth.
Good place to stop. Sitting B needs your Mac, about 7 hours, and a terminal in the repository.
Building the board
The vmapple board is behind a cargo feature, experimental-vmapple, off by default; a default build refuses it before creating anything:
scripts/sign-and-run.sh target/debug/macvmm run --machine vmapple --bios /System/Library/Frameworks/Virtualization.framework/Versions/A/Resources/AVPBooter.vmapple2.binmacvmm: --machine vmapple: built without experimental-vmapple (rebuild with `--features experimental-vmapple`)usage: macvmm run [options]options: --mem SIZE guest RAM, e.g. 64M, 2G (default 512M; 64M..255G, a multiple of 2M) --cpus N number of vCPUs, 1..64 and at most what this Mac allows (default 1); vCPU 0 boots, the others wait for PSCI CPU_ON --kernel FILE an ELF test guest or an arm64 Linux Image (detected from its bytes; an EFI zboot vmlinuz is refused: run scripts/fetch.sh linux) --initrd FILE an initramfs for an Image kernel, placed above the kernel --cmdline STRING the kernel command line for an Image (at most 2047 bytes; default console=ttyAMA0 earlycon=pl011,<the PL011 address>) --machine BOARD virt (default) or vmapple (experimental: AVPBooter's first device accesses, needs a build with --features experimental-vmapple; it does not boot macOS; at most two per user, an advisory lock in $HOME/.cache/macvmm/vmapple-slots) --bios FILE a firmware ROM image, at most 64 MiB (virt: U-Boot in flash bank 0, entered at 0x0 instead of --kernel; vmapple: default the system AVPBooter, read in place and never copied) --dry-run print the boot plan, memory map and device-tree summary, then exit 0 without creating a VM (needs no entitlement) --raw FILE@0xADDR load FILE's bytes at guest-physical ADDR (repeatable); the first one is the entry point when there is no --kernel --timeout SECS stop the guest after SECS seconds (exit code 5) --unhandled-mmio POLICY fatal (default: exit code 3) or log (read as zero, ignore writes) --trace exits:FILE[:CATS][,max=SIZE] write one JSON line per VM exit to FILE (created 0600; never a symlink). CATS: comma-separated mmio,hvc,sysreg,psci,cancel,all (default all). SIZE caps the file (default 1G) --testdev map the 512-register test device at 0x0b000000 --disk FILE[,ro] add a virtio-blk disk backed by the raw image FILE (repeatable; the first is /dev/vda). ,ro opens it read-only. The image is locked (flock) while macvmm runs; a locked image is refused --rng add a virtio-rng device fed by the host CSPRNG (getentropy) --net unixgram:LOCAL,peer=REMOTE[,mac=XX:XX:XX:XX:XX:XX] add a virtio-net NIC whose wire is a Unix datagram socket bound at LOCAL; frames go to, and are accepted only from, the socket at REMOTE (another macvmm's LOCAL). Both must be in a directory you own that is not group- or world-writable. A stale socket of yours at LOCAL is replaced; anything else there is refused. Repeatable (at most 4). Default MAC 02:6d:76 plus 3 random bytes. unixgram:LOCAL,learn instead locks the peer to the first sender (logged). No host network access and no entitlement --on-reset ACTION reboot (default: rebuild the VM in-process) or exit (exit code 4) when the guest calls PSCI SYSTEM_RESET --debug-hvc, --no-debug-hvc force the macvmm debug hypercalls on or off (default: on for ELF and --raw test guests, off for kernels and firmware) --dtb-out FILE write the generated device tree to FILE (created 0600; never a symlink), with its rng-seed and kaslr-seed zeroed --serial SINK[,strict|,raw][,max=SIZE] where the PL011 console goes: stdio (default; also gets stdin, with Ctrl-A x quit, Ctrl-A t trace ring, Ctrl-A s stats), file:FILE (created 0600, never a symlink, capped at SIZE, default 1G) or none. Guest output is filtered for terminal safety; strict shows every control visibly, raw disables the filter (not recommended) --console SINK[,strict|,raw][,max=SIZE] add a virtio-console (Linux /dev/hvc0) whose output goes to stdio or file:FILE, filtered like --serial. At most one of --serial and --console may be stdio, and that one gets stdin: --console stdio needs --serial file:FILE or --serial none --stats print the console I/O counters, the exit counts, the vCPU exec and WFI time and the host CPU time when the VM stops --log LEVEL error|warn|info|debug|trace (default warn; also MACVMM_LOG) --no-sandbox run unconfined. By default, after opening every file, macvmm confines itself: no file opened by path, no network, no new process (macOS sandbox, threat model SBX-2), and exits 1 if the sandbox cannot be applied. Needed for --net ...,learn --sandbox[=best-effort] --sandbox is the default and changes nothing; best-effort warns and runs unconfined if the sandbox cannot be applied. Not together with --no-sandboxExit code 2 is a usage error; no virtual machine was created.
Now ask a feature build for the boot plan; cargo run builds it, and --dry-run creates no virtual machine. This replaces target/debug/macvmm: run a plain cargo build -q -p macvmm before returning to other chapters.
cargo run -q -p macvmm --features experimental-vmapple -- run --machine vmapple --bios /System/Library/Frameworks/Virtualization.framework/Versions/A/Resources/AVPBooter.vmapple2.bin --mem 4G --unhandled-mmio log --dry-runcargo run -q -p macvmm --features experimental-vmapple -- run --machine vmapple --bios /System/Library/Frameworks/Virtualization.framework/Versions/A/Resources/AVPBooter.vmapple2.bin --mem 4G --unhandled-mmio log --dry-runmacvmm vmapple board (dry run, no VM created; experimental, does not boot macOS)entry pc=0x100000 x0=0 cpsr=0x3c5 (EL1h, MMU off, no DTB)rom 335096 bytes of --bios in a 1048576-byte read+execute ROMmemory map (VmApple): 0x00100000..0x00200000 avpbooter rom 0x00400000..0x00410000 cfg unknown-MMIO logger 0x10000000..0x10010000 gicd in-kernel GIC 0x10010000..0x10410000 gicr in-kernel GIC (one 128 KiB frame; the rest: unknown-MMIO logger) 0x20010000..0x20020000 pl011 pl011 0x20050000..0x20051000 pl031 unknown-MMIO logger 0x20060000..0x20061000 pl061 unknown-MMIO logger 0x20070000..0x20070002 pvpanic unknown-MMIO logger 0x30000000..0x30200000 bdif unknown-MMIO logger 0x70000000..0x170000000 ram ramunknown MMIO: logged, read as zero (cap 256); debug hypercalls: offBesides RAM, four rows have a model behind them: the ROM, the GIC distributor, the first 128 KiB redistributor frame and the PL011. Everything else goes to the unknown-MMIO logger. --bios defaults to the system path:
/// Where macOS keeps the vmapple boot ROM (Virtualization.framework, macOS 12 and later). The/// `--machine vmapple` default for `--bios`. Read in place; never copied (module docs).pub const AVPBOOTER_VMAPPLE2: &str = "/System/Library/Frameworks/Virtualization.framework/Versions/A/Resources/AVPBooter.vmapple2.bin";The map follows QEMU's up to bdif; the graphics, AES and PCI Express rows are left out, so an access there is logged as a bare address. A Reserved row only names an address for the logger ("cfg"). The comments on ROM_BASE and BDIF_BASE state as fact what our claims table keeps inferred and unknown; read them as QEMU's documentation, not our observation:
/// AVPBooter's load and entry address. The CPU starts here, at EL1, with the MMU off.pub const ROM_BASE: u64 = 0x0010_0000;/// The ROM window: 1 MiB (AVPBooter.vmapple2.bin is about 335 KB on macOS 27.2).pub const ROM_SIZE: u64 = 0x0010_0000;/// The configuration block VZ fills in (ECID, serial, RAM size, ...): not modelled yet.pub const CFG_BASE: u64 = 0x0040_0000;pub const GICD_BASE: u64 = 0x1000_0000;pub const GICD_SIZE: u64 = 0x0001_0000;pub const GICR_BASE: u64 = 0x1001_0000;/// Room for the redistributor frames; HVF implements one 128 KiB frame per vCPU at the base.pub const GICR_WINDOW: u64 = 0x0040_0000;pub const PL011_BASE: u64 = 0x2001_0000;/// SPI 1 → INTID 33, as on `virt`.pub const PL011_INTID: u32 = 33;pub const PL031_BASE: u64 = 0x2005_0000;pub const PL061_BASE: u64 = 0x2006_0000;pub const PVPANIC_BASE: u64 = 0x2007_0000;/// The "backdoor" block interface iBoot reads its disks through (not modelled yet).pub const BDIF_BASE: u64 = 0x3000_0000;/// RAM. AVPBooter is told nothing about its size here (no DTB, no cfg block).pub const RAM_BASE: u64 = 0x7000_0000;use RegionKind::*;/// Every non-RAM row of the vmapple board, sorted by base.#[rustfmt::skip]pub const VMAPPLE_REGIONS: &[Region] = &[ Region { name: "avpbooter", base: ROM_BASE, size: ROM_SIZE, kind: Rom, intid: None }, Region { name: "cfg", base: CFG_BASE, size: 0x0001_0000, kind: Reserved, intid: None }, Region { name: "gicd", base: GICD_BASE, size: GICD_SIZE, kind: GicDist, intid: None }, Region { name: "gicr", base: GICR_BASE, size: GICR_WINDOW, kind: GicRedist, intid: None }, Region { name: "pl011", base: PL011_BASE, size: 0x0001_0000, kind: Mmio, intid: Some(PL011_INTID) }, Region { name: "pl031", base: PL031_BASE, size: 0x1000, kind: Reserved, intid: Some(34) }, Region { name: "pl061", base: PL061_BASE, size: 0x1000, kind: Reserved, intid: Some(37) }, Region { name: "pvpanic", base: PVPANIC_BASE, size: 0x2, kind: Reserved, intid: None }, Region { name: "bdif", base: BDIF_BASE, size: 0x0020_0000, kind: Reserved, intid: None },];The CPU starts like a real core leaving reset: PC at the ROM's first byte, argument registers zero (no device tree), and PSTATE 0x3c5, EL1h with everything masked, as in chapter 02:
let boot = BootParams { pc: layout::ROM_BASE, x: [0; 4], cpsr: CPSR_EL1H_DAIF_MASKED,};And the two-copy rule: before any Hypervisor.framework call, the run takes one of two lock files, 0.lock and 1.lock, in a directory under your home directory. Each is held with flock, an advisory lock the kernel drops when the file closes, so a crashed macvmm never keeps its slot. First the function checks the directory: it must be yours, mode 0700, and not a symbolic link, so nobody else can take your slots. Then it tries each slot in turn:
for slot in 0..slots { let path = dir.join(format!("{slot}.lock")); let (file, _) = open_output(&path, &[])?; match file.try_lock() { Ok(()) => { return Ok(SlotLock { slot, path, _file: file, }); } Err(std::fs::TryLockError::WouldBlock) => continue, Err(std::fs::TryLockError::Error(err)) => { return Err(InputError::SlotLock { path, err }); } }}Err(InputError::SlotsBusy { dir: dir.to_path_buf(), slots,})The lock counts only macvmm's vmapple runs, not VZ machines beside them.
Every unknown access, written down
On virt, an access to no device is a guest bug, and the default unhandled-MMIO policy stops at the first one with exit code 3. A ROM written for another board will touch devices we lack, and the question is "which ones, in what order?". So the logger answers each the way an empty bus would, RAZ/WI (read as zero, writes ignored), and records it.
Where does that answer come from? A board needs to see accesses no device claims, and some exits, before the generic run loop decides what to do with them. So each machine profile may install a watcher: a hook called before each exit is handled and for each unclaimed access, which may take over the decision. virt installs none; vmapple installs one. Chapter 07's MMIO path offers an unclaimed access to the watcher first, then to the policy:
Err(BusError::Unmapped { .. } | BusError::Straddle { .. }) => { // A machine profile's watch may take the access instead of the policy. let unclaimed = UnclaimedAccess { pc, ipa, size: rec.size.unwrap_or(0), write: access.write, }; let verdict = env.watch.and_then(|w| w.unclaimed_mmio(&unclaimed)); match verdict.unwrap_or_else(|| unhandled_mmio_policy(env.unhandled_mmio, ipa, da, pc)) { MmioVerdict::Fatal(why) => { rec.action = None; Ok(MmioOutcome::Fatal(why)) } MmioVerdict::RazWi => { if access.write.is_none() { regs.set_x(access.reg, 0)?; } rec.value = Some(access.write.unwrap_or(0)); Ok(MmioOutcome::Done) } }}RazWi writes 0 into the destination register for a read. Remember that line; the experiment below changes it. The logger itself pushes one entry, prints one line, and turns into a stop at the cap:
/// Record `a` and say what the guest sees: RAZ/WI, or (from the cap on) a stop.pub fn record(&self, a: &UnclaimedAccess) -> MmioVerdict { let dir = match a.write { Some(v) => Dir::Write(v), None => Dir::Read, }; self.push(a.pc, a.ipa, a.size, dir)}/// Record an ISV = 0 access that was not emulated (module docs). The caller stops the VM/// either way; the verdict only says whether this entry was the one that hit the cap.pub fn record_undecoded(&self, pc: u64, ipa: u64, write: bool) -> MmioVerdict { self.push(pc, ipa, 0, Dir::Undecoded { write })}fn push(&self, pc: u64, ipa: u64, size: u8, dir: Dir) -> MmioVerdict { let mut g = crate::sync::lock(&self.inner); if g.entries.len() >= UNKNOWN_MMIO_CAP { g.over_cap = g.over_cap.saturating_add(1); return MmioVerdict::Fatal(summary_line(g.entries.len(), true)); } let entry = UnknownAccess { pc, ipa, size, dir, region: layout::vmapple().find(ipa).map(|r| r.name), }; g.entries.push(entry); let n = g.entries.len(); let line = entry.line(n); // `warn`, the default level: the summary below counts lines the user can see. crate::warn!("{line}"); g.lines.push(line); if n < UNKNOWN_MMIO_CAP { return MmioVerdict::RazWi; } let summary = summary_line(n, true); emit_summary(&mut g, &summary); MmioVerdict::Fatal(summary)}Why a cap? A ROM polling a register we lack spins forever, and every spin is an access: the guest decides how often, the VMM decides how much it writes down. The watcher adds three rules: print the first exit, stop on any hypercall macvmm has no designed answer for, and stop on an ISV=0 access:
impl ExitWatch for Watch { fn before_exit(&self, regs: &dyn VcpuRegs, exit: &Exit) -> Result<Option<String>> { let pc = regs.pc()?; if self.first_exit.set(pc).is_ok() { crate::warn!("vmapple: first exit at pc={pc:#x}: {exit}"); } let (conduit, imm) = match *exit { Exit::Hvc { imm } => ("HVC", imm), Exit::Smc { imm } => ("SMC", imm), _ => return Ok(None), }; let x0 = regs.x(0)?; if imm != 0 || !hvc_supported(x0) { return Ok(Some(format!( "vmapple: stopped at unsupported {conduit} {x0:#x} (imm {imm:#x}) at pc {pc:#x}" ))); } Ok(None) } fn unclaimed_mmio(&self, access: &UnclaimedAccess) -> Option<MmioVerdict> { let verdict = self.unknown.record(access); // `fatal`: the access is logged, then the usual unhandled-MMIO stop applies. self.keep_going.then_some(verdict) } fn refused_isv0(&self, access: &RefusedAccess) -> Option<String> { // Counted like any access to no device (a device-backed one is not "unknown"), then a // stop under either policy: no abort is injected into the ROM (module docs). if access.unclaimed { self.unknown .record_undecoded(access.pc, access.ipa, access.write); } Some(format!( "vmapple: ISV=0 {} at {:#x} pc {:#x} not emulated; stopping instead of injecting \ an abort", if access.write { "write" } else { "read" }, access.ipa, access.pc )) }}Under the hood
Chapter 21 handled an ISV=0 access by fetching and decoding the faulting instruction, even from flash. Here the board deliberately leaves that ROM-fetch path off: decoding AVPBooter's instructions is disassembly, which the licence section above rules out. Injecting an abort is out too: the ROM would never see one under VZ, so it would turn the rest of the trace into a record of our behaviour. So the board counts the access and stops.
The first probe
Now run it for twenty seconds, with the logger, an exit trace under .cache/ (which git ignores) and the statistics:
mkdir -p .cache/vmapplecargo run -q -p macvmm --features experimental-vmapple -- run --machine vmapple --bios /System/Library/Frameworks/Virtualization.framework/Versions/A/Resources/AVPBooter.vmapple2.bin --mem 4G --unhandled-mmio log --trace exits:.cache/vmapple/avp.jsonl --timeout 20 --statsYour terminal also shows one vmapple: unknown MMIO #n line per logged access; our capture removed them:
cargo run -q -p macvmm --features experimental-vmapple -- run --machine vmapple --bios /System/Library/Frameworks/Virtualization.framework/Versions/A/Resources/AVPBooter.vmapple2.bin --mem 4G --unhandled-mmio log --trace exits:.cache/vmapple/avp.jsonl --timeout 20 --statsmacvmm: warn: [vcpu0] vmapple: first exit at pc=0x103478: data abort (EC 0x24): ISV=1 SAS=2 (4 bytes) SSE=0 SRT=27 SF=0 AR=0 FnV=0 S1PTW=0 WnR=1 DFSC=0x7 (translation fault)macvmm: warn: [main] vmapple: 34 unknown MMIO accesses loggedmacvmm: warn: [main] vmapple: 33 in cfgmacvmm: warn: [main] vmapple: 1 in pvpanicmacvmm: timeout: the guest was still running after --timeout 20smacvmm: stats: serial_input_dropped=0 serial_input_queued=0 serial_written=0 serial_sink_dropped=0 serial_capped=0 serial_lost=0 serial_filtered=0macvmm: stats: vcpu0 exits: vtimer 0, wfx 0, total 35: canceled 1, data abort 34macvmm: stats: vcpu0 time: exec 19.027 s, wfi 0.000 smacvmm: stats: host cpu 19.174 s over 20.004 s wall (96%)macvmm: stats: rlimit core=0 nofile=1048576Your times will differ; the first-exit PC, the 34 accesses and their split by region should match if your AVPBooter is also 335,096 bytes. The first exit, at pc=0x103478 inside the ROM window, is a 4-byte store (WnR=1, a write, and SAS=2, 4 bytes: chapter 07's syndrome fields) to an address with no stage-2 mapping (DFSC=0x7, the fault status code for a translation fault: neither RAM nor a device sits behind cfg). It is the first of 34 accesses to no device, 33 in cfg and 1 in pvpanic; no hypercall or ISV=0 stop; --timeout ended it, exit code 5. --stats adds the strangest line: 19.0 of the 20 seconds spent executing guest instructions, none in WFI.
Reading a stall
Three jq commands (jq ships with recent macOS) turn the trace into numbers you can publish. The kinds of exit:
jq -r '.fn // .action // .reason' .cache/vmapple/avp.jsonl | sort | uniq -c 1 canceled 34 mmioHow many distinct IPAs the ROM touched:
jq -r 'select(.ipa) | .ipa' .cache/vmapple/avp.jsonl | sort -u | wc -l 14And when, in milliseconds, with the exits of the last 10 ms:
jq -s '(.[-1].t_ns) as $end | {first_ms: (.[0].t_ns / 1e6), last_mmio_ms: ([.[] | select(.action == "mmio") | .t_ns] | max / 1e6), end_ms: ($end / 1e6), exits_in_last_10ms: ([.[] | select(.t_ns > $end - 1e7)] | length)}' .cache/vmapple/avp.jsonl{ "first_ms": 0.185166, "last_mmio_ms": 0.491, "end_ms": 20003.9185, "exits_in_last_10ms": 1}Fourteen addresses, 34 accesses, all between 0.19 ms and 0.49 ms; then nothing until --timeout cancelled the vCPU at 20,004 ms (the one exit in the last 10 ms). A stalled guest can look three ways:
| Shape | Exits near the end | exec time | WFI time | Example |
|---|---|---|---|---|
| polling a device | many, at the same IPA | high | low | a driver spinning on a status bit |
| waiting for an interrupt | none (in-kernel WFI, chapter 12) | low | high | chapter 12's timer guest sleeping: exec 0.000 s, wfi 1.048 s |
| running without exits | none, or very few | high | low or none | chapter 12's no-drain run (a million interrupts, 164 exits, exec up from 0.000 s to 0.396 s); this run, exec 19.0 s of 20 |
Three stalls, three fingerprints. Only the first is visibly "waiting for a device".
On this board a loop polling a register we lack would hit the logger's 256-entry cap and stop with its summary: a capped run, not a timeout, is the polling fingerprint here. Polling something that never exits, such as an in-kernel GIC register, lands in the third row.
Back to the question from the top of the page: waiting, or given up? Observed: after its last device access, at 0.49 ms, the ROM ran for the rest of the 20 seconds (19.0 s of it executing guest instructions, by --stats) without one exit or WFI. Inferred: it touches only things that never exit to us: its ROM and RAM, the in-kernel GIC, the generic timer and the system registers Hypervisor.framework handles itself (chapter 12). Unknown: which of those it touches and why; a GIC or timer poll and a deliberate halt look the same from here.
Try it
One of the 34 accesses went to pvpanic. Read QEMU's docs/specs/pvpanic.rst (tag v10.0.0): what does a guest mean by writing there? Which column does "AVPBooter gave up" belong in, and what experiment would move it? Answer at the end of your Q1 answer in your journal.
Breaking it on purpose: what an unknown register says
Our logger's 0 is not neutral. To the ROM, a register that reads 0 says something: a status bit clear, a count of zero, a version that does not exist. On an undocumented machine, the experiment is to change one controlled variable, keep everything else fixed, and compare traces.
Deliberate breakage 1: unknown reads return all ones. Copy the tree outside the repository and make the trace directory the copy lacks:
rsync -a --exclude target --exclude .cache --exclude .git ./ ../vmapple-ones/cd ../vmapple-ones && mkdir -p .cache/vmappleThen make one edit, in the copy only:
- Open
crates/vmm/src/vcpu/mmio.rsand find theMmioVerdict::RazWiarm shown above, with itsregs.set_x(access.reg, 0)for reads. - Immediately before that call, compute all ones of the access size.
unclaimed.sizeis the size in bytes (au8): for 8 bytes the answer isu64::MAX; otherwise it is(1 << 8*size) - 1, computed inu64. - Pass that value to
regs.set_xinstead of0.
The trace's value field still records 0 for reads; ignore it here. Rerun the first probe's command in the copy; its first build starts from nothing and takes a few minutes.
Predict With every unknown read returning all ones (0xff for a byte, 0xffff_ffff for a word) instead of 0, will AVPBooter touch more distinct addresses than the 14 it touched with zeros, fewer, or the same, before the run stops making progress or ends? Will it reach any row it did not reach before, and how will the run end: a timeout, the logger's cap, a stop, a reset?
Write a number and a sentence of reasoning under ## Predict in your journal. "I cannot know" is allowed, if you say which outcome would surprise you.
cargo run -q -p macvmm --features experimental-vmapple -- run --machine vmapple --bios /System/Library/Frameworks/Virtualization.framework/Versions/A/Resources/AVPBooter.vmapple2.bin --mem 4G --unhandled-mmio log --trace exits:.cache/vmapple/avp.jsonl --timeout 20 --statsmacvmm: warn: [vcpu0] vmapple: first exit at pc=0x103478: data abort (EC 0x24): ISV=1 SAS=2 (4 bytes) SSE=0 SRT=27 SF=0 AR=0 FnV=0 S1PTW=0 WnR=1 DFSC=0x7 (translation fault)macvmm: warn: [main] vmapple: 63 unknown MMIO accesses loggedmacvmm: warn: [main] vmapple: 60 in cfgmacvmm: warn: [main] vmapple: 1 in pvpanicmacvmm: warn: [main] vmapple: 2 in bdifmacvmm: warn: [vcpu0] vmapple: first exit at pc=0x103478: data abort (EC 0x24): ISV=1 SAS=2 (4 bytes) SSE=0 SRT=27 SF=0 AR=0 FnV=0 S1PTW=0 WnR=1 DFSC=0x7 (translation fault)macvmm: warn: [main] vmapple: 63 unknown MMIO accesses loggedmacvmm: warn: [main] vmapple: 60 in cfgmacvmm: warn: [main] vmapple: 1 in pvpanicmacvmm: warn: [main] vmapple: 2 in bdifmacvmm: warn: [vcpu0] vmapple: first exit at pc=0x103478: data abort (EC 0x24): ISV=1 SAS=2 (4 bytes) SSE=0 SRT=27 SF=0 AR=0 FnV=0 S1PTW=0 WnR=1 DFSC=0x7 (translation fault)macvmm: warn: [main] vmapple: 63 unknown MMIO accesses loggedmacvmm: warn: [main] vmapple: 60 in cfgmacvmm: warn: [main] vmapple: 1 in pvpanicmacvmm: warn: [main] vmapple: 2 in bdifmacvmm: warn: [vcpu0] vmapple: first exit at pc=0x103478: data abort (EC 0x24): ISV=1 SAS=2 (4 bytes) SSE=0 SRT=27 SF=0 AR=0 FnV=0 S1PTW=0 WnR=1 DFSC=0x7 (translation fault)macvmm: warn: [main] vmapple: 63 unknown MMIO accesses loggedmacvmm: warn: [main] vmapple: 60 in cfgmacvmm: warn: [main] vmapple: 1 in pvpanicmacvmm: warn: [main] vmapple: 2 in bdifmacvmm: warn: [vcpu0] vmapple: first exit at pc=0x103478: data abort (EC 0x24): ISV=1 SAS=2 (4 bytes) SSE=0 SRT=27 SF=0 AR=0 FnV=0 S1PTW=0 WnR=1 DFSC=0x7 (translation fault)macvmm: warn: [main] vmapple: 63 unknown MMIO accesses loggedmacvmm: warn: [main] vmapple: 60 in cfgmacvmm: warn: [main] vmapple: 1 in pvpanicmacvmm: warn: [main] vmapple: 2 in bdifmacvmm: warn: [vcpu0] vmapple: first exit at pc=0x103478: data abort (EC 0x24): ISV=1 SAS=2 (4 bytes) SSE=0 SRT=27 SF=0 AR=0 FnV=0 S1PTW=0 WnR=1 DFSC=0x7 (translation fault)macvmm: warn: [main] vmapple: 63 unknown MMIO accesses loggedmacvmm: warn: [main] vmapple: 60 in cfgmacvmm: warn: [main] vmapple: 1 in pvpanicmacvmm: warn: [main] vmapple: 2 in bdifmacvmm: warn: [vcpu0] vmapple: first exit at pc=0x103478: data abort (EC 0x24): ISV=1 SAS=2 (4 bytes) SSE=0 SRT=27 SF=0 AR=0 FnV=0 S1PTW=0 WnR=1 DFSC=0x7 (translation fault)macvmm: warn: [main] vmapple: 63 unknown MMIO accesses loggedmacvmm: warn: [main] vmapple: 60 in cfgmacvmm: warn: [main] vmapple: 1 in pvpanicmacvmm: warn: [main] vmapple: 2 in bdifmacvmm: warn: [vcpu0] vmapple: first exit at pc=0x103478: data abort (EC 0x24): ISV=1 SAS=2 (4 bytes) SSE=0 SRT=27 SF=0 AR=0 FnV=0 S1PTW=0 WnR=1 DFSC=0x7 (translation fault)macvmm: warn: [main] vmapple: 63 unknown MMIO accesses loggedmacvmm: warn: [main] vmapple: 60 in cfgmacvmm: warn: [main] vmapple: 1 in pvpanicmacvmm: warn: [main] vmapple: 2 in bdifmacvmm: warn: [vcpu0] vmapple: first exit at pc=0x103478: data abort (EC 0x24): ISV=1 SAS=2 (4 bytes) SSE=0 SRT=27 SF=0 AR=0 FnV=0 S1PTW=0 WnR=1 DFSC=0x7 (translation fault)macvmm: warn: [main] vmapple: 63 unknown MMIO accesses loggedmacvmm: warn: [main] vmapple: 60 in cfgmacvmm: warn: [main] vmapple: 1 in pvpanicmacvmm: warn: [main] vmapple: 2 in bdifmacvmm: warn: [vcpu0] vmapple: first exit at pc=0x103478: data abort (EC 0x24): ISV=1 SAS=2 (4 bytes) SSE=0 SRT=27 SF=0 AR=0 FnV=0 S1PTW=0 WnR=1 DFSC=0x7 (translation fault)macvmm: warn: [main] vmapple: 63 unknown MMIO accesses loggedmacvmm: warn: [main] vmapple: 60 in cfgmacvmm: warn: [main] vmapple: 1 in pvpanicmacvmm: warn: [main] vmapple: 2 in bdifmacvmm: warn: [vcpu0] vmapple: first exit at pc=0x103478: data abort (EC 0x24): ISV=1 SAS=2 (4 bytes) SSE=0 SRT=27 SF=0 AR=0 FnV=0 S1PTW=0 WnR=1 DFSC=0x7 (translation fault)macvmm: warn: [main] vmapple: 63 unknown MMIO accesses loggedmacvmm: warn: [main] vmapple: 60 in cfgmacvmm: warn: [main] vmapple: 1 in pvpanicmacvmm: warn: [main] vmapple: 2 in bdifmacvmm: guest fatal: reset storm: more than 10 resets within 10 smacvmm: stats: serial_input_dropped=0 serial_input_queued=0 serial_written=0 serial_sink_dropped=0 serial_capped=0 serial_lost=0 serial_filtered=0macvmm: stats: vcpu0 exits: vtimer 0, wfx 0, total 65: hvc 2, data abort 63macvmm: stats: vcpu0 time: exec 0.000 s, wfi 0.000 smacvmm: stats: host cpu 0.000 s over 0.000 s wall (132%)macvmm: stats: rlimit core=0 nofile=1048576Then, still in the copy where the new trace is, the same two summaries:
jq -r '.fn // .action // .reason' .cache/vmapple/avp.jsonl | sort | uniq -c 693 mmio 11 PSCI_SYSTEM_RESET 11 PSCI_VERSIONjq -r 'select(.ipa) | .ipa' .cache/vmapple/avp.jsonl | sort -u | wc -l 16One changed value, a different machine. Each boot made 63 logged accesses, 60 in cfg, 1 in pvpanic and, for the first time, 2 in bdif; across the whole trace they hit 16 distinct addresses. Then two hypercalls: PSCI PSCI_VERSION, then SYSTEM_RESET. macvmm answers a system reset by rebuilding the machine, so all of it repeated 11 times (693 = 11 x 63) until chapter 08's cap on resets stopped it with exit code 3. Each rebuilt machine starts with a fresh logger, so the 256-entry cap never filled: 63 per boot, 693 in the file. --stats describes only the last boot, which lasted under a millisecond, so its times round to 0.000 and its percentage is noise.
Zero gave a silent spin after 14 addresses; all ones gave a path into bdif and then a reset, every time. The all-ones run never stalled: it ended in a reset storm, and that is itself an observation.
The misconception it exposes: "the run that gets further is the right one". All ones handed the ROM a different wrong machine; neither value is what VZ's cfg holds, so both traces describe our machine as much as Apple's ROM. The tool: a controlled variable and a counts-only summary, recorded as observed, never as "the fix".
A global change shows that the answers matter, not which one. The finer experiment changes one register. In the copy's RazWi arm, pass regs.set_x a candidate value when unclaimed.ipa equals one cfg address from your own trace, and 0 for every other address. To separate hypotheses about it (a flag, a count, a version), run once per candidate value (0, all ones, cfg's version 2) and compare the counts. We have not run it, so we show no results.
Return to the repository with cd - (or cd to your repository's path). Keep ../vmapple-ones for Your turn, and delete it when you are done.
The CPU mode you cannot have
Suppose you modelled every device: would a current macOS boot? A patch series posted to QEMU's mailing list, and not merged, reports that recent macOS guests need a private "Apple ISA" CPU mode (ISA, instruction set architecture), switched on by a Hypervisor.framework function no header declares: Mohamed Mediouni's "[RFC PATCH v7 0/7] vmapple: making it work on the latest macOS host releases", March 2026, whose patch 7/7, "hvf: do not merge: enable private ISA" calls that function with the value 3 and swaps the public entitlement for a private one. We have not been able to check that a guest needs the mode; we can check whether we may have it. The probe in tools/hv-denied-probe/, signed like macvmm, asks for the mode once, finding that function by name at run time with dlsym, the C call that looks up a symbol in the loaded libraries:
int main(void) { /* Mach-O symbol `__hv_vm_config_set_isa`; dlsym takes the C name (one underscore fewer). */ set_isa_fn set_isa = (set_isa_fn)dlsym(RTLD_DEFAULT, "_hv_vm_config_set_isa"); if (set_isa == NULL) { puts("hv_vm_config_set_isa: symbol not present on this macOS"); return 2; } hv_vm_config_t cfg = hv_vm_config_create(); hv_return_t set = set_isa(cfg, 3); /* 3: the value QEMU's out-of-tree vmapple RFC uses */ hv_return_t ret = hv_vm_create(cfg); printf("hv_vm_config_set_isa(3): 0x%08x\n", (unsigned)set); printf("hv_vm_create with private ISA 3: %s (0x%08x)\n", ret == HV_DENIED ? "HV_DENIED" : ret == HV_SUCCESS ? "HV_SUCCESS" : "other", (unsigned)ret); if (ret == HV_SUCCESS) hv_vm_destroy(); return ret == HV_DENIED ? 0 : 1;}tools/hv-denied-probe/run.shtools/hv-denied-probe/run.shhv_vm_config_set_isa(3): 0x00000000hv_vm_create with private ISA 3: HV_DENIED (0xfae94007)Observed: the configuration call returned 0, then the virtual machine was refused, HV_DENIED, the correct answer on a normally configured Mac. Read that 0 with care: the function's signature and the value 3 are guesses taken from the patch, so a 0 does not prove the mode was set. The solid observation is the pair: hv_vm_create succeeds without the call (every macvmm run in this course) and returns HV_DENIED with it. Also observed: VZ's helper process for each virtual machine (chapter 23's XPC service) carries com.apple.private.hypervisor, one of the restricted entitlements no ad-hoc signature can carry (the codesign-entitlements primer):
XPC=/System/Library/Frameworks/Virtualization.framework/Versions/A/XPCServices/com.apple.Virtualization.VirtualMachine.xpccodesign -d --entitlements - "$XPC" 2>&1 | grep -A1 private.hypervisorcodesign -d --entitlements - "$XPC" 2>&1 | grep -A1 private.hypervisor [Key] com.apple.private.hypervisor [Value]Inferred, from our two observations plus that patch, which asks for exactly this entitlement: the entitlement unlocks the mode, and the mode is what is refused to us. Testing that patch means switching off macOS's system protections; this course never asks you to.
Production note
This is why VZ is the product and vmapple is research: VZ's helper has the private mode, the graphics bridge and the keys, and Apple can change any of them. A tempting belief is "if QEMU can do it, it is a few days of porting". But QEMU's own cfg block has fields named unk1 to unk10, the keys are Apple's, and the CPU mode is refused to us: each device is an investigation, and an honest progress report is part of the engineering.
Never copied
Before you write anything up, check that no file in your tree is AVPBooter. Only files of exactly the ROM's size are hashed, so it is fast:
AVP=/System/Library/Frameworks/Virtualization.framework/Versions/A/Resources/AVPBooter.vmapple2.binfind . -type f -size "$(stat -f %z "$AVP")c" -not -path './.git/*' -exec shasum -a 256 {} + | grep -c "$(shasum -a 256 "$AVP" | cut -c1-64)"find . -type f -size "$(stat -f %z "$AVP")c" -not -path './.git/*' -exec shasum -a 256 {} + | grep -c "$(shasum -a 256 "$AVP" | cut -c1-64)"0Zero matches; grep -c exits 1 when it counts nothing, so exit 1 is the good answer.
Your turn
This is the capstone; there is no scaffolding. In your workspace:
- Your own trace. Run the first probe and the summaries. Record your AVPBooter's size (
stat -f %z "$AVP") and the first 16 hex digits of its sha256 (shasum -a 256 "$AVP" | cut -c1-16), never the file. - The controlled experiment. Run zero and all ones, changing nothing else. The all-ones edit lives in
../vmapple-ones; run the zero case in the repository. - The design record. Write
learner/docs/macos/design.mdwith the sections Question, Setup (Mac, macOS build, ROM size and hash prefix, commit), Observed, Inferred (with sources), Unknown, Experiments run, Next experiment, Stop criteria. Then writelearner/docs/adr/0002-avpbooter-tracing.md, an architecture decision record titled "How far we trace AVPBooter". As in chapter 21, an ADR is a short record of one decision, its context and its consequences (Michael Nygard's original post). - The next device, planned. The trace asks for cfg. From QEMU's field list, write which fields you would fill and with what. If you installed macOS in chapter 23, take the ECID from
tools/vz-mac/run.sh ecid --bundle .cache/macvmm/macos-vm; no bundle? Write the fields with a placeholder ECID and say so in Setup. Then run one per-register experiment, editing../vmapple-ones, and record what changed. Building the whole device is optional: the reference stops at the unmodelled cfg block, and nobody knows whether a filled one gets further.
Stuck? A capstone has no hint ladder. The lab's fallback table and the "What now works" list below show how far the reference got.
Checkpoint
The default build must refuse --machine vmapple (exit code 2), and no file in your tree or caches may have AVPBooter's sha256. A feature build, made in target/vmapple-feature so target/debug/macvmm is untouched, runs the first probe for 20 seconds: the first exit must be inside the ROM and the unknown-MMIO summary must appear (the reference's milestone). Per-access lines and the trace stay in the run's scratch directory. Last, the private-mode probe must get HV_DENIED. The first run compiles for a few minutes.
Checkpoint
Needs a MacRun this from the repository root:
scripts/checkpoint.sh 24You should see, as the last line:
CHECKPOINT 24 PASSscripts/checkpoint.sh 24checkpoint: implementation <tree>[INFO] contract tests none for this chapter[PASS] runs on your Mac refusal: 1/1 serial markers, exit 2 in 0.06s[PASS] runs on your Mac no-copy: 1/1 serial markers, exit 0 in 0.15s[PASS] runs on your Mac rom-probe: 4/4 serial markers, exit 5 in 20.34s[PASS] runs on your Mac isa-denied: 1/1 serial markers, exit 0 in 0.27s[INFO] journal not checked (not a learner tree)CHECKPOINT 24 PASSThe end-to-end tests also check exit code 3 under the default fatal policy and a refused third concurrent run. Default build:
cargo test -q -p macvmm --features hvf-tests --test e2e_vmapple -- --test-threads=1cargo test -q -p macvmm --features hvf-tests --test e2e_vmapple -- --test-threads=1running 3 tests...test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.39sWith the feature:
cargo test -q -p macvmm --features hvf-tests,experimental-vmapple --test e2e_vmapple -- --test-threads=1cargo test -q -p macvmm --features hvf-tests,experimental-vmapple --test e2e_vmapple -- --test-threads=1running 6 tests......test result: ok. 6 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 20.50sThe checkpoint checks that your journal answers every question; check your design record against Your turn yourself. Nothing checks for "macOS booted", because it did not.
What now works:
- macvmm runs Apple's boot ROM, read in place, on a second board, and records every access to a device it lacks;
- you can tell polling, waiting and running stalls apart from
--statsand the trace; - you can change one variable on an undocumented machine and report the result as observed, inferred and unknown;
- you know the three gates on the low road: undocumented devices, a CPU mode reserved for Apple, and a licence that forbids reading the code.
The next chapter starts from the reference at the end of chapter 24.
What's next
Part XI turns the VMM into something you could hand to someone else. Chapter 25 writes the threat model of everything you built, fuzzes the queue code that reads guest data (the discipline bdif's guest-controlled addresses demanded above), turns a hostile guest loose on your VMM, and confines the process with a sandbox.
Open question
After the first five devices, what would convince you to stop and write "not feasible in the time we have"? Set the criteria now, before spending the time, and say what each would look like in a trace.
Spec hunt
- QEMU
hw/vmapple/bdif.cat tagv10.0.0: which register offset does the guest write to start a read, what length must the first descriptor entry have, and what is the largest request QEMU accepts? - The macOS software licence agreement on your Mac, sections 2K and 2N: which sentence makes "load from the host, never copy" a requirement rather than good manners?