diff options
| author | user <user@clank> | 2026-07-17 01:04:16 +0200 |
|---|---|---|
| committer | user <user@clank> | 2026-07-17 01:04:16 +0200 |
| commit | 73295e7acc1e5ec3ee8814fd4ccc45f7cee63392 (patch) | |
| tree | 88f66fb3db17e8ee755b2d2a408ce232292f9248 /src/syscall.asm | |
| parent | term: compute the OSK view offset from the cursor row (keep input visible) (diff) | |
| download | gbos-73295e7acc1e5ec3ee8814fd4ccc45f7cee63392.tar.gz gbos-73295e7acc1e5ec3ee8814fd4ccc45f7cee63392.tar.xz gbos-73295e7acc1e5ec3ee8814fd4ccc45f7cee63392.zip | |
kernel+sh: real anonymous pipes (concurrent, streaming, SIGPIPE)
Replace the shell's temp-file pipe hack with proper in-kernel FIFOs.
Kernel (src/pipe.asm, new):
- A small pool of bounded ring buffers (PIPE_MAX=2, 64 B each) with
writers/readers refcounts. Pipe fds are $F0+idx*2 (read) / +1 (write);
$FF stays "console".
- SYS_PIPE allocates one (writers=readers=1) and returns the read fd
(write = read+1). getb/putb/close dispatch pipe fds here; sys_exit drops
the refcounts held as PROC_STDIN/PROC_STDOUT.
- Blocking with SchedYield, which is the flow control: read blocks while
empty with a writer (EOF once writers hit 0), write blocks while full
with a reader, and if the last reader is gone the writer is killed
(SIGPIPE -> exit 141). Cooperative-scheduler friendly.
Shell (c/sh.c):
- run_pipeline(): split on '|', make a pipe between adjacent stages, and
fork ALL stages concurrently (no wait between), wiring stdin/stdout;
then wait for all. Per-stage >/< still honored; orphaned pipe ends are
closed on a lookup miss so EOF/EPIPE propagate.
- Drop the __pipe temp file and its 2 KB / serialized limits.
libc: pipe(). New c/ptest.c exercises the FIFO (write, read back, EOF).
Now works (old version couldn't): multi-stage a|b|c; streaming beyond 2 KB
(count 120 | wc = 3372 bytes through a 64 B buffer); early-exit SIGPIPE
(count 200 | true kills count instead of hanging/overflowing a file).
Diffstat (limited to '')
| -rw-r--r-- | src/syscall.asm | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/syscall.asm b/src/syscall.asm index cb2c996..c602097 100644 --- a/src/syscall.asm +++ b/src/syscall.asm @@ -62,6 +62,7 @@ SyscallTable: dw sys_mkdir ; 25 MKDIR dw sys_chdir ; 26 CHDIR dw sys_opendir ; 27 OPENDIR + dw sys_pipe ; 28 PIPE ; ----------------------------------------------------------------------------- sys_nosys: @@ -256,7 +257,24 @@ sys_yield: ; - wake our parent if it is blocked in wait() ; - schedule away forever (RAM bank + PCB slot are freed by the reaper) ; ----------------------------------------------------------------------------- -sys_exit: +sys_exit:: + ; release any pipe ends held as stdin/stdout (so EOF/free fire) + ld a, [wCurProc] + add PROC_STDIN + ld l, a + ld a, [wCurProc+1] + adc 0 + ld h, a + ld a, [hl] + call pipe_close + ld a, [wCurProc] + add PROC_STDOUT + ld l, a + ld a, [wCurProc+1] + adc 0 + ld h, a + ld a, [hl] + call pipe_close ; PROC_STATE = PS_ZOMBIE ld a, [wCurProc] ld l, a |
