From 41dd342751541ab843262c13420e08db1a0035b0 Mon Sep 17 00:00:00 2001 From: user Date: Fri, 17 Jul 2026 01:11:11 +0200 Subject: pipe: PIPE_MAX 2->4 (5-stage pipelines) + fix cross-yield byte corruption Bump PIPE_MAX to 4 so a|b|c|d|e (4 pipes) works. This stays within the single-byte buffer-offset math (idx*64+pos <= 3*64+63 = 255) and the fd space ($F0..$F7, clear of $FF console). The bump exposed a data-corruption bug that also affected the 2-pipe case (just invisibly - a wc-only test can't see mangled bytes): pipe_write kept the byte-to-write in the SHARED wPipeByte global across its SchedYield (buffer full), so a concurrent pipe op clobbered it and the writer then stored the wrong byte. Now the byte is held in D across the yield, and pipe_bufptr no longer clobbers D; pipe_read/pipe_write also push their idx across SchedYield rather than assume the yield preserves registers. Verified: count N | cat now streams EXACT content (no 'linn'/'llne' corruption); count 60 | cat | cat | wc = 60 180 1671; 5-stage count 4 | cat | cat | cat | cat prints line 1..4; SIGPIPE (count 200|true) and count 100|wc still fine, no hangs. --- include/gbos.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/gbos.inc') diff --git a/include/gbos.inc b/include/gbos.inc index aca92e3..bd7fbc2 100644 --- a/include/gbos.inc +++ b/include/gbos.inc @@ -181,7 +181,7 @@ DEF OF_POS EQU 3 DEF OF_SIZE EQU 5 ; anonymous pipes -DEF PIPE_MAX EQU 2 ; concurrent pipes +DEF PIPE_MAX EQU 4 ; concurrent pipes (up to 5-stage pipelines) DEF PIPE_BUFSZ EQU 64 ; ring buffer bytes per pipe DEF PIPE_FD_BASE EQU $F0 ; pipe fds: $F0+idx*2 (read), +1 (write); $FF=console -- cgit v1.3.1-sl0p