aboutsummaryrefslogtreecommitdiffstats
path: root/src/proc.asm
diff options
context:
space:
mode:
authoruser <user@clank>2026-07-16 11:10:45 +0200
committeruser <user@clank>2026-07-16 11:10:45 +0200
commit2d3597c3a02f821bb364b8ecc23fc5949fca738d (patch)
tree714cc7463eb36306f44fcfd67fcf52de0c13b3d1 /src/proc.asm
parentshell: I/O redirection (>/<) and pipes (|); rewrite shell in C (diff)
downloadgbos-2d3597c3a02f821bb364b8ecc23fc5949fca738d.tar.gz
gbos-2d3597c3a02f821bb364b8ecc23fc5949fca738d.tar.xz
gbos-2d3597c3a02f821bb364b8ecc23fc5949fca738d.zip
kill + ps: implement SYS_KILL (pid 1 immortal) and a ps tool
- PCB gains PROC_PROG (running program id), set by exec, inherited on fork. - sys_kill(pid): reject pid 1 (immortal) and unknown/dead pids; mark the target zombie, reparent its children to init, wake its parent if blocked in wait; schedule away if a process kills itself. Reuses FindPcbByPid/ReparentToInit. - sys_ps(slot,buf)->{pid,state,prog}; sys_progname(id) via NameTable reverse lookup. NameTable gains sh/ps/kill. - libc: kill/psget/progname; tools ps (pid state cmd) and kill <pid>. - verified: ps lists sh(B)+ps(R); kill 1 refused; kill 42 fails.
Diffstat (limited to 'src/proc.asm')
-rw-r--r--src/proc.asm18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/proc.asm b/src/proc.asm
index ab1c807..cd79160 100644
--- a/src/proc.asm
+++ b/src/proc.asm
@@ -224,7 +224,9 @@ ProcCreate::
ld [hl+], a ; PROC_EXIT
ld a, STD_CONSOLE
ld [hl+], a ; PROC_STDIN = console
- ld [hl], a ; PROC_STDOUT = console
+ ld [hl+], a ; PROC_STDOUT = console
+ ld a, $FF
+ ld [hl], a ; PROC_PROG = none
; build the initial stack frame in the task's RAM bank
ld a, [wTmpEntry]
@@ -453,7 +455,10 @@ sys_fork::
ld [hl+], a ; child STDIN = parent STDIN
inc de
ld a, [de]
- ld [hl], a ; child STDOUT = parent STDOUT
+ ld [hl+], a ; child STDOUT = parent STDOUT
+ inc de
+ ld a, [de]
+ ld [hl], a ; child PROC_PROG = parent PROC_PROG
; ---- return to the parent with child pid ----
ld a, [wForkUserSP]
@@ -484,6 +489,15 @@ sys_fork::
; our demo programs keep no pre-initialized RAM.
; =============================================================================
sys_exec::
+ ; record the running program id in the PCB (for ps)
+ ld a, [wCurProc]
+ add PROC_PROG
+ ld l, a
+ ld a, [wCurProc+1]
+ adc 0
+ ld h, a
+ ld a, b
+ ld [hl], a
; HL = &ProgramTable[B] = ProgramTable + B*4
ld hl, ProgramTable
ld a, b