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 --- include/gbos.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include/gbos.inc') diff --git a/include/gbos.inc b/include/gbos.inc index e15f7cb..7919bd6 100644 --- a/include/gbos.inc +++ b/include/gbos.inc @@ -48,6 +48,7 @@ DEF KSTACK_TOP EQU $D000 ; kernel stack top (grows down into WRAM0) DEF MAX_PROCS EQU 8 DEF NUM_RAM_BANKS EQU 4 ; MBC5 cart RAM banks available (-r 3 = 32 KiB) DEF KSTACK_TOP2 EQU $D000 ; kernel stack top reused for syscalls (fork) +DEF INIT_PID EQU 1 ; pid of the init task (orphan reaper) ; process states DEF PS_FREE EQU 0 @@ -88,7 +89,6 @@ DEF SYS_MAX EQU 12 ; ----------------------------------------------------------------------------- ; Program table indices (see programs.asm). exec() takes one of these in B. ; ----------------------------------------------------------------------------- -DEF PROG_PING EQU 0 -DEF PROG_PONG EQU 1 +DEF PROG_WORKER EQU 0 ENDC -- cgit v1.3.1-sl0p