aboutsummaryrefslogtreecommitdiffstats
path: root/src/syscall.asm
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/syscall.asm58
1 files changed, 58 insertions, 0 deletions
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