code wiki / _hdl_build / nx_nishios_kernel_emit.nx
nx_nishios_kernel_emit.nx
buildroot/runtime/_hdl_build/nx_nishios_kernel_emit.nx
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
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
structs
| none |
consts
| 25 | const NK_MAGIC_16384: i64 = 16384 |
| 27 | const NK_OUT: *u8 = "runtime/_hdl_build/_boot_nishi_virt.bin" |
| 28 | const NK_GOLD: *u8 = "runtime/_hdl_build/_boot_nishi_virt.bin.gold" |
| 29 | const NK_LOG: *u8 = "knowledge/status/boot_stub.log" |
| 31 | const NK_UART: i64 = 0x10000000 |
| 32 | const NK_FIN: i64 = 0x100000 |
| 33 | const NK_PASS: i64 = 0x5555 |
| 34 | const NK_MEM_BASE: i64 = 0x80000000 |
| 35 | const NK_MTIMECMP: i64 = 0x02004000 |
| 36 | const NK_MTIME: i64 = 0x0200BFF8 |
| 38 | const NK_CSR_SSTATUS: i64 = 0x100 |
| 39 | const NK_CSR_STVEC: i64 = 0x105 |
| 40 | const NK_CSR_SEPC: i64 = 0x141 |
| 41 | const NK_CSR_SATP: i64 = 0x180 |
| 42 | const NK_CSR_MSTATUS: i64 = 0x300 |
| 43 | const NK_CSR_MEDELEG: i64 = 0x302 |
| 44 | const NK_CSR_MIE: i64 = 0x304 |
| 45 | const NK_CSR_MTVEC: i64 = 0x305 |
| 46 | const NK_CSR_MEPC: i64 = 0x341 |
| 47 | const NK_CSR_MCAUSE: i64 = 0x342 |
| 49 | const NK_MRET: i64 = 0x30200073 |
| 50 | const NK_SRET: i64 = 0x10200073 |
| 51 | const NK_ECALL: i64 = 0x00000073 |
| 53 | const NK_MPP_S: i64 = 0x800 |
| 54 | const NK_SPP_BIT: i64 = 0x100 |
| 55 | const NK_MIE_MTIE: i64 = 0x80 |
| 56 | const NK_MSTATUS_MIE: i64 = 0x08 |
| 57 | const NK_TICK: i64 = 0x40 |
| 58 | const NK_MEDELEG_U: i64 = 0x100 |
| 61 | const NK_PGROOT: i64 = 0x80008000 |
| 62 | const NK_PGPPN: i64 = 0x80008 |
| 63 | const NK_PTE_KERN: i64 = 0x2000000F |
| 64 | const NK_PTE_DATA: i64 = 0x20000007 |
| 65 | const NK_PTE_USER: i64 = 0x2000001F |
| 66 | const NK_SENT_PA: i64 = 0x80009000 |
| 67 | const NK_SENT_VAL: i64 = 0x5ECA1234 |
| 68 | const NK_DATA_VA: i64 = 0xC0009000 |
| 69 | const NK_USER_VA: i64 = 0x40000000 |
| 70 | const NK_SV39: i64 = 8 |
| 72 | const NK_SYS_YIELD: i64 = 1 |
| 73 | const NK_SYS_EXIT: i64 = 2 |
| 74 | const NK_YIELDS: i64 = 12 |
| 76 | const RV_X0: i64 = 0 |
| 77 | const RV_T0: i64 = 5 |
| 78 | const RV_T1: i64 = 6 |
| 79 | const RV_T2: i64 = 7 |
| 80 | const RV_S1: i64 = 9 |
| 81 | const RV_A7: i64 = 17 |
| 82 | const RV_T3: i64 = 28 |
| 83 | const RV_T4: i64 = 29 |
| 84 | const RV_T5: i64 = 30 |
| 85 | const RV_T6: i64 = 31 |
| 88 | const NK_S_MHANDLER: i64 = 0 |
| 89 | const NK_S_SYSCALL: i64 = 1 |
| 90 | const NK_S_DOYIELD: i64 = 2 |
| 91 | const NK_S_TIMERISR: i64 = 3 |
| 92 | const NK_S_TASKA: i64 = 4 |
| 93 | const NK_S_TASKB: i64 = 5 |
| 94 | const NK_S_AFTERSCHED:i64 = 6 |
| 95 | const NK_S_AFTERTIMER:i64 = 7 |
| 96 | const NK_S_SPHASE: i64 = 8 |
| 97 | const NK_S_SHANDLER: i64 = 9 |
| 98 | const NK_S_USERCODE: i64 = 10 |
| 99 | const NK_S_EXITOK: i64 = 11 |
| 100 | const NK_S_HALT: i64 = 12 |
| 101 | const NK_S_PGFAIL: i64 = 13 |
| 102 | const NK_S_TRAPBAD: i64 = 14 |
| 103 | const NK_S_TASKP: i64 = 15 |
| 104 | const NK_S_TASKQ: i64 = 16 |
| 105 | const NK_S_AFTERPRE: i64 = 17 |
| 106 | const NK_S_ONESHOT: i64 = 18 |
| 107 | const NK_S_PREDONE: i64 = 19 |
| 108 | const NK_S_PRINTQ: i64 = 20 |
| 109 | const NK_S_SWAP: i64 = 21 |
| 110 | const NK_S_BLKFAIL: i64 = 22 |
| 111 | const NK_S_AFTERBLK: i64 = 23 |
| 112 | const NK_S_NETFAIL: i64 = 24 |
| 113 | const NK_S_AFTERNET: i64 = 25 |
| 114 | const NK_S_HEAPFAIL: i64 = 26 |
| 115 | const NK_S_AFTERHEAP: i64 = 27 |
| 116 | const NK_S_N: i64 = 28 |
| 121 | const NK_HEAP_CELL: i64 = 0x8000D000 |
| 122 | const NK_HEAP_BASE: i64 = 0x8000D010 |
| 123 | const NK_HEAP_MAGIC: i64 = 0x5ECAFE01 |
| 124 | const NK_HEAP_CHUNK: i64 = 16 |
| 127 | const NK_VIO_BASE: i64 = 0x10001000 |
| 128 | const NK_VIO_MAGIC_VAL: i64 = 0x74726976 |
| 129 | const NK_VIO_BLK_ID: i64 = 2 |
| 130 | const NK_VIO_OFF_MAGIC: i64 = 0x000 |
| 131 | const NK_VIO_OFF_DEVICEID: i64 = 0x008 |
| 132 | const NK_VIO_OFF_GUESTFEAT:i64 = 0x020 |
| 133 | const NK_VIO_OFF_QSEL: i64 = 0x030 |
| 134 | const NK_VIO_OFF_QNUMMAX: i64 = 0x034 |
| 135 | const NK_VIO_OFF_QNUM: i64 = 0x038 |
| 136 | const NK_VIO_OFF_QPFN: i64 = 0x040 |
| 137 | const NK_VIO_OFF_STATUS: i64 = 0x070 |
| 138 | const NK_VIO_QNUM: i64 = 8 |
| 139 | const NK_VIO_RING_PFN: i64 = 0x8000A |
| 140 | const NK_VIO_ST_ACK: i64 = 1 |
| 141 | const NK_VIO_ST_ACKDRV: i64 = 3 |
| 142 | const NK_VIO_ST_FEATOK: i64 = 11 |
| 143 | const NK_VIO_ST_DRVOK: i64 = 15 |
| 144 | const NK_VIO_FEAT: i64 = 0x20 |
| 146 | const NK_VIO_NET_BASE: i64 = 0x10002000 |
| 147 | const NK_VIO_NET_ID: i64 = 1 |
| 148 | const NK_VIO_NET_RING_PFN: i64 = 0x8000C |
| 153 | const NK_CODE_LIMIT: i64 = 0x8000 |
| 155 | const RV_S2: i64 = 18 |
| 156 | const RV_S3: i64 = 19 |
| 157 | const NK_PREEMPTS: i64 = 6 |
| 158 | const NK_CH_P: i64 = 80 |
| 159 | const NK_CH_Q: i64 = 81 |
functions
| 161 | func nk_lui(rd: i64, imm20: i64) -> i64 { return ((imm20 & 0xFFFFF) << 12) | (rd << 7) | 0x37 } |
| 162 | func nk_addi(rd: i64, rs1: i64, imm: i64) -> i64 { return ((imm & 0xFFF) << 20) | (rs1 << 15) | (rd << 7) | 0x13 } |
| 163 | func nk_load(rd: i64, rs1: i64, f3: i64, imm: i64) -> i64 { return ((imm & 0xFFF) << 20) | (rs1 << 15) | (f3 << 12) | (rd << 7) | 0x03 } |
| 164 | func nk_store(rs2: i64, rs1: i64, f3: i64, imm: i64) -> i64 |
| 169 | func nk_branch(rs1: i64, rs2: i64, f3: i64, imm: i64) -> i64 |
| 176 | func nk_jal(rd: i64, imm: i64) -> i64 called by 1: nk_emit_image |
| 183 | func nk_slli(rd: i64, rs1: i64, shamt: i64) -> i64 { return ((shamt & 0x3f) << 20) | (rs1 << 15) | (1 << 12) | (rd << 7) | 0x13 } |
| 184 | func 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 |
| 185 | func 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 |
| 186 | func 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 |
| 187 | func 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 |
| 188 | func 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 |
| 190 | func nk_w32(buf: *u8, off: i64, w: i64) -> i64 |
| 195 | func nk_li32(buf: *u8, off: i64, rd: i64, val: i64) -> i64 |
| 204 | func nk_li32u(buf: *u8, off: i64, rd: i64, val: i64) -> i64 |
| 211 | func nk_str(buf: *u8, off: i64, s: *u8) -> i64 |
| 222 | func 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 } |
| 223 | func 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 } |
| 224 | func 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 } |
| 231 | func nk_devup(buf: *u8, off: i64, base: i64, devid: i64, pfn: i64, failoff: i64) -> i64 |
| 276 | func nk_emit_image(buf: *u8, tgt: *i64, pos: *i64, medeleg: i64, data_pte: i64, vio_base: i64, heap_cell: i64) -> i64 |
| 564 | func nk_streq(a: *u8, b: *u8) -> i64 called by 1: main |
| 571 | func main(argc: i64, argv: *i64) -> i64 |