code wiki / (root) / nx_elf_exec.nx

nx_elf_exec.nx

buildroot/runtime/nx_elf_exec.nx

10318 B292 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind tooltopic elf
docsdependenciesstructsconstsfunctions

about

nx_elf_exec.nx -- executable ELF writer. Consumes the layout output from nx_link.nx (or any caller that provides aligned text/rodata/data/bss segments + entry vaddr) and emits a complete static ELF64 executable suitable for nx_loader to consume. Output layout (file offsets): 0x00 - 0x40 Elf64_Ehdr 64 bytes 0x40 - 0x? Program header table 2 * 56 bytes (RX, RW) page boundary 0x1000+ RX segment (text + rodata) page boundary 0xN000+ RW segment (data; bss is NOBITS) We emit STATIC executables only (no dynamic linker, no PT_INTERP, no PT_DYNAMIC, no PHDR self-reference). That matches what the off-C path produces today. Pairs with nx_link (provides the layout) + nx_loader (consumes the output) + nx_rv64_sim (executes the loaded image).

dependencies 1 imports · 0 importers

syscalls.nx nx_elf_exec.nx

imports: syscalls.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main nx_elfexec_emit nx_elfexec_write_ehdr nx_elfexec_write_u8 nx_elfexec_write_u16 nx_elfexec_write_u32 nx_elfexec_write_u64 nx_elfexec_write_phdr nx_elfexec_write_u32 ↻ nx_elfexec_write_u64 ↻

structs

none

consts

31const NX_MAGIC_65536: i64 = 65536
35const NX_ELFEXEC_PAGE: i64 = 0x1000
37const NX_ELFEXEC_EHDR_BYTES: i64 = 64
38const NX_ELFEXEC_PHDR_BYTES: i64 = 56
41const NX_ELFEXEC_EI_MAG0: i64 = 0x7F
42const NX_ELFEXEC_EI_MAG1: i64 = 0x45
43const NX_ELFEXEC_EI_MAG2: i64 = 0x4C
44const NX_ELFEXEC_EI_MAG3: i64 = 0x46
45const NX_ELFEXEC_EI_CLASS_64: i64 = 2
46const NX_ELFEXEC_EI_DATA_LSB: i64 = 1
47const NX_ELFEXEC_EI_VERSION: i64 = 1
50const NX_ELFEXEC_ET_EXEC: i64 = 2
53const NX_ELFEXEC_EM_RISCV: i64 = 0xF3
56const NX_ELFEXEC_PT_LOAD: i64 = 1
57const NX_ELFEXEC_PF_X: i64 = 1
58const NX_ELFEXEC_PF_W: i64 = 2
59const NX_ELFEXEC_PF_R: i64 = 4

functions

63func nx_elfexec_write_u8(buf: *u8, off: i64, v: i64) -> i64
68func nx_elfexec_write_u16(buf: *u8, off: i64, v: i64) -> i64
74func nx_elfexec_write_u32(buf: *u8, off: i64, v: i64) -> i64
82func nx_elfexec_write_u64(buf: *u8, off: i64, v: i64) -> i64
96func nx_elfexec_write_ehdr(buf: *u8, entry_vaddr: i64, e_phoff: i64, e_phnum: i64) -> i64
127func nx_elfexec_write_phdr(
162func nx_elfexec_emit(
233func main() -> i64
calls 1: nx_elfexec_emit