code wiki / _hdl_build / nx_nishios_kernel_emit.nx

nx_nishios_kernel_emit.nx

buildroot/runtime/_hdl_build/nx_nishios_kernel_emit.nx

32051 B679 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tooltopic nishios
docsdependenciesstructsconstsfunctions

about

nx_nishios_kernel_emit.nx -- THE COMPOSED NishiOS KERNEL IMAGE (closes the boot adoption gap). THE DEFECT THIS CLOSES: the kernel lane had 26 gate-proven stage binaries (strap / paging / trap_syscall / timer_irq / coopsched / virtio ...), each a SEPARATE tiny image run in isolation -- while the image the pinned BOOTSOV runner actually boots (_boot_nishi_virt.bin) was a 72-byte, 17-step BANNER that exercised NONE of them. Capability proven in a gate but not wired at the live chokepoint IS the baseline. This emitter authors ONE image where the stages FALL THROUGH into a single real boot, so what boots is what was proven. BOOT SEQUENCE (each phase leaves a serial marker; only the last halts): 1 RESET (M) UART up, mtvec + stvec + medeleg installed -> "NISHI " 2 TRAP (M) ecall from M -> kernel trap dispatcher -> mret -> "TRAP " 3 SCHED (M) two tasks, ecall(SYS_YIELD), round-robin mepc swap -> "ABABABABABAB SCHED " 4 TIMER (M) CLINT mtimecmp armed, MIE+MTIE, MTIP preempts the spin -> "TICK " 5 PAGING (S) mret to S-mode, Sv39 root PTEs laid, satp on, VA load -> "PAGE " 6 USER (U) sret to U-mode on a U-bit gigapage, ecall delegated by medeleg to the S-mode handler, sret back, exit syscall -> "USER OK" A real dispatcher: it decodes mcause (interrupt vs exception, ecall-from-M/S/U) and a7 as the syscall number -- not a per-phase hand-installed stub. Failure of any phase prints its own distinct marker (TX / PGX / UX) instead of falling silent, so the gate can never pass vacuously. nx_nishios_kernel_emit [outpath] -> the flat rv64 image + .gold expected transcript Sovereign: syscalls only, no gcc/.sh. license_tier: ORIGINAL

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_nishios_kernel_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 nk_streq nk_p sys_write sys_exit sys_mmap nk_emit_image nk_w32 nk_lui nk_li32u nk_li32 nk_w32 ↻ nk_lui ↻ nk_addi nk_w32 ↻ nk_slli nk_srli nk_csrrw nk_li32 ↻ nk_str nk_w32 ↻ nk_addi ↻ nk_store nk_addi ↻ nk_jal nk_load nk_store ↻ nk_csrrs nk_devup nk_li32u ↻ nk_w32 ↻ nk_load ↻ nk_li32 ↻ nk_branch nk_addi ↻ nk_store ↻ nk_branch ↻ nk_slli ↻ nk_or nk_csrrc

structs

none

consts

25const NK_MAGIC_16384: i64 = 16384
27const NK_OUT: *u8 = "runtime/_hdl_build/_boot_nishi_virt.bin"
28const NK_GOLD: *u8 = "runtime/_hdl_build/_boot_nishi_virt.bin.gold"
29const NK_LOG: *u8 = "knowledge/status/boot_stub.log"
31const NK_UART: i64 = 0x10000000
32const NK_FIN: i64 = 0x100000
33const NK_PASS: i64 = 0x5555
34const NK_MEM_BASE: i64 = 0x80000000
35const NK_MTIMECMP: i64 = 0x02004000
36const NK_MTIME: i64 = 0x0200BFF8
38const NK_CSR_SSTATUS: i64 = 0x100
39const NK_CSR_STVEC: i64 = 0x105
40const NK_CSR_SEPC: i64 = 0x141
41const NK_CSR_SATP: i64 = 0x180
42const NK_CSR_MSTATUS: i64 = 0x300
43const NK_CSR_MEDELEG: i64 = 0x302
44const NK_CSR_MIE: i64 = 0x304
45const NK_CSR_MTVEC: i64 = 0x305
46const NK_CSR_MEPC: i64 = 0x341
47const NK_CSR_MCAUSE: i64 = 0x342
49const NK_MRET: i64 = 0x30200073
50const NK_SRET: i64 = 0x10200073
51const NK_ECALL: i64 = 0x00000073
53const NK_MPP_S: i64 = 0x800
54const NK_SPP_BIT: i64 = 0x100
55const NK_MIE_MTIE: i64 = 0x80
56const NK_MSTATUS_MIE: i64 = 0x08
57const NK_TICK: i64 = 0x40
58const NK_MEDELEG_U: i64 = 0x100
61const NK_PGROOT: i64 = 0x80008000
62const NK_PGPPN: i64 = 0x80008
63const NK_PTE_KERN: i64 = 0x2000000F
64const NK_PTE_DATA: i64 = 0x20000007
65const NK_PTE_USER: i64 = 0x2000001F
66const NK_SENT_PA: i64 = 0x80009000
67const NK_SENT_VAL: i64 = 0x5ECA1234
68const NK_DATA_VA: i64 = 0xC0009000
69const NK_USER_VA: i64 = 0x40000000
70const NK_SV39: i64 = 8
72const NK_SYS_YIELD: i64 = 1
73const NK_SYS_EXIT: i64 = 2
74const NK_YIELDS: i64 = 12
76const RV_X0: i64 = 0
77const RV_T0: i64 = 5
78const RV_T1: i64 = 6
79const RV_T2: i64 = 7
80const RV_S1: i64 = 9
81const RV_A7: i64 = 17
82const RV_T3: i64 = 28
83const RV_T4: i64 = 29
84const RV_T5: i64 = 30
85const RV_T6: i64 = 31
88const NK_S_MHANDLER: i64 = 0
89const NK_S_SYSCALL: i64 = 1
90const NK_S_DOYIELD: i64 = 2
91const NK_S_TIMERISR: i64 = 3
92const NK_S_TASKA: i64 = 4
93const NK_S_TASKB: i64 = 5
94const NK_S_AFTERSCHED:i64 = 6
95const NK_S_AFTERTIMER:i64 = 7
96const NK_S_SPHASE: i64 = 8
97const NK_S_SHANDLER: i64 = 9
98const NK_S_USERCODE: i64 = 10
99const NK_S_EXITOK: i64 = 11
100const NK_S_HALT: i64 = 12
101const NK_S_PGFAIL: i64 = 13
102const NK_S_TRAPBAD: i64 = 14
103const NK_S_TASKP: i64 = 15
104const NK_S_TASKQ: i64 = 16
105const NK_S_AFTERPRE: i64 = 17
106const NK_S_ONESHOT: i64 = 18
107const NK_S_PREDONE: i64 = 19
108const NK_S_PRINTQ: i64 = 20
109const NK_S_SWAP: i64 = 21
110const NK_S_BLKFAIL: i64 = 22
111const NK_S_AFTERBLK: i64 = 23
112const NK_S_NETFAIL: i64 = 24
113const NK_S_AFTERNET: i64 = 25
114const NK_S_HEAPFAIL: i64 = 26
115const NK_S_AFTERHEAP: i64 = 27
116const NK_S_N: i64 = 28
121const NK_HEAP_CELL: i64 = 0x8000D000
122const NK_HEAP_BASE: i64 = 0x8000D010
123const NK_HEAP_MAGIC: i64 = 0x5ECAFE01
124const NK_HEAP_CHUNK: i64 = 16
127const NK_VIO_BASE: i64 = 0x10001000
128const NK_VIO_MAGIC_VAL: i64 = 0x74726976
129const NK_VIO_BLK_ID: i64 = 2
130const NK_VIO_OFF_MAGIC: i64 = 0x000
131const NK_VIO_OFF_DEVICEID: i64 = 0x008
132const NK_VIO_OFF_GUESTFEAT:i64 = 0x020
133const NK_VIO_OFF_QSEL: i64 = 0x030
134const NK_VIO_OFF_QNUMMAX: i64 = 0x034
135const NK_VIO_OFF_QNUM: i64 = 0x038
136const NK_VIO_OFF_QPFN: i64 = 0x040
137const NK_VIO_OFF_STATUS: i64 = 0x070
138const NK_VIO_QNUM: i64 = 8
139const NK_VIO_RING_PFN: i64 = 0x8000A
140const NK_VIO_ST_ACK: i64 = 1
141const NK_VIO_ST_ACKDRV: i64 = 3
142const NK_VIO_ST_FEATOK: i64 = 11
143const NK_VIO_ST_DRVOK: i64 = 15
144const NK_VIO_FEAT: i64 = 0x20
146const NK_VIO_NET_BASE: i64 = 0x10002000
147const NK_VIO_NET_ID: i64 = 1
148const NK_VIO_NET_RING_PFN: i64 = 0x8000C
153const NK_CODE_LIMIT: i64 = 0x8000
155const RV_S2: i64 = 18
156const RV_S3: i64 = 19
157const NK_PREEMPTS: i64 = 6
158const NK_CH_P: i64 = 80
159const NK_CH_Q: i64 = 81

functions

161func nk_lui(rd: i64, imm20: i64) -> i64 { return ((imm20 & 0xFFFFF) << 12) | (rd << 7) | 0x37 }
162func nk_addi(rd: i64, rs1: i64, imm: i64) -> i64 { return ((imm & 0xFFF) << 20) | (rs1 << 15) | (rd << 7) | 0x13 }
163func nk_load(rd: i64, rs1: i64, f3: i64, imm: i64) -> i64 { return ((imm & 0xFFF) << 20) | (rs1 << 15) | (f3 << 12) | (rd << 7) | 0x03 }
164func nk_store(rs2: i64, rs1: i64, f3: i64, imm: i64) -> i64
169func nk_branch(rs1: i64, rs2: i64, f3: i64, imm: i64) -> i64
176func nk_jal(rd: i64, imm: i64) -> i64
called by 1: nk_emit_image
183func nk_slli(rd: i64, rs1: i64, shamt: i64) -> i64 { return ((shamt & 0x3f) << 20) | (rs1 << 15) | (1 << 12) | (rd << 7) | 0x13 }
184func nk_srli(rd: i64, rs1: i64, shamt: i64) -> i64 { return ((shamt & 0x3f) << 20) | (rs1 << 15) | (5 << 12) | (rd << 7) | 0x13 }
called by 1: nk_li32u
185func nk_or(rd: i64, rs1: i64, rs2: i64) -> i64 { return (rs2 << 20) | (rs1 << 15) | (6 << 12) | (rd << 7) | 0x33 }
called by 1: nk_emit_image
186func nk_csrrw(rd: i64, csr: i64, rs1: i64) -> i64 { return ((csr & 0xfff) << 20) | (rs1 << 15) | (1 << 12) | (rd << 7) | 0x73 }
called by 1: nk_emit_image
187func nk_csrrs(rd: i64, csr: i64, rs1: i64) -> i64 { return ((csr & 0xfff) << 20) | (rs1 << 15) | (2 << 12) | (rd << 7) | 0x73 }
called by 1: nk_emit_image
188func nk_csrrc(rd: i64, csr: i64, rs1: i64) -> i64 { return ((csr & 0xfff) << 20) | (rs1 << 15) | (3 << 12) | (rd << 7) | 0x73 }
called by 1: nk_emit_image
190func nk_w32(buf: *u8, off: i64, w: i64) -> i64
195func nk_li32(buf: *u8, off: i64, rd: i64, val: i64) -> i64
204func nk_li32u(buf: *u8, off: i64, rd: i64, val: i64) -> i64
211func nk_str(buf: *u8, off: i64, s: *u8) -> i64
called by 1: nk_emit_image calls 3: nk_w32nk_addink_store
222func nk_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
223func nk_fp(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 }
called by 1: main calls 1: sys_write
224func nk_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
231func nk_devup(buf: *u8, off: i64, base: i64, devid: i64, pfn: i64, failoff: i64) -> i64
276func nk_emit_image(buf: *u8, tgt: *i64, pos: *i64, medeleg: i64, data_pte: i64, vio_base: i64, heap_cell: i64) -> i64
564func nk_streq(a: *u8, b: *u8) -> i64
called by 1: main
571func main(argc: i64, argv: *i64) -> i64