SchOS/docs/architecture
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Nexoniarz 60d06658f0 gfx: draw the console in RAM, and write it to the card write-combined
On the first real machine with a discrete card (an RTX 3060, 800x600 from
the UEFI GOP) the console was slow enough to photograph mid-scroll, and the
boot died on CPU 1's "cpu1: starting": CPU 0 spun 200M times on the console
lock while CPU 1 held it, scrolling, and called it a deadlock.

The framebuffer is device memory in the uncached 3-4 GB page of the direct
map. QEMU's stdvga is RAM underneath, so nothing showed there; on a card,
gfx_scroll_up's memmove read the whole screen back across the bus one byte
at a time, and every anti-aliased glyph read back each pixel it blended.

So the console now draws into a copy of the screen in RAM (vmap_alloc: kalloc
pages behind a page table of their own, since nothing needs it contiguous),
and gfx_flush() copies the changed rectangle onto the card through an
ioremap_wc() mapping -- PAT entry 4 set to write-combining on every CPU.
Flushes happen where drawing ends: a message, a terminal write, an echo, a
terminal switch. Scrolling moves eight bytes at a time instead of one.

/dev/fb0 reads and writes the card itself, as before. The early console's
fb_info now carries the physical address it always should have.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S1giNvrHTrPMPw7V6x1kQ4
2026-10-22 23:46:58 +02:00
..
audio.md licence: SchOS is GPL-2.0-or-later, no longer Apache-2.0 2026-10-22 08:48:45 +02:00
boot.md storage: NVMe, so a laptop's SSD is a disk SchOS can boot from 2026-10-22 15:48:11 +02:00
debugging.md dbg: the boot menu can turn on remote debugging, in a debug build 2026-09-24 15:05:23 +02:00
devices.md acpi: uACPI, for interrupt routing, the power button and power-off 2026-10-22 16:12:28 +02:00
filesystem.md zsh: two more cache answers that claimed capabilities SchOS lacks 2026-09-22 00:36:48 +02:00
graphics.md gfx: draw the console in RAM, and write it to the card write-combined 2026-10-22 23:46:58 +02:00
init.md hybrid: the driver is killed, and the driver comes back 2026-09-14 00:05:43 +02:00
kernel.md memfd: a shared memory object you reach by descriptor 2026-09-22 09:47:31 +02:00
ldls.md licence: SchOS is GPL-2.0-or-later, no longer Apache-2.0 2026-10-22 08:48:45 +02:00
networking.md net: an RTL8139 driver, and the e1000 stops refusing the PCIe parts 2026-09-24 15:30:38 +02:00
README.md audio: /dev/dsp, AudioEngine, and an AC'97 under it 2026-09-24 14:23:13 +02:00
schfs.md schfs: records at arbitrary offsets are packed, and the compiler is told 2026-09-12 17:56:36 +02:00
syscalls.md sockets: a descriptor can cross between processes 2026-09-13 19:49:37 +02:00
terminals.md licence: SchOS is GPL-2.0-or-later, no longer Apache-2.0 2026-10-22 08:48:45 +02:00
usb.md usb: plug and play -- hot-plug, unplug, every interface, real mice 2026-10-22 11:38:13 +02:00

The system, layer by layer

What SchOS is today. Everything in this directory is built and running; what is merely intended lives in ../plan/.


The names, and what each one covers

uname -s reports SchIFT, the way every Unix reports its kernel rather than its distribution.

Layer Name What it is
System SchOS The distribution — kernel, userland, tooling
Kernel SchIFT Multi-core x86-64 kernel with a modular VFS
Filesystem SchFS Transactional, copy-on-write, the root filesystem
API SchAPI The native programming interface — designed, not built
Compositor Schcom Owns the display; v0 runs

Six virtual terminals sit under all of it -- /dev/tty1..tty6, AltGr+F1..F6 or chvt N -- each with its own screen, line discipline and foreground process group. See terminals.md.


The stack, bottom to top

      ┌─────────────────────────────────────────────────┐
      │ toybox  kilo  mksh  zsh  musl  first-party cmd/ │   userland
      ├─────────────────────────────────────────────────┤
      │  vgpud — a driver that is an ordinary process   │
      ├─────────────────────────────────────────────────┤
      │  schinit — PID 1, job manifests, supervision    │
      ├─────────────────────────────────────────────────┤
      │  syscall table — Linux numbering, one .inc file │   ← the ABI seam
      ╞═════════════════════════════════════════════════╡
      │  VFS │ sockets │ signals │ mmap │ poll │ procfs │
      ├──────┴─────────┴─────────┴──────┴──────┴────────┤
      │  SchFS  │  lwIP  │  vt/gfx  │  buffer cache     │
      ├─────────┴────────┴──────────┴───────────────────┤
      │  device model — class vtables, bus binding      │   ← the driver seam
      ├─────────────────────────────────────────────────┤
      │  /dev/pci — MMIO, DMA and IRQs to a process     │   ← the eviction seam
      ├─────────────────────────────────────────────────┤
      │ drivers: xHCI  e1000  virtio-gpu  VBE  IDE  PS/2│
      ├─────────────────────────────────────────────────┤
      │  scheduler │ paging │ traps │ IRQ │ SMP │ DMA   │   SchIFT core
      └─────────────────────────────────────────────────┘
                            ▲
                   UEFI loader (boot/uefi)

Three seams matter. Above the syscall table, software is ordinary and portable — musl and toybox are unmodified. Below the device model, a driver never names its consumer and a consumer never names a driver. And at /dev/pci, a driver stops having to be in the kernel at all: a process is handed a device's registers, DMA memory and interrupts, and the in-kernel driver that held it releases it cleanly. vgpud is the virtio-gpu driver living out there today. See ../plan/hybrid.md.


Where it came from

SchOS began as xv6 and is now mostly something else. What survives from xv6 is the shape of the process table, the sleep/wakeup discipline, and the buffer cache. What has been replaced: the scheduler and trap path (rewritten for x86-64 and for more than one processor), the memory manager, the entire filesystem, the syscall layer, and every driver.

That inheritance is worth knowing when reading the code, because the parts that still look like xv6 follow xv6's conventions and the parts that do not, do not.


The documents

Read in this order if you are new:

boot.md Firmware to the first userspace process. The shortest path through the whole system.
kernel.md Memory, processes, scheduling, traps, signals, SMP.
syscalls.md The one table everything is generated from, and how a musl binary runs unmodified.
filesystem.md The VFS, the buffer cache, mounts, procfs.
schfs.md The copy-on-write root filesystem.
devices.md Buses, classes, binding, and the vtables consumers talk to.
usb.md xHCI, the USB core, and the three class drivers.
graphics.md Framebuffer, text rendering, the console, and PSOGM.
terminals.md The six virtual terminals, and the chord that switches them.
networking.md NIC drivers, lwIP, and both socket families.
audio.md /dev/dsp, AudioEngine, and the AC'97 driver under it.
init.md schinit, PID 1 as a role, and the job manifests.
debugging.md Symbols, a log that outlives the kernel, and asking the kernel a question.
ldls.md Running somebody else's drivers: a Linux .ko, in a process, reaching hardware through /dev/pci.

Three rules that hold across all of it

The kernel and the host tools compile the same SchFS source. mkschfs cannot disagree with the kernel about the on-disk format, because there is only one implementation. Format bugs are found on the host, where a test takes a second instead of a boot.

Syscalls are declared in exactly one place. kernel/sys/table.inc. The constants, the dispatch table and the Linux translation map are all generated from it, so a syscall cannot be half-registered.

A list you can read beats a list assembled by side effects. Drivers are written out by hand in kernel/drivers/registry.c rather than collected by a linker section, and platform devices are registered in one function rather than inside each driver's init. The tradeoff is deliberate: self-registration is nicer to write, and it means the list of what is in your kernel is not written down anywhere you can read.