code wiki / _hdl_build / nx_nishi_usb_paging.nx

nx_nishi_usb_paging.nx

buildroot/runtime/_hdl_build/nx_nishi_usb_paging.nx

16100 B271 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind tooltopic nishi
docsdependenciesstructsconstsfunctions

about

nx_nishi_usb_paging.nx -- x86 ladder R-KERN-2: the long-mode kernel sets up PAGING (CR3 + 4-level walk). Second OS-internals rung at the long-mode entry. The kernel LOADED OFF the persisted image, after it reaches long mode, BUILDS a 4-level page-table tree IN MEMORY with its own x86 stores (PML4 -> PDPT -> PD -> PT), loads CR3 with `mov cr3, rax`, and HLTs. The emu then performs the long-mode 4-level page walk (VA[47:39]->PML4, [38:30]->PDPT, [29:21]->PD, [20:12]->PT, +[11:0] offset; bit0=present) over the tables the kernel built, and reports the translations -- proving the kernel's page tables are real and walkable. pg_walk is reused verbatim from the proven nx_emu_x86_paging_test (the x86 twin of our rv64 SV39 MMU); the unified emu is extended with `mov cr3` (0F 22 /3). KAT: (T1) booted off disk; (T2) LONG mode; (T3) CR3 loaded with the kernel's PML4 base; (T4) VA 0x1000 translates to PA 0x40000 through the kernel-built tables; (T5) offset preserved (0x1123->0x40123); (T6) a second mapping (0x2000->0x50000); (T7) an unmapped VA faults. NEG/liar-kill (T8): a sibling image whose CR3 is loaded with a WRONG base translates nothing -- so the translations depend on the kernel having built the tables AND loaded the right CR3, not on a constant. HONEST SCOPE: 4KB pages + present bit; long mode is modeled flat so the emu walks the kernel's tables on demand but does not yet route every instruction fetch through the TLB (large pages / A-D bits / permission faults / full MMU routing = refinements). NEVER-BRICK (Rule 26): writes a FILE; INT 13h *reads* only; no /dev. expect_exit: 0 license_tier: ORIGINAL

dependencies 2 imports · 0 importers

nx_syscalls.nx nx_itoa_lib.nx nx_nishi_usb_paging.nx

imports: nx_syscalls.nxnx_itoa_lib.nx

imported by: nobody (leaf or entry point)

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

main pg_puts sys_write sys_mmap build_image uf_movr emit_pte uf_movr ↻ sys_openat_wr sys_exit sys_write ↻ sys_close pg_read sys_openat_rd sys_read sys_close ↻ boot_image sys_mmap ↻ emu_x86_boot_page sys_mmap ↻ pg_mode pg_walk pg_rd pg_st64 pg_num nxi_out nxi_fd sys_mmap ↻ ccz_cat_num sys_write ↻ sys_munmap

structs

none

consts

23const IMG_MAGIC_2000000: i64 = 2000000
24const IMG_MAGIC_32767: i64 = 32767
25const IMG_MAGIC_65536: i64 = 65536
129const IMG_SZ: i64 = 1024

functions

27func pg_puts(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
32func pg_num(v: i64) -> i64 { nxi_out(v); return 0 }
called by 1: main calls 1: nxi_out
33func pg_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 }
called by 1: emu_x86_boot_page
34func pg_st64(mem: *u8, a: i64, v: i64) -> i64 { var i: i64=0; while i<8 { mem[a+i]=((v>>(i*8))&0xff) as u8; i=i+1 } return 0 }
called by 1: emu_x86_boot_page
35func pg_rd(mem: *u8, a: i64) -> i64 { var v: i64=0; var i: i64=0; while i<8 { v=v|((mem[a+i] as i64)<<(i*8)); i=i+1 } return v }
called by 1: pg_walk
38func pg_walk(mem: *u8, cr3: i64, va: i64) -> i64
called by 1: emu_x86_boot_page calls 1: pg_rd
60func emu_x86_boot_page(mem: *u8, disk: *u8, entry: i64, console: *u8, clen: *i64, st: *i64) -> i64
131func uf_movr(img: *u8, base: i64, o: i64, modrm: i64, imm: i64) -> i64
called by 2: emit_ptebuild_image
138func emit_pte(img: *u8, base: i64, o: i64, val: i64, addr: i64) -> i64
called by 1: build_image calls 1: uf_movr
147func build_image(img: *u8, info: *i64) -> i64
called by 1: main calls 2: uf_movremit_pte
201func boot_image(img: *u8, console: *u8, clen: *i64, st: *i64, loaded: *i64) -> i64
called by 1: main calls 2: sys_mmapemu_x86_boot_page
214func pg_read(path: *u8, out: *u8, cap: i64) -> i64
called by 1: main calls 3: sys_openat_rdsys_readsys_close
223func main() -> i64