Boot, platform handoff, and service recovery¶
Firmware adapters¶
System uses platform/arch for build profiles and output paths, such as
build/uefi/riscv64/. Xmake’s -p selects the platform profile and
-a selects the CPU architecture, including the byte-order variant
on PowerPC. Each profile selects the image backend, kernel entry adapter,
firmware and board support, and virtual machine configuration where applicable.
The default build profile is -p uefi -a x86_64. The native image uses
a GPT disk and starts the serial login chain from the root filesystem.
The public system target lives at the repository root. The additional
profiles below build early kernel entry images with explicit QEMU tests.
Kernel boot adapters under packages/kernel/boot/ translate native boot
protocols. They own protocol requests, parsing, CPU discovery and release, and
firmware-dependent linker sections. Architecture code initializes each
released CPU. Runtime firmware and board services, such as SBI and OPAL, live
under packages/kernel/platforms/. CPU mechanisms can be shared across platforms,
including PowerVM and PowerNV under the same PowerPC architecture code.
Platform and CPU |
Entry path |
|---|---|
|
Limine preloads the kernel, root image, and bundle. RISC-V boots on
QEMU |
|
An IEEE 1275 Open Firmware ELF can carry the kernel and its payload
in one file. QEMU |
|
Petitboot loads a PPC64 wrapper with |
|
Stock firmware loads |
|
Stock firmware loads |
Reuse the image and boot adapter for later boards that accept the same handoff. Add a board profile when the image format or boot handoff needs its own configuration.
Kernel entry and resident service images¶
The uefi-entry target packages the AMD64 or ARM64 kernel on a FAT32
ESP together with the resident root task and VM server. With ACPI, the
early kernel checks the interrupt table. It feeds the
firmware memory map to the page allocator, switches page-table roots and
kernel stacks, checks a userspace trap and translation fault, returns from
a breakpoint, delivers a local timer interrupt, and releases a second
CPU through Limine’s MP interface. AMD64 and ARM64 also route an
interprocessor interrupt from the boot CPU to each released CPU and
verify acknowledgement from the selected logical CPU.
The AMD64 console uses PC COM1. ARM64 reads the PL011 address from the ACPI
SPCR or the device tree’s /chosen/stdout-path and creates one
privileged device mapping for it. AMD64 uses an x2APIC timer. ARM64 uses the
EL1 physical timer with either GICv2 or GICv3. GICv2 uses the memory-mapped
CPU interface. GICv3 discovers redistributor ranges through ACPI or device
tree, validates the redistributor affinity for each CPU, and uses the
system-register interface. QEMU tests each controller version with both
hardware descriptions. Each entry image
checks scheduled IPC and timer expiration, then starts the resident root
supervisor. The supervisor starts the VM server, triggers a deliberate
fault, and checks successful IPC to a replacement started from RAM.
On AMD64 UEFI, the diagnostic image ends after the resident checks and
halts the guest. With --application-debug=y, the supervisor starts the
RAM block, ext4 and VFS services after the recovery check, mounts their
read-only application root, and starts a serial shell.
--resident-debug=y pauses the resident VM server for debugging.
Native boot on UEFI supplies the root partition GUID and filesystem
server as a Limine module selection. AMD64 uses a userspace ATA driver
for QEMU’s IDE controller. ARM64 uses the device-tree-described VirtIO
MMIO transport. The Raspberry Pi and PowerPC disk images carry the
same filesystem-server selection in the firmware payload and use the
userspace SD driver. The supervisor delegates block authority to GPT,
mounts the selected root, and starts the same native /sbin/init,
getty, login, and shell on each profile.
On AMD64 QEMU PC, the kernel exposes power control to the root supervisor when it finds the QEMU ACPI fixed description table with a usable PM1a control port. The PC adapter requests the sleep type defined by QEMU for S5 and resets through the emulated 8042 controller. The root supervisor checks native credentials before exercising its power capability. Other AMD64 firmware needs a platform power adapter.
The native allocator requires fresh boot entropy. Limine supplies it on
UEFI. Raspberry Pi uses a firmware device-tree seed or the board RNG200.
PowerVM uses the PAPR random-number hypercall. PowerNV accepts a
device-tree seed or uses the conditioned DARN operation on POWER9 and
later processors. The QEMU Pi harness supplies a fresh device-tree seed,
and the PowerVM harness attaches a virtual RNG backed by the host.
On AMD64, ARM64, and PowerPC, each secondary released by the boot check runs and joins kernel threads in a private run queue before announcing readiness. The boot CPU releases secondaries in order, so they reuse the same scratch pages for this check.
The Raspberry Pi targets produce ARM64 Image binaries with a low physical
load address and a high virtual kernel address. The adapter builds an
EL1 map with separate permissions for kernel text, read-only data,
writable data, and device registers. The early map can use 4 KiB pages
through the first 4 MiB of physical memory to cover the kernel image,
including the trace rings. The linker checks this bound. The adapter removes the low identity map after
entering the high half. The boot CPU discovers firmware RAM, excludes
the DTB, initrd, image and firmware reservations, and uses the remaining
pages to test address-space switches and EL0 faults. It checks the initrd
against the kernel and DTB ranges before decoding it. BCM2711 releases
secondaries through the stock firmware spin table and routes PL011 to
the GPIO header using the firmware’s disable-bt overlay. BCM2712 uses
the firmware’s PSCI CPU_ON SMC and the dedicated debug UART.
The Pi build produces a boot payload containing the ARM64 root supervisor
and VM server. Its cmdline.txt selects the resident service and fault
recovery checks. The Pi 4 QEMU tests check all four CPU entries, targeted GICv2 interprocessor
interrupts, the GICv2
physical timer, recovery of the VM server, and rejection of a truncated
initrd. The Pi 5 test checks the image, configuration, and payload. The available QEMU Raspberry
Pi family models extend through Pi 4B.
The powerpc-entry target builds both byte orders, named ppc64
and ppc64le in Xmake. It produces powerpc-entry.elf and
boot-payload.img. The PowerVM ELF embeds the payload for standalone
Open Firmware boot. The PowerNV ELF embeds its root task and accepts the
separate payload as an initrd. On powervm the test checks SLOF’s Open Firmware
entry registers and uses the PAPR virtual console. On powernv it
embeds the flat kernel in the existing wrapper and discovers the OPAL
console from the supplied device tree. The entry image packages the
matching root supervisor and VM server. Both profiles verify the PPC64
ELFv2 stack switch in each byte order. They start a secondary core through
Open Firmware or OPAL and check program, decrementer, and userspace
exceptions. The interrupt check sends and receives a targeted IPI.
PowerVM uses the PAPR XICS hypercalls. In PowerNV, POWER8 uses the physical
interrupt presentation registers described by firmware and POWER9 and
later use a hypervisor doorbell addressed to the processor ID.
PowerVM modifies its partition’s hash table
through PAPR hypercalls. PowerNV installs a temporary native hash table
and uses SDR1 on POWER8 or a partition table entry on POWER9 and later.
A second read of the remapped address checks invalidation in each case.
The managed mapping check also creates two address spaces, maps the same
virtual address to distinct physical frames, switches between them,
changes permissions, and replaces a mapping. PowerVM reads the PTE group
count from Open Firmware and uses PAPR hypercalls. PowerNV publishes and
invalidates entries in its native hash table. The real-mode kernel gives
each space distinct virtual segment IDs and uses up to 31 SLB slots per
active space on the boot CPU.
The PowerNV probe also enters non-hypervisor supervisor mode through
hrfid and checks the register state on return through sc 1.
POWER4 through POWER6 would require separate firmware and CPU work.
PowerPC also exercises the shared scheduler, capability IPC, and IPC deadlines. The resident supervisor runs on the boot CPU using a bootstrap memory arena. The entry tests start and recover the VM server under SLOF and skiboot in both byte orders. The resident diagnostic images do not mount a native root. Native disk startup and service device interrupt routing remain RISC-V paths. The PowerNV QEMU tests enter through skiboot. The separate wrapper is suitable for the Petitboot handoff. Board firmware and Petitboot menu boot on physical systems are outside this verification.
Resident payload for Raspberry Pi and PowerPC¶
Build boot-payload.img with packages/boot/mkpayload.py. The header
uses little-endian fields in both PPC64 byte orders. It carries its version,
total byte length, the root, archive, and filesystem image lengths, and the
two canonical halves of the root partition GUID. Each present section
starts at a 4 KiB offset relative to the start of the initrd. The archive
is required, and the filesystem image and PARTUUID are supplied as a
pair.
Raspberry Pi firmware passes the address and size in the device tree.
The PowerVM wrapper passes the address and size in r3 and r4 and
preserves the Open Firmware callback in r5. The PowerNV wrapper carries
the root task separately and passes the initrd as part of its handoff.
The decoder requires exactly one source of the root task. The boot
adapter identifies the resident spans by the same roles as Limine.
The kernel treats the archive as opaque. The root supervisor owns
decoding and starting the servers once the native runtime is available.
-
bool boot::read_payload(const boot_task_image_t &image, const boot_task_image_t &embedded_root, handoff_t &boot)¶
Decode the root task, server archive, and optional root filesystem selection. An embedded root task replaces the root section on PowerNV. The input spans must stay resident and the output is unchanged on failure.
-
struct boot_task_image_t¶
A borrowed, resident image span supplied by the boot adapter.
The wrapper runs in big-endian mode. It encodes the handoff in the kernel
payload’s byte order and switches the CPU to little-endian mode when
entering a PPC64LE image. The kernel starts in real mode with the physical
address of this record in r3. The PowerNV kernel adapter will establish
the direct map and preserve the incoming ranges during common init.
-
struct handoff_t¶
The kernel-private handoff describes the direct map, kernel location, command line, memory ranges, and boot payloads. Memory map entries use physical addresses. The kernel distinguishes allocator-usable memory from RAM that can be included in a crash dump. The adapter keeps borrowed firmware data and payload pages reserved while the kernel depends on them.
On RISC-V, the Limine adapter reads the /cpus/timebase-frequency cell
from the firmware device tree. The parser bounds the tree by the reserved
range that owns it. The kernel passes ticks per second to the supervisor
and derives its two-millisecond scheduling quantum from the same frequency.
The QEMU virt platform supplies its 10 MHz fallback when firmware
omits the property. The PowerNV wrapper uses the same bounded parser for
its /chosen initrd properties.
The Limine adapter requests two entropy words and conveys them through the private boot handoff to the root supervisor. The supervisor derives a separate key for each application using its kernel task handle and SipHash-2-4. Applications receive their own derived key in the auxiliary vector. Limine’s entropy is best effort and depends on firmware or hardware support. A boot without entropy leaves the key unavailable.
Hardware description¶
UEFI configuration tables can carry ACPI or a flattened device tree (FDT). The Limine adapter requests both descriptions and passes the validated data and selected source through the kernel-private handoff. It bounds the FDT by the bootloader-reclaimable range that owns it. The ACPI reader verifies the RSDP signature and checksums, validates the RSDT or XSDT directory, and resolves physical table addresses through mapped ACPI or firmware-reserved ranges. Individual tables are checked when looked up. These ranges stay out of the page allocator.
Use one hardware description for device enumeration. If both formats are available, follow an explicit preference for the platform and architecture. The Limine adapter prefers the device tree on RISC-V and ACPI on the AMD64 and ARM64 UEFI paths. It reports the selected source on the kernel console. The RISC-V timebase lookup uses the selected device tree. The hosted ACPI test checks both directory formats and malformed table bounds. The QEMU RISC-V boot check verifies the device tree and the firmware timebase.
Root task and native root filesystem¶
The kernel and each server are separate binaries. Xmake flattens the root
task’s fixed-layout ELF into root-task.bin and packs boot-critical server
ELFs into the uncompressed newc archive boot-servers.cpio. Limine
loads these two files and kernel from /boot/core/default. The
profile also contains the individual boot-server ELFs. Additional Limine
menu entries can select other profile directories under /boot/core.
The kernel maps the root task and passes the archive as an opaque read-only
module alongside its initial resource authority. It maps the boot modules
starting at 4 GiB in the root task’s virtual address space so large debug
bundles leave room for the supervisor’s low IPC and ELF loading buffers.
The supervisor reads each module address and size from the boot info.
The following userspace ABI is separate from the firmware handoff above.
-
struct boot_info_t¶
Public Members
-
int64_t unix_time¶
Firmware UTC seconds since the Unix epoch, or -1 if unavailable.
-
uint64_t unix_time_ticks¶
Monotonic timer sample at the kernel entry corresponding to unix_time.
-
uint64_t root_guid[2]¶
Unique GPT partition GUID in canonical digit order, or zero.
-
uint64_t entropy[2]¶
Boot-derived key for applications, available only to the supervisor.
-
int64_t unix_time¶
The root supervisor validates the version and size of the boot info, indexes the archive by name, and loads static ELF servers into independent address spaces. The shared boot module limit is twelve entries. The supervisor grants service-specific capabilities and starts the services in dependency order. The pager and the services required to mount storage are eagerly mapped. The supervisor handles archive lookup and ELF loading in userspace. The firmware may supply early demonstration programs in the same archive while the native root filesystem is being brought up.
The optional application debugging profile includes a small ext4 boot volume. The supervisor maps its pages read-only into an independent RAM block server and starts the ordinary ext4 and VFS servers over it. VFS publishes a single read-only root mount. The profile starts a serial shell through the native process supervisor without a separate ESP mount.
The static ELF loader validates the complete load layout before mapping it. Segment addresses and file offsets can start partway into a page when their page offsets agree. The mapped ranges must occupy disjoint pages. A segment with no initialized bytes maps zeroed pages, including its leading padding. The native application loader also recognizes the runtime interpreter listed in Native processes, loading, and the C runtime. Boot services retain the static loader.
The native boot disk uses GPT with a FAT32 boot partition
and a separate ext4 root by default. The image builder sizes the root
partition from the staged files and leaves space for filesystem metadata
and local changes. The boot bundle contains the pager, selected block
driver, GPT partition, msdosfs, and VFS servers. RISC-V also includes
the VirtIO Ethernet driver and IP service in its default bundle. Its
optional network profile keeps these servers on the native filesystem
for later activation.
See Native server activation and supervision. Limine preloads the root filesystem
server as an individual module from the boot profile. The supervisor starts those servers
in dependency order and uses a bootstrap VFS session to load
/sbin/init from the read-only root. PID 1 starts getty, which
starts login on the firmware serial console. An authenticated login
starts FreeBSD /bin/sh. The native executable
loader checks the login process’s credentials when starting its shell
and applies the shell’s credentials when loading commands. It releases
the staging pages after each load.
The diagnostic ISO retains the bootstrap shell. A native disk boot entry
with cmdline: system.bootstrap-shell runs a one-shot native init and
then starts the diagnostic /usr/libexec/bootstrap-sh. Native-disk regression tests use a
disposable image copy with this option when exercising the bootstrap
path. A boot entry can combine diagnostic flags in its cmdline.
The kernel matches each whitespace-delimited flag by its complete name.
On RISC-V, QEMU firmware boots the disk through its own VirtIO PCI
function. After firmware handoff, the guest driver reads the same disk
through a separate VirtIO PCI function with DMA translation.
Plain xmake run boots this disk. The local multi-user milestone
transfers login startup to a persistent /sbin/init. The supervisor
continues to own resident system services and delegates process and
terminal authority to the native login chain. The ISO remains available
for bootstrap and diagnostic runs through xmake run system. See Native processes, loading, and the C runtime for the login
session design.
VFS exposes the ESP at /boot/efi and its boot profiles at
/boot/core. The directories are owned by root:wheel with
mode 0755, so users can list and traverse them. A process with
effective UID 0 can read the regular files, which have mode 0400.
Both views are mounted read-only and execution is disabled. The host
can publish and select compatible generations on an offline disk image
through the procedure in Base packages and system updates. General mount namespaces and
in-guest boot updates are planned.
Set system.writable-fat-data in a native boot entry to attach the
writable FAT data partition described in Filesystems, block storage, and networking at
/mnt. The boot entry selects this volume independently of the
root’s write policy. Add system.fat-data-noauto to provision the
service and leave the volume detached at startup. Root can attach it
with mount -t msdosfs gpt:fat-data /mnt and detach it with
umount /mnt.
The root supervisor holds kernel-enforced authority to start, stop,
and reap boot-critical services.
The boot profile’s filesystem needs to be readable by the bootloader. Limine can read FAT and ISO 9660, so the UEFI build keeps profiles on the ESP. Each native boot entry pairs a filesystem server with the unique GPT partition GUID of its root. For example, after the kernel, root task, and archive entries, add these two lines using the actual root partition GUID.
module_path: boot():/boot/core/default/ext4
module_string: root=PARTUUID=594b6a28-1fec-4bd2-a070-cc6392cefce1
The Limine adapter passes the server under the root-fs role and
passes the GUID separately. It rejects malformed GUIDs and repeated root
selectors. The supervisor configures GPT with the GUID before delegating
the partition endpoint. GPT requires exactly one match on the attached
disk and rejects selection of the ESP as root. The image builder generates
a GUID for the native root partition and writes the matching module string.
The build can also select a UFS2 root and preload its server.
Entries that share the ESP can supply different server paths and root
GUIDs. The guest currently discovers one native VirtIO disk.
Service lifecycle and failure¶
See Native server activation and supervision for the required and optional server sets and their activation policies.
Keep the root task’s code, stack, and bootstrap state resident, together with immutable service images and a bounded recovery memory reserve. A boot-critical service can then restart even while its VM, VFS, or storage dependencies are down. When a boot-critical service exits, close its old endpoint, complete pending requests with an error, retire its task, revoke stale authority, and start a replacement from RAM. Clients explicitly reconnect. Bound retries and report failures. If the root task exits abnormally, log the failure and request a system restart. The RISC-V root task has a resident 16 KiB stack for nested loader and supervision calls.
The native boot supervisor can restart VFS from its resident image when an application load detects that the VFS task has exited. It reaps the task, discards the old endpoint, clears its open handles on the root and EFI servers, and gives the replacement fresh endpoint authority. The backing filesystem tasks and their shared pages survive this restart. Application loading then retries through the replacement, subject to the supervisor’s restart limit.
The supervisor also puts a deadline on its file requests. If VFS blocks or spins while serving an application load, the supervisor times out, stops and reaps the old task, and runs the same restart procedure. The supervisor uses the boot timebase for a one-second deadline and allows two replacement attempts. An ordinary file error from a live VFS does not consume that budget. Tests exercise an IPC stall and a spinning service separately.
If an application load finds an exited storage provider, or times out and a bounded readiness check finds a hung provider, the supervisor retires VFS and its storage dependencies in reverse order. It restarts VirtIO block, GPT, both filesystem servers, and VFS from their resident images, delegates fresh endpoints, and retries the load. The restart shares the same budget as a VFS-only replacement. Existing file sessions lose their old authority when VFS is replaced. Newly launched processes receive fresh sessions.
The supervisor uses the same deadline for VM readiness and fault requests. A fault timeout stops and reaps the old VM task. Its replacement starts from the resident ELF using the reserved memory pool and receives fresh authority for the faulting task. It can reuse a mapping that survived the first pager. Private paging state recovery is a later VM milestone.
While the shell waits for serial input, the supervisor defers the console reply and uses timed receives between polls. This keeps fault and exit handling active while there is no shell input.
In the native shell session, the supervisor checks the pager, storage providers, VFS, the Ethernet driver, and its IP service once per second, including while waiting for input or child status. The service table records each task and readiness request and associates it with a restart group. The supervisor checks task exit status and uses bounded readiness calls. The VM readiness reply carries a success status. The VM’s diagnostic ping separately returns the number of resolved faults. A failed storage provider triggers a restart in dependency order. VFS, VM, and Ethernet have separate restart paths for their own failures. Existing private VM state and open file handles are tied to the original service instances. The supervisor gives subsequent applications authority to the replacements. The boot supervisor owns this table. Runtime service registration, push exit notifications, and rebind for surviving clients remain future work. Deadline and retry policy stays in userspace.
Service restart and restoration of a client’s state have separate requirements. Mappings whose backing frames and address spaces survived can be preserved. Restart dependent tasks when their private state cannot be recovered. Transparent pager recovery requires recoverable VM object, backing store, and swap metadata. See Virtual memory.