src/ — zero C, zero libc, zero external crates
morgana-x86 from source (20 ms for morgana-a64) on desktop x86_64
morgana-a64 --preflight compiles into an arm64 ARX (<16 MiB) and runs on the phone itself
What It Is — and What It Refuses to Be
QEMU is fast and broad, which makes it an indispensable oracle — and a poor microscope when a bare-metal kernel hangs silently on a physical laptop or a phone with no serial port. Morgana exists to be the microscope: small enough to read end to end, strict enough to fail loudly, and held continuously against QEMU so it cannot drift into agreeing only with itself.
- Halt-and-name, never guess: Any unimplemented instruction or unmodelled device access stops the machine immediately and prints the exact PC, opcode, or MMIO address. Morgana never skips a register write to keep a boot moving.
- Strict
stdout/stderrseparation: Guest serial output goes exclusively tostdout. Emulator diagnostics (--devlog,--trace, step counts, verdicts) go exclusively tostderr, so turning diagnostics on never alters a compared transcript. - QEMU is the oracle, not a peer: Every divergence between Morgana and QEMU is treated as a bug in Morgana until proven otherwise. Both transcripts must also be non-empty — two empty files never count as a pass.
- Interpreter, not a JIT: Deliberately simple and deterministic. Booting the handset kernel to the shell (~551M instructions) takes ~1 minute on a desktop and ~19 minutes on the phone's Cortex-A55. Fast enough for a gate, slow enough that nobody mistakes it for a hypervisor.
The Two Machines
Each target is a standalone KernRift binary with its own ISA decoder, MMU, interrupt controller, and device models.
morgana-x86 (x86_64)
Full 64-bit interpreter with 4-level paging, Ring 0/3 privilege transitions, int 0x80 & SYSCALL/SYSRET, Multiboot, and a built-in UEFI + GOP environment (--uefi=ESPDIR --gop) that boots ApexRift's real BOOTX64.EFI.
Modelled devices: 16550 UART, 8259 PIC, 8254 PIT, xAPIC / x2APIC, ACPI / PM timer, HPET, e1000, RTL8125, virtio-blk, ramfb, xHCI + USB hub/HID/CDC, and q35 / G815 PCI topologies.
morgana-a64 (AArch64)
64-bit AArch64 interpreter implementing EL0 / EL1, SVC, TTBR0/TTBR1 stage-1 MMU page walks, atomics/exclusives (LDXR/STXR, LSE), GICv3 CPU/distributor/redistributor, and the architectural generic timer.
Memory & firmware: Generates a real DTB for QEMU virt or handset layouts and backs guest RAM with 64 KiB demand-paged chunks (--ram-cap=) so a 4 GiB physical address space fits inside a 47 MiB arena on the phone.
Live Oracle Verification
# Full ApexRift x86_64 kernel: boot, uname, mem, poweroff $ printf 'uname\nmem\npoweroff\n' | ./scripts/x86-vs-qemu.sh ../ApexRift/apexrift.img IDENTICAL: 1137 bytes # morgana-x86 compiled in 98.30 ms (71,241 tokens, 684,184 B), 3,519,734 steps # AArch64 L3 stage-1 MMU page-walk witness against qemu-system-aarch64 (GICv3) $ QEMU_SECS=3 EMU_STEPS=5000000 ./scripts/a64-vs-qemu.sh tests/fixtures/a64_mmu_l3_witness.kr PASS: a64_mmu_l3_witness.kr -- qemu and morgana-a64 agree byte for byte # morgana-a64 compiled in 20.29 ms (17,469 tokens, 203,528 B), 5,000,000 steps
For UEFI graphics, ./scripts/uefi-vs-ovmf.sh boots ApexRift's BOOTX64.EFI under both QEMU q35 + OVMF and morgana-x86 --uefi --gop, then diffs the rendered desktop framebuffer via scripts/fb-compare.py — requiring a pixel-identical first desktop frame.
Physical Digital Twins
Standard QEMU boards do not look like real consumer hardware. Morgana carries two machine profiles derived directly from hardware dumps so kernel bring-up bugs are caught before flashing or rebooting physical silicon.
| Profile Flag | Physical Machine | What Is Modelled From Hardware Captures |
|---|---|---|
--machine=g815 |
ASUS ROG Strix G18 (G815LW) | Captured ACPI tables, PCI bus layout, and boot-5 reports: xAPIC/x2APIC, HPET, xHCI + USB, RTL8125 NIC, VT-d, high-physical GOP framebuffer (>4 GiB). |
--machine=begonia |
Redmi Note 8 Pro (MT6785) | Handset physical memory window, clocks, GICv3, UART/SoC blocks, and 64 KiB demand-paged guest RAM with configurable --ram-cap=. |
On-Device Stage-0 --preflight
On a phone with no UART header, a bad kernel flashed or loaded via kexec dies silently as a black screen. To eliminate blind flashes, scripts/a64-preflight-arx.sh compiles morgana-a64 into a standalone ApexRift arm64 ARX (<16 MiB) that runs inside ApexRift on the handset itself.
Measured on the Redmi Note 8 Pro's Cortex-A55: 551,000,000 emulated instructions to the interactive shell complete in ~19 minutes inside a 47 MiB arena — slow, deterministic, and completely independent of a host PC.
Source Layout & Mutation Campaigns
All 14,778 lines live in 10 files under src/. No code generator, no C FFI, no hidden runtime.
| File | Lines | Role |
|---|---|---|
src/morgana-x86.kr | 5,341 | x86_64 ISA decoder, 4-level MMU, interrupts, PIC/PIT/APIC, e1000, virtio-blk, ramfb |
src/morgana-a64.kr | 3,878 | AArch64 ISA decoder, TTBR0/TTBR1 stage-1 MMU, GICv3, generic timer, DTB, demand-paged RAM, --preflight |
src/morgana-uefi.kr | 1,700 | UEFI Boot/Runtime Services, PE/COFF loader, memory map, ExitBootServices |
src/morgana-xhci.kr | 1,341 | xHCI host controller (rings, doorbells, TRBs, transfer events) |
src/morgana-g815.kr | 713 | ASUS ROG Strix G18 physical machine profile (ACPI, HPET, RTL8125, VT-d) |
src/hostsys.kr | 499 | Direct Linux / ARX host syscall wrappers (file I/O, mmap, clocks, exit) |
src/morgana-usb.kr | 354 | USB device models attached to xHCI |
src/morgana-q35-gop.kr | 338 | UEFI Graphics Output Protocol (GOP) framebuffer & pixel dump |
src/morgana-q35.kr | 330 | QEMU q35 PCI root complex & chipset registers |
src/morgana-g815-pci.kr | 284 | G815 captured PCI configuration space topology |
Build, Compare & Mutate
$ git clone https://github.com/Pantelis23/Morgana_VM.git && cd Morgana_VM $ ./scripts/x86-vs-qemu.sh /path/to/apexrift.img # byte-exact x86_64 vs QEMU $ ./scripts/a64-vs-qemu.sh tests/fixtures/a64_mmu_l3_witness.kr # arm64 MMU vs QEMU $ ./scripts/uefi-vs-ovmf.sh # pixel-identical UEFI GOP vs OVMF $ ./scripts/a64-preflight-arx.sh # package on-device arm64 ARX # Prove every gate row is non-vacuous (each mutation must force its gate to fail) $ ./scripts/mutate-x86.sh $ ./scripts/mutate-a64-dtb.sh $ ./scripts/mutate-a64-machine.sh
Morgana_VM is free software under GPL-3.0-only. Full design notes and device-model logs live in docs/EMULATOR.md and docs/g815-provisional.md.
Bug Reports & Discussions