Commit Graph
35 Commits
Author SHA1 Message Date
daniel 0730e77530 threads(M3): join, detach, and cross-core parallelism
thread_spawn takes a 4th arg, an exit-endpoint handle: spawnThreadSupervised
resolves and refcounts it under the spawn lock (like spawnProcessSupervised), so
a thread's death posts a child-exit notification carrying its tid. runtime
Thread.join blocks in replyWait on that (private) endpoint for its tid, then
munmaps the stack; detach relinquishes the join (stack reclaimed at process
exit, for now). New current_core=39 syscall + Thread.currentCore() lets a worker
observe which core it ran on.

The closure now lives at the top of the thread's own (private) stack instead of
the heap, so spawn/join never touch the not-yet-thread-safe runtime heap.

thread-test gains a join mode: 4 workers x 100k atomic increments, joined, with
counter == N*K and >1 core stamped (real parallelism), plus a detached worker.
Gate thread-join PASS (4x, non-flaky); 17 guardrail/M1/M2 cases green; build +
host tests clean.
2026-07-20 21:19:17 +01:00
daniel 73df864fd2 threads(M2): thread_spawn/thread_exit + runtime.Thread.spawn
A thread is a task sharing the caller's address space. New private syscalls
thread_spawn(entry, stack_top, arg)=37 and thread_exit=38: thread_spawn goes
through scheduler.spawnThread (retains the shared aspace), thread_exit ends the
task like a process exit(0) (terminateCurrent -> releaseAspace, so the space
survives while siblings hold it). The closure pointer reaches the new thread in
rdi via a new jump_to_user_arg asm path and a per-task user_arg (0 for a normal
process, whose _start ignores it) - so the runtime trampoline is a plain C-ABI
Zig function, no naked asm.

runtime.Thread (library/runtime/thread.zig) mirrors std.Thread.spawn: mmap a
stack, heap-allocate the args closure, hand the kernel the trampoline + closure.
addThreadedUserBinary opts a binary into single_threaded=false; thread-test is
the first, and proves a worker runs in the shared address space via a shared
global the main thread polls.

Gate thread-spawn PASS; 16 guardrail cases green (incl. args/init/process on the
new jump_to_user_arg path) + aspace-refcount; build + host tests clean.
2026-07-20 21:04:23 +01:00
daniel 11e363896f threads(M1): address-space reference counting
Route address-space lifetime through a refcount keyed by the page-table root
(scheduler.zig aspace_refs): retainAspace on the spawnUserLocked success path,
releaseAspace from both teardown paths (exitUserLocked, destroyTaskLocked),
destroying the space only when the last task on it exits. Behaviour is identical
today (every space has exactly one task); this is the foundation shared-address-
space threads (docs/threading.md) build on.

Test-observable liveAspaceCount/aspaceDestroyCount + a new aspace-refcount kernel
self-test and QEMU case: spawn and reap 5 ring-3 probes, assert live spaces return
to baseline and destructions advance by exactly 5 (destroyed once each, no leak,
no double-free). Gate passes; 13 guardrail cases green; build + host tests clean.
2026-07-20 20:47:37 +01:00
daniel 6e8b02d771 threads: design doc + /loop build plan
Add docs/threading.md (native runtime.Thread mirroring std.Thread over a
private thread ABI) and docs/threading-plan.md (6 milestones, each with a
serial-checkable gate + guardrail, plus an unattended /loop execution
contract). Index both in docs/README.md.
2026-07-20 20:39:24 +01:00
daniel d26515706e removing init heartbeat in releases 2026-07-20 20:10:24 +01:00
daniel acf8ff2c33 added microsoft ps/2 support 2026-07-20 19:45:08 +01:00
daniel 6f6ccc8bc9 moving kernel code to kernel/ 2026-07-05 10:19:11 +01:00
daniel 7c3cffb337 moving efi code to boot 2026-07-05 10:01:01 +01:00
daniel ae1552414d printing debug messages to serial only 2026-07-05 09:48:06 +01:00
daniel 6cd6669a8d Add RAM and VRAM footprint 2026-07-05 09:10:59 +01:00
daniel d055de7141 documenting things to research 2026-07-03 21:40:59 +01:00
daniel a6de418e42 documenting smp and scheduling to research 2026-07-03 21:24:44 +01:00
daniel f9f0511ac2 documenting research for arm and device discovery 2026-07-03 20:22:48 +01:00
daniel 99d6bf5ce3 renaming run-efi to run-x86-64 2026-07-03 19:45:44 +01:00
daniel 21b9691486 reclaiming uefi memory 2026-07-03 19:31:32 +01:00
daniel 31bf86af56 IPC 2026-07-03 15:09:16 +01:00
daniel df774691c8 Fixed-priority preemptive scheduler 2026-07-03 14:30:33 +01:00
daniel e80043b611 Calibrated timer / clock 2026-07-03 14:17:00 +01:00
daniel 9a834c91ff Pin zig version to 0.16 LTS 2026-07-03 13:49:47 +01:00
daniel 269729f2f2 Built heap allocation 2026-07-03 13:41:55 +01:00
daniel 20b4661ff3 Hardened paging into a real VMM 2026-07-03 13:29:34 +01:00
daniel d910e6261a Documenting sysv 2026-07-03 13:06:43 +01:00
daniel 56219b4050 Documenting sysv 2026-07-03 13:06:27 +01:00
daniel 5ea521d054 Built device interrupts 2026-07-03 12:57:40 +01:00
daniel c8e89e8115 Cross-architecture test suite 2026-07-03 12:39:26 +01:00
daniel 9cf135302d Built paging / the kernel's own page tables (with a TSS+IST) 2026-07-03 12:23:55 +01:00
daniel 0cc71ec8aa Built GDT + IDT + exception handlers 2026-07-03 12:05:41 +01:00
daniel 6312e84262 added physical memory manager 2026-07-03 11:43:14 +01:00
daniel cb2f49cb48 added physical memory manager 2026-07-03 11:24:26 +01:00
daniel 628c4f6d57 Move to multi arch support and added memory map 2026-07-03 11:11:19 +01:00
daniel c2435760c4 Add README file in docs 2026-07-03 10:31:08 +01:00
daniel 6a08081bfe selecting the displays native resolution 2026-07-03 10:07:51 +01:00
daniel 21cc0c87e4 setup framebuffer with console 2026-07-03 09:32:15 +01:00
daniel ca3c3d131c booting into the kernel 2026-07-01 19:51:06 +01:00
daniel 3c8656fb25 started project with basic efi setup 2026-07-01 18:32:56 +01:00