SchOS/docs/plan/README.md
Nexoniarz 1dd4ba0186 debugger: the kernel can be asked a question
docs/plan/debugger.md, milestones D0, D1 and D2. What they replace is the
ninety-second loop -- add a cprintf, rebuild, boot, read the serial log --
which answers exactly the one question you thought of before the rebuild.

The rule the shape follows: **it observes, it does not control.** No
stepping, no software breakpoints, no stopping the world. Half the bugs
this kernel produces are timing -- an interrupt storm, a level-triggered
line nobody acknowledges, a driver that faults only on its second start --
and every one of them disappears when you halt the machine to look. And
the layering rule, which is the circularity rule the display already has:
a debugger that needs lwIP cannot debug lwIP.

D0 -- symbols. tools/ksyms.pl turns the first link pass into a table the
second pass carries. Two passes is enough because .ksym is placed after
.text and .rodata, so carrying the table cannot move anything recorded in
it; the build lists both passes' text symbols and refuses to link if they
ever disagree, because a symbol table that is subtly wrong gives confident
false answers. ksym.c reads it through weak symbols, so pass one -- which
has no table -- still links. A crash chain now reads panic+0x5f <-
proc_sysrq_cmd+0x99 <- ... <- syscall+0xf6.

D1 -- a log that outlives the kernel. Every character through consputc()
lands in a byte ring with a timestamp per line, readable as /proc/kmsg.
It sits in a region carved before the page allocator gets anything, with a
magic header, so a kernel finds the previous kernel's log still there --
including the whole PSOGM report. panic.c's own comment said "there is no
core dump and no log to go back to"; that is no longer true.

  The obvious place for it is the top of RAM beside the DMA arena. That
  was the first attempt and the magic came back as ASCII on the reboot,
  because the top of usable memory is exactly where the firmware makes its
  own allocations. It lives above the kernel image instead, which is a
  stable address across boots of the same build.

D2 -- the introspection registry. A subsystem publishes its state with one
line at the bottom of the file that owns the data:

  dbg_register("dma", dma_dump, "the DMA arena's free extents");

Seven views -- dma, mem, proc, vma, claims, pci, sock -- reachable three
ways: sysrq 'g' (always, no process and no filesystem), /dev/dbg (echo a
line, cat the answer), and schdbg. The protocol is lines of text because
the same bytes have to work where nothing can allocate or frame a record,
and because a protocol you cannot drive by hand is one you cannot debug.
struct sbuf moved out of kernel/dev/procfs.c into include/sbuf.h rather
than being written a second time.

Several views exist because of a specific bug. `vma` is the table that
decides whether exit() frees a page, and the DMA ownership bug that made
this worth building was a block that was never in it.

Also fixed, found by building with clang for the first time in a while:
struct iovec was defined in both posix.h and socket.h, and every file that
included both was a redefinition. GCC 15 defaults to C23, which permits an
identical struct redeclaration, so the gcc path never noticed -- while
clang defaults to gnu17 and rejected it, breaking the one toolchain
shell.nix exists to provide and the UEFI loader requires. Both are now
guarded.

D3 (`whose <addr>`, the cross-subsystem ownership query) and D4 (hardware
watchpoints on DR0-DR3) are not built and are described honestly as
missing in the architecture doc's "What it does not do".

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VQ7Qx8E1q1M1bbCq8QLHS2
2026-09-14 00:58:45 +02:00

6.2 KiB
Raw Blame History

What happens next

Everything in this directory is unbuilt. When a piece of it is finished it leaves — deleted from here, rewritten as a description in ../architecture/. See the rule.

Read 1.0.md first.

It draws a finish line and puts most of the work below on the far side of it. Anything not named there is not being worked on, and the documents in this directory describe more than 1.0 contains.

It also holds the register of unfinished work, which is the one place anything half-built is listed. No new capability starts until that register is empty, and a row leaves it only by being finished or by being deleted from the tree.


The three current decisions

Taken together, because they turn out to need the same foundation.

wayland.md The GUI stack becomes Wayland. SchWM and SchDE are deleted — actually gone from the tree, not marked; Schcom survives and changes its wire format.
hybrid.md The kernel becomes hybrid — drivers move out into userspace processes, starting with the GPU. Partly built: all four mechanisms exist and the GPU driver already runs outside the kernel.
init.md Built. PID 1 is now a role the kernel refills; the description moved to ../architecture/init.md.

And the one they all wait on:

foundations.md Descriptor passing, shared memory, sockets in the filesystem. The critical path. Item 1 is built — sendmsg/recvmsg with SCM_RIGHTS.

And the one that says which parts of the above are actually being worked on:

1.0.md The finish line. Four gates, and everything else explicitly deferred.

And one that is a tool rather than a capability:

debugger.md A debugger for this kernel — one that observes rather than halts, and answers in this kernel's own vocabulary. Mostly built: symbols, a log that outlives the kernel, and /dev/dbg are done and described in ../architecture/debugging.md.

Two longer-horizon documents sit behind these: schapi.md, the API layering and the compatibility promise, and roadmap.md, which holds everything still open that is not one of the three above.


The order

Set by 1.0.md, which is the authority. In short:

0. Fix what is already wrong — first

Not a document of its own; it is Gate 0 of 1.0.md, assembled from the What it does not do sections in ../architecture/.

Before any new capability, and the reason is the one that put netdev_selftest() before the TCP/IP stack: a compositor built on a kernel with an unexplained hang and a socket layer that reports success for things it did not do will fail in ways indistinguishable from its own bugs.

1. foundations.md — the critical path

Both the Wayland work and the hybrid work stop here. Descriptor passing and shared memory are the substrate for handing a buffer to a compositor and for handing a device to a driver process. Doing it once for both is the entire reason these are one plan rather than three.

2. init.md — before the desktop, not after — done

A compositor being brought up for the first time crashes constantly, and something that restarts it and says why is worth far more during that work than at the end of it. Built; see ../architecture/init.md.

3. hybrid.md — moved up, and the reason is worth recording

This document used to put the hybrid work after 1.0, deliberately last, on this argument:

designing a userspace driver interface with no driver consuming it produces an interface that is wrong in ways nobody can see

The argument was sound and the conclusion drawn from it was wrong. What forced the change was the driver situation: SchOS cannot write a driver for every device that exists, no project can, and the only route to the hardware support an established OS has is a compatibility layer with the foreign drivers kept outside the kernel. That layer is this plan's mechanisms. It is not optional and it is not late work.

The original argument still holds, and it is answered rather than ignored: SchOS's own drivers are the consumers. vgpud is a real driver, with real requirements, and building the interface against it is what keeps it a general mechanism rather than a hole shaped like something foreign. The compositor is still a demanding consumer — it is no longer the only one available.

Four mechanisms, all built. One eviction done, one to go, then the foreign driver host.

4. wayland.md — with the GPU driver either side of the seam

W1–W3 and a terminal. W4 and W5 are post-1.0. Item 1 of foundations.md — descriptor passing — was the thing it could not start without, and it now exists.


In one sentence

Fix what is broken, build the descriptor-passing and shared-memory substrate, make init survivable, move the drivers out through an interface SchOS's own drivers have to live with first — and put a terminal on the screen.


What this plan does not address

Stated here so it is not mistaken for covered:

  • No IOMMU, so the hybrid work isolates against bugs and not against a hostile driver.
  • No page cache, so foundations.md delivers a memfd and not a general answer to shared file mappings. The general answer is still owed.
  • No garbage collector for descriptors in flight, so an AF_UNIX socket passed over itself and never received leaks. Bounded at thirty-two sockets, and nothing on this plan does it.
  • No dynamic linking, so no Mesa, no accelerated clients, and no third party shipping a .so for anything.
  • A new compatibility surface between PID 1 and PID 2, created by a plan whose own schapi.md §3 spends a section warning about those.
  • The three open networking items — getsockname, routing, and interrupt-driven receive — are untouched by any of this and still open. They are in roadmap.md.