code wiki / (root) / nx_arm64_e2e_test.nx

nx_arm64_e2e_test.nx source

↩ module page · 38 lines · 1695 B

1// nx_arm64_e2e_test.nx -- aarch64 end-to-end: the sovereign ENCODER 2// builds real A64 programs and the sovereign EMULATOR runs them. Both 3// are built independently from the ARM A64 spec; their agreement on the 4// result cross-validates both (the spec is the oracle). No qemu. 5// 6// expect_exit: 0 7// license_tier: ORIGINAL 8 9import "nxasm_arm64_enc.nx" 10import "nx_emu_arm64.nx" 11import "nx_syscalls_x86_64.nx" 12 13func main() -> i64 { 14 // Program 1: exit(42) 15 let p1: *u8 = sys_mmap(64) 16 var c: i64 = a64_mov_imm64(p1, 0, 0, 42) // x0 = 42 17 c = a64_mov_imm64(p1, c, 8, 93) // x8 = 93 (exit) 18 c = a64_put_u32le(p1, c, a64_enc_svc0()) // svc #0 19 let r1: i64 = emu_arm64_run(p1, c) 20 if r1 != 42 { return 1 } 21 22 // Program 2: sum 0..8 = 36 via a cmp/b.ne loop 23 let p2: *u8 = sys_mmap(64) 24 var o: i64 = 0 25 o = a64_put_u32le(p2, o, a64_enc_movz(1, 0, 0, 0)) // x0 = 0 26 o = a64_put_u32le(p2, o, a64_enc_movz(1, 1, 0, 0)) // x1 = 0 27 o = a64_put_u32le(p2, o, a64_enc_movz(1, 2, 9, 0)) // x2 = 9 28 o = a64_put_u32le(p2, o, a64_enc_add_shifted(1, 0, 0, 1, 0, 0)) // loop: add x0,x0,x1 29 o = a64_put_u32le(p2, o, a64_enc_add_imm(1, 1, 1, 1, 0)) // add x1,x1,#1 30 o = a64_put_u32le(p2, o, a64_enc_cmp_reg(1, 1, 2)) // cmp x1,x2 31 o = a64_put_u32le(p2, o, a64_enc_bcond(1, 0 - 12)) // b.ne loop 32 o = a64_put_u32le(p2, o, a64_enc_movz(1, 8, 93, 0)) // x8 = 93 33 o = a64_put_u32le(p2, o, a64_enc_svc0()) // svc #0 34 let r2: i64 = emu_arm64_run(p2, o) 35 if r2 != 36 { return 2 } 36 37 return 0 38}