nx_smoke_objdump.nx source
↩ module page · 62 lines · 2561 B
1// nx_smoke_objdump.nx -- write -> read round-trip smoke test.
2//
3// Hand-builds an ELF (header + 1 PT_LOAD + 12 bytes of code), then
4// inspects it via our sovereign nx_elf_read + nx_objdump tools.
5// Verifies that what elf_writer-shape bytes look like, our reader
6// correctly decodes -- the producer/consumer loop is round-trip
7// clean entirely in NishiLang.
8//
9// No docker / qemu / binutils dependency. Run on any host with
10// our nxc2.exe.
11
12// nx_safety_envelope:
13// intended_use: AUTO_APPLIED -- primitive-specific tuning queued
14// sil_target: SIL1
15// evidence: [bulk_applied_2026-05-16, see-file-comment-for-detail]
16// verdict: NOT_YET_EVALUATED
17
18import "syscalls.nx"
19import "nx_elf_read.nx"
20import "nx_objdump.nx"
21
22func main() -> i64 {
23 // Build the same shape elf_writer produces for an exit-42 prog.
24 let elf: *u8 = sys_mmap(256)
25 var i: i64 = 0
26 while i < 256 { elf[i] = 0; i = i + 1 }
27
28 // ELF header (64 bytes).
29 elf[0] = 0x7F; elf[1] = 0x45; elf[2] = 0x4C; elf[3] = 0x46
30 elf[4] = 2; elf[5] = 1; elf[6] = 1
31 elf[16] = 2; elf[18] = 0xF3
32 elf[24] = 0x78; elf[25] = 0x00; elf[26] = 0x01; elf[27] = 0x00
33 elf[32] = 64
34 elf[52] = 64; elf[54] = 56; elf[56] = 1
35
36 // PT_LOAD program header.
37 elf[64] = 1; elf[68] = 5
38 elf[72] = 120
39 elf[80] = 0x00; elf[81] = 0x00; elf[82] = 0x01; elf[83] = 0x00
40 elf[96] = 12; elf[104] = 12
41
42 // Code: addi a0,zero,42; addi a7,zero,93; ecall.
43 elf[120] = 0x13; elf[121] = 0x05; elf[122] = 0xA0; elf[123] = 0x02
44 elf[124] = 0x93; elf[125] = 0x08; elf[126] = 0xD0; elf[127] = 0x05
45 elf[128] = 0x73; elf[129] = 0x00; elf[130] = 0x00; elf[131] = 0x00
46
47 // PHASE 1: the parser sees a valid header.
48 let h: *NxElfHeader = nx_elf_parse_header(elf, 132)
49 if h.valid != 1 { sys_write(2, "fail: invalid header\n" as *u8, 21); return 1 }
50 if h.is_64bit != 1 { sys_write(2, "fail: not 64-bit\n" as *u8, 17); return 2 }
51 if h.is_little != 1 { sys_write(2, "fail: not LE\n" as *u8, 13); return 3 }
52 if h.e_machine != 0xF3 { sys_write(2, "fail: not RISC-V\n" as *u8, 17); return 4 }
53 if h.e_entry != 0x10078 { sys_write(2, "fail: wrong entry\n" as *u8, 18); return 5 }
54 if h.e_phnum != 1 { sys_write(2, "fail: wrong phnum\n" as *u8, 18); return 6 }
55
56 // PHASE 2: print header to stdout via the sovereign objdump.
57 sys_write(2, "smoke_objdump: header dump:\n" as *u8, 28)
58 nx_objdump_elf_header(elf, 132, 2)
59
60 sys_write(2, "smoke_objdump: write/read round-trip OK\n" as *u8, 40)
61 return 0
62}