TannX OS GitHub

Architecture

One kernel file. One gate. Everything else in ring 3.

The kernel is agentos32.S, about 16.8k lines of GNU assembler (AT&T syntax, no compiler, no libc, no BIOS calls after boot). Agents, drivers, the desktop and the apps are freestanding C in ring 3, behind a single DPL-3 interrupt gate. Everything on this page is taken from docs/ARCHITECTURE.md.

The layer model

Kernel, ring 0: agentos32.S

GDT/IDT, paging with an unmapped page 0 (NULL protection) and fault isolation – #PF, #GP and #UD kill one agent, never the box – preemptive round-robin multitasking, opt-in SMP (INIT-SIPI, per-core scheduler, spinlocks around the task tables), one syscall gate, a kernel heap, a dmesg ring, E820/SMBIOS/cpuid, CPU and RAM self-tests and a watchdog for runaway agents.

In-kernel drivers: VGA text and VBE/GOP framebuffer with its own font, PS/2 keyboard and mouse, EHCI USB HID, 16550 serial, PIT/RTC, ATA PIO, AHCI/SATA + ATAPI, RTL8139, RTL8168, e1000, virtio-net, AC97 and the PC speaker. Size budget: the kernel content must stay under 131072 bytes.

Boot paths

Three ways in, one kernel at 0x7E00.

BIOS

Stage 1 · two-sector-batch loader

The boot sector loads 256 kernel sectors in two 128-sector INT 13h reads (SeaBIOS refuses more per call), or via CHS when the boot drive is a floppy. Stage 2 makes the last BIOS call, collects E820, enables A20, loads the GDT and jumps.

UEFI

agentos-uefi.S · hand-laid PE32+

Runs in long mode, reads kernel32.bin from the ESP, enumerates GOP modes, calls ExitBootServices and descends to protected mode with its own GDT. It leaves a boot-info block at 0x28000; the kernel renders the console into the GOP framebuffer with its own 8×16 font.

PXE

pxe_stage1.S · 512 bytes · diskless

The NIC's option ROM downloads pxe.img to 0x7C00; the kernel lands at 0x7E00 exactly where the disk loader would have put it. No disk: AgentFS slots become RAM-backed, so the loop runs on a diskless machine without ever writing someone else's disk.

Memory map

Identity-mapped, page 0 unmapped.

Physical equals virtual for the first 32 MB. A selection of the map; the full table with every DMA ring and stack lives in the architecture doc. Hardcoded addresses are named .equ constants in the kernel.

0x00000–0x00FFFpage 0: unmapped – NULL protection. IVT and BDA are dead after boot.
0x07C00Stage 1 (boot sector + MBR partition table)
0x07E00–0x27DFFthe kernel, 256 sectors – readable from ring 3, not writable
0x28000UEFI boot info (framebuffer base, resolution, GOP mode list)
0x2F000IDT, 256 gates built at runtime
0x30000–0x38FFFpage directory and 8 page tables
0x41000–0x48FFFkernel stacks of the agent threads, TID 1–8, 4 KB each
0x50000–0x8FFFFkernel heap (kmalloc/kfree, supervisor-only; relocates to 64 MB on machines with ≥ 96 MB)
0xB8000VGA text RAM, supervisor-only – task scan b8000 kills the agent
0x102000dmesg ring
0x141000+user stacks of the agent threads
0x400000the ring-3 C program (user.bin, loaded by run)
disk LBA 256medium marker AGENTOS-MEDIUM – without it diskon arms RAM-backed slots, a foreign disk is never written
disk LBA 257–264AgentFS, 8 slots × 512 B (ring 3 writes them only via SYS_WRITE_SLOT)
disk LBA 265–272the wish slots

The syscall table

27 numbers, one door.

INT 0x30, EAX = number. The user-space stubs are in user/libc.h.

  • 0yield
  • 1claim
  • 2progress
  • 3finish
  • 4exit
  • 5write
  • 6putc
  • 7fbinfo
  • 8getkey
  • 9uptime
  • 10read_sectors
  • 11sbrk
  • 12net_tx
  • 13net_rx
  • 14net_mac
  • 15write_slot
  • 16pci_cfg
  • 17mmio_map
  • 18task_info
  • 19console
  • 20agents
  • 21atp
  • 22setmission
  • 23sysinfo
  • 24kbgrab
  • 25fgrab
  • 26shell

Notable doors: 15 write_slot writes AgentFS slots only and is diskon-gated – this is how llmscript persists model-written scripts. 16 pci_cfg and 17 mmio_map (an uncached 4 MB user page, refused for anything inside mapped system RAM) are why drivers can live in ring-3 C. 26 shell types a line into the shell – the guided tour runs spawn prime for real this way.

Iron rules

Six rules every session works by.

  1. make test-all green before every commit. No exceptions.
  2. Protected strings. The test gate greps the banner word TannX, the prompt tannx>, the status names and a few messages. They change only together with the test.
  3. ASCII only in OS strings; code, comments and docs in English.
  4. Size budget: kernel content under 131072 bytes. Growing past 256 sectors means relocating the UEFI info block, the user stacks and the NIC rings – not a one-line bump.
  5. Page 0 is off-limits, never set CR0.WP. The kernel writes U=1/W=0 pages only because WP=0; UEFI firmware hands over with WP=1, which once meant a #PF recursion and a triple fault. Exactly one DPL-3 gate.
  6. One change = one commit.

Trust model

Decided, documented, not a bug.

TannX OS is a lab OS. It assumes a trusted LAN and treats its ring-3 userspace as trusted. The MMU still protects the kernel – NULL guard, fault isolation, sc_chkbuf on every pointer syscall, sys_mmio_map refuses pages inside system RAM – but a ring-3 program with a DMA engine can defeat that by design, because that is what lets drivers live in C.

The remote-control channel on UDP 4713 is compiled out of the default build and exists only with make REMOTE_CTL=1. The host proxy binds to localhost. There is no TLS in the OS and none is planned.

Lessons paid for

"Works in QEMU" is not "works on silicon".

The segment-nulling triple fault (v1.9–v1.11)

The first boot on the real test PC rebooted on spawn math. A real CPU NULLs any data segment register that still holds a DPL-0 selector on a return to ring 3 – a privilege-leak guard QEMU does not implement. The kernel now loads the target ring's data segments before the iret. The gap between emulator and silicon is widest exactly at privilege transitions, DMA and firmware handover.

A storage driver written blind (v1.52–v1.57)

The test PC's chipset exposes SATA only through AHCI. The driver was developed against QEMU's ICH9 AHCI and then brought up on the real machine without a screen or keyboard: it reported its own registers over UDP, found an ATAPI DVD drive on port 4, and read the model string and "no media" from a real SCSI round-trip. A driver that reports its registers over the wire can be brought up on hardware you cannot see.

One clobbered register (v1.92–v1.95)

The EHCI keyboard driver saw every key, yet nothing echoed: the periodic USB poll, called from the idle loop, clobbered EDI – the shell's line-buffer pointer. One pushal/popal pair fixed it. Rule carried forward: a routine called from the idle loop must preserve every register.

A protective refusal that blocked the headline feature (v2.60)

On a diskless, PXE-booted box diskon refused, because the only disk was a foreign Linux install – so the whole agent-language loop could not run on the actual hardware. The fix keeps the promise: diskon now arms RAM-backed slots instead of refusing. Writes are volatile, the foreign disk is never touched, and a real model wrote a script into RAM slot 7 that the OS executed.

The harvest was blind for ~70 versions (v2.47)

A disk-layout move had left three host-side scripts on the old sector numbers: make wishes read mid-kernel bytes instead of the wish slots, the live boot ran a half-refreshed kernel, and the live image had no medium marker. Every QEMU suite stayed green, because they use fresh images and the OS-internal paths agreed with themselves. A layout move must grep the host scripts too.