nx_hal.nx
buildroot/runtime/nx_hal.nx
about
nx_hal.nx -- substrate Hardware Abstraction Layer.
Cardinal 2026-05-21 ("bits up eliminate and for the rest we want to
be hardware agnostic as in the future nishi silicon will run all
of this"): every substrate primitive above this layer expresses
hardware-level operations in HAL terms, NOT Linux-syscall terms.
The HAL is the substrate-defined contract that ANY backing
implementation (Linux today, bare-metal Nishi kernel tomorrow,
future Nishi silicon eventually) must provide.
Substrate's bottom-up sovereignty story:
- Top of stack: Elder AI services + UI -- can run on whatever OS
the substrate currently runs on (Win-native + bash-launched
today; future substrate-hosted on a NishiLang container)
- Middle: substrate primitives (HAL clients) -- hardware-agnostic;
compile + run unchanged on any HAL implementation
- Bottom: HAL implementation (per-target shim) -- the thin
adapter that turns hardware-level HAL ops into actual machine
behavior. Today: Linux syscall ABI. Tomorrow: bare-metal
MMIO + page-table walks. Eventually: future Nishi silicon.
The win: as we eliminate third parties layer by layer (Docker,
Linux, Win32, NVIDIA), the substrate primitives DO NOT CHANGE.
Only the HAL shim changes. The investment in shipped substrate
is preserved.
V1 operations (the hardware-level concepts any silicon must
provide; bare-metal Nishi kernel + future Nishi silicon both
implement these):
nx_hal_clock_now_ns monotonic nanosecond timestamp
nx_hal_alloc_pages contiguous page allocation
nx_hal_release_pages return pages to substrate
nx_hal_console_write debug-channel byte output
nx_hal_random_bytes hardware-quality entropy
nx_hal_yield cooperative scheduling hint
nx_hal_exit process termination
nx_hal_spawn fork + exec; substrate becomes parent
nx_hal_wait reap child + read exit code
nx_hal_kill send signal to child
dependencies 1 imports · 25 importers
diagram shows first 10 each side; +0 more imports, +15 more importers in the complete lists below.
imports: nx_syscalls.nx
imported by: nx_camera_q14.nxnx_checkers_test.nxnx_crater_field.nxnx_elder_supervisor_main.nxnx_forest_layout.nxnx_hal_test.nxnx_pe_container_datachar.nxnx_pe_container_gen.nxnx_pe_container_httpd.nxnx_pe_container_sdserver.nxnx_pe_container_uiserve.nxnx_pe_container_win.nxnx_pe_container_win_io.nxnx_pe_container_win_ping.nxnx_pe_container_win_sup.nxnx_pe_hello_test.nxnx_pe_job_limit_test.nxnx_pe_job_run_test.nxnx_pe_job_self_test.nxnx_pe_spawn_test.nxnx_pe_writer.nxnx_pe_writer_test.nxnx_solar_system_catalog.nxnx_substrate_python_spawn_test.nxnx_world_event.nx
structs
| none |
consts
| 94 | const NX_MAGIC_1000000000: i64 = 1000000000 |
| 101 | const NX_HAL_OP_CLOCK_NOW_NS: i64 = 0 |
| 102 | const NX_HAL_OP_ALLOC_PAGES: i64 = 1 |
| 103 | const NX_HAL_OP_RELEASE_PAGES: i64 = 2 |
| 104 | const NX_HAL_OP_CONSOLE_WRITE: i64 = 3 |
| 105 | const NX_HAL_OP_RANDOM_BYTES: i64 = 4 |
| 106 | const NX_HAL_OP_YIELD: i64 = 5 |
| 107 | const NX_HAL_OP_EXIT: i64 = 6 |
| 108 | const NX_HAL_OP_SPAWN: i64 = 7 // fork+exec; substrate becomes parent |
| 109 | const NX_HAL_OP_WAIT: i64 = 8 // reap child + read exit code |
| 110 | const NX_HAL_OP_KILL: i64 = 9 // send signal to child |
| 111 | const NX_HAL_OP_N_KINDS: i64 = 10 |
| 120 | const NX_HAL_SHIM_LINUX: i64 = 0 |
| 121 | const NX_HAL_SHIM_BARE_METAL: i64 = 1 // future: substrate kernel on bare hw |
| 122 | const NX_HAL_SHIM_NISHI_SILICON: i64 = 2 // future: custom Nishi ASIC |
| 123 | const NX_HAL_SHIM_N_KINDS: i64 = 3 |
| 132 | const NX_HAL_OK: i64 = 0 |
| 133 | const NX_HAL_BAD_INPUT: i64 = 1 |
| 134 | const NX_HAL_NO_BACKING: i64 = 2 // shim not implemented for this op |
| 135 | const NX_HAL_FAULT: i64 = 3 // hardware/syscall returned error |
| 136 | const NX_HAL_N_VERDICTS: i64 = 4 |
| 157 | const NX_HAL_ACTIVE_SHIM_KIND: i64 = NX_HAL_SHIM_LINUX |
| 168 | const NX_HAL_SYS_GETRANDOM: i64 = 318 |
| 169 | const NX_HAL_SYS_SCHED_YIELD: i64 = 24 |
| 170 | const NX_HAL_SYS_KILL: i64 = 62 |
| 174 | const NX_HAL_SYS_GETRANDOM: i64 = 278 |
| 175 | const NX_HAL_SYS_SCHED_YIELD: i64 = 124 |
| 176 | const NX_HAL_SYS_KILL: i64 = 129 |
functions
| 113 | func nx_hal_op_is_valid(op: i64) -> i64 called by 1: main |
| 125 | func nx_hal_shim_is_valid(s: i64) -> i64 called by 1: main |
| 138 | func nx_hal_verdict_is_valid(v: i64) -> i64 called by 1: main |
| 159 | func nx_hal_active_shim() -> i64 |
| 183 | func nx_hal_clock_now_ns_linux() -> i64 |
| 193 | func nx_hal_clock_now_ns_bare_metal() -> i64 called by 1: nx_hal_clock_now_ns |
| 201 | func nx_hal_clock_now_ns_nishi_silicon() -> i64 called by 1: nx_hal_clock_now_ns |
| 209 | func nx_hal_clock_now_ns() -> i64 |
| 221 | func nx_hal_alloc_pages_linux(n_bytes: i64) -> *u8 |
| 225 | func nx_hal_alloc_pages_bare_metal(n_bytes: i64) -> *u8 called by 1: nx_hal_alloc_pages |
| 233 | func nx_hal_alloc_pages_nishi_silicon(n_bytes: i64) -> *u8 called by 1: nx_hal_alloc_pages |
| 242 | func nx_hal_alloc_pages(n_bytes: i64) -> *u8 |
| 256 | func nx_hal_release_pages_linux(ptr: *u8, n_bytes: i64) -> i64 called by 1: nx_hal_release_pages |
| 262 | func nx_hal_release_pages_bare_metal(ptr: *u8, n_bytes: i64) -> i64 called by 1: nx_hal_release_pages |
| 268 | func nx_hal_release_pages_nishi_silicon(ptr: *u8, n_bytes: i64) -> i64 called by 1: nx_hal_release_pages |
| 274 | func nx_hal_release_pages(ptr: *u8, n_bytes: i64) -> i64 |
| 288 | func nx_hal_console_write_linux(buf: *u8, len: i64) -> i64 |
| 292 | func nx_hal_console_write_bare_metal(buf: *u8, len: i64) -> i64 called by 1: nx_hal_console_write |
| 300 | func nx_hal_console_write_nishi_silicon(buf: *u8, len: i64) -> i64 called by 1: nx_hal_console_write |
| 308 | func nx_hal_console_write(buf: *u8, len: i64) -> i64 |
| 323 | func nx_hal_random_bytes_linux(buf: *u8, len: i64) -> i64 called by 1: nx_hal_random_bytes |
| 330 | func nx_hal_random_bytes_bare_metal(buf: *u8, len: i64) -> i64 called by 1: nx_hal_random_bytes |
| 339 | func nx_hal_random_bytes_nishi_silicon(buf: *u8, len: i64) -> i64 called by 1: nx_hal_random_bytes |
| 348 | func nx_hal_random_bytes(buf: *u8, len: i64) -> i64 |
| 362 | func nx_hal_yield_linux() -> i64 called by 1: nx_hal_yield |
| 368 | func nx_hal_yield_bare_metal() -> i64 called by 1: nx_hal_yield |
| 375 | func nx_hal_yield_nishi_silicon() -> i64 called by 1: nx_hal_yield |
| 383 | func nx_hal_yield() -> i64 called by 1: main calls 4: nx_hal_active_shimnx_hal_yield_linuxnx_hal_yield_bare_metalnx_hal_yield_nishi_silicon |
| 395 | func nx_hal_exit_linux(code: i64) -> i64 called by 1: nx_hal_exit |
| 400 | func nx_hal_exit_bare_metal(code: i64) -> i64 called by 1: nx_hal_exit |
| 408 | func nx_hal_exit_nishi_silicon(code: i64) -> i64 called by 1: nx_hal_exit |
| 416 | func nx_hal_exit(code: i64) -> i64 |
| 440 | func nx_hal_spawn_linux(exec_path: *u8, argv: *i64, envp: *i64) -> i64 |
| 455 | func nx_hal_spawn_bare_metal(exec_path: *u8, argv: *i64, envp: *i64) -> i64 called by 1: nx_hal_spawn |
| 464 | func nx_hal_spawn_nishi_silicon(exec_path: *u8, argv: *i64, envp: *i64) -> i64 called by 1: nx_hal_spawn |
| 471 | func nx_hal_spawn(exec_path: *u8, argv: *i64, envp: *i64) -> i64 |
| 487 | func nx_hal_wait_linux(pid: i64, exit_code_out: *i64) -> i64 |
| 496 | func nx_hal_wait_bare_metal(pid: i64, exit_code_out: *i64) -> i64 called by 1: nx_hal_wait |
| 503 | func nx_hal_wait_nishi_silicon(pid: i64, exit_code_out: *i64) -> i64 called by 1: nx_hal_wait |
| 509 | func nx_hal_wait(pid: i64, exit_code_out: *i64) -> i64 called by 2: mainmain calls 4: nx_hal_active_shimnx_hal_wait_linuxnx_hal_wait_bare_metalnx_hal_wait_nishi_silicon |
| 524 | func nx_hal_kill_linux(pid: i64, signal: i64) -> i64 called by 1: nx_hal_kill |
| 530 | func nx_hal_kill_bare_metal(pid: i64, signal: i64) -> i64 called by 1: nx_hal_kill |
| 539 | func nx_hal_kill_nishi_silicon(pid: i64, signal: i64) -> i64 called by 1: nx_hal_kill |
| 545 | func nx_hal_kill(pid: i64, signal: i64) -> i64 called by 1: main calls 4: nx_hal_active_shimnx_hal_kill_linuxnx_hal_kill_bare_metalnx_hal_kill_nishi_silicon |