This guide traces how Milo boots on AArch64 (qemu-system-aarch64 -M virt), initializes hardware and freestanding kernel subsystems in kmain, mounts the initial filesystems, and launches user-space (EL0) shells and binaries.
arch/aarch64-linux-gnu/linker.ld)The linker script places the kernel entry point at physical/virtual load address 0x40080000 (RAM_BASE 0x40000000 + 512 KiB, leaving room for QEMU bootloader/DTB placement) and defines three PT_LOAD segments:
.text (RX, flags 5): starts at _text_start (0x40080000), places *(.text.boot) first so _start sits at the segment base, follows with *(.text .text.*), aligns to 2048 bytes for vector_table in *(.text.vectors), and ends at _text_end..rodata (R, flags 4): aligned to a 4096-byte page boundary before _rodata_start, holding *(.rodata .rodata.*) up to _rodata_end..data and .bss (RW, flags 6): aligned to 4096 bytes before _data_start, holding *(.data .data.*), the 8-byte aligned constructor table __init_array_start..__init_array_end up to _data_end, followed by .bss (__bss_start..__bss_end).Note (
[WIP]/ Linker vs. Loader):.bssis reserved inlinker.ldbetween__bss_startand__bss_end, whileboot.sdoes not run an explicit zero-loop over__bss_start..__bss_endprior tokmain(relying on the loader/image state).
arch/aarch64-linux-gnu/boot.s)When QEMU enters _start at 0x40080000 with the DTB physical address in x0:
cpacr_el1, sets FPEN = 0b11 (#(3 << 20)), and executes isb so floating-point/SIMD instructions do not trap in EL1 or EL0.vector_table into vbar_el1 and executes isb.sp to boot_stack_top (top of the 16384-byte .bss stack boot_stack_bottom..boot_stack_top).kmain: Invokes bl kmain with x0 (dtb_paddr) intact. If kmain ever returns, _start loops on wfe.kmain Bring-Up Sequence (kernel/main.cpp)kmain(uintptr_t dtb_paddr) records g_dtb_paddr = dtb_paddr and brings up the kernel in eight stages:
HAL::get_console().init() (initializing the Pl011Uart instance at 0x09000000 with FIFOs enabled and interrupts masked) and calls run_init_array() across __init_array_start..__init_array_end.kernel/boot/fdt.cpp): Validates the DTB header via Kernel::Boot::validate_header(dtb_paddr, &dtb_size), collects usable RAM regions via find_memory_regions(dtb_paddr), reads /memreserve/ spans via find_memory_reservations(dtb_paddr), and locates the initrd via find_initrd(dtb_paddr) (stored in g_initrd_loc). If no valid DTB is present, find_memory_regions falls back to HAL::get_platform_info().ram_base with 256 MiB (0x10000000).discovered_ram_span = mem_map.max_paddr - mem_map.min_paddr and calls HAL::set_platform_memory(mem_map.min_paddr, discovered_ram_span).kernel/mm/pfa.cpp): Calls Kernel::MM::pfa_init(...) with [ _text_start, __bss_end ), DTB span, initrd span, and reserve_map, carving out the Page metadata array in usable RAM and marking non-bank gaps and reserved spans as Reserved.arch/aarch64-linux-gnu/mmu_aarch64.cpp): Calls HAL::get_mmu().activate(), which maps GICv2 (0x08000000, 0x08010000) and UART0 (0x09000000) as Device memory, maps .text (RX), .rodata (R), and .data/.bss (RW) at 4 KiB granularity in both TTBR0_EL1 and TTBR1_EL1 (+ 0xFFFF800000000000), maps remaining physical RAM outside the kernel using 2 MiB blocks / 4 KiB pages, and enables the MMU/caches. kmain then calls HAL::console_on_mmu_enabled() and Kernel::MM::pfa_on_mmu_enabled() to rebase MMIO and Page array pointers into the higher half.Kernel::MM::heap_init(), then mounts rootfs at / via Kernel::FS::rootfs_mount_from_initrd(g_initrd_loc), devfs at /dev via Kernel::FS::devfs_init_and_mount(), and tmpfs at /tmp via Kernel::FS::tmpfs_init_and_mount().HAL::Platform::init_irq_controller() (GicV2::init(0x08000000, 0x08010000)), HAL::Platform::init_periodic_timer(100U), HAL::Platform::enable_timer_irq(), and Kernel::Scheduler::init().VirtioMmioBus::instance().discover(dtb_paddr) (using FDT virtio,mmio nodes or falling back to 32 slots at 0x0A000000, stride 0x200, SPIs 48..79).HAL::Platform::init_network_devices(dtb_paddr)), input (HAL::Platform::init_input_devices(dtb_paddr), registering /dev/input/event<N>), and GPU (HAL::Platform::init_gpu_devices(dtb_paddr)), clearing/drawing a banner and flushing scanout if a GPU is bound.fw_cfg (find_fw_cfg_device(dtb_paddr) or default 0x09020000, size 0x18) and, if no primary framebuffer exists yet and etc/ramfb is present with DMA support, initializes RamfbDevice and sets it as primary framebuffer.Kernel::FS::devfs_register_fb0() to expose /dev/fb0 when a primary framebuffer is initialized.HAL::Platform::init_block_devices(dtb_paddr), attempts Kernel::FS::ext2_mount(blk, "/mnt/disk", nullptr) if a primary block device is present, and runs verify_primary_block_device() (writing and reading back a 512-byte pattern on LBA 0).HAL::get_cpu().disable_interrupts()) and enters Kernel::Shell::run().init / Shells & EL0 Binaries)Milo does not hardcode a single /sbin/init daemon at boot; instead, after Kernel::Shell::run() starts:
kernel/shell/shell.cpp): Kernel::Shell::run() first invokes Tests::run_lazy_memory_acceptance_suite() (test_lazy_mm_suite.cpp), which exercises concurrent PFA refcounting, EL0 Copy-on-Write isolation, and 1 GiB demand-zero paging, before printing the milo> prompt.cmd_sh and cmd_bash in kernel/shell/shell.cpp): Both delegate to launch_initrd_shell(...):
/bin/bash (or /bin/busybox in cmd_sh when /bin/bash is absent) inside g_initrd_loc via Kernel::FS::cpio_lookup.AddressSpace via Kernel::Loader::load_elf(...).Process (Process::create(0U)), sets exe_path, builds the auxiliary vector (populate_standard_auxv), attaches the loaded ELF (proc->attach_elf(...)), maps a 64 KiB user stack at 0x3FFF0000 (UserStackBuilder::create_and_map), and writes argc/argv/envp/auxv (UserStackBuilder::build_abi_layout).init_user_cpu_context with SPSR_EL1 = 0x00 for EL0t), sets the TTY foreground PGID to proc->pgid(), runs proc->execute() (switching to the user address space and running the scheduler until the process becomes Zombie), restores the previous foreground PGID, and destroys the Process.user/, kernel/syscalls/ProcessSyscalls.cpp, kernel/shell/tests/): EL0 binaries such as /bin/hello, /bin/hello_musl, /bin/hello_dyn, /bin/fb_test, /bin/evdev_smoke, /bin/unix_echo_server, /bin/unix_echo_client, and /bin/unix_sock_smoke are packaged into initrds/busybox.cpio or initrds/bash.cpio by Makefile, and can be executed via sys_execve (supporting ELF64 executables, PT_INTERP dynamic linkers such as /lib/ld-musl-aarch64.so.1 with AT_BASE, and #! shebang scripts) or via test * shell commands.sequenceDiagram
autonumber
participant Boot as QEMU / Bootloader
participant Asm as boot.s (_start)
participant KMain as kmain (kernel/main.cpp)
participant FDT as fdt.cpp & PFA (pfa.cpp)
participant MMU as mmu_aarch64.cpp & Heap
participant VFS as rootfs / devfs / tmpfs / ext2
participant Subsys as GICv2 / Timer / Sched / VirtIO
participant Shell as Shell (shell.cpp) & EL0
Boot->>Asm: Jump to 0x40080000 (x0 = dtb_paddr)
Asm->>Asm: Enable CPACR_EL1 FP/SIMD, set VBAR_EL1, set sp = boot_stack_top
Asm->>KMain: bl kmain(x0)
KMain->>KMain: init PL011 console & run_init_array()
KMain->>FDT: validate_header, find_memory_regions, find_memory_reservations, find_initrd
KMain->>FDT: pfa_init(mem_map, kernel, dtb, initrd, reserve_map)
KMain->>MMU: HAL::get_mmu().activate() (TTBR0/TTBR1, W^X, 2MiB/4KiB RAM)
KMain->>FDT: console_on_mmu_enabled() & pfa_on_mmu_enabled()
KMain->>MMU: heap_init()
KMain->>VFS: rootfs_mount_from_initrd(/), devfs_init_and_mount(/dev), tmpfs_init_and_mount(/tmp)
KMain->>Subsys: init_irq_controller(), init_periodic_timer(100Hz), enable_timer_irq(), Scheduler::init()
KMain->>Subsys: VirtioMmioBus::discover(), net, input, gpu, fw_cfg/ramfb, devfs_register_fb0(), blk/ext2
KMain->>Shell: disable_interrupts() & Kernel::Shell::run()
Shell->>Shell: run_lazy_memory_acceptance_suite() & print milo> prompt
Shell-->>Boot: Optional EL0 /bin/sh or /bin/bash via load_elf + Process::execute()