code wiki / _hdl_build / _seed_ncf_kinds67.nx
_seed_ncf_kinds67.nx source
↩ module page · 57 lines · 2918 B
1// _seed_ncf_kinds67.nx -- SEED self-validation for the DECLARED-SCAFFOLD pe8 field-kinds
2// 6 (KEYWORD_NUL_SPLIT) + 7 (CRC32_TRAILER), operator-authorized R3 (X-AUT-NCF-001).
3// This is a SEED PROOF, not the reader: it drives pe8_author_struct_walk2 on a generic
4// [KEYWORD_NUL_SPLIT][CRC32_TRAILER] record and asserts (a) the emitter authors it,
5// (b) the malformed-table rails REFUSE. The authored KAT (with the emitter-COMPUTED crc
6// trailer + the crc-tamper arm) is built+run green by the sovereign driver, not here.
7// It writes ZERO reader logic -- it only confirms the seed primitives are generic +
8// composable. The PNG-tEXt reader stays organ-authored (Build/gate phase). license_tier: ORIGINAL
9import "nx_pattern_emit8.nx"
10import "nx_syscalls.nx"
11
12func sd_w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
13
14func main() -> i64 {
15 // generic record: KEYWORD_NUL_SPLIT (out-slot base 2) then CRC32_TRAILER (crc start 0).
16 // No PNG/tEXt literal -- pure byte-cursor: "abc\0val" + crc32 trailer over [0..7).
17 let kinds: *i64 = sys_mmap(64) as *i64
18 let widths: *i64 = sys_mmap(64) as *i64
19 kinds[0] = 6; widths[0] = 2
20 kinds[1] = 7; widths[1] = 0
21 let a: i64 = pe8_author_struct_walk2("_pe_kw_crc" as *u8,
22 "runtime/_hdl_build/_pe_kw_crc.nx" as *u8,
23 "runtime/_hdl_build/_pe_kw_crc_test.nx" as *u8,
24 kinds, widths, 2)
25
26 // RAIL 1: kind 6 may not be the LAST field (it consumes no value otherwise) -> REFUSE
27 let r1k: *i64 = sys_mmap(64) as *i64
28 let r1w: *i64 = sys_mmap(64) as *i64
29 r1k[0] = 6; r1w[0] = 2
30 let r1: i64 = pe8_author_struct_walk2("_pe_badkw" as *u8,
31 "/tmp/_pe_badkw.nx" as *u8, "/tmp/_pe_badkw_test.nx" as *u8, r1k, r1w, 1)
32
33 // RAIL 2: kind 6 with an out-slot base < 2 (would clobber the [0]/[1] block slots) -> REFUSE
34 let r2k: *i64 = sys_mmap(64) as *i64
35 let r2w: *i64 = sys_mmap(64) as *i64
36 r2k[0] = 6; r2w[0] = 1
37 r2k[1] = 7; r2w[1] = 0
38 let r2: i64 = pe8_author_struct_walk2("_pe_badslot" as *u8,
39 "/tmp/_pe_badslot.nx" as *u8, "/tmp/_pe_badslot_test.nx" as *u8, r2k, r2w, 2)
40
41 // RAIL 3: unknown kind 8 -> REFUSE (the ceiling held)
42 let r3k: *i64 = sys_mmap(64) as *i64
43 let r3w: *i64 = sys_mmap(64) as *i64
44 r3k[0] = 8; r3w[0] = 0
45 let r3: i64 = pe8_author_struct_walk2("_pe_badk8" as *u8,
46 "/tmp/_pe_badk8.nx" as *u8, "/tmp/_pe_badk8_test.nx" as *u8, r3k, r3w, 1)
47
48 var rails: i64 = 0
49 if r1 == 0 { if r2 == 0 { if r3 == 0 { rails = 1 } } }
50 if a == 1 { if rails == 1 {
51 sd_w("SEED OK: pe8 scaffold kinds 6 KEYWORD_NUL_SPLIT + 7 CRC32_TRAILER authored _pe_kw_crc (generic, body-relative, multi-slot) -- rails REFUSE bad-table; KAT carries emitter-computed crc + crc-tamper arm\n" as *u8)
52 sys_exit(0)
53 } }
54 sd_w("SEED FAIL: scaffold author or rail broken (a=" as *u8)
55 sys_exit(1)
56 return 1
57}