code wiki / _hdl_build / nx_ktest.nx
nx_ktest.nx source
↩ module page · 26 lines · 931 B
1// nx_ktest.nx -- R1 probe: what does nx_cc emit for a freestanding-style kernel function?
2// kpoke writes bytes to a caller-passed pointer (a "framebuffer") using only pointer stores +
3// arithmetic -- NO syscalls. This is the shape a compiled bare-metal kernel body would take
4// (draw to a framebuffer the boot stub hands it). We compile this and inspect kpoke's asm to
5// learn the calling convention + the exact x86-64 instructions nx_cc generates.
6import "nx_syscalls.nx"
7
8// the kernel-body shape: pure pointer writes, no syscalls -- write "NI" into fb, return a sum.
9func kpoke(fb: *u8, n: i64) -> i64 {
10 var i: i64 = 0
11 var sum: i64 = 0
12 while i < n {
13 fb[i] = ((78 + i) & 0xff) as u8
14 sum = sum + i
15 i = i + 1
16 }
17 return sum
18}
19
20func main(argc: i64, argv: *i64) -> i64 {
21 let b: *u8 = sys_mmap(64)
22 let s: i64 = kpoke(b, 5)
23 sys_write(1, b, 5)
24 sys_exit(0)
25 return s
26}