Porting to x86_64
Milestone 161, the third architecture, and the one milestone 20 named as the real test of whether
arch/ is a hardware abstraction layer or an accident of two similar RISC machines. aarch64 and
RISC-V share a device tree, weak memory ordering, a boot handoff in the width the kernel runs in,
and a page-table shape. x86_64 shares none of those.
This note is what the port learned, in the order a reader needs it. That is how the machine is
entered and what had to change above arch/ (very little, with the exceptions listed). Then the
three things that genuinely do not fit the existing seam, and an honest account of what exists.
Status, and it is a partial port
Built, running, and gated: the boot path, the console, the GDT/TSS, the IDT and trap frame, the
page-table format, the boot-handoff parser. The ACPI tables (the RSDP scan, the root-table walk with
checksums, the MADT and the MCFG), the local APIC and a calibrated periodic timer. The frame
allocator, the fine-grained W^X kernel page tables, the IO APIC and a routed device line. User
address spaces, the system_call pair and ring 3, the scheduler, preemption, kernel threads and real
ring-3 processes. The kernel's own test suite and a script/test leg, the address
arithmetic, interrupt masking, the context switch, and the test exit. A boot under QEMU's q35
prints a tour and takes real hardware interrupts from the CPU's own timer and from a device. It
builds and installs its own page tables, brings up the scheduler, and runs a kernel thread. It
builds two processes out of untyped memory and runs them at CPL 3 (one invokes a capability and
exits, one faults and its supervisor receives the fault), and halts.
And since 2026-08-24, userspace: every program in user/ compiles for x86_64-unknown-none,
xtask packs the same archive RISC-V's leg does, QEMU's PVH loader hands it over as a module, and
cfg(initial_ramdisk) is on. script/test --arch x86_64 runs 170 tests and skips 67, where it ran 97
and skipped 7 the day before.
Not built: VT-d and SMP bring-up, both loud unimplemented!()s in arch/x86_64/ that name
themselves and why. What bounds this architecture now is not userspace but devices. No PCI bus
is enumerated, so no virtio function of any kind is found. The console UART is in an I/O port
space with no capability shape yet (DECISIONS §121). See "What a userspace still does not have here"
below, and design/roadmap/0161-x86-64-kernel-port.md for the order the rest comes in.
Reproducing it
cargo build -p kernel --target x86_64-unknown-none
helpers/qemu-bounded.sh 20 qemu-system-x86_64 \
-machine q35 -cpu max -smp 1 -m 256M -display none -serial stdio -no-reboot \
-device isa-debug-exit,iobase=0xf4,iosize=0x04 \
-kernel target/x86_64-unknown-none/debug/kernel
or, equivalently, cargo run -p kernel --target x86_64-unknown-none (the runner in
.cargo/config.toml builds the same command line; bound it, because the kernel halts rather than
exiting).
The tour it prints on 2026-08-24, with how to read it (the mmu line, the faulting child of each
round, what changes from boot to boot), is in
boot.md. It ends
nife x86_64: boot complete, halting.
To run the kernel's own suite instead of the tour:
script/test --arch x86_64
To see a triple fault instead of a blank terminal, add -d int,cpu_reset -D /tmp/x86.log.
What the gates cover, and what they do not
script/lint runs clippy over the x86_64 kernel binary at -D warnings, which covers every line of
arch/x86_64/ and every portable file compiled with target_arch = "x86_64". Three narrowings, each
argued where the gate is (see script/lint):
- No
--all-targets: written when the test suite did not compile for this target. It does now (milestone 161's item 4), so this narrowing is stale and is the next thing to widen; the suite is gated byscript/test --arch x86_64in the meantime, which is the stronger check of the two. - No feature loop: all eight boot-mode features fail on x86_64, measured, because each selects a boot path needing an arch layer this port has not written.
-A dead_code: partly stale for the same reason. The tour no longer halts before the scheduler, so much of what had no reference now has one; what remains dead here is what needs a userspace (the services, the drivers). Code dead on all three architectures is still caught by the other two passes; what can hide is code dead on x86_64 alone.
There is a script/test leg: --arch x86_64, in xtask's test, and it runs by default
alongside the other two. That sentence used to end "it builds nothing before it boots, because there
is no userspace archive to pack and the runner attaches no disks", and every clause of it has since
stopped being true: milestone 161 packed an archive, 164 added the FS server, 215 attached the first
virtio-blk-pci disk and 303 the RedoxFS fixture. The leg now builds the FS server, the archive, and
the nifefs, RedoxFS and NVMe images before it boots.
What had to change above arch/
This is the part that matters for the milestone-20 claim, so it takes the form of a list rather than
a conclusion. Making the entire kernel compile for a third architecture took 42 compiler errors,
every one of them "this arch:: name does not exist yet", and:
crates/page_tablesdid not change at all.page_tables::x86_64::Ia32eis sixty lines of bit encoding behind the existingPageFormattrait;LEVELS = 4andSPLIT_SHIFT = 47were the whole of the geometry, and the sharedMapperwalk needed nothing.drivers/ns16550.rsgained a type parameter and no second driver. The same 16550 QEMU's RISC-Vvirtputs at physical0x1000_0000is, on every x86 machine, at I/O port0x3f8: a separate address space reached only byin/out. That is a difference in how eight registers are reached and in nothing else, so it is aRegisterSpaceimplementation (defaulting toMmio, so every existing use means what it always did) with the port-space half underarch/x86_64/.console.rs,user.rs,drivers/mod.rsanduser/fs_service.rsgainedcfgarms, in the same places they already had two.
That is the whole diff above arch/. A new ISA was a new directory.
The appendices
notes/x86-port/ holds the measurements and reasons behind each part of
milestone 161 (the x86_64 kernel port), one file each. None of them is needed to build, boot or test it.
| appendix | what it holds |
|---|---|
| boot.md | Why the kernel boots by PVH and not Multiboot, the real-firmware path through uefi_loader, and the 32-bit trampoline into long mode. |
| acpi-and-pci.md | The PVH memory map, the ACPI tables as q35 reports them, the discovery seam milestone 20 (a portable HAL) promised, and why a PCI function's interrupt is MSI-X rather than the legacy pin. |
| interrupts-and-the-fine-map.md | The PIT-calibrated clock, the IO APIC and its legacy-interrupt trap, the W^X kernel page tables, and the direct map in blocks. |
| traps.md | The IDT and its 256 stubs, the system call ABI and why it returns by iretq, the vector bands, MSI, the GDT and TSS, and port grants in the TSS bitmap. |
| ring-3.md | Address spaces, swapgs, the system_call pair, and the hand-assembled probe that first ran at CPL 3. |
| scheduler.md | The trap-path split, TSS.RSP0, the self-IPI, and four places portable code was wrong for a third architecture. |
| user-mode-runtime.md | The ring-3 system call stubs, why rdtsc is ambient here, the CR4.PCE door that was closed, and cntfrq(). |
| userspace.md | How the archive arrives as a PVH module, the suite's skips by cause, and four latent bugs userspace found. |
| what-does-not-fit.md | The four places the arch/ seam did not stretch, the segment-base bug, the SMP counting bug, and where TSO pays out. |
| the-port-range-tests.md | Why each PortRange test runs a ring-3 out, checks the core it ran on, exits rather than reports, and narrows the rights. |
| cpu-state.md | The control-register bits each core sets (PAT, SMEP, PCE), the port I/O gate, the boot CPU's id and the per-CPU pointer, the thread pointer, the FP and SSE unit, and the CPUID boot gates. |
| smp-bring-up.md | INIT-SIPI-SIPI, the one trampoline page every secondary shares, and the timing of the wait for each core. |
| kernel-page-tables.md | The two kernel bases, what the direct map claims and in which order, the 32-bit MMIO hole and the BAR window, the user address spaces without PCID, and the MMU's BUGS. |
| tco-watchdog.md | The Intel TCO watchdog: the second timeout that resets the platform, the register map on ICH9 and the 200-series PCH with its sources, and its BUGS. |
BUGS
- Multiboot is still not an option, and nothing here added a header. The refusal in boot.md is a
property of QEMU's loader rather than of this kernel, so it stands. GRUB Multiboot 2 remains the
path for a BIOS-only machine and would cost a header plus a second handoff decoder; it was priced
against UEFI and lost on testability (
brew info grub: no formula on this machine at all). See notes/x86-uefi-boot.md's fork. - The four places the
arch/contract does not fit x86 are recorded in what-does-not-fit.md. Two of them are names, and names are an architect's. - The swapgs exit window is open to an NMI or a machine check, because there is no paranoid entry path. See ring-3.md.
rdtscis readable from ring 3 by inheritance, not by decision. Closing it needs a coarse time source first. See user-mode-runtime.md.
Two boot-mode features that do not compile here
These are the scope notes §19 (architectural parity is a tenet) asks for, one for each gap
helpers/lint_arch_parity.py allowlists, written 2026-10-08 (UTC). Neither has a plan. Under §71 (a
limitation is promoted when it becomes a plan), each stays a BUGS entry until one of that
section's triggers fires, and each names the one that would.
--features fastpath_paddoes not compile, because this port has no padding sled.kernel/src/fastpath_pad.rscallsarch::fastpath_pad_body. aarch64 and riscv64 each define it as aglobal_asm!run ofnops, and their linker scripts place its section right after.text.hot;kernel/link-x86_64.ldhas no such line. The sled exists for E3 in milestone 134 (the register of measures), a footprint experiment aimed at radon's 32 KB L1i (notes/footprint-perturbation.md). x86_64 joinedscript/fastpath-footprinton 2026-08-27, after the sled was written, and no x86 measurement has asked for one since. What the gap costs: milestone 796 (pin the hot trap path's placement) gets only its containment check on this ISA, not the shift check, andscript/lintcannot clippy the feature here. The port is small, a thirdfastpath_pad.rsof about 50 lines sized againstbench/fastpath-x86_64.txt, plus one linker-script line. It becomes a plan when someone proposes an E3 run on xenon, or wants 796's shift check on x86_64.--features icountdoes not compile, because nobody wrote the x86_64 timer half of the instrument from milestone 78 (the load-sensitive assertions).kernel/src/icount.rsreadsarch::timer::{ARRIVAL_BOUND, HANDLER_BOUND, calibration_loop, deadline, missed_ticks}, and this port has none of the five. The cause is the timer. The instrument checks every tick against the deadline the kernel armed (notes/instruction-clock.md). Here the local APIC timer is a periodic hardware reload (interrupt_controller::arm_periodic_timer), so there is no armed deadline to read and no missed tick to count. Porting it means first changing how this port ticks, to the APIC's one-shot or TSC-deadline mode. That is a timer redesign rather than a port, and neither mode has been tried under TCG here. A partial port to the periodic tick would have to redefine claim 2, whose span starts at the armed deadline. Nothing waits on it:cargo xtask bench --x86already gates instruction counts on this ISA, and milestone 161 found thatCR4.PGE, the one question that wanted an icount leg here, does not move under icount at all. It becomes a plan if the tick moves to a deadline mode for its own reasons, or if a milestone needs an instruction-denominated bound on this port's handler.
What a userspace still does not have here
The bound on everything above, listed because it is the next lane's brief rather than a caveat.
Every item is a device or a toolchain, and none is user_mode_runtime any more.
- No device a ring-3 process can reach. The console UART is in the I/O port space, so
user::UART_PHYSis zero andconsole,input,keyboard_driverandswapperare packed but cannot run. Their armstrap()rather than no-op, so a boot that reached one would say so on the first byte. That is DECISIONS §121, still PROPOSED. One foot gun is marked rather than removed:spawn_elf_child_buildergrants slot 2 a device capability overUART_PHYS, which on this architecture is physical page zero. The slot is positional, so declining to grant would renumber the interrupt capability and every role that names it, and there is nothing better to put there until §121 is answered. Nothing reaches it: every fixture that would map it asksuser::machine_has_no_device_page_for_the_console()first. - The kernel enumerates the PCI bus, and a driver drives one function (milestones 165 and 215).
ACPI's MCFG fills
memory::pci_regions(), and the runner attaches avirtio-blk-pcidisk, which VT-d confines and a driver at ring 3 reads and writes. What is still not attached is a NIC, a GPU, a keyboard, an RNG, or a second disk: each is a line inhelpers/qemu-runner-x86_64.shand a wiring, not a mechanism. - The ACPI walk reads the boot map, and the boot map ends at 4 GiB.
arch::x86_64::machine::BOOT_DIRECT_MAP_LIMITis that bound. Firmware puts its tables just under the top of RAM. A bound below it finds no RSDP, no MADT, no MCFG and no DMAR, and comes up with no APIC, no timer, no PCI and no VT-d on a machine that describes all four. A 256 MiB QEMU run cannot show it, socargo xtask uefi-bootboots at 2 GiB for exactly this reason (NIFE_MEMsets it back). An unreachable table says so during the walk rather than being skipped with the checksum failures. A machine that put its tables above 4 GiB (none seen; firmware keeps ACPI low so 32-bit loaders can read it) needsboot.swidened, not the bound loosened. - The 32-bit BAR window is a constant, and this kernel moves most of the bus into it.
arch::mmu::PCI_BAR_PHYSis0xc000_0000with 2 MiB mapped, checked once against QEMU'sinfo mtree, because the window a real machine wants BARs in is in its host bridge's_CRSand_CRSis AML.place_barsrelocates every BAR outside it, which is correct and exercised.pci::bar_censusprints how many that is on the boot line, and it is not a corner case: 5 of 8 functions under PVH, 3 of 6 under OVMF, 4 of 7 with avirtio-blk-pcidisk attached (2026-09-02). On xenon that number is the first thing to read: a machine whose RAM reaches above0xc000_0000would have this kernel move most of its bus on top of memory. - No MCFG means no PCI, deliberately. There is no fallback to the legacy
0xcf8/0xcfcconfiguration mechanism, which this kernel could reach and which would enumerate bus 0. Those ports see only the first 256 bytes of a function's configuration space, so a machine that fell back would enumerate a different set of capabilities than one that did not. Every extended capability would be absent, and a driver that then failed would fail somewhere else entirely. Milestone 215 refused the same shape one level down (a machine that wants MSI and meets a function without MSI-X fails loudly rather than falling back to a pin). - The kernel refuses an MCFG whose first bus is not 0 rather than adjusting it.
kernel/src/pci.rsaddresses a function asbase + (bus << 20 | ...)with an absolute bus number, and the subtraction that looks like the fix names a base below the windowmmu::map_everythingmaps. Every machine seen reports 0; none has to. No RedoxFS image is attached: closed by milestone 303. The runner attaches the-redoxfs.imgfixture as a secondvirtio-blk-pcifunction, andvirtio::find_block_device_nspans virtio-mmio and virtio-pci so a wiring on a machine with no mmio bus can find it. What is still missing is the rest of the fixture set (milestone 37's crash disk, milestone 57's GPT and blank disks); see design/roadmap/0420-the-rest-of-the-x86-64-fixture-set.md.No: closed by milestone 184.stdx86_64-unknown-nifeand its farm exist, andstd_exerciserpasses here.std::fsruns since milestone 303 gave the FS service a disk;std::netis compiled and unexercised for the NIC reason above. See notes/std.md.- No second core (item 5), and no ASID tags, because
CR4.PCIDEis off (item 3, calef's call, and it wants a number rather than an argument).