# limine-bootloader/limine architecture

> Architecture diagram of the GitHub repository limine-bootloader/limine, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/limine-bootloader/limine
- Repository: https://github.com/limine-bootloader/limine

## Overview

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: [`common/menu.c`](https://github.com/limine-bootloader/limine/blob/v12.x/common/menu.c) (Core runtime), [`configure.ac`](https://github.com/limine-bootloader/limine/blob/v12.x/configure.ac) (Build system), [`host/limine.c`](https://github.com/limine-bootloader/limine/blob/v12.x/host/limine.c) (limine tool), [`stage1/hdd/bootsect.asm`](https://github.com/limine-bootloader/limine/blob/v12.x/stage1/hdd/bootsect.asm) (Stage 1)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_host["Host side"]
  node_build["Build system<br/>autotools+make<br/>[configure.ac]"]
  node_hosttool["limine tool<br/>host CLI<br/>[limine.c]"]
  node_tests["Test payloads<br/>integration tests<br/>[limine.c]"]
end

subgraph group_boot["Boot runtime"]
  node_stage1["Stage 1<br/>boot entry<br/>[bootsect.asm]"]
  node_entry["Entry glue<br/>arch startup<br/>[entry.s2.c]"]
  node_platform["Platform glue<br/>firmware boundary"]
end

subgraph group_core["Shared core"]
  node_runtime["Core runtime<br/>portable loader<br/>[menu.c]"]
  node_lib["Shared lib<br/>runtime support<br/>[libc.c]"]
  node_mm["Memory mgr<br/>mm<br/>[pmm.c]"]
  node_sys["System layer<br/>cpu+platform<br/>[cpu.s2.c]"]
  node_fs["Filesystem<br/>media access<br/>[file.s2.c]"]
  node_pxe["PXE/TFTP<br/>network boot<br/>[pxe.s2.c]"]
  node_drivers["Drivers<br/>console/display<br/>[serial.c]"]
  node_protos["Protocols<br/>handoff<br/>[limine.c]"]
  node_menu["Boot menu<br/>ui<br/>[menu.c]"]
  node_compress["Compression<br/>codec<br/>[gzip.c]"]
  node_storage["Storage loaders<br/>disk+iso<br/>[disk.s2.c]"]
end

node_build -->|"builds"| node_hosttool
node_build -->|"builds"| node_stage1
node_build -->|"builds"| node_runtime
node_hosttool -->|"writes media"| node_stage1
node_stage1 -->|"enters"| node_platform
node_platform -->|"transitions"| node_entry
node_entry -->|"jumps to"| node_runtime
node_runtime -->|"depends on"| node_lib
node_runtime -->|"initializes"| node_mm
node_runtime -->|"initializes"| node_sys
node_runtime -->|"uses"| node_drivers
node_runtime -->|"scans"| node_fs
node_runtime -->|"network boots"| node_pxe
node_runtime -->|"reads"| node_storage
node_runtime -->|"presents"| node_menu
node_runtime -->|"decodes"| node_compress
node_runtime -->|"hands off"| node_protos
node_menu -->|"renders via"| node_drivers
node_menu -->|"parses via"| node_lib
node_fs -->|"uses"| node_lib
node_protos -.->|"verified by"| node_tests
node_hosttool -.->|"checked against"| node_tests

click node_build "https://github.com/limine-bootloader/limine/blob/v12.x/configure.ac"
click node_hosttool "https://github.com/limine-bootloader/limine/blob/v12.x/host/limine.c"
click node_stage1 "https://github.com/limine-bootloader/limine/blob/v12.x/stage1/hdd/bootsect.asm"
click node_entry "https://github.com/limine-bootloader/limine/blob/v12.x/common/entry.s2.c"
click node_runtime "https://github.com/limine-bootloader/limine/blob/v12.x/common/menu.c"
click node_lib "https://github.com/limine-bootloader/limine/blob/v12.x/common/lib/libc.c"
click node_mm "https://github.com/limine-bootloader/limine/blob/v12.x/common/mm/pmm.c"
click node_sys "https://github.com/limine-bootloader/limine/blob/v12.x/common/sys/cpu.s2.c"
click node_fs "https://github.com/limine-bootloader/limine/blob/v12.x/common/fs/file.s2.c"
click node_pxe "https://github.com/limine-bootloader/limine/blob/v12.x/common/pxe/pxe.s2.c"
click node_drivers "https://github.com/limine-bootloader/limine/blob/v12.x/common/drivers/serial.c"
click node_protos "https://github.com/limine-bootloader/limine/blob/v12.x/common/protos/limine.c"
click node_menu "https://github.com/limine-bootloader/limine/blob/v12.x/common/menu.c"
click node_compress "https://github.com/limine-bootloader/limine/blob/v12.x/common/compress/gzip.c"
click node_storage "https://github.com/limine-bootloader/limine/blob/v12.x/common/drivers/disk.s2.c"
click node_platform "https://github.com/limine-bootloader/limine/blob/v12.x/common/efi_thunk.asm_uefi_x86_64"
click node_tests "https://github.com/limine-bootloader/limine/blob/v12.x/test/limine.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_build,node_hosttool,node_tests toneBlue
class node_stage1,node_entry,node_platform toneAmber
class node_runtime,node_lib,node_mm,node_sys,node_fs,node_pxe,node_drivers,node_protos,node_menu,node_compress,node_storage toneMint
```

## Components

### Host side

User-space tooling and build pipeline

- [Build system](https://github.com/limine-bootloader/limine/blob/v12.x/configure.ac): autotools+make · Configure and make-based build and release orchestration · `configure.ac`
- [limine tool](https://github.com/limine-bootloader/limine/blob/v12.x/host/limine.c): host CLI · User-space tool that prepares and installs boot media · `host/limine.c`
- [Test payloads](https://github.com/limine-bootloader/limine/blob/v12.x/test/limine.c): integration tests · Sample kernels, trampolines, and linker scripts for protocol verification · `test/limine.c`

### Boot runtime

Firmware-facing stage1 and shared loader execution

- [Stage 1](https://github.com/limine-bootloader/limine/blob/v12.x/stage1/hdd/bootsect.asm): boot entry · Early BIOS/CD/HDD/PXE bootstrap code · `stage1/hdd/bootsect.asm`
- [Entry glue](https://github.com/limine-bootloader/limine/blob/v12.x/common/entry.s2.c): arch startup · Architecture-specific transition into portable loader code · `common/entry.s2.c`
- [Platform glue](https://github.com/limine-bootloader/limine/blob/v12.x/common/efi_thunk.asm_uefi_x86_64): firmware boundary · 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](https://github.com/limine-bootloader/limine/blob/v12.x/common/menu.c): portable loader · Shared bootloader logic for discovery, loading, and handoff · `common/menu.c`
- [Shared lib](https://github.com/limine-bootloader/limine/blob/v12.x/common/lib/libc.c): runtime support · Memory, strings, parsing, printing, images, config, and helpers · `common/lib/libc.c`
- [Memory mgr](https://github.com/limine-bootloader/limine/blob/v12.x/common/mm/pmm.c): mm · Physical and virtual memory management plus firmware page tables · `common/mm/pmm.c`
- [System layer](https://github.com/limine-bootloader/limine/blob/v12.x/common/sys/cpu.s2.c): cpu+platform · CPU, interrupt, SMP, APIC, PIC, IOMMU, SBI, and exception setup · `common/sys/cpu.s2.c`
- [Filesystem](https://github.com/limine-bootloader/limine/blob/v12.x/common/fs/file.s2.c): media access · FAT and ISO9660 readers plus file abstraction · `common/fs/file.s2.c`
- [PXE/TFTP](https://github.com/limine-bootloader/limine/blob/v12.x/common/pxe/pxe.s2.c): network boot · Network boot support over PXE and TFTP · `common/pxe/pxe.s2.c`
- [Drivers](https://github.com/limine-bootloader/limine/blob/v12.x/common/drivers/serial.c): console/display · Serial, VGA/VBE, GOP, EDID, and disk-facing driver glue · `common/drivers/serial.c`
- [Protocols](https://github.com/limine-bootloader/limine/blob/v12.x/common/protos/limine.c): handoff · Limine, Linux, Multiboot, and chainload handoff implementations · `common/protos/limine.c`
- [Boot menu](https://github.com/limine-bootloader/limine/blob/v12.x/common/menu.c): ui · Configuration-driven boot menu and selection flow · `common/menu.c`
- [Compression](https://github.com/limine-bootloader/limine/blob/v12.x/common/compress/gzip.c): codec · Runtime gzip and related asset/image decoding support · `common/compress/gzip.c`
- [Storage loaders](https://github.com/limine-bootloader/limine/blob/v12.x/common/drivers/disk.s2.c): disk+iso · Disk and filesystem media readers feeding payload loading · `common/drivers/disk.s2.c`

## Connections

- 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
