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 --- src/kdata.asm | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/kdata.asm') diff --git a/src/kdata.asm b/src/kdata.asm index efc780a..ba395f1 100644 --- a/src/kdata.asm +++ b/src/kdata.asm @@ -20,3 +20,14 @@ wTmpWramB:: DS 1 wTmpSlot:: DS 1 wTmpPid:: DS 1 wTmpSP:: DS 2 + +; cart-RAM bank allocator (bump; bank 0 taken by the init task) +wNextRamBank:: DS 1 + +; scratch used by sys_fork +wForkUserSP:: DS 2 ; parent user SP at fork entry (= Uafter) +wForkChildSlot:: DS 1 +wForkChildPid:: DS 1 +wForkParentBank::DS 1 +wForkChildBank:: DS 1 +wCopyBuf:: DS 256 ; bank-copy bounce buffer (WRAM0, always mapped) -- cgit v1.3.1-sl0p