code wiki / _hdl_build / nx_4kpage_emit.nx

nx_4kpage_emit.nx

buildroot/runtime/_hdl_build/nx_4kpage_emit.nx

10353 B184 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_4kpage_emit.nx

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

main k4_parse_num sys_mmap k4_emit_image k4_w32 k4_lui k4_li32u k4_li32 k4_w32 ↻ k4_lui ↻ k4_addi k4_w32 ↻ k4_slli k4_srli k4_li32 ↻ k4_store k4_addi ↻ k4_slli ↻ k4_or k4_csrrw k4_load k4_branch k4_emit_str k4_w32 ↻ k4_addi ↻ k4_store ↻ k4_jal sys_openat_wr k4_p sys_write sys_write ↻ sys_close k4_fn sys_mmap ↻ sys_write ↻ sys_openat_append

structs

none

consts

14const K4_MAGIC_8192: i64 = 8192
16const K4_OUT: *u8 = "runtime/_hdl_build/_4kpage_virt.bin"
17const K4_GOLD: *u8 = "runtime/_hdl_build/_4kpage_virt.bin.gold"
18const K4_LOG: *u8 = "knowledge/status/paging.log"
20const K4_UART: i64 = 0x10000000
21const K4_FIN: i64 = 0x100000
22const K4_PASS: i64 = 0x5555
23const K4_MEM_BASE: i64 = 0x80000000
24const K4_CSR_SATP: i64 = 0x180
25const K4_CSR_MSTATUS: i64 = 0x300
26const K4_CSR_MEPC: i64 = 0x341
27const K4_MRET: i64 = 0x30200073
28const K4_MPP_S: i64 = 0x800
30const RV_X0: i64 = 0
31const RV_T0: i64 = 5
32const RV_T1: i64 = 6
33const RV_T2: i64 = 7
34const RV_T3: i64 = 28
35const RV_T4: i64 = 29
36const RV_T5: i64 = 30
38const K4_ROOT: i64 = 0x80001000 // root table (ppn 0x80001)
39const K4_L1: i64 = 0x80002000 // level-1 table
40const K4_L0: i64 = 0x80003000 // level-0 table
41const K4_DATA: i64 = 0x80004000 // 4KB data page (the leaf target)
42const K4_SENT_VAL: i64 = 0x5ECA1234
43const K4_VA: i64 = 0xC0009000 // VPN2=3, VPN1=0, VPN0=9 -> full 3-level walk
44const K4_SATP_PPN: i64 = 0x80001 // root >> 12
45const K4_SV39: i64 = 8
46const K4_CODE_PTE: i64 = 0x2000000F // root[VPN2=2] identity gigapage (V|R|W|X) for the S-mode code
47const K4_ROOT3_PTE: i64 = 0x20000801 // root[VPN2=3] non-leaf -> L1 (V, ppn 0x80002)
48const K4_L0_LEAF: i64 = 0x20001007 // L0[VPN0=9] leaf -> data (V|R|W, ppn 0x80004)

functions

50func k4_lui(rd: i64, imm20: i64) -> i64 { return ((imm20 & 0xFFFFF) << 12) | (rd << 7) | 0x37 }
51func k4_addi(rd: i64, rs1: i64, imm: i64) -> i64 { return ((imm & 0xFFF) << 20) | (rs1 << 15) | (rd << 7) | 0x13 }
52func 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
53func k4_store(rs2: i64, rs1: i64, f3: i64, imm: i64) -> i64
58func k4_branch(rs1: i64, rs2: i64, f3: i64, imm: i64) -> i64
called by 1: k4_emit_image
65func k4_jal(rd: i64, imm: i64) -> i64
called by 1: k4_emit_image
72func k4_slli(rd: i64, rs1: i64, shamt: i64) -> i64 { return ((shamt & 0x3f) << 20) | (rs1 << 15) | (1 << 12) | (rd << 7) | 0x13 }
73func 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
74func 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
75func 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
76func 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 }
77func k4_li32(buf: *u8, off: i64, rd: i64, val: i64) -> i64
85func k4_li32u(buf: *u8, off: i64, rd: i64, val: i64) -> i64
91func k4_emit_str(buf: *u8, off: i64, s: *u8, n: i64) -> i64
called by 1: k4_emit_image calls 3: k4_w32k4_addik4_store
97func 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 }
called by 1: main calls 1: sys_write
98func 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 }
called by 1: main calls 2: sys_mmapsys_write
101func k4_emit_image(buf: *u8, cont_off: i64, fail_off: i64, halt_off: i64, pos_out: *i64, l1_pte: i64) -> i64
147func k4_parse_num(s: *u8) -> i64
called by 1: main
160func main(argc: i64, argv: *i64) -> i64