code wiki / (root) / crt0.nx

crt0.nx

buildroot/runtime/crt0.nx

2412 B56 linesdepth 3pulls 3 transitivereach 14 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

crt0.nx -- sovereign `_start` stub for NishiLang programs. Replaces the libc/crt0 that C programs silently link against. The Linux kernel hands us a stack laid out like: sp ------------------------> argc (i64) sp + 8 --------------------> argv[0] (*u8, program name) sp + 16 -------------------> argv[1] (*u8, first real arg) ... sp + 8 + argc*8 -----------> NULL ... envp[0], ..., NULL, auxv... We translate that into the (argc, argv) signature parse.nx expects for main() -- a0 = argc, a1 = argv -- then call main. On return, exit(a0) via the SYS_exit (93) syscall. This file defines `_start` only as source TEXT because NishiLang doesn't yet have a way to declare symbols at specific file offsets or pin a function's emission order. Drivers emit this text at the head of their assembled output so it lands at the ELF entry point. Usage (see runtime/nxc.nx): emit_start_stub(asm_buf) // ... emit user's functions ... assemble(asm_buf, ...) write_elf(code, code_len, fd)

dependencies 1 imports · 14 importers

nx_outbuf.nx crt0.nx _offc_nxc_small.nx nx_nxc.nx nx_smoke_nxc_pipeline.nx nx_smoke_nxc_pipeline10.nx nx_smoke_nxc_pipeline7.nx nx_smoke_nxc_pipeline8.nx nx_smoke_nxc_pipeline9.nx nx_smoke_nxc_tilde.nx nxc.nx smoke_nxc_pipeline.nx

diagram shows first 10 each side; +0 more imports, +4 more importers in the complete lists below.

imports: nx_outbuf.nx

imported by: _offc_nxc_small.nxnx_nxc.nxnx_smoke_nxc_pipeline.nxnx_smoke_nxc_pipeline10.nxnx_smoke_nxc_pipeline7.nxnx_smoke_nxc_pipeline8.nxnx_smoke_nxc_pipeline9.nxnx_smoke_nxc_tilde.nxnxc.nxsmoke_nxc_pipeline.nxsmoke_nxc_pipeline10.nxsmoke_nxc_pipeline7.nxsmoke_nxc_pipeline8.nxsmoke_nxc_pipeline9.nx

structs

none

consts

none

functions

46func emit_crt0_start(o: *OutBuf) -> i64 {