entry-libc.P1pp (895B)
1 # P1/entry-libc.P1pp — executable entry stub for links that include 2 # our libc (vendor/mes-libc + boot2-syscall.c). 3 # 4 # Same shape as entry-plain.P1pp but threads __libc_init in front of 5 # main. __libc_init (boot2-syscall.c) reads argv's NULL terminator 6 # to populate `environ` so getenv()/etc don't dereference a NULL 7 # environment pointer on the first call. argc/argv arrive in a0/a1 8 # from the bootstrap _start; save them across __libc_init so main sees 9 # the original process arguments even if libc init returns through a0. 10 # 11 # Cat this in exactly once at the head of a libc-using catm chain 12 # and pair with P1/elf-end.P1pp at the tail. Library TUs (libc, 13 # client) should be built with cc.scm --lib=PFX so they don't 14 # also try to define :p1_main. 15 16 %fn(p1_main, 16, { 17 %st(a0, sp, 0) 18 %st(a1, sp, 8) 19 %call(&__libc_init) 20 %ld(a0, sp, 0) 21 %ld(a1, sp, 8) 22 %call(&main) 23 })