ajhahn.de
← FlashOS
Flash 30 lines
// Minimal AArch64 freestanding ELF for the [TEST] exec-elf scenario.
// Transpiled by flashc at build time and built as a separate executable
// in build.zig (pie=false, strip, ReleaseSmall), then staged into the
// initramfs at /test/hello.elf so the exec-elf scenario can open it via
// sys_openFile, read it into an EL0 buffer, and hand the bytes to
// sys_exec.
//
// Body is pure inline asm with the syscall numbers from
// lib/syscall_defs.zig hard-coded (SYS_WRITE=33 with x0=fd[1=stdout],
// x1=buf, x2=len; SYS_EXIT=2). The payload string lives in the same
// .text section, reached PC-relative via `adr` so the loader is free to
// map this segment anywhere — the blob is fully position-independent at
// instruction granularity even though the ELF itself is ET_EXEC.

export fn _start() callconv(.naked) noreturn {
    asm volatile (
        \\.balign 8
        \\    mov x8, #33
        \\    mov x0, #1
        \\    adr x1, 1f
        \\    mov x2, #(2f - 1f)
        \\    svc #0
        \\    mov x8, #2
        \\    svc #0
        \\1:
        \\    .ascii "elf hello\n"
        \\2:
    )
}