code wiki / _hdl_build / nx_coopsched_emit.nx

nx_coopsched_emit.nx

buildroot/runtime/_hdl_build/nx_coopsched_emit.nx

7449 B121 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_coopsched_emit.nx -- COOPERATIVE (yield-syscall) SCHEDULER: the K-R1 syscall surface now DRIVES the scheduler. Two tasks each { emit marker; ecall(YIELD) }; the trap handler treats the ecall as yield -- advances mepc PAST the ecall (mepc+4, the exception convention) then ROUND-ROBINS with the csrrw-mepc-swap trick. Deterministic (one switch per yield) -> byte-exact golden "ABAB...". Distinct from the preemptive scheduler (voluntary, syscall-driven, deterministic vs timer-driven); proves syscalls + scheduler integrated. Reuses the proven encoder; NO new forms. AUTHOR=ORGAN, table-computed image + golden. Sovereign, no gcc/.sh. license_tier: ORIGINAL

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_coopsched_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 sys_mmap cs_w32 cs_auipc cs_addi cs_csrrw cs_lui cs_jal cs_branch cs_csrrs cs_store sys_openat_wr cs_p sys_write sys_write ↻ sys_close cs_fn sys_mmap ↻ sys_write ↻ sys_openat_append cs_fp sys_write ↻ sys_now_realtime_sec sys_mmap ↻ sys_clock_gettime_real

structs

none

consts

9const CS_MAGIC_4096: i64 = 4096
11const CS_OUT: *u8 = "runtime/_hdl_build/_coopsched_virt.bin"
12const CS_GOLD: *u8 = "runtime/_hdl_build/_coopsched_virt.bin.gold"
13const CS_LOG: *u8 = "knowledge/status/coopsched.log"
15const CS_UART: i64 = 0x10000000
16const CS_FIN: i64 = 0x100000
17const CS_PASS: i64 = 0x5555
18const CS_K: i64 = 12 // yields then halt (golden = 12 chars "ABABABABABAB")
19const CS_MTVEC: i64 = 0x305
20const CS_MEPC: i64 = 0x341
21const CS_CH_A: i64 = 65
22const CS_CH_B: i64 = 66
24const CS_HANDLER: i64 = 32
25const CS_HALT: i64 = 64
26const CS_TASKA: i64 = 84
27const CS_TASKB: i64 = 100
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_T4: i64 = 29
34const RV_T5: i64 = 30
35const RV_T6: i64 = 31

functions

37func cs_lui(rd: i64, imm20: i64) -> i64 { return ((imm20 & 0xFFFFF) << 12) | (rd << 7) | 0x37 }
called by 1: main
38func cs_auipc(rd: i64, imm20: i64) -> i64 { return ((imm20 & 0xFFFFF) << 12) | (rd << 7) | 0x17 }
called by 1: main
39func cs_addi(rd: i64, rs1: i64, imm: i64) -> i64 { return ((imm & 0xFFF) << 20) | (rs1 << 15) | (rd << 7) | 0x13 }
called by 1: main
40func cs_store(rs2: i64, rs1: i64, f3: i64, imm: i64) -> i64
called by 1: main
45func cs_branch(rs1: i64, rs2: i64, f3: i64, imm: i64) -> i64
called by 1: main
52func cs_jal(rd: i64, imm: i64) -> i64
called by 1: main
59func cs_csrrw(rd: i64, csr: i64, rs1: i64) -> i64 { return ((csr & 0xFFF) << 20) | (rs1 << 15) | (1 << 12) | (rd << 7) | 0x73 }
called by 1: main
60func cs_csrrs(rd: i64, csr: i64, rs1: i64) -> i64 { return ((csr & 0xFFF) << 20) | (rs1 << 15) | (2 << 12) | (rd << 7) | 0x73 }
called by 1: main
61func cs_w32(buf: *u8, off: i64, w: i64) -> i64
called by 1: main
65func cs_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
66func cs_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
67func cs_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
69func main() -> i64