code wiki / _hdl_build / nx_coopsched_emit.nx
nx_coopsched_emit.nx
buildroot/runtime/_hdl_build/nx_coopsched_emit.nx
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
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
| 9 | const CS_MAGIC_4096: i64 = 4096 |
| 11 | const CS_OUT: *u8 = "runtime/_hdl_build/_coopsched_virt.bin" |
| 12 | const CS_GOLD: *u8 = "runtime/_hdl_build/_coopsched_virt.bin.gold" |
| 13 | const CS_LOG: *u8 = "knowledge/status/coopsched.log" |
| 15 | const CS_UART: i64 = 0x10000000 |
| 16 | const CS_FIN: i64 = 0x100000 |
| 17 | const CS_PASS: i64 = 0x5555 |
| 18 | const CS_K: i64 = 12 // yields then halt (golden = 12 chars "ABABABABABAB") |
| 19 | const CS_MTVEC: i64 = 0x305 |
| 20 | const CS_MEPC: i64 = 0x341 |
| 21 | const CS_CH_A: i64 = 65 |
| 22 | const CS_CH_B: i64 = 66 |
| 24 | const CS_HANDLER: i64 = 32 |
| 25 | const CS_HALT: i64 = 64 |
| 26 | const CS_TASKA: i64 = 84 |
| 27 | const CS_TASKB: i64 = 100 |
| 28 | const RV_X0: i64 = 0 |
| 29 | const RV_T0: i64 = 5 |
| 30 | const RV_T1: i64 = 6 |
| 31 | const RV_T2: i64 = 7 |
| 32 | const RV_T3: i64 = 28 |
| 33 | const RV_T4: i64 = 29 |
| 34 | const RV_T5: i64 = 30 |
| 35 | const RV_T6: i64 = 31 |
functions
| 37 | func cs_lui(rd: i64, imm20: i64) -> i64 { return ((imm20 & 0xFFFFF) << 12) | (rd << 7) | 0x37 } called by 1: main |
| 38 | func cs_auipc(rd: i64, imm20: i64) -> i64 { return ((imm20 & 0xFFFFF) << 12) | (rd << 7) | 0x17 } called by 1: main |
| 39 | func cs_addi(rd: i64, rs1: i64, imm: i64) -> i64 { return ((imm & 0xFFF) << 20) | (rs1 << 15) | (rd << 7) | 0x13 } called by 1: main |
| 40 | func cs_store(rs2: i64, rs1: i64, f3: i64, imm: i64) -> i64 called by 1: main |
| 45 | func cs_branch(rs1: i64, rs2: i64, f3: i64, imm: i64) -> i64 called by 1: main |
| 52 | func cs_jal(rd: i64, imm: i64) -> i64 called by 1: main |
| 59 | func cs_csrrw(rd: i64, csr: i64, rs1: i64) -> i64 { return ((csr & 0xFFF) << 20) | (rs1 << 15) | (1 << 12) | (rd << 7) | 0x73 } called by 1: main |
| 60 | func cs_csrrs(rd: i64, csr: i64, rs1: i64) -> i64 { return ((csr & 0xFFF) << 20) | (rs1 << 15) | (2 << 12) | (rd << 7) | 0x73 } called by 1: main |
| 61 | func cs_w32(buf: *u8, off: i64, w: i64) -> i64 called by 1: main |
| 65 | func 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 } |
| 66 | func 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 } |
| 67 | func 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 } |
| 69 | func main() -> i64 |