code wiki / _hdl_build / nx_paging.nx

nx_paging.nx

buildroot/runtime/_hdl_build/nx_paging.nx

5835 B83 linesdepth 3pulls 4 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_paging.nx -- SOVEREIGN VIRTUAL-MEMORY MODEL (deepens MEMORY-MGMT beyond the nx_alloc heap). Page table (vpn->pfn), address translation, PAGE FAULTS, a physical-frame allocator, DEMAND paging + LRU eviction, and per-page protection bits. This is the VM POLICY/data-structure. ★ NEVER-BRICK (cardinal 26): this is a MODEL only -- it does NOT touch the real hardware MMU (no CR3/TLB/ring0, no firmware/page-table writes). By construction it cannot brick anything. The real-MMU binding is a separate, guarded hardware-axis capability. T1 map + translate (hit). T2 unmapped page -> FAULT. T3 demand page-in. T4 eviction (LRU; evicted page faults). T5 teeth: write to a read-only page is DENIED (protection). expect_exit: 0 Sovereign: nx_syscalls.

dependencies 3 imports · 0 importers

nx_syscalls.nx nx_itoa_lib.nx nx_g_puts_lib.nx nx_paging.nx

imports: nx_syscalls.nxnx_itoa_lib.nxnx_g_puts_lib.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main g_puts sys_write sys_mmap vm_access vm_translate g_pn nxi_out nxi_fd sys_mmap ↻ ccz_cat_num sys_write ↻ sys_munmap ck g_puts ↻ vm_can_write sys_openat_append sys_write ↻ sys_close sys_exit

structs

none

consts

21const PS: i64 = 4096 // page size
22const NV: i64 = 16 // virtual pages
23const NF: i64 = 4 // physical frames (small -> exercises eviction)

functions

18func g_pn(v: i64) -> i64 { nxi_out(v); return 0 }
called by 1: main calls 1: nxi_out
19func ck(name: *u8, c: i64) -> i64 { if c==1 { g_puts(" PASS " as *u8) } else { g_puts(" FAIL " as *u8) } g_puts(name); g_puts("\n" as *u8); return c }
called by 1: main calls 1: g_puts
25func vm_translate(ptab: *i64, vaddr: i64) -> i64 { let vpn: i64=vaddr/PS; if ptab[vpn]>=0 { return ptab[vpn]*PS + (vaddr%PS) } return 0-1 }
called by 1: main
27func vm_access(ptab: *i64, frown: *i64, lastu: *i64, vpn: i64, clk: i64) -> i64
called by 1: main
37func vm_can_write(prot: *i64, vpn: i64) -> i64 { return (prot[vpn]>>1)&1 } // prot bit1 = write
called by 1: main
39func main() -> i64