diff options
| author | user <user@clank> | 2026-07-17 12:39:01 +0200 |
|---|---|---|
| committer | user <user@clank> | 2026-07-17 12:39:01 +0200 |
| commit | 09ae37313a8b6d567a05a3ae886de78e88cd1afe (patch) | |
| tree | 8d4707fbd2c6c7fec56a1c9c31abbd9dc66cf7bb /include | |
| parent | net: ping - GB-originated ICMP echo (a Game Boy pings the real internet) (diff) | |
| download | gbos-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 '')
| -rw-r--r-- | include/gbos.inc | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/include/gbos.inc b/include/gbos.inc index a80841c..a4c9d52 100644 --- a/include/gbos.inc +++ b/include/gbos.inc @@ -130,7 +130,36 @@ DEF SYS_SSEND EQU 29 ; link-port: transmit one byte (E=byte) DEF SYS_SRECV EQU 30 ; link-port: receive one byte (-> A=byte, blocks) DEF SYS_SRECVNB EQU 31 ; link-port: receive, non-blocking (-> A=byte, CF=none) DEF SYS_POLLIN EQU 32 ; poll OSK for a typed char (-> A=char or 0) -DEF SYS_MAX EQU 33 +DEF SYS_NET EQU 33 ; socket layer (DE=&netreq -> A=result) +DEF SYS_MAX EQU 34 + +; ---- socket layer (SYS_NET) -------------------------------------------------- +; netreq struct (in caller RAM; DE points to it): +DEF NR_OP EQU 0 ; operation (below) +DEF NR_SOCK EQU 1 ; socket id +DEF NR_BUF EQU 2 ; 2: pointer to payload buffer +DEF NR_LEN EQU 4 ; 1: payload length (in) / bytes received (out) +DEF NR_IP EQU 5 ; 4: IPv4 address +DEF NR_PORT EQU 9 ; 2: port (hi,lo) +DEF NR_SIZE EQU 11 +; ops +DEF NET_SOCKET EQU 0 ; NR_SOCK(type in) -> A=sockid or $FF +DEF NET_CONNECT EQU 1 ; NR_SOCK, NR_IP, NR_PORT -> set peer +DEF NET_SEND EQU 2 ; NR_SOCK, NR_BUF, NR_LEN -> A=0/$FF +DEF NET_RECV EQU 3 ; NR_SOCK, NR_BUF, NR_LEN(max) -> A=len or $FF(timeout); fills NR_IP +DEF NET_CLOSE EQU 4 ; NR_SOCK +DEF NET_BIND EQU 5 ; NR_SOCK, NR_PORT -> bind local port (UDP) +DEF NET_POLL EQU 6 ; pump RX once (answer pings) -> A=0 +; socket types +DEF SOCK_ICMP EQU 1 +DEF SOCK_UDP EQU 2 +DEF SOCK_TCP EQU 3 +DEF MAX_SOCKS EQU 4 +; SLIP framing (RFC 1055) +DEF SLIP_END EQU $C0 +DEF SLIP_ESC EQU $DB +DEF SLIP_ESC_END EQU $DC +DEF SLIP_ESC_ESC EQU $DD ; SYS_KILL (9) is now implemented (B=pid -> A=0/$FF; pid 1 is immortal) ; (SYS_OPEN=4 / SYS_CLOSE=5 are now implemented by the filesystem) |
