code wiki / _hdl_build / nx_syscall_emit.nx

nx_syscall_emit.nx

buildroot/runtime/_hdl_build/nx_syscall_emit.nx

8863 B167 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tooltopic syscall
docsdependenciesstructsconstsfunctions

about

nx_syscall_emit.nx -- functioning SYSCALL ABI (args + dispatch + return + resume). Completes the user/kernel boundary: a U-mode program makes REAL syscalls (a0 = syscall number, a1 = argument), the M-mode kernel DISPATCHES on a0, SERVICES the call, advances mepc past the ecall, and mret's back so the user RESUMES after the call. Multiple calls prove resumption: user(U): syscall(PUTC,'A'); syscall(PUTC,'B'); syscall(EXIT) kernel(M, mtvec): if a0==EXIT(0) -> finisher (halt); else PUTC(1) -> emit a1 over UART, mepc += 4 (skip the ecall), mret -> resume the user after the call. Success transcript "AB": two PUTC syscalls were serviced AND the user resumed between them (the mepc+4 + mret return path works), then EXIT halted -- a working syscall round-trip. nx_syscall_emit -> runtime/_hdl_build/_syscall_virt.bin + .gold Sovereign, no gcc/.sh. license_tier: ORIGINAL

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_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 sc_parse_num sys_mmap sc_emit_image sc_w32 sc_lui sc_li32u sc_li32 sc_w32 ↻ sc_lui ↻ sc_addi sc_w32 ↻ sc_slli sc_srli sc_csrrw sc_li32 ↻ sc_addi ↻ sc_jal sc_branch sc_store sc_csrrs sys_openat_wr sc_p sys_write sys_write ↻ sys_close sc_fn sys_mmap ↻ sys_write ↻ sys_openat_append

structs

none

consts

14const SC_MAGIC_8192: i64 = 8192
16const SC_OUT: *u8 = "runtime/_hdl_build/_syscall_virt.bin"
17const SC_GOLD: *u8 = "runtime/_hdl_build/_syscall_virt.bin.gold"
18const SC_LOG: *u8 = "knowledge/status/priv.log"
20const SC_UART: i64 = 0x10000000
21const SC_FIN: i64 = 0x100000
22const SC_PASS: i64 = 0x5555
23const SC_MEM_BASE: i64 = 0x80000000
24const SC_CSR_MSTATUS: i64 = 0x300
25const SC_CSR_MTVEC: i64 = 0x305
26const SC_CSR_MEPC: i64 = 0x341
27const SC_MRET: i64 = 0x30200073
28const SC_ECALL: i64 = 0x00000073
29const SC_MPP_U: i64 = 0
31const RV_X0: i64 = 0
32const RV_T0: i64 = 5
33const RV_T1: i64 = 6
34const RV_T4: i64 = 29
35const RV_T5: i64 = 30
36const RV_A0: i64 = 10
37const RV_A1: i64 = 11
39const SC_CH_A: i64 = 65
40const SC_CH_B: i64 = 66

functions

42func sc_lui(rd: i64, imm20: i64) -> i64 { return ((imm20 & 0xFFFFF) << 12) | (rd << 7) | 0x37 }
43func sc_addi(rd: i64, rs1: i64, imm: i64) -> i64 { return ((imm & 0xFFF) << 20) | (rs1 << 15) | (rd << 7) | 0x13 }
44func sc_store(rs2: i64, rs1: i64, f3: i64, imm: i64) -> i64
called by 1: sc_emit_image
49func sc_branch(rs1: i64, rs2: i64, f3: i64, imm: i64) -> i64
called by 1: sc_emit_image
56func sc_jal(rd: i64, imm: i64) -> i64
called by 1: sc_emit_image
63func sc_slli(rd: i64, rs1: i64, shamt: i64) -> i64 { return ((shamt & 0x3f) << 20) | (rs1 << 15) | (1 << 12) | (rd << 7) | 0x13 }
called by 1: sc_li32u
64func sc_srli(rd: i64, rs1: i64, shamt: i64) -> i64 { return ((shamt & 0x3f) << 20) | (rs1 << 15) | (5 << 12) | (rd << 7) | 0x13 }
called by 1: sc_li32u
65func sc_csrrw(rd: i64, csr: i64, rs1: i64) -> i64 { return ((csr & 0xfff) << 20) | (rs1 << 15) | (1 << 12) | (rd << 7) | 0x73 }
called by 1: sc_emit_image
66func sc_csrrs(rd: i64, csr: i64, rs1: i64) -> i64 { return ((csr & 0xfff) << 20) | (rs1 << 15) | (2 << 12) | (rd << 7) | 0x73 }
called by 1: sc_emit_image
67func sc_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 }
68func sc_li32(buf: *u8, off: i64, rd: i64, val: i64) -> i64
76func sc_li32u(buf: *u8, off: i64, rd: i64, val: i64) -> i64
82func sc_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
83func sc_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
86func sc_emit_image(buf: *u8, user_off: i64, handler_off: i64, exit_off: i64, pos_out: *i64, advance: i64) -> i64
130func sc_parse_num(s: *u8) -> i64
called by 1: main
143func main(argc: i64, argv: *i64) -> i64