diff options
| author | user <user@clank> | 2026-07-15 23:54:13 +0200 |
|---|---|---|
| committer | user <user@clank> | 2026-07-15 23:54:13 +0200 |
| commit | ab3ebbe227c72b745a46f9233fbfbb27477586b8 (patch) | |
| tree | d71f87605d17c5653f34ebcdef3941f898cd5b91 /src/tasks.asm | |
| parent | gbos scaffold: working cooperative microkernel (verified ABAB in emulator) (diff) | |
| download | gbos-ab3ebbe227c72b745a46f9233fbfbb27477586b8.tar.gz gbos-ab3ebbe227c72b745a46f9233fbfbb27477586b8.tar.xz gbos-ab3ebbe227c72b745a46f9233fbfbb27477586b8.zip | |
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
Diffstat (limited to 'src/tasks.asm')
| -rw-r--r-- | src/tasks.asm | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/src/tasks.asm b/src/tasks.asm index 1f84142..459ccb6 100644 --- a/src/tasks.asm +++ b/src/tasks.asm @@ -1,33 +1,39 @@ ; ============================================================================= -; tasks.asm - two demo userland tasks (text-in-ROM model). -; Each loops: write its letter to the console, then yield. This exercises the -; whole pipeline: syscall trap, console, and the HRAM context switch swapping -; RAM banks / SVBK between tasks. +; tasks.asm - the init task demonstrates fork(). +; init forks once; the parent loops printing 'P', the child loops printing 'C'. +; Both run the same ROM text, diverging on fork()'s return value (0 in child). +; Exercises: syscall trap, fork (8 KiB bank copy + child frame), scheduler, +; and the HRAM context switch swapping cart-RAM banks per task. ; ============================================================================= INCLUDE "include/gbos.inc" SECTION "tasks", ROM0 -TaskA:: -.loop - ld de, .msg - ld b, 1 ; len +TaskInit:: + ld c, SYS_FORK + rst $30 ; A = child pid (parent) or 0 (child) + or a + jr z, .child + +.parent + ld de, .pmsg + ld b, 1 ld c, SYS_WRITE rst $30 ld c, SYS_YIELD rst $30 - jr .loop -.msg - db "A" + jr .parent -TaskB:: -.loop - ld de, .msg +.child + ld de, .cmsg ld b, 1 ld c, SYS_WRITE rst $30 ld c, SYS_YIELD rst $30 - jr .loop -.msg - db "B" + jr .child + +.pmsg + db "P" +.cmsg + db "C" |
