# die-banane/bootloader architecture

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

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

## Overview

This is a small x86 BIOS bootloader: stage 1 loads stage 2, whose C entry initializes the console, locates the active partition, and initializes a FAT volume. The sampled FAT code also provides directory lookup and FAT16 file-reading logic, backed by BIOS disk reads. Stage-2 support includes real-mode entry, A20/GDT setup, VGA text output, and freestanding formatting/string helpers. Several assembly modules and FAT-related paths are represented from the tree, but their internal call relationships were not sampled; those links are omitted.

Main entry points: [`src/stage2/main.c`](https://github.com/die-banane/bootloader/blob/main/src/stage2/main.c) (Stage-2 Main), [`src/stage2/fs/fat/fat.c`](https://github.com/die-banane/bootloader/blob/main/src/stage2/fs/fat/fat.c) (FAT Volume Init), [`src/stage2/bios.c`](https://github.com/die-banane/bootloader/blob/main/src/stage2/bios.c) (Disk Read Wrapper), [`src/stage2/console.c`](https://github.com/die-banane/bootloader/blob/main/src/stage2/console.c) (VGA Console)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_boot["Boot Stages"]
  node_stage1["Stage-1 MBR<br/>[mbr.asm]"]
  node_stage2entry["Stage-2 Entry<br/>[entry.asm]"]
  node_a20["A20 Setup<br/>[a20.asm]"]
  node_gdt["GDT Setup<br/>[gdt.asm]"]
end

subgraph group_fs["FAT Filesystem"]
  node_fatinit["FAT Volume Init<br/>[fat.c]"]
  node_partition["Active Partition<br/>[fat.c]"]
  node_rootdir["Root Directory<br/>[fat.c]"]
  node_fatread["FAT File Reading<br/>[fat.c]"]
  node_fsapi["Filesystem API<br/>[filesystem.h]"]
  node_fsutil["Filesystem Error Text<br/>[fs.c]"]
end

subgraph group_io["BIOS Disk I/O"]
  node_biosread["Disk Read Wrapper<br/>[bios.c]"]
  node_biosint["BIOS Disk Interrupt<br/>[bios16.asm]"]
end

subgraph group_runtime["Stage-2 Runtime"]
  node_main["Stage-2 Main<br/>[main.c]"]
  node_stdio["Formatted Output<br/>[stdio.c]"]
  node_console["VGA Console<br/>[console.c]"]
  node_strings["String Primitives<br/>[string.c]"]
  node_ctype["Character Helpers<br/>[ctype.c]"]
end

node_firmware(("BIOS Firmware"))

node_main -->|"clears screen"| node_console
node_main -->|"finds partition"| node_partition
node_main -->|"initializes volume"| node_fatinit
node_main -->|"prints errors"| node_stdio
node_main -->|"sets color"| node_console
node_fatinit -->|"uses partition"| node_partition
node_fatinit -->|"loads directory"| node_rootdir
node_fatinit -->|"reads boot sector"| node_biosread
node_rootdir -->|"reads directory sectors"| node_biosread
node_fatread -->|"reads file clusters"| node_biosread
node_biosread -->|"calls disk service"| node_biosint
node_biosint -.->|"requests disk I/O"| node_firmware
node_stdio -->|"writes characters"| node_console
node_stage1 -->|"loads stage two"| node_stage2entry

click node_stage1 "https://github.com/die-banane/bootloader/blob/main/src/stage1/mbr.asm"
click node_stage2entry "https://github.com/die-banane/bootloader/blob/main/src/stage2/entry.asm"
click node_a20 "https://github.com/die-banane/bootloader/blob/main/src/stage2/a20.asm"
click node_gdt "https://github.com/die-banane/bootloader/blob/main/src/stage2/gdt.asm"
click node_main "https://github.com/die-banane/bootloader/blob/main/src/stage2/main.c"
click node_fatinit "https://github.com/die-banane/bootloader/blob/main/src/stage2/fs/fat/fat.c"
click node_partition "https://github.com/die-banane/bootloader/blob/main/src/stage2/fs/fat/fat.c"
click node_rootdir "https://github.com/die-banane/bootloader/blob/main/src/stage2/fs/fat/fat.c"
click node_fatread "https://github.com/die-banane/bootloader/blob/main/src/stage2/fs/fat/fat.c"
click node_fsapi "https://github.com/die-banane/bootloader/blob/main/src/stage2/include/filesystem.h"
click node_biosread "https://github.com/die-banane/bootloader/blob/main/src/stage2/bios.c"
click node_biosint "https://github.com/die-banane/bootloader/blob/main/src/stage2/bios16.asm"
click node_stdio "https://github.com/die-banane/bootloader/blob/main/src/stage2/stdio.c"
click node_console "https://github.com/die-banane/bootloader/blob/main/src/stage2/console.c"
click node_strings "https://github.com/die-banane/bootloader/blob/main/src/stage2/string.c"
click node_ctype "https://github.com/die-banane/bootloader/blob/main/src/stage2/ctype.c"
click node_fsutil "https://github.com/die-banane/bootloader/blob/main/src/stage2/fs/fs.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_stage1,node_stage2entry,node_a20,node_gdt toneBlue
class node_fatinit,node_partition,node_rootdir,node_fatread,node_fsapi,node_fsutil toneAmber
class node_biosread,node_biosint toneMint
class node_main,node_stdio,node_console,node_strings,node_ctype toneRose
class node_firmware toneIndigo
```

## Components

### Boot Stages

- [Stage-1 MBR](https://github.com/die-banane/bootloader/blob/main/src/stage1/mbr.asm): `src/stage1/mbr.asm`
- [Stage-2 Entry](https://github.com/die-banane/bootloader/blob/main/src/stage2/entry.asm): `src/stage2/entry.asm`
- [A20 Setup](https://github.com/die-banane/bootloader/blob/main/src/stage2/a20.asm): `src/stage2/a20.asm`
- [GDT Setup](https://github.com/die-banane/bootloader/blob/main/src/stage2/gdt.asm): `src/stage2/gdt.asm`

### FAT Filesystem

- [FAT Volume Init](https://github.com/die-banane/bootloader/blob/main/src/stage2/fs/fat/fat.c): `src/stage2/fs/fat/fat.c`
- [Active Partition](https://github.com/die-banane/bootloader/blob/main/src/stage2/fs/fat/fat.c): `src/stage2/fs/fat/fat.c`
- [Root Directory](https://github.com/die-banane/bootloader/blob/main/src/stage2/fs/fat/fat.c): `src/stage2/fs/fat/fat.c`
- [FAT File Reading](https://github.com/die-banane/bootloader/blob/main/src/stage2/fs/fat/fat.c): `src/stage2/fs/fat/fat.c`
- [Filesystem API](https://github.com/die-banane/bootloader/blob/main/src/stage2/include/filesystem.h): `src/stage2/include/filesystem.h`
- [Filesystem Error Text](https://github.com/die-banane/bootloader/blob/main/src/stage2/fs/fs.c): `src/stage2/fs/fs.c`

### BIOS Disk I/O

- [Disk Read Wrapper](https://github.com/die-banane/bootloader/blob/main/src/stage2/bios.c): `src/stage2/bios.c`
- [BIOS Disk Interrupt](https://github.com/die-banane/bootloader/blob/main/src/stage2/bios16.asm): `src/stage2/bios16.asm`

### Stage-2 Runtime

- [Stage-2 Main](https://github.com/die-banane/bootloader/blob/main/src/stage2/main.c): `src/stage2/main.c`
- [Formatted Output](https://github.com/die-banane/bootloader/blob/main/src/stage2/stdio.c): `src/stage2/stdio.c`
- [VGA Console](https://github.com/die-banane/bootloader/blob/main/src/stage2/console.c): `src/stage2/console.c`
- [String Primitives](https://github.com/die-banane/bootloader/blob/main/src/stage2/string.c): `src/stage2/string.c`
- [Character Helpers](https://github.com/die-banane/bootloader/blob/main/src/stage2/ctype.c): `src/stage2/ctype.c`

### Other components

- **BIOS Firmware**

## Connections

- Stage-2 Main → VGA Console: clears screen (evidence: `src/stage2/main.c`)
- Stage-2 Main → Active Partition: finds partition (evidence: `src/stage2/main.c`)
- Stage-2 Main → FAT Volume Init: initializes volume (evidence: `src/stage2/main.c`)
- Stage-2 Main → Formatted Output: prints errors (evidence: `src/stage2/main.c`)
- Stage-2 Main → VGA Console: sets color (evidence: `src/stage2/main.c`)
- FAT Volume Init → Active Partition: uses partition (evidence: `src/stage2/fs/fat/fat.c`)
- FAT Volume Init → Root Directory: loads directory (evidence: `src/stage2/fs/fat/fat.c`)
- FAT Volume Init → Disk Read Wrapper: reads boot sector (evidence: `src/stage2/fs/fat/fat.c`)
- Root Directory → Disk Read Wrapper: reads directory sectors (evidence: `src/stage2/fs/fat/fat.c`)
- FAT File Reading → Disk Read Wrapper: reads file clusters (evidence: `src/stage2/fs/fat/fat.c`)
- Disk Read Wrapper → BIOS Disk Interrupt: calls disk service (evidence: `src/stage2/bios.c`)
- BIOS Disk Interrupt → BIOS Firmware: requests disk I/O
- Formatted Output → VGA Console: writes characters (evidence: `src/stage2/stdio.c`)
- Stage-1 MBR → Stage-2 Entry: loads stage two
