From 19a2b63bab71b796ee456b3ae8bec1a2ab297158 Mon Sep 17 00:00:00 2001 From: user Date: Thu, 16 Jul 2026 00:12:43 +0200 Subject: kernel: complete the process lifecycle (exit/wait/reap + bank free list) - exit(): zombie + status, reparent orphans to init, wake blocked parent, schedule away forever (resources reclaimed by the reaper) - wait(): scan for a zombie child; reap (free cart-RAM bank + PCB slot) and return pid/code; block PS_BLOCKED + yield if children still live; $FF if none - cart-RAM banks are now a free list (wBankUsed bitmap): AllocRamBank/FreeRamBank - scheduler: FindNextReady returns carry when nothing runnable; yield idles instead of blindly picking slot 0 - helpers: FindPcbByPid, ReparentToInit - demo: init forks 3 workers -> exec -> exit(pid) -> wait/reap => wwwR2R3R4! verified bank recycling with 6 workers over 3 banks (w2w3w4w5w6w7) - README: document the lifecycle + syscall status --- src/sched.asm | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/sched.asm') diff --git a/src/sched.asm b/src/sched.asm index c871f7a..a540c49 100644 --- a/src/sched.asm +++ b/src/sched.asm @@ -31,13 +31,14 @@ SchedRunFirst:: ; caller when this task is eventually rescheduled. ; ----------------------------------------------------------------------------- SchedYield:: - call FindNextReady ; DE = &next PCB + call FindNextReady ; DE = &next PCB, CF if none runnable + ret c ; nobody else ready: keep running current call hSwitchTo ret ; ----------------------------------------------------------------------------- -; FindNextReady - round-robin from wSchedNext. out: DE = &PCB (updates cursor) -; Scaffold: assumes at least one PS_READY task exists. +; FindNextReady - round-robin from wSchedNext. +; out: DE = &PCB and CF clear on success; CF set if nothing is PS_READY. ; ----------------------------------------------------------------------------- FindNextReady:: ld a, [wSchedNext] @@ -56,14 +57,13 @@ FindNextReady:: pop af ; restore candidate slot dec b jr nz, .scan - ; nothing ready: fall back to slot 0 (idle behavior) - xor a - call PcbPtr + scf ; nothing runnable ret .found pop af ; A = chosen slot ld [wSchedNext], a call PcbPtr ; DE = &PCB + and a ; clear carry ret ; ----------------------------------------------------------------------------- -- cgit v1.3.1-sl0p