Internals
The sections below follow Subverge from power-on to the prompt, and then cover how the parts fit together while it runs.
The pieces
| Piece | What it is | More |
|---|---|---|
| MBR and stage 2 | the bootloader for installed disks | boot |
boot.asm |
Multiboot entry, page tables, long mode | boot |
kmain |
brings everything up in order | below |
| interrupts | IDT, the two PICs, the PIT at 100 Hz | scheduler |
| scheduler | four tasks, one per tab, preemptive | scheduler |
| heap | one first-fit allocator for everything | memory |
| VGA | text mode, a buffer per tab, the font and palette, and graphics mode | screen |
| keyboard | PS/2, a key queue per task | ports |
| ATA | PIO, polled, four drives at most | disk layout |
| persistence | the state header and the five slots | saving |
| omega | the interpreter, worlds, transactions, GC | gc |
| ordinals | Cantor normal form and cardinal arithmetic | ordinals |
| root | the units, built at boot and rebuilt on edit | root |
| JIT | quotes to x86-64, plus the disassembler | JIT, dis |
| help | the table every word must be in | help |
| scrawl | the editor | scrawl |
Boot, in order
- The ISO's GRUB, or an installed disk's own bootloader, loads the kernel at 1 MiB and jumps to it in 32-bit protected mode with Multiboot information.
boot.asmbuilds an identity map of the first 4 GiB from 2 MiB pages, turns on PAE and long mode, loads a 64-bit GDT and callskmain.kmainfirst copies the kernel's.datasection aside, before anything's had a chance to change it, so thatinstallcan later write out a clean kernel.- VGA, the font and palette, and the CPU tables come up: the IDT, the remapped PICs.
- The Multiboot info is read for the memory size, the memory map and the loader's name.
- The heap is set up after the kernel, up to 64 MiB.
- The scheduler, then persistence, which looks for an installed drive and reads its state header.
- Every built-in word is registered, ordinals are initialised, and root is built from the units linked into the kernel, or from the root slot if there is one and it builds.
- Four tasks are started, one per tab, the PIT is set to 100 Hz, the keyboard is turned on, and interrupts are enabled.
kmainbecomes the idle task, runninghltin a loop.
When each tab's task first runs, it loads its saved world from its slot if there is one, tab 1 runs startup, and all four wait at a prompt.
Design
Most of the design follows from two decisions. Everything runs in ring 0 in a single address space, so the kernel and omega work on the same data structures directly. And nothing in an omega world is modified in place, which is what makes transactions, back and saving fast.
subverge