code wiki / _hdl_build / nx_ad_emit.nx

nx_ad_emit.nx

buildroot/runtime/_hdl_build/nx_ad_emit.nx

10419 B183 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tooltopic ad
docsdependenciesstructsconstsfunctions

about

nx_ad_emit.nx -- ACCESSED/DIRTY bit tracking (Sv39 A/D, X-PAGE-AD-001). The demand-paging foundation: the hardware sets the leaf PTE's Accessed bit (6) on ANY access and the Dirty bit (7) on a STORE, so the OS can drive page replacement (evict un-accessed pages) + dirty write-back (flush only D=1 pages). The PTE starts A=0,D=0; an S-mode load (sets A) then store (sets D) to the page; an ecall to the M-mode kernel, which reads the leaf PTE PHYSICALLY (M-mode identity) and confirms A=1 && D=1 -> "ADOK". do_access (argv[1]) -- default 1. The gate's control passes 0 (NO access) -> A/D stay 0 -> "ADN", proving the bits are SET BY THE ACCESS, not pre-set. out-path (argv[2]). Sovereign, no gcc/.sh. license_tier: ORIGINAL

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_ad_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 ad_parse_num sys_mmap ad_emit_image ad_w32 ad_lui ad_li32u ad_li32 ad_w32 ↻ ad_lui ↻ ad_addi ad_w32 ↻ ad_slli ad_srli ad_csrrw ad_li32 ↻ ad_store ad_addi ↻ ad_slli ↻ ad_or ad_load ad_jal ad_andi ad_branch ad_emit_str ad_w32 ↻ ad_addi ↻ ad_store ↻ sys_openat_wr ad_p sys_write sys_write ↻ sys_close ad_fn sys_mmap ↻ sys_write ↻ sys_openat_append

structs

none

consts

10const AD_MAGIC_8192: i64 = 8192
12const AD_OUT: *u8 = "runtime/_hdl_build/_ad_virt.bin"
13const AD_GOLD: *u8 = "runtime/_hdl_build/_ad_virt.bin.gold"
14const AD_LOG: *u8 = "knowledge/status/paging.log"
16const AD_UART: i64 = 0x10000000
17const AD_FIN: i64 = 0x100000
18const AD_PASS: i64 = 0x5555
19const AD_MEM_BASE: i64 = 0x80000000
20const AD_CSR_SATP: i64 = 0x180
21const AD_CSR_MSTATUS: i64 = 0x300
22const AD_CSR_MTVEC: i64 = 0x305
23const AD_CSR_MEPC: i64 = 0x341
24const AD_MRET: i64 = 0x30200073
25const AD_ECALL: i64 = 0x00000073
26const AD_MPP_S: i64 = 0x800
28const RV_X0: i64 = 0
29const RV_T0: i64 = 5
30const RV_T1: i64 = 6
31const RV_T2: i64 = 7
32const RV_T3: i64 = 28
33const RV_T5: i64 = 30
35const AD_PTE_ADDR: i64 = 0x80008000
36const AD_DATA_PTE_PHYS: i64 = 0x80008018 // root[VPN2=3] -- the data leaf the handler inspects
37const AD_CODE_PTE: i64 = 0x2000000F // root[VPN2=2] identity code (V|R|W|X)
38const AD_DATA_PTE: i64 = 0x20000007 // root[VPN2=3] data gigapage (V|R|W, A=0 D=0)
39const AD_SENT_PA: i64 = 0x80009000
40const AD_SENT_VAL: i64 = 0x5ECA1234
41const AD_VA: i64 = 0xC0009000
42const AD_SATP_PPN: i64 = 0x80008
43const AD_SV39: i64 = 8

functions

45func ad_lui(rd: i64, imm20: i64) -> i64 { return ((imm20 & 0xFFFFF) << 12) | (rd << 7) | 0x37 }
46func ad_addi(rd: i64, rs1: i64, imm: i64) -> i64 { return ((imm & 0xFFF) << 20) | (rs1 << 15) | (rd << 7) | 0x13 }
47func ad_andi(rd: i64, rs1: i64, imm: i64) -> i64 { return ((imm & 0xFFF) << 20) | (rs1 << 15) | (7 << 12) | (rd << 7) | 0x13 }
called by 1: ad_emit_image
48func ad_load(rd: i64, rs1: i64, f3: i64, imm: i64) -> i64 { return ((imm & 0xFFF) << 20) | (rs1 << 15) | (f3 << 12) | (rd << 7) | 0x03 }
called by 1: ad_emit_image
49func ad_store(rs2: i64, rs1: i64, f3: i64, imm: i64) -> i64
54func ad_branch(rs1: i64, rs2: i64, f3: i64, imm: i64) -> i64
called by 1: ad_emit_image
61func ad_jal(rd: i64, imm: i64) -> i64
called by 1: ad_emit_image
68func ad_slli(rd: i64, rs1: i64, shamt: i64) -> i64 { return ((shamt & 0x3f) << 20) | (rs1 << 15) | (1 << 12) | (rd << 7) | 0x13 }
69func ad_srli(rd: i64, rs1: i64, shamt: i64) -> i64 { return ((shamt & 0x3f) << 20) | (rs1 << 15) | (5 << 12) | (rd << 7) | 0x13 }
called by 1: ad_li32u
70func ad_or(rd: i64, rs1: i64, rs2: i64) -> i64 { return (rs2 << 20) | (rs1 << 15) | (6 << 12) | (rd << 7) | 0x33 }
called by 1: ad_emit_image
71func ad_csrrw(rd: i64, csr: i64, rs1: i64) -> i64 { return ((csr & 0xfff) << 20) | (rs1 << 15) | (1 << 12) | (rd << 7) | 0x73 }
called by 1: ad_emit_image
72func ad_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 }
73func ad_li32(buf: *u8, off: i64, rd: i64, val: i64) -> i64
81func ad_li32u(buf: *u8, off: i64, rd: i64, val: i64) -> i64
87func ad_emit_str(buf: *u8, off: i64, s: *u8, n: i64) -> i64
called by 1: ad_emit_image calls 3: ad_w32ad_addiad_store
93func ad_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
94func ad_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
97func ad_emit_image(buf: *u8, cont_off: i64, handler_off: i64, adn_off: i64, halt_off: i64, pos_out: *i64, do_access: i64) -> i64
145func ad_parse_num(s: *u8) -> i64
called by 1: main
158func main(argc: i64, argv: *i64) -> i64