aboutsummaryrefslogtreecommitdiffstats
path: root/src/syscall.asm
diff options
context:
space:
mode:
authoruser <user@clank>2026-07-16 00:31:27 +0200
committeruser <user@clank>2026-07-16 00:31:27 +0200
commitd5c06116d3d1257b46c476cf73b634cf089bcb82 (patch)
tree8912008c1ca483d9a8192961d703161dcf274411 /src/syscall.asm
parentkernel: complete the process lifecycle (exit/wait/reap + bank free list) (diff)
downloadgbos-d5c06116d3d1257b46c476cf73b634cf089bcb82.tar.gz
gbos-d5c06116d3d1257b46c476cf73b634cf089bcb82.tar.xz
gbos-d5c06116d3d1257b46c476cf73b634cf089bcb82.zip
wip: sys_read + serial console shell (read-store bug under investigation)
- sys_read (SYS_READ): blocking console input via external-clock serial poll; yields while waiting. Verified working (direct-echo cat: 'hi' -> 'hi'). - shell (PROG_SH): prompt/read/parse/fork+exec+wait; worker+hello programs; StrEqual/SkipName helpers; command table. - init now execs the shell. - KNOWN BUG: storing the typed char to the line buffer at $A000 (cart RAM of an exec'd program) corrupts the following sys_read; sys_write reading $A000 also returns $3E. Kernel syscalls themselves are correct; isolating the cart-RAM / exec RAM-bank interaction next.
Diffstat (limited to 'src/syscall.asm')
-rw-r--r--src/syscall.asm21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/syscall.asm b/src/syscall.asm
index 4b8771c..bf75865 100644
--- a/src/syscall.asm
+++ b/src/syscall.asm
@@ -36,7 +36,7 @@ SyscallTrap::
SyscallTable:
dw sys_exit ; 0
dw sys_fork ; 1 FORK
- dw sys_nosys ; 2 READ (TODO)
+ dw sys_read ; 2 READ
dw sys_write ; 3 WRITE
dw sys_nosys ; 4 OPEN (TODO)
dw sys_nosys ; 5 CLOSE (TODO)
@@ -71,6 +71,25 @@ sys_write:
ret
; -----------------------------------------------------------------------------
+; sys_read() -> A = one input byte from the console (blocking).
+; Uses an external-clock serial transfer as a clean RX: it completes only when
+; the host has a byte (no stdout echo). While waiting we yield so other procs
+; run. Preserves BC/DE/HL (the context switch saves/restores them).
+; -----------------------------------------------------------------------------
+sys_read:
+.poll
+ ld a, $80
+ ld [rSC], a ; request a byte (external clock)
+ ld a, [rSC]
+ bit 7, a
+ jr z, .got ; bit7 clear => transfer completed
+ call SchedYield ; nothing yet: let others run, then retry
+ jr .poll
+.got
+ ld a, [rSB]
+ ret
+
+; -----------------------------------------------------------------------------
; sys_getpid() -> A = current pid
; -----------------------------------------------------------------------------
sys_getpid: