From ab3ebbe227c72b745a46f9233fbfbb27477586b8 Mon Sep 17 00:00:00 2001 From: user Date: Wed, 15 Jul 2026 23:54:13 +0200 Subject: kernel: implement fork() - sys_fork: switch to a kernel stack, bump-allocate a cart-RAM bank, copy the parent's 8 KiB bank via a WRAM bounce buffer, plant a switch-in frame so the child returns 0 to the post-fork PC, fill the child PCB (shared ROM text) - add AllocRamBank (bump allocator) + FindFreeSlot helpers - demo: init forks; parent prints P, child prints C (PCPC...); nested fork gives three distinct pids (123...) - README: document the fork mechanism, mark syscall status --- include/gbos.inc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include/gbos.inc') diff --git a/include/gbos.inc b/include/gbos.inc index c22344a..0727b02 100644 --- a/include/gbos.inc +++ b/include/gbos.inc @@ -46,6 +46,8 @@ DEF KSTACK_TOP EQU $D000 ; kernel stack top (grows down into WRAM0) ; Process table ; ----------------------------------------------------------------------------- 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) ; process states DEF PS_FREE EQU 0 -- cgit v1.3.1-sl0p