From 0a77a11e17f697bf797655c4ae87b927432b1f88 Mon Sep 17 00:00:00 2001 From: user Date: Thu, 16 Jul 2026 00:04:09 +0200 Subject: 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 --- src/tasks.asm | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-) (limited to 'src/tasks.asm') 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 -- cgit v1.3.1-sl0p