code wiki / _hdl_build / nx_trap_syscall_emit.nx

nx_trap_syscall_emit.nx

buildroot/runtime/_hdl_build/nx_trap_syscall_emit.nx

16551 B356 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_trap_syscall_emit.nx -- the TRAP+SYSCALL emitter (K-R1 of the kernel-up ladder). A NEW kernel syscall surface IS A SPEC FILE: reads (banner, 8x `sys <name> <a7> <emit>`, out) DATA and AUTHORS a bare-metal rv64 flat image for qemu-virt whose trap vector dispatches an 8-syscall mini-surface. The trap dispatch IS a STATE_MACHINE (shape 18 / pe13) instance: read a7, branch to the matching per-syscall handler row, emit that syscall's transcript byte to the UART, advance mepc+4, mret. exit (a7=93) writes the SiFive finisher = clean halt. Zero hand-written machine code per surface; the emitter is a tiny rv64 encoder (the few forms a trap surface needs: auipc/lui/addi/sb/sw + B-type branch + jal + csrrw/csrrs + ecall + mret) and the IMAGE + the GOLDEN transcript are TABLE-COMPUTED from the spec, byte-reproducibly. nx_trap_syscall_emit <specpath> -> writes the flat image to the spec's `out` and the table-computed golden transcript to <out>.golden VERDICT log -> knowledge/status/trap_syscall.log (TRAPEMIT rows, the gate's evidence). Sovereign: syscalls only, no gcc/.sh. license_tier: ORIGINAL

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_trap_syscall_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 ts_p sys_write sys_exit sys_mmap nxa_die sys_write ↻ sys_exit ↻ nxa_lock_take nxa_lock_addr sys_write ↻ nxa_lock_give nxa_lock_addr ↻ nxa_report_overrun sys_write ↻ nxa_dump_printable sys_write ↻ nxa_dump_sizes sys_write ↻ sys_read_file sys_openat_rd sys_lseek sys_mmap ↻ sys_read sys_munmap sys_close ts_log sys_openat_append ts_fp sys_write ↻ ts_fn sys_mmap ↻ sys_write ↻ sys_close ↻ ts_field ts_parse_sys ts_skip_sp ts_skip_tok ts_fn ↻ ts_emit_image

structs

none

consts

16const TS_MAGIC_8192: i64 = 8192
19const TS_UART: i64 = 0x10000000 // NS16550A THR (write a byte = transmit)
20const TS_FIN: i64 = 0x100000 // SiFive test finisher (write to exit)
21const TS_PASS: i64 = 0x5555 // FINISHER_PASS low half -> clean halt
23const TS_MTVEC: i64 = 0x305
24const TS_MEPC: i64 = 0x341
26const RV_X0: i64 = 0
27const RV_T0: i64 = 5
28const RV_T1: i64 = 6
29const RV_T2: i64 = 7
30const RV_A7: i64 = 17
31const RV_T3: i64 = 28
32const RV_T4: i64 = 29
34const TS_NSYS: i64 = 8

functions

36func ts_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
37func ts_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: ts_log calls 1: sys_write
38func ts_fn(fd: i64, v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(fd,"-" as *u8,1)}; 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 2: ts_logmain calls 2: sys_mmapsys_write
41func ts_lui(rd: i64, imm20: i64) -> i64 { return ((imm20 & 0xFFFFF) << 12) | (rd << 7) | 0x37 }
42func ts_auipc(rd: i64, imm20: i64) -> i64 { return ((imm20 & 0xFFFFF) << 12) | (rd << 7) | 0x17 }
called by 1: ts_emit_boot
43func ts_addi(rd: i64, rs1: i64, imm: i64) -> i64 { return ((imm & 0xFFF) << 20) | (rs1 << 15) | (rd << 7) | 0x13 }
45func ts_store(rs2: i64, rs1: i64, f3: i64, imm: i64) -> i64
51func ts_branch(rs1: i64, rs2: i64, f3: i64, imm: i64) -> i64
called by 1: ts_emit_dispatch
59func ts_jal(rd: i64, imm: i64) -> i64
67func ts_csrrw(rd: i64, csr: i64, rs1: i64) -> i64 { return ((csr & 0xFFF) << 20) | (rs1 << 15) | (1 << 12) | (rd << 7) | 0x73 }
68func ts_csrrs(rd: i64, csr: i64, rs1: i64) -> i64 { return ((csr & 0xFFF) << 20) | (rs1 << 15) | (2 << 12) | (rd << 7) | 0x73 }
called by 1: ts_emit_ret
70func ts_w32(buf: *u8, off: i64, w: i64) -> i64
84func ts_trap_entry_byte(blen: i64) -> i64
89func ts_handler0_byte(blen: i64) -> i64
94func ts_handler_byte(blen: i64, idx: i64) -> i64
called by 1: ts_emit_dispatch calls 1: ts_handler0_byte
98func ts_trap_ret_byte(blen: i64) -> i64
105func ts_emit_boot(buf: *u8, off: i64, banner: *u8, blen: i64) -> i64
123func ts_emit_driver(buf: *u8, off: i64, nums: *i64) -> i64
called by 1: ts_emit_image calls 3: ts_w32ts_addits_jal
136func ts_emit_dispatch(buf: *u8, off: i64, nums: *i64, blen: i64) -> i64
154func ts_emit_handler(buf: *u8, off: i64, ch: i64, blen: i64) -> i64
164func ts_emit_exit(buf: *u8, off: i64, ch: i64) -> i64
180func ts_emit_ret(buf: *u8, off: i64) -> i64
190func ts_emit_image(buf: *u8, banner: *u8, blen: i64, nums: *i64, emits: *u8) -> i64
209func ts_field(buf: *u8, ls: i64, le: i64, key: *u8, out: *u8) -> i64
called by 1: main
224func ts_skip_tok(buf: *u8, p: i64, le: i64) -> i64
called by 1: ts_parse_sys
231func ts_skip_sp(buf: *u8, p: i64, le: i64) -> i64
called by 1: ts_parse_sys
239func ts_parse_sys(buf: *u8, ls: i64, le: i64, outnum: *i64, outemit: *u8) -> i64
called by 1: main calls 2: ts_skip_spts_skip_tok
266func ts_log(name: *u8, bytes: i64, golden: *u8, verdict: *u8) -> i64
278func main(argc: i64, argv: *i64) -> i64