aboutsummaryrefslogtreecommitdiffstats
path: root/src/tasks.asm
diff options
context:
space:
mode:
authoruser <user@clank>2026-07-16 00:04:09 +0200
committeruser <user@clank>2026-07-16 00:04:09 +0200
commit0a77a11e17f697bf797655c4ae87b927432b1f88 (patch)
tree97cafaa103aec412f692daff9e068fc63f0496bf /src/tasks.asm
parentkernel: implement fork() (diff)
downloadgbos-0a77a11e17f697bf797655c4ae87b927432b1f88.tar.gz
gbos-0a77a11e17f697bf797655c4ae87b927432b1f88.tar.xz
gbos-0a77a11e17f697bf797655c4ae87b927432b1f88.zip
kernel: implement exec()
- sys_exec(B=program id): look up ProgramTable, point PROC_ROMB at the program's ROM text bank, map it into $4000-$7FFF, reset stack, jp to entry (no return) - programs.asm: two demo programs (ping/pong) ORG'd at the SAME $4000 in banks 2 and 3 - proves execution is driven purely by PROC_ROMB - demo: init forks; parent execs PROG_PING (bank2, '1'), child execs PROG_PONG (bank3, '2') -> '1212...', 2000/2000 balanced, zero garbage - README: document exec + text-in-ROM model
Diffstat (limited to '')
-rw-r--r--src/tasks.asm36
1 files changed, 12 insertions, 24 deletions
diff --git a/src/tasks.asm b/src/tasks.asm
index 459ccb6..0b5276d 100644
--- a/src/tasks.asm
+++ b/src/tasks.asm
@@ -1,9 +1,10 @@
; =============================================================================
-; 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.
+; tasks.asm - the init task demonstrates fork() + exec().
+;
+; init forks; the parent exec()s PROG_PING (ROM bank 2), the child exec()s
+; PROG_PONG (ROM bank 3). Both program images are ORG'd at $4000, so the output
+; "1212..." proves each process runs from its own ROM bank via PROC_ROMB - not
+; from shared ROM0.
; =============================================================================
INCLUDE "include/gbos.inc"
@@ -16,24 +17,11 @@ TaskInit::
jr z, .child
.parent
- ld de, .pmsg
- ld b, 1
- ld c, SYS_WRITE
- rst $30
- ld c, SYS_YIELD
- rst $30
- jr .parent
+ ld b, PROG_PING
+ ld c, SYS_EXEC
+ rst $30 ; never returns
.child
- ld de, .cmsg
- ld b, 1
- ld c, SYS_WRITE
- rst $30
- ld c, SYS_YIELD
- rst $30
- jr .child
-
-.pmsg
- db "P"
-.cmsg
- db "C"
+ ld b, PROG_PONG
+ ld c, SYS_EXEC
+ rst $30 ; never returns