Networking
From nexOS Wiki
RTL8139 Ethernet with real TX/RX, ARP table, honest TCP status
Rewritten in Phase A6/C. The old register pokes never touched the wire. The current driver (net.c) is PCI-probed, builds correct frames, transmits through real TX descriptors, receives through an 8 KiB ring in the NIC interrupt, and learns an ARP table. Verified by capturing a real ARP request from the guest. TCP proper is still Phase D.
Contents[hide] |
Hardware and QEMU
| Item | Value |
|---|---|
| NIC | RTL8139, I/O base + IRQ from PCI (QEMU: IRQ11) |
| MAC | Read from card IDR0–5 (52:54:00:12:34:56 on QEMU) |
| IP | IP_ADDR 0x5DB8D822, gateway 0x0A000202, DNS 0x0A000203 |
| QEMU | -device rtl8139,netdev=n0 -netdev user,id=n0 |
| RX | 8 KiB ring, ISR-driven + 10 Hz poll backup |
| TX | 4×1536 descriptors, round-robin |
Driver (net.c / net.h)
net_init(): PCI scan for 10EC:8139 → IO BAR + IRQ + bus mastering; MAC from IDR; software reset; publish 8 KiB RX ring (RBSTART); RCR accept broadcast/match; IMR ROK+TOK; enable receiver+transmitter. rtl_tx_raw(): copy frame to next TX buffer, ring TSAD/TSD descriptors. net_rx_ring(): drain ring by CAPR/CURR pointers, learn ARP replies into an 8-entry table, flag packets for net_poll(). net_handler(): ISR — ack ISR register, drain RX, EOI both PICs. net_poll(): returns 1 only when a packet arrived (no more forced redraws every 10 ticks).
Protocols
| Function | What it does |
|---|---|
| net_arp_request(gw) | Build a correct 60-byte ARP request (broadcast dst, card MAC/IP) and transmit it |
| net_arp_lookup(ip, mac) | Look up learned ARP table entries |
| send_tcp_syn | Craft a correct SYN (IP header + checksum, TCP header) |
| net_http_get(ip, path, buf, sz) | Resolves MAC via ARP first (-1 = no reply); TCP handshake itself is Phase D (-2) |
| net_dns_resolve(host, ip) | Stub: always returns IP_ADDR (Phase D) |
Terminal and browser integration
PING -> net_arp_request(net_get_gw()); learned MAC shown as
GW MAC xx:xx:xx:xx:xx:xx, else "ARP SENT TO GW"
FETCH -> "NO ARP REPLY" (-1) or "ARP OK, TCP IN PHASE D" (-2);
no fake OK anymore
BROWSER -> toggle browser_open; "BROWSER OPEN/CLOSED"
The browser window (draw_browser_window()) strips <tags> and wraps at 44 columns × 8 rows. Empty state shows “WELCOME TO nexOS WEB / OPEN TERMINAL, TYPE FETCH”.
Limits
- RX ring + ISR work; TCP receive state machine, retransmit and real DNS are Phase D.
- No TLS (and none planned for the kernel).
- IP is static; DHCP is Phase D.
Categories: nexOS | Networking