aboutsummaryrefslogtreecommitdiffstats
path: root/src/tasks.asm
diff options
context:
space:
mode:
authoruser <user@clank>2026-07-16 00:31:27 +0200
committeruser <user@clank>2026-07-16 00:31:27 +0200
commitd5c06116d3d1257b46c476cf73b634cf089bcb82 (patch)
tree8912008c1ca483d9a8192961d703161dcf274411 /src/tasks.asm
parentkernel: complete the process lifecycle (exit/wait/reap + bank free list) (diff)
downloadgbos-d5c06116d3d1257b46c476cf73b634cf089bcb82.tar.gz
gbos-d5c06116d3d1257b46c476cf73b634cf089bcb82.tar.xz
gbos-d5c06116d3d1257b46c476cf73b634cf089bcb82.zip
wip: sys_read + serial console shell (read-store bug under investigation)
- sys_read (SYS_READ): blocking console input via external-clock serial poll; yields while waiting. Verified working (direct-echo cat: 'hi' -> 'hi'). - shell (PROG_SH): prompt/read/parse/fork+exec+wait; worker+hello programs; StrEqual/SkipName helpers; command table. - init now execs the shell. - KNOWN BUG: storing the typed char to the line buffer at $A000 (cart RAM of an exec'd program) corrupts the following sys_read; sys_write reading $A000 also returns $3E. Kernel syscalls themselves are correct; isolating the cart-RAM / exec RAM-bank interaction next.
Diffstat (limited to 'src/tasks.asm')
-rw-r--r--src/tasks.asm62
1 files changed, 4 insertions, 58 deletions
diff --git a/src/tasks.asm b/src/tasks.asm
index 028d074..687bddf 100644
--- a/src/tasks.asm
+++ b/src/tasks.asm
@@ -1,67 +1,13 @@
; =============================================================================
-; tasks.asm - init exercises the full process lifecycle.
-;
-; init fork()s three children; each child exec()s PROG_WORKER, which prints 'w'
-; and exit()s with its pid as the status. init then wait()s in a loop, printing
-; 'R' + the reaped pid digit for each child, until wait() returns $FF (no more
-; children), then prints '!' and idles. This drives fork + exec + exit + wait +
-; zombie reaping + cart-RAM bank recycling.
-;
-; The fork counter lives at $A000 (bottom of init's own RAM bank) because the
-; register file does not survive a fork() call.
+; tasks.asm - init just becomes the shell.
+; init (pid 1) exec()s PROG_SH; the shell then drives fork+exec+wait to run
+; commands typed on the serial console. As pid 1 it is also the orphan reaper.
; =============================================================================
INCLUDE "include/gbos.inc"
-DEF ASCII0 EQU $30 ; '0', added to a pid to print it as a digit
-DEF CH_R EQU $52 ; 'R'
-DEF CH_BANG EQU $21 ; '!'
-
SECTION "tasks", ROM0
TaskInit::
- ld a, 3
- ld [$A000], a ; children left to spawn
-
-.forkloop
- ld c, SYS_FORK
- rst $30
- or a
- jr z, .child ; A==0 -> we are the child
- ; parent: one more child spawned
- ld a, [$A000]
- dec a
- ld [$A000], a
- jr nz, .forkloop
-
-.waitloop
- ld c, SYS_WAIT
- rst $30 ; A = reaped pid (B = code), or $FF if none left
- cp $FF
- jr z, .done
- ; print 'R' then the reaped pid as a digit
- push af
- ld a, CH_R
- ld [$FF01], a
- ld a, $81
- ld [$FF02], a
- pop af
- add ASCII0
- ld [$FF01], a
- ld a, $81
- ld [$FF02], a
- jr .waitloop
-
-.done
- ld a, CH_BANG
- ld [$FF01], a
- ld a, $81
- ld [$FF02], a
-.idle
- ld c, SYS_YIELD
- rst $30
- jr .idle
-
-.child
- ld b, PROG_WORKER
+ ld b, PROG_SH
ld c, SYS_EXEC
rst $30 ; never returns