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/boot.asm | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'src/boot.asm') diff --git a/src/boot.asm b/src/boot.asm index 513c392..73ea860 100644 --- a/src/boot.asm +++ b/src/boot.asm @@ -50,18 +50,12 @@ KernelInit: call CopyHramCode ; move context-switch trampoline into HRAM call ProcInit ; wipe process table - ; --- spawn the two demo tasks (text-in-ROM model) --- - ; task A: entry TaskA, RAM bank 0, u-area WRAM bank 1 - ld hl, TaskA - ld b, 0 ; RAM bank + ; --- spawn the init task (pid 1); it fork()s the rest --- + ld hl, TaskInit + ld b, 0 ; cart-RAM bank 0 ld c, 1 ; WRAM u-area bank call ProcCreate - ld hl, TaskB - ld b, 1 - ld c, 2 - call ProcCreate - call SchedInit ; pick first task, set wCurProc ; interrupts: enable timer for preemption -- cgit v1.3.1-sl0p