aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authoruser <user@clank>2026-07-16 11:15:12 +0200
committeruser <user@clank>2026-07-16 11:15:12 +0200
commitbb4f468b73c8a888bec1e5b2ba7f1575ab7f8456 (patch)
tree24e681e7ca242f3041f6a3effa197445ada451fb /src
parentkill + ps: implement SYS_KILL (pid 1 immortal) and a ps tool (diff)
downloadgbos-bb4f468b73c8a888bec1e5b2ba7f1575ab7f8456.tar.gz
gbos-bb4f468b73c8a888bec1e5b2ba7f1575ab7f8456.tar.xz
gbos-bb4f468b73c8a888bec1e5b2ba7f1575ab7f8456.zip
jobs: background execution (&), non-blocking reap, spin demo
- sys_reap: nohang reap of a finished zombie child (-> pid or 0). - shell: 'cmd &' launches in the background (prints [pid], no wait); reaps finished jobs at the prompt ([pid done]). Foreground now waits for its own child specifically (loops wait(), reporting bg completions meanwhile) so kill reports the right pid. - spin: a process that yields forever - a target for ps/kill. - verified: spin &; ps shows it; kill <pid> removes just that one; immortal init; self-finishing bg worker reaped with [pid done].
Diffstat (limited to 'src')
-rw-r--r--src/programs.asm7
-rw-r--r--src/syscall.asm58
2 files changed, 65 insertions, 0 deletions
diff --git a/src/programs.asm b/src/programs.asm
index f21d40b..e83d29e 100644
--- a/src/programs.asm
+++ b/src/programs.asm
@@ -94,6 +94,9 @@ ProgPs:
SECTION "prog_kill", ROMX[$4000], BANK[19]
ProgKill:
INCBIN "c/kill.bin"
+SECTION "prog_spin", ROMX[$4000], BANK[20]
+ProgSpin:
+ INCBIN "c/spin.bin"
; -----------------------------------------------------------------------------
; PROG_SH (bank 3) - the shell, now written in C (c/sh.c): parses >/</| and
@@ -172,6 +175,8 @@ ProgramTable::
dw ProgPs
db LOW(BANK(ProgKill)), HIGH(BANK(ProgKill))
dw ProgKill
+ db LOW(BANK(ProgSpin)), HIGH(BANK(ProgSpin))
+ dw ProgSpin
; -----------------------------------------------------------------------------
; NameTable (ROM0) - command name -> program id, searched by sys_lookup.
@@ -214,4 +219,6 @@ NameTable::
db PROG_PS
db "kill", 0
db PROG_KILL
+ db "spin", 0
+ db PROG_SPIN
db 0
diff --git a/src/syscall.asm b/src/syscall.asm
index 0b47c05..2fc66b6 100644
--- a/src/syscall.asm
+++ b/src/syscall.asm
@@ -56,6 +56,7 @@ SyscallTable:
dw sys_lookup ; 19 LOOKUP
dw sys_ps ; 20 PS
dw sys_progname ; 21 PROGNAME
+ dw sys_reap ; 22 REAP
; -----------------------------------------------------------------------------
sys_nosys:
@@ -554,3 +555,60 @@ sys_progname::
xor a
ld [de], a
ret
+
+; =============================================================================
+; sys_reap() -> A = pid of a reaped zombie child, or 0 (never blocks).
+; Used by the shell to clean up finished background jobs.
+; =============================================================================
+sys_reap::
+ ld a, [wCurProc]
+ add PROC_PID
+ ld l, a
+ ld a, [wCurProc+1]
+ adc 0
+ ld h, a
+ ld a, [hl]
+ ld [wWaitMyPid], a
+ ld c, 0
+.scan
+ ld a, c
+ call PcbPtr ; DE = &PCB[c]
+ ld a, [de]
+ cp PS_ZOMBIE
+ jr nz, .next
+ ld h, d
+ ld l, e
+ ld a, l
+ add PROC_PARENT
+ ld l, a
+ ld a, h
+ adc 0
+ ld h, a
+ ld a, [wWaitMyPid]
+ cp [hl]
+ jr nz, .next
+ ; reap: pid, free bank, free slot
+ ld h, d
+ ld l, e
+ inc hl ; PROC_PID
+ ld a, [hl]
+ ld [wWaitRetPid], a
+ ld a, e
+ add PROC_RAMB
+ ld l, a
+ ld a, d
+ adc 0
+ ld h, a
+ ld a, [hl]
+ call FreeRamBank
+ ld a, PS_FREE
+ ld [de], a
+ ld a, [wWaitRetPid]
+ ret
+.next
+ inc c
+ ld a, c
+ cp MAX_PROCS
+ jr c, .scan
+ xor a
+ ret