crt.c (1457B)
1 /* Freestanding entry point for the bounce harness. 2 * 3 * The harness compiles this with a -DBOUNCE_<ARCH> define selecting the 4 * guest architecture (kit does not predefine __x86_64__ etc.). _start 5 * calls bounce_main with a normal C call so the compiler emits the proper 6 * cross-translation-unit relocation — the very edge the format-bounce 7 * exercises — then exits via exit_group with its return value. 8 * 9 * The syscall is set up with explicit `mov` instructions taking the exit 10 * code through a generic "r" operand rather than GCC local register 11 * variables (which kit does not honor) or per-arch call/syscall pseudos 12 * (which the standalone assembler does not model). */ 13 14 int bounce_main(void); 15 16 __attribute__((noreturn)) static void sys_exit(int code) { 17 #if defined(BOUNCE_X64) 18 __asm__ volatile( 19 "movl %0, %%edi\n\t" 20 "movl $231, %%eax\n\t" /* exit_group */ 21 "syscall\n\t" 22 : 23 : "r"(code) 24 : "eax", "edi", "memory"); 25 #elif defined(BOUNCE_AARCH64) 26 __asm__ volatile( 27 "mov x0, %0\n\t" 28 "mov x8, #94\n\t" 29 "svc #0\n\t" 30 : 31 : "r"((long)code) 32 : "x0", "x8", "memory"); 33 #elif defined(BOUNCE_RV64) 34 __asm__ volatile( 35 "mv a0, %0\n\t" 36 "li a7, 94\n\t" 37 "ecall\n\t" 38 : 39 : "r"((long)code) 40 : "a0", "a7", "memory"); 41 #else 42 #error "define BOUNCE_X64 / BOUNCE_AARCH64 / BOUNCE_RV64" 43 #endif 44 for (;;) { 45 } 46 } 47 48 void _start(void) { sys_exit(bounce_main()); }