Commit Graph

119 Commits

Author SHA1 Message Date
Daniel Samson eabb81684a
M7: synchronous IPC — endpoints, handle table, IPC_Call/ReplyWait
The microkernel message backbone the VFS server and drivers will ride on.

- src/kernel/ipc_sync.zig: Endpoint (sender FIFO threaded via Task.next +
  a recv WaitQueue for servers + a small notification ring). call() (client
  sends, wakes a server, blocks) and replyWait() (server replies to the held
  caller, then receives the next). Reply routing keys on Task.ipc_client —
  synchronous IPC owes one reply at a time. Payloads copy frame-to-frame
  through the physmap (copyAcross on arch.translate, added in M5); an unmapped
  page fails the copy instead of #PF-ing. MSG_MAX 256.
- Bootstrap naming: an integer name registry (danos.ServiceId, vfs=1) with
  create_endpoint / ipc_register / ipc_lookup — any process finds a server
  without threading a handle through spawn.
- notifyFromIsr(): ISR-safe async wake (badge with the high bit set), the
  hook M10's IRQ-as-message needs. Unused/untested until then.
- Task gains handles[16] (opaque *Endpoint, to avoid a sched<->ipc import
  cycle) + ipc_client/send/reply/status fields; sched gains
  blockCurrentLocked/readyLocked; arch gains setSyscallResult2 (rdx badge).
- Syscalls 6..10 wired in process.zig; exit() now drops the caller's endpoint
  refs. lib/ipc.zig: user-side createEndpoint/register/lookup/call
  (server-side replyWait lands with the first server in M9).
- New `ipc-call` test: two kernel tasks ping-pong 100 calls, every reply
  request+1. Suite 29/29.
2026-07-09 07:20:57 +01:00
Daniel Samson 9316f9f1c3
M5: rename usermode->process, add yield + mmap/munmap syscalls
Start the user-space driver track (VFS + IPC + heap). This lays the
process/syscall foundation the runtime heap will grow on.

- Rename usermode.zig -> process.zig; drop the retired hello/ping blob and
  its `user` test (subsumed by the real /sbin/init exerciser). Keep the
  isolation-proof pf blob and the user-pf test.
- Add danos.Syscall as the single source of truth for syscall numbers, shared
  by the kernel dispatcher and (later) the user runtime lib. Dispatch on the
  enum. New calls: 1=yield, 4=mmap, 5=munmap. Widen debug_write's bounds
  check to the whole user low half so heap buffers are writable.
- mmap grants zeroed RW+NX pages from a per-process bump arena
  (Task.heap_next, PML4[224] above image+stack); munmap frees the frames.
  Add paging.translateIn / unmapInto (+ arch.translate / unmapUserPageInto)
  as the primitives munmap and future cross-AS copies need.
- New `usermem` test: grant three pages into a fresh AS, translate them,
  release via the munmap path, tear down, and assert no frames leak.
  Suite 28/28 (user -> usermem).
2026-07-09 06:55:09 +01:00
Daniel Samson 7384a730be
Rename the arch interface to arch-neutral terms
The generic kernel imports cpu.zig as @import("arch") but still spoke
x86: readCr3/readCr2, pml4 and rip/rsp parameters, lapicHz/tscHz,
ioapicEntry*, IST stacks, APIC ids. Rename the public interface so the
same names work for x86_64, aarch64, and riscv64:

- readCr3 -> activePageTable; pml4 params -> root; vectorName ->
  exceptionName; postCode -> checkpoint; lapicHz/tscHz ->
  timerClockHz/clockHz; ioapicEntry* -> irqRoute*; ist_stack_size/
  setApIstStack -> fault_stack_size/setFaultStack; startSecondary
  takes a hw_id (APIC id here; MPIDR/hart id elsewhere)
- New trap-frame accessors (instructionPointer, stackPointer,
  fromUser, faultAddress, syscallNumber/syscallArg/setSyscallResult)
  so the generic syscall dispatcher and fault printer never name an
  x86 register; readCr2 folds into faultAddress (null unless #PF)
- Generic-kernel identifiers follow: Task.pml4 -> aspace, rsp -> sp,
  user_rip/user_rsp -> user_ip/user_sp, PerCpu.apic_id -> hw_id

PlatformConfig fields and the ACPI apic_id stay as-is: they describe
hardware actually discovered on this platform, and another arch would
define its own. The user-mode tests now assert fromUser instead of
the exact CS selector; the user-pf expectation follows the fault
printer's RIP -> IP label. All 28 QEMU tests pass.
2026-07-09 05:52:05 +01:00
Daniel Samson 37fb3cb0cf
M3: real user processes — address spaces, syscall/sysret, swapgs
Per-process address spaces (AddressSpace = a PML4 with an empty user
half and the shared kernel half copied in; create/destroy in paging.zig)
with CR3 switched on context switch and TSS.rsp0/kernel_rsp published per
switch. The GS base now points at an arch per-CPU block and every ring
transition observes the swapgs discipline, so a ring-3 `mov %ax,%gs` can
no longer poison per-CPU access. syscall/sysret is the primary user entry
(int 0x80 kept as a test path); one handler, installed once at boot,
serves both and dispatches on whether the caller is a scheduled process
or a borrowed test thread. spawnProcess loads an ELF into a fresh address
space and schedules it; exit frees the address space after switching to
the kernel tables. New `process` test: init runs twice as a real process
(create/exit/recreate) on its own page tables, coexisting with a kernel
task under preemption. Suite 28/28.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-09 00:04:20 +01:00
Daniel Samson 546dd44a2a
isolation M1: ring 3 + a real /sbin/init, end to end
Ring 3 works: user GDT descriptors (sysret-ready layout), TSS.rsp0,
U/S-bit user mappings (W^X preserved), an int 0x80 syscall gate with a
mutable trap frame, and a setjmp-style enter/exit path. /sbin/init is a
real freestanding Zig binary built from sbin/, shipped on the ESP,
loaded by the bootloader (BootInfo.init_base/len), validated and mapped
by an in-kernel user-ELF loader, and run at CPL 3 — syscalls: exit,
ping, write. Tests: user, user-pf (U/S isolation proof, error code
0x5), init. Suite 27/27.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-08 22:15:07 +01:00
Daniel Samson 26ac97df31
test fault-on-AP and affinity; report the faulting core
fault-ap-df pins a #DF to an AP (its own IST must catch it); affinity checks a pinned task never migrates. onException now names the core, so an AP fault is attributed and shown contained. Both teeth-checked.
2026-07-08 14:45:28 +01:00
Daniel Samson f02259cae0
close audited test gaps: discovery, W^X, power
Add a discovery case (asserts stable ACPI/MADT/FADT/AML facts) and a wx case (audits R+X code vs NX data/rodata/heap/stack via arch.pageExecutable). Wire the existing poweroff/reboot cases into the harness. Suite: 18 -> 22.
2026-07-08 14:17:54 +01:00
Daniel Samson 91f2cfa17b
add smp-retry test for the AP wake retry path
Test hook forces the first wake to fail; the case asserts every core still comes online. Verified it fails when retry is disabled.
2026-07-08 13:41:14 +01:00
Daniel Samson dba3939a0f
add an SMP lock-stress test case
Four pairs push 400k sequenced messages through small channels; checks FIFO order and cross-core execution. Verified to fail with the lock disabled.
2026-07-08 12:45:02 +01:00
Daniel Samson 43afe6bf2e
schedule tasks across all cores
Per-core GDT/TSS and AP scheduler entry; fix AP SSE + single_threaded.
2026-07-08 12:35:30 +01:00
Daniel Samson 6f6ccc8bc9 moving kernel code to kernel/ 2026-07-05 10:19:11 +01:00
Daniel Samson 50f3610768
Update build to run qemu on MacOS 2026-07-03 16:43:00 +01:00
Daniel Samson 31bf86af56 IPC 2026-07-03 15:09:16 +01:00
Daniel Samson df774691c8 Fixed-priority preemptive scheduler 2026-07-03 14:30:33 +01:00
Daniel Samson e80043b611 Calibrated timer / clock 2026-07-03 14:17:00 +01:00
Daniel Samson 269729f2f2 Built heap allocation 2026-07-03 13:41:55 +01:00
Daniel Samson 20b4661ff3 Hardened paging into a real VMM 2026-07-03 13:29:34 +01:00
Daniel Samson 5ea521d054 Built device interrupts 2026-07-03 12:57:40 +01:00
Daniel Samson c8e89e8115 Cross-architecture test suite 2026-07-03 12:39:26 +01:00