code wiki / _hdl_build / nx_spore_syscalls.nx
nx_spore_syscalls.nx source
↩ module page · 56 lines · 1989 B
1// nx_spore_syscalls.nx -- the SPORE's minimal syscall surface.
2//
3// The full nx_syscalls.nx carries ~40 wrappers (socket/connect/sendto/execve/
4// fork/getdents/clock...) -- everything the MATURE system eventually needs. The
5// SPORE needs only the six to verify a piece and measure itself, and a NishiLang
6// build links the whole imported module (no dead-code elimination yet), so a
7// spore that imported the full surface dragged ~6 KB of wrappers it never calls.
8//
9// This is the architecturally-correct bootstrap: the spore carries the SMALLEST
10// syscall surface that lets it (a) read bytes, (b) verify them, (c) know its own
11// footprint. The richer surface (networking, processes, dirs) arrives as later
12// SEED pieces, germinated through the same trust gate. Additive: this does NOT
13// modify the protected shared nx_syscalls.nx.
14//
15// Dual-target (RV64 default / x86_64 under --target) preserved exactly.
16
17@ifdef TARGET_X86_64
18const SYS_WRITE: i64 = 1
19const SYS_CLOSE: i64 = 3
20const SYS_LSEEK: i64 = 8
21const SYS_OPENAT: i64 = 257
22const SYS_EXIT: i64 = 60
23const SYS_MMAP: i64 = 9
24@endif
25
26@ifndef TARGET_X86_64
27const SYS_WRITE: i64 = 64
28const SYS_CLOSE: i64 = 57
29const SYS_LSEEK: i64 = 62
30const SYS_OPENAT: i64 = 56
31const SYS_EXIT: i64 = 93
32const SYS_MMAP: i64 = 222
33@endif
34
35const AT_FDCWD: i64 = -100
36const O_RDONLY: i64 = 0
37
38func sys_write(fd: i64, buf: *u8, count: i64) -> i64 {
39 return __syscall(SYS_WRITE, fd, buf, count, 0, 0, 0)
40}
41func sys_close(fd: i64) -> i64 {
42 return __syscall(SYS_CLOSE, fd, 0, 0, 0, 0, 0)
43}
44func sys_lseek(fd: i64, offset: i64, whence: i64) -> i64 {
45 return __syscall(SYS_LSEEK, fd, offset, whence, 0, 0, 0)
46}
47func sys_exit(code: i64) -> i64 {
48 return __syscall(SYS_EXIT, code, 0, 0, 0, 0, 0)
49}
50func sys_mmap(size: i64) -> *u8 {
51 let r: i64 = __syscall(SYS_MMAP, 0, size, 3, 0x22, -1, 0)
52 return r as *u8
53}
54func sys_openat_rd(path: *u8) -> i64 {
55 return __syscall(SYS_OPENAT, AT_FDCWD, path, O_RDONLY, 0, 0, 0)
56}