aboutsummaryrefslogtreecommitdiffstats
path: root/c/libc.s
diff options
context:
space:
mode:
authoruser <user@clank>2026-07-17 12:39:01 +0200
committeruser <user@clank>2026-07-17 12:39:01 +0200
commit09ae37313a8b6d567a05a3ae886de78e88cd1afe (patch)
tree8d4707fbd2c6c7fec56a1c9c31abbd9dc66cf7bb /c/libc.s
parentnet: ping - GB-originated ICMP echo (a Game Boy pings the real internet) (diff)
downloadgbos-09ae37313a8b6d567a05a3ae886de78e88cd1afe.tar.gz
gbos-09ae37313a8b6d567a05a3ae886de78e88cd1afe.tar.xz
gbos-09ae37313a8b6d567a05a3ae886de78e88cd1afe.zip
net: proper socket API in the kernel (SYS_NET) - no more SLIP in userland
The network stack moves into the kernel. src/socket.asm owns SLIP framing, IPv4, RFC1071 checksums, and ICMP; programs now speak a socket API through one syscall (SYS_NET, DE=&netreq dispatched by op): net_socket/connect/send/recv/ close/poll (c/sock.h). No program touches SLIP, IP headers, or checksums. - Socket table (4 sockets) + tx/rx buffers in WRAM0; our IP = 10.0.0.2. - net_pump: drains the link, reassembles SLIP frames, demuxes IPv4. Inbound ICMP echo requests are auto-answered in-kernel, so the GB replies to pings whenever any process pumps RX. - ICMP sockets: send() emits an echo request to the connected peer; recv() returns the matching reply (with a spin/yield timeout). ping.c is now a ~15-line socket client; netd.c is just `for(;;){net_poll(); yield();}`. Verified over tunbridge: /# ping 1.1.1.1 -> replies from the real internet (kernel builds it all) host# ping 10.0.0.2 -> 4/4, 0% loss (kernel auto-answers) Gotchas recorded: gbos.inc isn't a make dep (touch asm after editing); this crt0 doesn't copy initializers (fill arrays at runtime); and the arg string at 0xA000 overlaps _DATA, so parse targets must sit past it (big buffer first). UDP and TCP sockets build on this same core next.
Diffstat (limited to 'c/libc.s')
-rw-r--r--c/libc.s7
1 files changed, 7 insertions, 0 deletions
diff --git a/c/libc.s b/c/libc.s
index 7897a79..724fc3b 100644
--- a/c/libc.s
+++ b/c/libc.s
@@ -1,6 +1,7 @@
.module libc
.globl _writes, _putc, _puts, _nl, _strlen, _readc, _sexit, _getpid, _getargs
.globl _open, _close, _fgetc, _fputc, _flist, _fremove, _pipe, _ssend, _srecv, _srecv_nb, _pollin
+ .globl _sys_net
;; SDCC sm83 sdcccall(1): 1st arg -> A (byte) or DE (pointer); ret A / BC.
;; rst $30 (the trap) clobbers BC/DE/HL; SDCC treats them caller-saved, so
;; wrappers need not preserve them - but we compute cleanly regardless.
@@ -116,6 +117,12 @@ _srecv_nb:
1$: ld bc, #0xffff
ret
+ ;; unsigned char sys_net(void *req /*DE*/) -> A -- socket layer trap
+_sys_net:
+ ld c, #33 ; SYS_NET (DE already = &netreq)
+ rst #0x30
+ ret
+
;; unsigned char pollin(void) -> A (typed OSK char, or 0)
_pollin:
ld c, #32 ; SYS_POLLIN