How limine-bootloader/limine works
1. What this repository is
Limine is a multi-architecture bootloader and boot manager. The repo is split between:
- boot-time firmware/OS-facing code that runs on bare metal, and
- a host-side toolchain that prepares boot media and package artifacts.
2. Top-level architecture
The codebase is organized around a shared “common” bootloader core plus platform-specific entry/transition code. Most functionality lives in common/, while stage1/ contains early bootstrap assembly for different boot paths, and host/ contains the user-space limine tool used to install/build bootable images.
3. Boot chain and execution stages
The boot flow is staged:
- Stage 1: very early code in stage1/ handles BIOS/CD/HDD/PXE entry points and loads the next stage.
- Common bootloader core: once execution is established, the shared code in common/ handles hardware discovery, filesystems, protocols, memory, menus, and payload loading.
- Protocol handoff: the loader eventually transfers control to an OS kernel using one of the supported boot protocols.
4. Platform entry boundaries
Architecture-specific startup glue exists in assembly files under common/ and stage1/ for:
- IA-32 / x86-64
- aarch64
- riscv64
- loongarch64
These files are the boundary where control moves from firmware/real mode/UEFI into the portable C portions of the loader.
5. Boot environments supported
Limine supports both:
- BIOS-style booting on x86, and
- UEFI booting on x86-64, IA-32, aarch64, riscv64, and loongarch64.
The repo includes separate linker scripts and thunk/spinup assembly for these environments, indicating different startup and CPU-mode transition paths.
6. Core runtime services in common/lib
common/lib/ is the shared runtime layer. It provides:
- memory, string, and libc-like support
- printing/terminal/UI primitives
- image and compression utilities
- GUID/URI/config parsing
- ELF/PE parsing
- RNG, timing, panic, tracing, and TPM helpers
This layer is the central dependency for most other subsystems and is what makes the loader portable across boot environments.
7. Hardware and firmware abstraction
Several directories map directly to hardware-facing subsystems:
- common/mm/ for physical/virtual memory management, EFI page tables, MTRRs
- common/sys/ for CPU, APIC, PIC, IDT/GDT, SMP, IOMMU, SBI, exceptions
- common/drivers/ for console/display and serial output
- common/pxe/ for network boot via TFTP/PXE
These are the boundaries where the loader interacts with machine state and platform services.
8. Storage and filesystem layer
common/fs/ contains the bootloader’s media readers:
- FAT12/16/32
- ISO9660
- generic file abstraction
common/lib/part.* and common/sys/e820.* suggest storage and memory enumeration are integrated with partition parsing and BIOS/firmware memory maps. This layer feeds the payload loading and menu/config logic.
9. Boot protocol support
common/protos/ is the protocol handoff layer. It contains support for:
- Limine protocol
- Linux booting
- Multiboot 1
- Multiboot 2
- Chainloading
This is a key architectural boundary: the loader can discover a kernel or another boot target, build the required handoff structure, and transfer control using the selected protocol.
10. User interface and configuration
The boot menu and configuration parsing live in common/menu.c, common/lib/config.*, common/lib/term.*, and related helpers. The menu depends on display/terminal drivers and shared parsing/runtime code, making it a thin UI layer over the bootloader core rather than a separate subsystem.
11. Compression, image, and packing tooling
There are two compression-related paths:
- common/compress/gzip.* and common/lib/qoi.* for runtime handling in the loader
- tools/limlzpack.c and common/stb_image.c/patching for build-time packaging and image handling
These support packaging boot assets and decoding certain image/compressed resources used by the menu or boot media.
12. Host-side tooling and packaging
host/ builds the limine executable that runs on the developer’s machine, not on the target system. It is used to install/configure boot media and likely to assemble release layouts. This is the main host/target boundary in the repo: host code prepares artifacts, while stage1/ and common/ run on the machine being booted.
13. Build and release system
The project uses an Autotools + make style build (configure.ac, GNUmakefile.in, host/*.mk, common/common.mk, test/*.mk). GitHub Actions workflows in .github/workflows/ handle checks and releases. Generated linker scripts and assembly variants show the build is highly target-aware and produces multiple binaries per architecture/boot mode.
14. Validation and examples
The test/ directory contains sample kernels/payloads and linker scripts for verifying boot protocols, plus trampolines for Multiboot tests. contrib/test_gzip_qemu.sh suggests QEMU-based integration testing of the boot path. These tests exercise the full chain from prepared boot media through protocol handoff.
15. How to draw the diagram
A clear architecture diagram should show:
- Host tool / build pipeline on one side
- Stage1 boot loaders as the first runtime entry
- Shared common runtime in the middle
- Subsystems for memory, disk/filesystem, network, drivers, and UI feeding into
- Protocol-specific handoff modules
- OS kernel / chainloaded target as the final destination
The main idea is a layered bootloader: host tooling prepares artifacts, stage1 gets control from firmware, common services initialize hardware and load media, and protocol modules hand off to the chosen OS payload.
Main entry points: menu.c Core runtime · configure.ac Build system · limine.c limine tool · bootsect.asm Stage 1
Components 17
Host side
User-space tooling and build pipeline
- Build system · Configure and make-based build and release orchestration
configure.ac - limine tool · User-space tool that prepares and installs boot media
host/limine.c - Test payloads · Sample kernels, trampolines, and linker scripts for protocol verification
test/limine.c
Boot runtime
Firmware-facing stage1 and shared loader execution
- Stage 1 · Early BIOS/CD/HDD/PXE bootstrap code
stage1/hdd/bootsect.asm - Entry glue · Architecture-specific transition into portable loader code
common/entry.s2.c - Platform glue · UEFI thunks, spinups, and linker-script variants per architecture
common/efi_thunk.asm_uefi_x86_64
Shared core
Portable runtime and subsystem implementations
- Core runtime · Shared bootloader logic for discovery, loading, and handoff
common/menu.c - Shared lib · Memory, strings, parsing, printing, images, config, and helpers
common/lib/libc.c - Memory mgr · Physical and virtual memory management plus firmware page tables
common/mm/pmm.c - System layer · CPU, interrupt, SMP, APIC, PIC, IOMMU, SBI, and exception setup
common/sys/cpu.s2.c - Filesystem · FAT and ISO9660 readers plus file abstraction
common/fs/file.s2.c - PXE/TFTP · Network boot support over PXE and TFTP
common/pxe/pxe.s2.c - Drivers · Serial, VGA/VBE, GOP, EDID, and disk-facing driver glue
common/drivers/serial.c - Protocols · Limine, Linux, Multiboot, and chainload handoff implementations
common/protos/limine.c - Boot menu · Configuration-driven boot menu and selection flow
common/menu.c - Compression · Runtime gzip and related asset/image decoding support
common/compress/gzip.c - Storage loaders · Disk and filesystem media readers feeding payload loading
common/drivers/disk.s2.c
Connections 22
- Build system → limine tool: builds · Build system produces the host-side installer tool
- Build system → Stage 1: builds · Build system assembles stage1 boot binaries and variants
- Build system → Core runtime: builds · Build system links the shared loader runtime for multiple targets
- limine tool → Stage 1: writes media · Host tool prepares bootable images containing stage1 and loader assets
- Stage 1 → Platform glue: enters · Firmware or BIOS hands control to architecture-specific startup glue
- Platform glue → Entry glue: transitions · Thunk and spinup code enters portable entry paths
- Entry glue → Core runtime: jumps to · Entry glue transfers control into the shared loader core
- Core runtime → Shared lib: depends on · Core logic uses the shared runtime library layer
- Core runtime → Memory mgr: initializes · Loader core sets up memory management
- Core runtime → System layer: initializes · Loader core configures CPU and platform state
- Core runtime → Drivers: uses · Runtime uses console, display, serial, and disk drivers
- Core runtime → Filesystem: scans · Runtime scans boot media through filesystem readers
- Core runtime → PXE/TFTP: network boots · PXE path supplies network-loaded payloads
- Core runtime → Storage loaders: reads · Storage layer provides disk and ISO access to payload loading
- Core runtime → Boot menu: presents · Menu provides boot selection and configuration UI
- Core runtime → Compression: decodes · Compression and image helpers support boot assets and menu resources
- Core runtime → Protocols: hands off · Protocol modules build kernel handoff state and transfer control
- Boot menu → Drivers: renders via · Menu output depends on display and terminal drivers
- Boot menu → Shared lib: parses via · Menu relies on config and shared parsing helpers
- Filesystem → Shared lib: uses · Filesystem readers rely on common parsing and utility code
- Protocols → Test payloads: verified by · Protocol implementations are exercised by sample payloads and trampolines
- limine tool → Test payloads: checked against · Host tooling and layouts are validated with integration test assets