code wiki / _hdl_build / _gpu_dxg_r4c_recon.nx

_gpu_dxg_r4c_recon.nx source

↩ module page · 79 lines · 5512 B

1// _gpu_dxg_r4c_recon.nx -- SOVEREIGN-GPU ladder R4c RECON (allocate real GPU memory on the 5080). 2// 3// LX_DXCREATEALLOCATION (nr=0x06 in the dxgkrnl table) is the real-GPU-memory rung. Unlike device/context, 4// it carries an allocation_info array + (for a UMD-less "standard allocation") a private-runtime-data 5// descriptor, so it will NOT succeed on all-zeros -- this recon just MAPS the ABI: which _IOC_SIZE for 6// nr=0x06 is recognized (non-ENOTTY) vs which are -ENOTTY, with the device handle at offset 0 and the rest 7// zero. The recognized size + the error (expected -EINVAL = "recognized, needs real descriptors") tells us 8// the struct size so a focused R4c gate can build the d3dkmt_allocationinfo2 + standard-allocation header. 9// raw syscalls only. No log writes. license_tier: ORIGINAL 10import "nx_syscalls.nx" 11 12const ENUM2_CODE: i64 = 0xC0104714 13const QAI_CODE: i64 = 0xC0184709 14const OAFL_CODE: i64 = 0xC00C4701 15const CDEV_CODE: i64 = 0xC0404702 16 17func p(s: *u8) -> i64 { var nn: i64=0; while s[nn]!=(0 as u8){nn=nn+1} sys_write(1,s,nn); return 0 } 18func n(v: i64) -> i64 { let bb: *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;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{bb[i]=t[k-1-i];i=i+1}; sys_write(1,bb,k); return 0 } 19func x(v: i64) -> i64 { p("0x" as *u8); let bb:*u8=sys_mmap(20); var k:i64=0; var m:i64=v; if m==0{bb[0]=48;k=1}; while m>0{ let d:i64=m&15; if d<10{bb[k]=(48+d) as u8}else{bb[k]=(87+d) as u8}; m=(m>>4); k=k+1 } var i:i64=0; let o:*u8=sys_mmap(20); while i<k{o[i]=bb[k-1-i];i=i+1} sys_write(1,o,k); return 0 } 20func iowr(nr: i64, size: i64) -> i64 { return (3 << 30) | ((size & 0x3fff) << 16) | (0x47 << 8) | (nr & 0xff) } 21func rd32(buf: *u8, off: i64) -> i64 { return (buf[off] as i64)|((buf[off+1] as i64)<<8)|((buf[off+2] as i64)<<16)|((buf[off+3] as i64)<<24) } 22 23func query_type(fd: i64, handle: i64, qtype: i64, psize: i64, outv: *i64) -> i64 { 24 let priv: *u8 = sys_mmap(64); var zz: i64 = 0; while zz < 64 { priv[zz] = 0 as u8; zz = zz + 1 } 25 let req: *u8 = sys_mmap(64); var y: i64 = 0; while y < 64 { req[y] = 0 as u8; y = y + 1 } 26 let h: *i64 = (req as i64 + 0) as *i64; h[0] = (handle & 0xffffffff) | ((qtype & 0xffffffff) << 32) 27 let pd: *i64 = (req as i64 + 8) as *i64; pd[0] = priv as i64 28 let pds: *i64 = (req as i64 + 16) as *i64; pds[0] = psize & 0xffffffff 29 let ret: i64 = sys_ioctl(fd, QAI_CODE, req as i64); outv[0] = rd32(priv, 0); return ret 30} 31func open_from_luid(fd: i64, luid_lo: i64, luid_hi: i64, outh: *i64) -> i64 { 32 let req: *u8 = sys_mmap(64); var y: i64 = 0; while y < 64 { req[y] = 0 as u8; y = y + 1 } 33 let lo: *i64 = (req as i64 + 0) as *i64; lo[0] = (luid_lo & 0xffffffff) | ((luid_hi & 0xffffffff) << 32) 34 let ret: i64 = sys_ioctl(fd, OAFL_CODE, req as i64); outh[0] = rd32(req, 8); return ret 35} 36func create_device(fd: i64, adapter: i64, outd: *i64) -> i64 { 37 let buf: *u8 = sys_mmap(512); var bz: i64 = 0; while bz < 512 { buf[bz] = 0 as u8; bz = bz + 1 } 38 let a0: *i64 = (buf as i64) as *i64; a0[0] = adapter & 0xffffffff 39 let ret: i64 = sys_ioctl(fd, CDEV_CODE, buf as i64); outd[0] = rd32(buf, 12); return ret 40} 41 42func main() -> i64 { 43 p("=== R4c RECON: map LX_DXCREATEALLOCATION (nr=0x06) ABI on the 5080 device ===\n" as *u8) 44 let fd: i64 = sys_openat_rd("/dev/dxg" as *u8) 45 if fd < 0 { p("open(/dev/dxg) failed\n" as *u8); sys_exit(1); return 1 } 46 let ainfo: *u8 = sys_mmap(4096); var z: i64 = 0; while z < 4096 { ainfo[z] = 0 as u8; z = z + 1 } 47 let ereq: *u8 = sys_mmap(64); ereq[0] = 8 as u8; let r8: *i64 = (ereq as i64 + 8) as *i64; r8[0] = ainfo as i64 48 sys_ioctl(fd, ENUM2_CODE, ereq as i64); let nc: i64 = rd32(ereq, 0) 49 let v: *i64 = sys_mmap(16); var disc_lo: i64 = 0; var disc_hi: i64 = 0 50 var ai: i64 = 0 51 while ai < nc { 52 let base: i64 = ai * 20; let eh: i64 = rd32(ainfo, base) 53 let qret: i64 = query_type(fd, eh, 15, 4, v); let t: i64 = v[0] 54 if qret == 0 { if ((t>>4)&1) == 1 { if ((t>>2)&1) == 0 { disc_lo = rd32(ainfo, base+4); disc_hi = rd32(ainfo, base+8) } } } 55 ai = ai + 1 56 } 57 let ah: *i64 = sys_mmap(16); open_from_luid(fd, disc_lo, disc_hi, ah) 58 let dh: *i64 = sys_mmap(16); let dr: i64 = create_device(fd, ah[0], dh) 59 p(" device_create ret=" as *u8); n(dr); p(" device=" as *u8); x(dh[0]); p("\n" as *u8) 60 61 p("\n-- size sweep for nr=0x06 (device@0, rest zero). non-ENOTTY = recognized size --\n" as *u8) 62 let sizes: *i64 = sys_mmap(512) 63 sizes[0]=56; sizes[1]=64; sizes[2]=72; sizes[3]=80; sizes[4]=88; sizes[5]=96; sizes[6]=104; sizes[7]=112; sizes[8]=120; sizes[9]=128; sizes[10]=136; sizes[11]=144; sizes[12]=160; sizes[13]=176; sizes[14]=192; sizes[15]=0 64 var si: i64 = 0 65 while sizes[si] != 0 { 66 let sz: i64 = sizes[si] 67 let buf: *u8 = sys_mmap(1024); var bz: i64 = 0; while bz < 1024 { buf[bz] = 0 as u8; bz = bz + 1 } 68 let d0: *i64 = (buf as i64) as *i64; d0[0] = dh[0] & 0xffffffff // device @0 69 let code: i64 = iowr(6, sz) 70 let ret: i64 = sys_ioctl(fd, code, buf as i64) 71 p(" size=" as *u8); n(sz); p(" code=" as *u8); x(code); p(" ret=" as *u8); n(ret) 72 if ret != 0 - 25 { p(" <- RECOGNIZED (non-ENOTTY: this is the struct size; err means it needs real alloc descriptors)" as *u8) } 73 p("\n" as *u8) 74 si = si + 1 75 } 76 sys_close(fd) 77 p("=== R4c RECON DONE ===\n" as *u8) 78 return 0 79}