code wiki / _hdl_build / nx_nishios_net_wire.nx

nx_nishios_net_wire.nx source

↩ module page · 511 lines · 29742 B

1// nx_nishios_net_wire.nx -- BROWSER-ON-ALL-OS arc, rung N3-WIRE: NishiOS on the REAL INTERNET. 2// 3// N3 (nx_nishios_net) proved the NIC driver path -- descriptor programming + doorbell by EXECUTED x86 4// store -- against a hermetic loopback peer. This rung replaces the loopback with the WIRE BRIDGE: 5// the NIC device backend terminates on the LIVE sovereign network stack (own DNS -> TCP -> TLS 1.3 -> 6// HTTP via nx_https_get + the Mozilla trust store), the standard user-net/slirp architecture (guest NIC 7// TX -> host network stack). The kernel driver (executed x86) rings the doorbell; the device parses the 8// request URL out of the TX buffer, fetches it over the REAL internet, and delivers the raw wire bytes 9// into the RX buffer; the browser parses HTTP (status/content-length/chunked -- the same idiom as 10// nx_browser load_page) and renders the REAL page into the NishiOS desktop. Target = example.com (the 11// stack's proven smallest live host; body carries "Example Domain"). 12// 13// KAT: T1 booted off the persisted image; T2 LONG mode + banner; T3 doorbell fired exactly once by the 14// executed x86; T4 device delivered (RX_STATUS==1) AND the driver read it back (scratch==1); T5 the wire 15// returned real bytes (nx_https_get rc>0); T6 browser-side HTTP parse says 200; T7 the body contains 16// "Example Domain" = content from the REAL internet; T8 the browser laid it out; T9 rendered into the 17// desktop (h1 bar); T10 BMP exported at the exact expected size. NEG/liar-kill: T11 no doorbell -> no 18// delivery; T12 THE WIRE LIAR-KILL -- the SAME bridge pointed at a guaranteed-nonexistent RFC-2606 19// .invalid host FAILS (wire rc<=0, RX_STATUS==2) and the executed driver observes the error 20// (scratch==2): a fabricated/hardcoded response could not distinguish the two hosts, so a pass here 21// proves the bytes really come from the network; T13 a 0-sector-load image never reaches long mode. 22// 23// HONEST SEAM (stated): the boot chain + the doorbell store execute as real x86; the device backend is 24// host-side NishiLang (exactly like slirp is host-side C for QEMU user networking). A guest-side TCP/IP 25// stack driven instruction-by-instruction is the far deeper rung. LIVE-NETWORK CAVEAT: T5-T9 depend on 26// real connectivity to example.com; on an offline host the gate goes honestly RED (no fake green). 27// NEVER-BRICK (Rule 26): writes FILE artifacts only; models INT 13h *reads*; network is client-side 28// egress via the proven sovereign stack; no /dev writes, no firmware. 29// expect_exit: 0 license_tier: ORIGINAL 30import "nx_browser_render.nx" 31import "nx_fb.nx" 32import "nx_x509_trust_store.nx" 33import "nx_trust_store_load_from_certdata.nx" 34import "nx_https_get.nx" 35import "nx_http_response_parse.nx" 36const NW_MAGIC_200000: i64 = 200000 37const NW_MAGIC_32767: i64 = 32767 38const NW_MAGIC_65536: i64 = 65536 39const NW_MAGIC_4096: i64 = 4096 40const NW_MAGIC_4094: i64 = 4094 41const NW_MAGIC_100000: i64 = 100000 42const NW_MAGIC_4194304: i64 = 4194304 43const NW_MAGIC_262144: i64 = 262144 44 45func nw_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 46func nw_num(v: i64) -> i64 { let b: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 } 47func nw_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 48func nw_contains(hay: *u8, hn: i64, ndl: *u8, nn: i64) -> i64 { 49 if nn==0 { return 1 } 50 var i: i64 = 0 51 while i + nn <= hn { var j: i64 = 0; var ok: i64 = 1; while j < nn { if hay[i+j]!=ndl[j] { ok=0; j=nn } else { j=j+1 } } if ok==1 { return 1 } i=i+1 } 52 return 0 53} 54func nw_mode(cr0: i64, efer: i64) -> i64 { let pe: i64=cr0&1; let pg: i64=(cr0>>31)&1; let lme: i64=(efer>>8)&1; if pe==0 { return 0 } if pg==1 { if lme==1 { return 2 } } return 1 } 55 56// UNIFIED boot-disk emu (proven in nx_nishi_usb_longmode/_desktop and rungs N1/N2/N3/N4). 57func nw_emu_boot_disk(mem: *u8, disk: *u8, entry: i64, console: *u8, clen: *i64, st: *i64) -> i64 { 58 var ip: i64=entry 59 var ax: i64=0 60 var bx: i64=0 61 var cx: i64=0 62 var dx: i64=0 63 var si: i64=0 64 var zf: i64=0 65 var rax: i64=0 66 var cr0: i64=0 67 var efer: i64=0 68 var guard: i64=0 69 st[0]=0; st[1]=0 70 while guard < NW_MAGIC_200000 { 71 guard = guard + 1 72 let op: i64 = mem[ip] as i64 73 if op == 0xF4 { st[0]=cr0; st[1]=nw_mode(cr0,efer); return 0 } 74 var h: i64 = 0 75 if h==0 { if op==0x48 { 76 if mem[ip+1]==(0xC7 as u8) { 77 let modrm: i64 = mem[ip+2] as i64 78 let imm: i64 = (mem[ip+3] as i64) | ((mem[ip+4] as i64)<<8) | ((mem[ip+5] as i64)<<16) | ((mem[ip+6] as i64)<<24) 79 if modrm==0xC0 { rax = imm } 80 ip=ip+7; h=1 81 } 82 } } 83 if h==0 { if op==0x0F { 84 let b1: i64 = mem[ip+1] as i64 85 if b1==0x22 { let m: i64=mem[ip+2] as i64; if ((m>>3)&7)==0 { cr0=rax }; ip=ip+3; h=1 } 86 if h==0 { if b1==0x30 { efer=rax; ip=ip+2; h=1 } } 87 if h==0 { if b1==0x05 { st[0]=cr0; st[1]=nw_mode(cr0,efer); return rax & 0xff } } 88 if h==0 { return 0 - 1 } 89 } } 90 if h==0 { if op==0xBE { si = (mem[ip+1] as i64) | ((mem[ip+2] as i64)<<8); ip=ip+3; h=1 } } 91 if h==0 { if op==0xB8 { ax = (mem[ip+1] as i64) | ((mem[ip+2] as i64)<<8); ip=ip+3; h=1 } } 92 if h==0 { if op==0xBB { bx = (mem[ip+1] as i64) | ((mem[ip+2] as i64)<<8); ip=ip+3; h=1 } } 93 if h==0 { if op==0xB9 { cx = (mem[ip+1] as i64) | ((mem[ip+2] as i64)<<8); ip=ip+3; h=1 } } 94 if h==0 { if op==0xBA { dx = (mem[ip+1] as i64) | ((mem[ip+2] as i64)<<8); ip=ip+3; h=1 } } 95 if h==0 { if op==0xAC { let al: i64 = mem[si] as i64; ax = (ax & 0xFF00) | al; si=si+1; ip=ip+1; h=1 } } 96 if h==0 { if op==0x08 { let al2: i64 = ax & 0xFF; if al2==0 { zf=1 } else { zf=0 } ip=ip+2; h=1 } } 97 if h==0 { if op==0x74 { var r: i64 = mem[ip+1] as i64; if r>127 { r=r-256 } if zf==1 { ip=ip+2+r } else { ip=ip+2 } h=1 } } 98 if h==0 { if op==0xB4 { ax = (ax & 0xFF) | ((mem[ip+1] as i64)<<8); ip=ip+2; h=1 } } 99 if h==0 { if op==0xEB { var r2: i64 = mem[ip+1] as i64; if r2>127 { r2=r2-256 } ip=ip+2+r2; h=1 } } 100 if h==0 { if op==0xE9 { var r3: i64 = (mem[ip+1] as i64) | ((mem[ip+2] as i64)<<8); if r3>NW_MAGIC_32767 { r3=r3-NW_MAGIC_65536 } ip=ip+3+r3; h=1 } } 101 if h==0 { if op==0xCD { 102 let vec: i64 = mem[ip+1] as i64 103 let ah: i64 = (ax >> 8) & 0xFF 104 if vec==0x10 { if ah==0x0E { console[clen[0]]=(ax & 0xFF) as u8; clen[0]=clen[0]+1 } } 105 if vec==0x13 { if ah==0x02 { 106 let count: i64 = ax & 0xFF 107 let sector: i64 = cx & 0xFF 108 let lba: i64 = sector - 1 109 var s: i64 = 0 110 while s < count*512 { mem[bx + s] = disk[lba*512 + s]; s=s+1 } 111 ax = ax & 0xFF 112 } } 113 ip=ip+2; h=1 114 } } 115 if h==0 { return 0 - 1 } 116 } 117 return 0 - 2 118} 119 120const NW_IMG_SZ: i64 = 1024 121func nw_movrax(img: *u8, base: i64, o: i64, b0: i64, b1: i64, b2: i64, b3: i64) -> i64 { 122 img[base+o]=0x48 as u8; img[base+o+1]=0xC7 as u8; img[base+o+2]=0xC0 as u8 123 img[base+o+3]=(b0&0xff) as u8; img[base+o+4]=(b1&0xff) as u8; img[base+o+5]=(b2&0xff) as u8; img[base+o+6]=(b3&0xff) as u8 124 return o+7 125} 126func nw_build_image(img: *u8) -> i64 { 127 var z: i64=0 128 while z<NW_IMG_SZ { img[z]=0 as u8; z=z+1 } 129 img[0]=0xB8 as u8; img[1]=0x01 as u8; img[2]=0x02 as u8 130 img[3]=0xBB as u8; img[4]=0x00 as u8; img[5]=0x80 as u8 131 img[6]=0xB9 as u8; img[7]=0x02 as u8; img[8]=0x00 as u8 132 img[9]=0xBA as u8; img[10]=0x80 as u8; img[11]=0x00 as u8 133 img[12]=0xCD as u8; img[13]=0x13 as u8 134 let rel16: i64 = 0x8000 - (0x7C00 + 14 + 3) 135 img[14]=0xE9 as u8; img[15]=(rel16 & 0xFF) as u8; img[16]=((rel16>>8) & 0xFF) as u8 136 img[510]=0x55 as u8; img[511]=0xAA as u8 137 var r: i64 = 0 138 img[512+r]=0xBE as u8; let si_r: i64 = r+1; r=r+3 139 let loop_r: i64 = r 140 img[512+r]=0xAC as u8; r=r+1 141 img[512+r]=0x08 as u8; img[512+r+1]=0xC0 as u8; r=r+2 142 img[512+r]=0x74 as u8; let jz_r: i64 = r+1; r=r+2 143 img[512+r]=0xB4 as u8; img[512+r+1]=0x0E as u8; r=r+2 144 img[512+r]=0xCD as u8; img[512+r+1]=0x10 as u8; r=r+2 145 img[512+r]=0xEB as u8; img[512+r+1]=((loop_r-(r+2)) & 0xFF) as u8; r=r+2 146 let after_r: i64 = r 147 r = nw_movrax(img, 512, r, 1, 0, 0, 0) 148 img[512+r]=0x0F as u8; img[512+r+1]=0x22 as u8; img[512+r+2]=0xC0 as u8; r=r+3 149 r = nw_movrax(img, 512, r, 0x00, 0x01, 0, 0) 150 img[512+r]=0x0F as u8; img[512+r+1]=0x30 as u8; r=r+2 151 r = nw_movrax(img, 512, r, 0x01, 0x00, 0x00, 0x80) 152 img[512+r]=0x0F as u8; img[512+r+1]=0x22 as u8; img[512+r+2]=0xC0 as u8; r=r+3 153 img[512+r]=0xF4 as u8; r=r+1 154 let msg_r: i64 = r 155 let msg: *u8 = "NishiOS\x0D\x0A\x00" 156 var mi: i64=0 157 while msg[mi]!=(0 as u8) { img[512+r]=msg[mi]; r=r+1; mi=mi+1 } 158 img[512+r]=0 as u8; r=r+1 159 img[512+jz_r] = ((after_r - (jz_r+1)) & 0xFF) as u8 160 let si_abs: i64 = 0x8000 + msg_r 161 img[512+si_r] = (si_abs & 0xFF) as u8 162 img[512+si_r+1] = ((si_abs>>8) & 0xFF) as u8 163 return 0 164} 165func nw_boot_image(img: *u8, console: *u8, clen: *i64, st: *i64, loaded: *i64) -> i64 { 166 let mem: *u8 = sys_mmap(NW_MAGIC_65536) 167 var k: i64=0 168 while k<NW_MAGIC_65536 { mem[k]=0 as u8; k=k+1 } 169 var j: i64=0 170 while j<512 { mem[0x7C00+j]=img[j]; j=j+1 } 171 loaded[0] = mem[0x8000] as i64 172 clen[0]=0 173 let rc: i64 = nw_emu_boot_disk(mem, img, 0x7C00, console, clen, st) 174 loaded[1] = mem[0x8000] as i64 175 return rc 176} 177func nw_str(fb: *u8, W: i64, H: i64, x: i64, y: i64, s: *u8, r: i64, g: i64, b: i64) -> i64 { 178 let table: *u8 = font8x8_table() 179 var i: i64=0 180 while s[i]!=(0 as u8) { 181 let cc: i64 = s[i] as i64 182 if cc>=0x20 { if cc<=0x7E { 183 let gi: i64=(cc-0x20)*8 184 var rr: i64=0 185 while rr<8 { let bits: i64=table[gi+rr] as i64; var co: i64=0; while co<8 { if ((bits>>co)&1)==1 { fb_setpx(fb,W,H, x+i*8+co, y+rr, r,g,b) } co=co+1 } rr=rr+1 } 186 } } 187 i=i+1 188 } 189 return 0 190} 191func nw_write_file(path: *u8, data: *u8, n: i64) -> i64 { 192 let fd: i64 = sys_openat_wr(path, 0x1a4) 193 if fd<=0 { return 0 - 1 } 194 sys_write(fd, data, n) 195 sys_close(fd) 196 return n 197} 198 199const NW_W: i64 = 640 200const NW_H: i64 = 480 201const NW_BW: i64 = 620 202const NW_BH: i64 = 426 203const NW_OX: i64 = 10 204const NW_OY: i64 = 38 205 206// NIC register block (same layout as N3): +0 TX_ADDR +4 TX_LEN +8 DOORBELL +12 RX_ADDR +16 RX_LEN 207// +20 RX_STATUS(1=delivered,2=wire-error) +24 SCRATCH 208const NW_NICREG: i64 = 0x2000 209const NW_TXOFF: i64 = 0x3000 210const NW_RXOFF: i64 = 0x5000 211const NW_MEMSZ: i64 = 0x10000 212const NW_DOORBELL: i64 = 0x2008 213const NW_RXCAP: i64 = 40000 214 215func nw_rd32(mem: *u8, off: i64) -> i64 { return (mem[off] as i64)|((mem[off+1] as i64)<<8)|((mem[off+2] as i64)<<16)|((mem[off+3] as i64)<<24) } 216func nw_wr32(mem: *u8, off: i64, v: i64) -> i64 { mem[off]=(v&0xFF) as u8; mem[off+1]=((v>>8)&0xFF) as u8; mem[off+2]=((v>>16)&0xFF) as u8; mem[off+3]=((v>>24)&0xFF) as u8; return 0 } 217func nw_appz(mem: *u8, p: i64, s: *u8) -> i64 { var q: i64=p; var i: i64=0; while s[i]!=(0 as u8) { mem[q]=s[i]; q=q+1; i=i+1 } return q } 218 219// THE WIRE BRIDGE device: fires on the doorbell store. Parses the URL out of the TX request and 220// fetches it over the LIVE sovereign stack (own DNS/TCP/TLS1.3/HTTP), delivering the raw wire bytes 221// into RX. ctx slots: [0]=trust store [1]=cr [2]=priv [3]=now [4]=rbuf [5]=cap [6]=wire_rc(out). 222func nw_device_wire(mem: *u8, ctx: *i64) -> i64 { 223 let txaddr: i64 = nw_rd32(mem, NW_NICREG+0) 224 let txlen: i64 = nw_rd32(mem, NW_NICREG+4) 225 let rxaddr: i64 = nw_rd32(mem, NW_NICREG+12) 226 // URL = between "GET " and the next space 227 let ps: i64 = txaddr + 4 228 var pe: i64 = ps 229 var go: i64 = 1 230 while go==1 { if pe >= txaddr + txlen { go=0 } else { if (mem[pe] as i64)==32 { go=0 } else { pe=pe+1 } } } 231 let urlz: *u8 = sys_mmap(NW_MAGIC_4096) 232 var ul: i64 = 0 233 var i: i64 = ps 234 while i < pe { if ul < NW_MAGIC_4094 { urlz[ul]=mem[i]; ul=ul+1 } i=i+1 } 235 urlz[ul] = 0 as u8 236 // LIVE fetch over the sovereign stack (retry <=3 for transient drops) 237 let store: *TrustStore = ctx[0] as *TrustStore 238 let cr: *u8 = ctx[1] as *u8 239 let priv: *u8 = ctx[2] as *u8 240 let now: i64 = ctx[3] 241 let rbuf: *u8 = ctx[4] as *u8 242 let cap: i64 = ctx[5] 243 var n: i64 = 0 - 1 244 var att: i64 = 0 245 while att < 3 { n = nx_https_get(urlz, cr, priv, store, now, rbuf, cap); if n > 0 { att = 3 } else { att = att + 1 } } 246 ctx[6] = n 247 if n <= 0 { nw_wr32(mem, NW_NICREG+20, 2); return n } // wire error -> status 2 248 var cp: i64 = n 249 if cp > NW_RXCAP { cp = NW_RXCAP } 250 var c: i64 = 0 251 while c < cp { mem[rxaddr + c] = rbuf[c]; c = c + 1 } 252 nw_wr32(mem, NW_NICREG+16, cp) 253 nw_wr32(mem, NW_NICREG+20, 1) 254 return cp 255} 256 257// the sovereign mini-emu for the NIC driver program (same encodings as N3), doorbell -> the WIRE bridge. 258func nw_run(mem: *u8, memsz: i64, entry: i64, fired: *i64, ctx: *i64) -> i64 { 259 var ip: i64 = entry 260 var rax: i64=0 261 var rdx: i64=0 262 var guard: i64=0 263 fired[0]=0 264 while guard < NW_MAGIC_100000 { 265 guard = guard + 1 266 let op: i64 = mem[ip] as i64 267 if op==0xF4 { return 0 } 268 var h: i64 = 0 269 if h==0 { if op==0x48 { 270 let b1: i64 = mem[ip+1] as i64 271 if b1==0xB8 { rax = (mem[ip+2] as i64)|((mem[ip+3] as i64)<<8)|((mem[ip+4] as i64)<<16)|((mem[ip+5] as i64)<<24)|((mem[ip+6] as i64)<<32)|((mem[ip+7] as i64)<<40)|((mem[ip+8] as i64)<<48)|((mem[ip+9] as i64)<<56); ip=ip+10; h=1 } 272 if h==0 { if b1==0xC7 { if (mem[ip+2] as i64)==0xC2 { rdx = (mem[ip+3] as i64)|((mem[ip+4] as i64)<<8)|((mem[ip+5] as i64)<<16)|((mem[ip+6] as i64)<<24); ip=ip+7; h=1 } } } 273 } } 274 if h==0 { if op==0x89 { if (mem[ip+1] as i64)==0x10 { 275 if rax<0 { return 0 - 3 } 276 if rax+4>memsz { return 0 - 3 } 277 nw_wr32(mem, rax, rdx & 0xFFFFFFFF) 278 if rax==NW_DOORBELL { if (rdx & 0xFFFFFFFF)!=0 { nw_device_wire(mem, ctx); fired[0]=fired[0]+1 } } 279 ip=ip+2; h=1 280 } } } 281 if h==0 { if op==0x8B { if (mem[ip+1] as i64)==0x10 { 282 if rax<0 { return 0 - 3 } 283 if rax+4>memsz { return 0 - 3 } 284 rdx = nw_rd32(mem, rax) 285 ip=ip+2; h=1 286 } } } 287 if h==0 { return 0 - 1 } 288 } 289 return 0 - 2 290} 291 292func nw_movabs(code: *u8, p: i64, v: i64) -> i64 { 293 code[p]=0x48 as u8; code[p+1]=0xB8 as u8 294 code[p+2]=(v&0xFF) as u8; code[p+3]=((v>>8)&0xFF) as u8; code[p+4]=((v>>16)&0xFF) as u8; code[p+5]=((v>>24)&0xFF) as u8 295 code[p+6]=((v>>32)&0xFF) as u8; code[p+7]=((v>>40)&0xFF) as u8; code[p+8]=((v>>48)&0xFF) as u8; code[p+9]=((v>>56)&0xFF) as u8 296 return p+10 297} 298func nw_movrdx(code: *u8, p: i64, v: i64) -> i64 { 299 code[p]=0x48 as u8; code[p+1]=0xC7 as u8; code[p+2]=0xC2 as u8 300 code[p+3]=(v&0xFF) as u8; code[p+4]=((v>>8)&0xFF) as u8; code[p+5]=((v>>16)&0xFF) as u8; code[p+6]=((v>>24)&0xFF) as u8 301 return p+7 302} 303func nw_store(code: *u8, p: i64) -> i64 { code[p]=0x89 as u8; code[p+1]=0x10 as u8; return p+2 } 304func nw_load(code: *u8, p: i64) -> i64 { code[p]=0x8B as u8; code[p+1]=0x10 as u8; return p+2 } 305 306// author the NIC driver: program TX descriptor + RX_ADDR, ring the doorbell (if ring==1), read 307// RX_STATUS back into SCRATCH (so the executed driver OBSERVES delivery or wire-error). 308func nw_author(code: *u8, txlen: i64, ring: i64) -> i64 { 309 var p: i64 = 0 310 p = nw_movabs(code, p, NW_NICREG+0); p = nw_movrdx(code, p, NW_TXOFF); p = nw_store(code, p) 311 p = nw_movabs(code, p, NW_NICREG+4); p = nw_movrdx(code, p, txlen); p = nw_store(code, p) 312 p = nw_movabs(code, p, NW_NICREG+12); p = nw_movrdx(code, p, NW_RXOFF); p = nw_store(code, p) 313 if ring==1 { p = nw_movabs(code, p, NW_DOORBELL); p = nw_movrdx(code, p, 1); p = nw_store(code, p) } 314 p = nw_movabs(code, p, NW_NICREG+20); p = nw_load(code, p) 315 p = nw_movabs(code, p, NW_NICREG+24); p = nw_store(code, p) 316 code[p]=0xF4 as u8; p=p+1 317 return p 318} 319 320func nw_draw_desktop(desk: *u8, page: *Page, url: *u8, ulen: i64) -> i64 { 321 let font: *u8 = sys_mmap(64) 322 let idx: *u8 = sys_mmap(8) 323 fb_nishi_font(font, idx) 324 var wy: i64=0 325 while wy<NW_H { let wr: i64=10-(8*wy)/NW_H; let wg: i64=30+(40*wy)/NW_H; let wb: i64=50+(30*wy)/NW_H; fb_rect(desk,NW_W,NW_H, 0,wy, NW_W,1, wr,wg,wb); wy=wy+1 } 326 fb_rect(desk,NW_W,NW_H, 0,0, NW_W,16, 28,28,110) 327 fb_text(desk,NW_W,NW_H, font, idx, 7, 6,4, 1, 255,255,255) 328 fb_window(desk,NW_W,NW_H, font,idx, 8,22, 624,444, 50,80,180, 210,210,225) 329 nw_str(desk,NW_W,NW_H, 8+3+66, 22+3, "- NISHI BROWSER (real internet)\x00" as *u8, 240,240,250) 330 let bfb: *Framebuffer = sys_mmap(NX_FRAMEBUFFER_BYTES) as *Framebuffer 331 let bpx: *u8 = sys_mmap(NW_BW*NW_BH*4 + 64) 332 nx_framebuffer_init(bfb, bpx, NW_BW, NW_BH) 333 br_draw_fb(bfb, page, NW_BW/2, url, ulen, 2) 334 var by: i64 = 0 335 while by < NW_BH { 336 var bx: i64 = 0 337 while bx < NW_BW { 338 let so: i64 = (by*NW_BW + bx)*4 339 let dof: i64 = ((NW_OY+by)*NW_W + (NW_OX+bx))*3 340 desk[dof]=bpx[so]; desk[dof+1]=bpx[so+1]; desk[dof+2]=bpx[so+2] 341 bx = bx + 1 342 } 343 by = by + 1 344 } 345 fb_rect(desk,NW_W,NW_H, 0,466, NW_W,14, 20,20,40) 346 fb_rect(desk,NW_W,NW_H, 4,469, 36,8, 80,200,80) 347 nw_str(desk,NW_W,NW_H, 46,469, "browser\x00" as *u8, 200,210,230) 348 fb_cursor(desk,NW_W,NW_H, 330,240) 349 return 0 350} 351 352func main() -> i64 { 353 nw_puts("BROWSER-ON-ALL-OS N3-WIRE: NishiOS fetches the REAL INTERNET (NIC bridge -> live sovereign DNS/TLS1.3/HTTP)\n" as *u8) 354 355 // ---- 0. the live stack's inputs: trust store + entropy + time (the nx_browser idiom) 356 var tr: i64 = nx_trust_store_load_from_certdata("data/mozilla_certdata.txt\x00" as *u8, 300, NW_MAGIC_4194304) 357 if tr <= 0 { tr = nx_trust_store_load_from_certdata("/tmp/mozilla_certdata.txt\x00" as *u8, 300, NW_MAGIC_4194304) } 358 if tr <= 0 { nw_puts("N3-WIRE RED: no CA bundle (data/mozilla_certdata.txt)\n" as *u8); sys_exit(1); return 1 } 359 let store: *TrustStore = tr as *TrustStore 360 let cr: *u8 = sys_mmap(32) 361 let priv: *u8 = sys_mmap(32) 362 let ufd: i64 = sys_openat_rd("/dev/urandom\x00" as *u8) 363 if ufd >= 0 { sys_read(ufd, cr, 32); sys_read(ufd, priv, 32); sys_close(ufd) } else { var z: i64=0; while z<32 { cr[z]=(0xC0+z) as u8; priv[z]=(0xA0+z) as u8; z=z+1 } } 364 let now: i64 = sys_now_realtime_sec() 365 let cap: i64 = NW_MAGIC_4194304 366 let rbuf: *u8 = sys_mmap(cap) 367 368 // ---- 1. persist + boot the NishiOS image 369 let img: *u8 = sys_mmap(NW_IMG_SZ + 16) 370 nw_build_image(img) 371 if nw_write_file("knowledge/status/nishios_browser.img\x00" as *u8, img, NW_IMG_SZ) <= 0 { nw_puts("N3-WIRE RED: cannot write image\n" as *u8); sys_exit(1); return 1 } 372 let ilp: *i64 = sys_mmap(16) as *i64 373 let rd: *u8 = sys_read_file("knowledge/status/nishios_browser.img\x00" as *u8, ilp) 374 let con: *u8 = sys_mmap(256) 375 let clen: *i64 = sys_mmap(8) as *i64 376 let st: *i64 = sys_mmap(64) as *i64 377 let ld: *i64 = sys_mmap(64) as *i64 378 nw_boot_image(rd, con, clen, st, ld) 379 nw_puts(" boot: 0x8000 " as *u8); nw_num(ld[0]); nw_puts("->" as *u8); nw_num(ld[1]); nw_puts(" mode=" as *u8); nw_num(st[1]); nw_puts("\n" as *u8) 380 381 // ---- 2. driver: request the REAL page; ring the doorbell via executed x86; wire bridge fetches LIVE 382 let mem: *u8 = sys_mmap(NW_MEMSZ) 383 var mz: i64=0 384 while mz<NW_MEMSZ { mem[mz]=0 as u8; mz=mz+1 } 385 var tq: i64 = NW_TXOFF 386 tq = nw_appz(mem, tq, "GET https://example.com/ HTTP/1.0\x0D\x0A\x0D\x0A\x00" as *u8) 387 let txlen: i64 = tq - NW_TXOFF 388 let ctx: *i64 = sys_mmap(64) as *i64 389 ctx[0] = store as i64 390 ctx[1] = cr as i64 391 ctx[2] = priv as i64 392 ctx[3] = now 393 ctx[4] = rbuf as i64 394 ctx[5] = cap 395 ctx[6] = 0 - 99 396 let fired: *i64 = sys_mmap(16) as *i64 397 var rc86: i64 = 0 - 9 398 if st[1]==2 { 399 nw_author(mem, txlen, 1) 400 rc86 = nw_run(mem, NW_MEMSZ, 0, fired, ctx) 401 } 402 let rx_status: i64 = nw_rd32(mem, NW_NICREG+20) 403 let scratch: i64 = nw_rd32(mem, NW_NICREG+24) 404 let rxlen: i64 = nw_rd32(mem, NW_NICREG+16) 405 nw_puts(" NIC: x86 rc=" as *u8); nw_num(rc86); nw_puts(" fired=" as *u8); nw_num(fired[0]); nw_puts(" wire_rc=" as *u8); nw_num(ctx[6]); nw_puts(" rx_status=" as *u8); nw_num(rx_status); nw_puts(" driver_saw=" as *u8); nw_num(scratch); nw_puts(" rxlen=" as *u8); nw_num(rxlen); nw_puts("\n" as *u8) 406 407 // ---- 3. browser side: parse the delivered WIRE BYTES exactly like nx_browser load_page 408 let resp: *u8 = ((mem as i64) + NW_RXOFF) as *u8 409 let r: *i64 = nx_http_resp_alloc() 410 var status: i64 = 0 - 1 411 var body: *u8 = resp 412 var body_len: i64 = 0 413 if rxlen > 0 { 414 let pv: i64 = nx_http_response_parse(resp, rxlen, r) 415 if pv == NX_HTTP_RESP_OK { 416 status = r[1] 417 let bo: i64 = r[6] 418 let kind: i64 = r[8] 419 body = ((resp as i64) + bo) as *u8 420 body_len = rxlen - bo 421 if kind == NX_HTTP_BODY_CONTENT_LENGTH { body_len = r[7]; if body_len > rxlen - bo { body_len = rxlen - bo } } 422 if kind == NX_HTTP_BODY_CHUNKED { let dcap: i64 = NW_MAGIC_262144; let dbuf: *u8 = sys_mmap(dcap); let dl: i64 = nx_http_dechunk(body, rxlen - bo, dbuf, dcap); if dl > 0 { body = dbuf; body_len = dl } } 423 } 424 } 425 var marker: i64 = 0 426 if body_len > 0 { marker = nw_contains(body, body_len, "Example Domain\x00" as *u8, 14) } 427 nw_puts(" http: status=" as *u8); nw_num(status); nw_puts(" body_len=" as *u8); nw_num(body_len); nw_puts(" real-content-marker=" as *u8); nw_num(marker); nw_puts("\n" as *u8) 428 429 // ---- 4. lay out + render the REAL page into the NishiOS desktop 430 let page: *Page = sys_mmap(NX_PAGE_BYTES) as *Page 431 var a_ok: i64 = 0 432 if body_len > 0 { page.raw = body; page.raw_len = body_len; br_layout(page, NW_BW/2); a_ok = page.ok; page.vec_headings = 2 } // 16px + modern vector headings 433 nw_puts(" layout: ok=" as *u8); nw_num(a_ok); nw_puts(" boxes=" as *u8); if a_ok==1 { nw_num(page.tree.count) } else { nw_num(0) } nw_puts("\n" as *u8) 434 let desk: *u8 = sys_mmap(NW_W*NW_H*3 + 16) 435 var bmpsz: i64 = 0 436 var cnt_h1: i64 = 0 437 if a_ok==1 { 438 nw_draw_desktop(desk, page, "https://example.com/\x00" as *u8, 20) 439 // rendered-TEXT-ink probe (near-black glyph pixels in the window). The old h1-bar-color probe was 440 // brittle against the page's OWN stylesheet (example.com's fixed width:600px div at the 16px 441 // viewport) -- ink proves the fetched content painted; T7 already proves the content is real. 442 var y: i64=0 443 while y<NW_BH { var x: i64=0; while x<NW_BW { let d: i64=((NW_OY+y)*NW_W+(NW_OX+x))*3; if (desk[d] as i64)<60 { if (desk[d+1] as i64)<60 { if (desk[d+2] as i64)<60 { cnt_h1=cnt_h1+1 } } } x=x+1 } y=y+1 } 444 bmpsz = fb_bmp_save(desk, NW_W, NW_H, "knowledge/status/nishios_net_wire.bmp\x00" as *u8) 445 let html: *u8 = "<!doctype html><html><body style=\x27margin:0;background:#0a0a12;display:flex;align-items:center;justify-content:center;height:100vh\x27><div><img src=\x27nishios_net_wire.bmp\x27 style=\x27image-rendering:pixelated;width:960px;border:1px solid #333\x27><div style=\x27color:#8af;font-family:monospace;text-align:center;margin-top:8px\x27>NishiOS on the REAL INTERNET: boot to LONG mode -&gt; the NIC driver rings the doorbell (executed x86 store) -&gt; the wire bridge fetches https://example.com/ over the live sovereign DNS + TLS 1.3 + HTTP stack -&gt; the Nishi browser renders the real page into the NishiOS desktop</div></div></body></html>\x00" 446 nw_write_file("knowledge/status/nishios_net_wire.html\x00" as *u8, html, nw_slen(html)) 447 nw_puts(" REAL page rendered -> knowledge/status/nishios_net_wire.bmp (" as *u8); nw_num(bmpsz); nw_puts(" bytes) + .html\n" as *u8) 448 } 449 450 // ---- 5. NEG 1: no doorbell -> no delivery (and no wire fetch at all) 451 let mem2: *u8 = sys_mmap(NW_MEMSZ) 452 var m2: i64=0 453 while m2<NW_MEMSZ { mem2[m2]=0 as u8; m2=m2+1 } 454 var tq2: i64 = NW_TXOFF 455 tq2 = nw_appz(mem2, tq2, "GET https://example.com/ HTTP/1.0\x0D\x0A\x0D\x0A\x00" as *u8) 456 let ctx2: *i64 = sys_mmap(64) as *i64 457 ctx2[0]=store as i64; ctx2[1]=cr as i64; ctx2[2]=priv as i64; ctx2[3]=now; ctx2[4]=rbuf as i64; ctx2[5]=cap; ctx2[6]=0-99 458 let fired2: *i64 = sys_mmap(16) as *i64 459 nw_author(mem2, tq2 - NW_TXOFF, 0) 460 nw_run(mem2, NW_MEMSZ, 0, fired2, ctx2) 461 let neg1_status: i64 = nw_rd32(mem2, NW_NICREG+20) 462 nw_puts(" NEG no-doorbell: fired=" as *u8); nw_num(fired2[0]); nw_puts(" rx_status=" as *u8); nw_num(neg1_status); nw_puts(" wire_rc(untouched)=" as *u8); nw_num(ctx2[6]); nw_puts("\n" as *u8) 463 464 // ---- 6. NEG 2 (THE WIRE LIAR-KILL): same bridge, guaranteed-nonexistent RFC-2606 .invalid host 465 let mem3: *u8 = sys_mmap(NW_MEMSZ) 466 var m3: i64=0 467 while m3<NW_MEMSZ { mem3[m3]=0 as u8; m3=m3+1 } 468 var tq3: i64 = NW_TXOFF 469 tq3 = nw_appz(mem3, tq3, "GET https://nishi-nonexistent-zzz.invalid/ HTTP/1.0\x0D\x0A\x0D\x0A\x00" as *u8) 470 let ctx3: *i64 = sys_mmap(64) as *i64 471 ctx3[0]=store as i64; ctx3[1]=cr as i64; ctx3[2]=priv as i64; ctx3[3]=now; ctx3[4]=rbuf as i64; ctx3[5]=cap; ctx3[6]=0-99 472 let fired3: *i64 = sys_mmap(16) as *i64 473 nw_author(mem3, tq3 - NW_TXOFF, 1) 474 nw_run(mem3, NW_MEMSZ, 0, fired3, ctx3) 475 let neg2_status: i64 = nw_rd32(mem3, NW_NICREG+20) 476 let neg2_scr: i64 = nw_rd32(mem3, NW_NICREG+24) 477 nw_puts(" NEG .invalid host: fired=" as *u8); nw_num(fired3[0]); nw_puts(" wire_rc=" as *u8); nw_num(ctx3[6]); nw_puts(" rx_status=" as *u8); nw_num(neg2_status); nw_puts(" driver_saw=" as *u8); nw_num(neg2_scr); nw_puts("\n" as *u8) 478 479 // ---- 7. NEG 3: 0-sector boot never reaches long mode 480 let bad: *u8 = sys_mmap(NW_IMG_SZ + 16) 481 var c2: i64=0 482 while c2<NW_IMG_SZ { bad[c2]=rd[c2]; c2=c2+1 } 483 bad[1]=0x00 as u8 484 let con2: *u8 = sys_mmap(256) 485 let clen2: *i64 = sys_mmap(8) as *i64 486 let st2: *i64 = sys_mmap(64) as *i64 487 let ld2: *i64 = sys_mmap(64) as *i64 488 nw_boot_image(bad, con2, clen2, st2, ld2) 489 490 // ---- KATs 491 let banner: *u8 = "NishiOS" as *u8 492 var pass: i64=0 493 var ttl: i64=0 494 ttl=ttl+1; nw_puts(" T1 booted off the persisted image (0x8000: 0->0xBE): " as *u8); if ld[0]==0 { if ld[1]==0xBE { pass=pass+1; nw_puts("PASS\n" as *u8) } else { nw_puts("FAIL\n" as *u8) } } else { nw_puts("FAIL\n" as *u8) } 495 ttl=ttl+1; nw_puts(" T2 LONG mode + banner: " as *u8); if st[1]==2 { if nw_contains(con, clen[0], banner, 7)==1 { pass=pass+1; nw_puts("PASS\n" as *u8) } else { nw_puts("FAIL\n" as *u8) } } else { nw_puts("FAIL\n" as *u8) } 496 ttl=ttl+1; nw_puts(" T3 executed x86 rang the doorbell exactly once: " as *u8); if fired[0]==1 { pass=pass+1; nw_puts("PASS\n" as *u8) } else { nw_puts("FAIL\n" as *u8) } 497 ttl=ttl+1; nw_puts(" T4 device delivered (RX_STATUS==1) AND driver read it back (scratch==1): " as *u8); if rx_status==1 { if scratch==1 { pass=pass+1; nw_puts("PASS\n" as *u8) } else { nw_puts("FAIL\n" as *u8) } } else { nw_puts("FAIL\n" as *u8) } 498 ttl=ttl+1; nw_puts(" T5 the wire returned real bytes (nx_https_get rc>0): " as *u8); if ctx[6]>0 { pass=pass+1; nw_puts("PASS\n" as *u8) } else { nw_puts("FAIL\n" as *u8) } 499 ttl=ttl+1; nw_puts(" T6 browser-side HTTP parse: status==200: " as *u8); if status==200 { pass=pass+1; nw_puts("PASS\n" as *u8) } else { nw_puts("FAIL\n" as *u8) } 500 ttl=ttl+1; nw_puts(" T7 body carries the REAL-internet marker ('Example Domain'): " as *u8); if marker==1 { pass=pass+1; nw_puts("PASS\n" as *u8) } else { nw_puts("FAIL\n" as *u8) } 501 ttl=ttl+1; nw_puts(" T8 browser laid out the real page (ok, boxes>=6): " as *u8); if a_ok==1 { if page.tree.count>=6 { pass=pass+1; nw_puts("PASS\n" as *u8) } else { nw_puts("FAIL\n" as *u8) } } else { nw_puts("FAIL\n" as *u8) } 502 ttl=ttl+1; nw_puts(" T9 real page rendered into the desktop (text ink >300 px): " as *u8); if cnt_h1>300 { pass=pass+1; nw_puts("PASS\n" as *u8) } else { nw_puts("FAIL\n" as *u8) } 503 ttl=ttl+1; nw_puts(" T10 BMP exported at the exact expected size: " as *u8); if bmpsz==(54 + NW_W*NW_H*3) { pass=pass+1; nw_puts("PASS\n" as *u8) } else { nw_puts("FAIL\n" as *u8) } 504 ttl=ttl+1; nw_puts(" T11 NEG: no doorbell -> no delivery, wire never touched: " as *u8); if fired2[0]==0 { if neg1_status==0 { if ctx2[6]==(0-99) { pass=pass+1; nw_puts("PASS\n" as *u8) } else { nw_puts("FAIL\n" as *u8) } } else { nw_puts("FAIL\n" as *u8) } } else { nw_puts("FAIL\n" as *u8) } 505 ttl=ttl+1; nw_puts(" T12 NEG WIRE LIAR-KILL: .invalid host FAILS + driver observes the error (status 2): " as *u8); if fired3[0]==1 { if ctx3[6]<=0 { if neg2_status==2 { if neg2_scr==2 { pass=pass+1; nw_puts("PASS\n" as *u8) } else { nw_puts("FAIL\n" as *u8) } } else { nw_puts("FAIL\n" as *u8) } } else { nw_puts("FAIL\n" as *u8) } } else { nw_puts("FAIL\n" as *u8) } 506 ttl=ttl+1; nw_puts(" T13 NEG: 0-sector load never reaches long mode: " as *u8); if st2[1]!=2 { pass=pass+1; nw_puts("PASS\n" as *u8) } else { nw_puts("FAIL\n" as *u8) } 507 508 nw_puts("NISHIOS-NET-WIRE-GATE passed " as *u8); nw_num(pass); nw_puts("/" as *u8); nw_num(ttl) 509 if pass==ttl { nw_puts(" verdict=GREEN (NishiOS fetched + rendered the REAL internet; open knowledge/status/nishios_net_wire.html)\n" as *u8); sys_exit(0); return 0 } 510 nw_puts(" verdict=RED\n" as *u8); sys_exit(1); return 1 511}