code wiki / _hdl_build / nx_4kpage_emit.nx
nx_4kpage_emit.nx
buildroot/runtime/_hdl_build/nx_4kpage_emit.nx
about
nx_4kpage_emit.nx -- FULL 3-LEVEL Sv39 walk with a 4KB-page leaf (X-PAGE-4K-001). Closes the noted
gap "single gigapage leaf exercised (walk is general 3-level)": all prior tests used a level-2 gigapage
leaf (one table read). Here VA 0xC0009000 resolves through ALL THREE levels -- root[VPN2=3] -> L1 table
-> L1[VPN1=0] -> L0 table -> L0[VPN0=9] = a 4KB leaf -> PA -- the real page granularity + the prerequisite
for distinct per-process page tables (which need 4KB pages to differ within the 64KB emu RAM).
Physical layout: code @0x80000000; root table @0x80001000 (ppn 0x80001); L1 @0x80002000; L0 @0x80003000;
data 4KB page @0x80004000 (sentinel). root[VPN2=2]=identity gigapage (so the S-mode code stays fetchable).
l1_pte (argv[1]) -- the L1 PTE (default 0x20000C01 = V, ->L0 ppn 0x80003). The gate tampers it to
0x20000C00 (V=0) to prove the walk genuinely VALIDATES the intermediate level.
out-path (argv[2]). S-mode loads VA 0xC0009000 -> "K4OK" iff the 3-level walk reads the sentinel.
Sovereign, no gcc/.sh. license_tier: ORIGINAL
dependencies 1 imports · 0 importers
imports: nx_syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 14 | const K4_MAGIC_8192: i64 = 8192 |
| 16 | const K4_OUT: *u8 = "runtime/_hdl_build/_4kpage_virt.bin" |
| 17 | const K4_GOLD: *u8 = "runtime/_hdl_build/_4kpage_virt.bin.gold" |
| 18 | const K4_LOG: *u8 = "knowledge/status/paging.log" |
| 20 | const K4_UART: i64 = 0x10000000 |
| 21 | const K4_FIN: i64 = 0x100000 |
| 22 | const K4_PASS: i64 = 0x5555 |
| 23 | const K4_MEM_BASE: i64 = 0x80000000 |
| 24 | const K4_CSR_SATP: i64 = 0x180 |
| 25 | const K4_CSR_MSTATUS: i64 = 0x300 |
| 26 | const K4_CSR_MEPC: i64 = 0x341 |
| 27 | const K4_MRET: i64 = 0x30200073 |
| 28 | const K4_MPP_S: i64 = 0x800 |
| 30 | const RV_X0: i64 = 0 |
| 31 | const RV_T0: i64 = 5 |
| 32 | const RV_T1: i64 = 6 |
| 33 | const RV_T2: i64 = 7 |
| 34 | const RV_T3: i64 = 28 |
| 35 | const RV_T4: i64 = 29 |
| 36 | const RV_T5: i64 = 30 |
| 38 | const K4_ROOT: i64 = 0x80001000 // root table (ppn 0x80001) |
| 39 | const K4_L1: i64 = 0x80002000 // level-1 table |
| 40 | const K4_L0: i64 = 0x80003000 // level-0 table |
| 41 | const K4_DATA: i64 = 0x80004000 // 4KB data page (the leaf target) |
| 42 | const K4_SENT_VAL: i64 = 0x5ECA1234 |
| 43 | const K4_VA: i64 = 0xC0009000 // VPN2=3, VPN1=0, VPN0=9 -> full 3-level walk |
| 44 | const K4_SATP_PPN: i64 = 0x80001 // root >> 12 |
| 45 | const K4_SV39: i64 = 8 |
| 46 | const K4_CODE_PTE: i64 = 0x2000000F // root[VPN2=2] identity gigapage (V|R|W|X) for the S-mode code |
| 47 | const K4_ROOT3_PTE: i64 = 0x20000801 // root[VPN2=3] non-leaf -> L1 (V, ppn 0x80002) |
| 48 | const K4_L0_LEAF: i64 = 0x20001007 // L0[VPN0=9] leaf -> data (V|R|W, ppn 0x80004) |
functions
| 50 | func k4_lui(rd: i64, imm20: i64) -> i64 { return ((imm20 & 0xFFFFF) << 12) | (rd << 7) | 0x37 } |
| 51 | func k4_addi(rd: i64, rs1: i64, imm: i64) -> i64 { return ((imm & 0xFFF) << 20) | (rs1 << 15) | (rd << 7) | 0x13 } |
| 52 | func k4_load(rd: i64, rs1: i64, f3: i64, imm: i64) -> i64 { return ((imm & 0xFFF) << 20) | (rs1 << 15) | (f3 << 12) | (rd << 7) | 0x03 } called by 1: k4_emit_image |
| 53 | func k4_store(rs2: i64, rs1: i64, f3: i64, imm: i64) -> i64 |
| 58 | func k4_branch(rs1: i64, rs2: i64, f3: i64, imm: i64) -> i64 called by 1: k4_emit_image |
| 65 | func k4_jal(rd: i64, imm: i64) -> i64 called by 1: k4_emit_image |
| 72 | func k4_slli(rd: i64, rs1: i64, shamt: i64) -> i64 { return ((shamt & 0x3f) << 20) | (rs1 << 15) | (1 << 12) | (rd << 7) | 0x13 } |
| 73 | func k4_srli(rd: i64, rs1: i64, shamt: i64) -> i64 { return ((shamt & 0x3f) << 20) | (rs1 << 15) | (5 << 12) | (rd << 7) | 0x13 } called by 1: k4_li32u |
| 74 | func k4_or(rd: i64, rs1: i64, rs2: i64) -> i64 { return (rs2 << 20) | (rs1 << 15) | (6 << 12) | (rd << 7) | 0x33 } called by 1: k4_emit_image |
| 75 | func k4_csrrw(rd: i64, csr: i64, rs1: i64) -> i64 { return ((csr & 0xfff) << 20) | (rs1 << 15) | (1 << 12) | (rd << 7) | 0x73 } called by 1: k4_emit_image |
| 76 | func k4_w32(buf: *u8, off: i64, w: i64) -> i64 { buf[off]=(w&0xff) as u8; buf[off+1]=((w>>8)&0xff) as u8; buf[off+2]=((w>>16)&0xff) as u8; buf[off+3]=((w>>24)&0xff) as u8; return off+4 } |
| 77 | func k4_li32(buf: *u8, off: i64, rd: i64, val: i64) -> i64 |
| 85 | func k4_li32u(buf: *u8, off: i64, rd: i64, val: i64) -> i64 |
| 91 | func k4_emit_str(buf: *u8, off: i64, s: *u8, n: i64) -> i64 |
| 97 | func k4_p(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } |
| 98 | func k4_fn(fd: i64, v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m}; 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(fd,bb,k); return 0 } |
| 101 | func k4_emit_image(buf: *u8, cont_off: i64, fail_off: i64, halt_off: i64, pos_out: *i64, l1_pte: i64) -> i64 |
| 147 | func k4_parse_num(s: *u8) -> i64 called by 1: main |
| 160 | func main(argc: i64, argv: *i64) -> i64 |