mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 08:24:32 -08:00
[libj6] Allow driver_main instead of main for accepting extra arguments
Clang will complain if main() is not declared with 0, 2, or 3 arguments. In order to allow an extra 4th parameter, a new weak main() symbol which just jumps to driver_main is defined, and _start passes the extra init pointer to main. Additionally, libc's crt0.s _start is made weak, and a matching _libc_crt0_start symbol is defined for implementations that wish to override _start but still call libc's _start. (Will be used by init.)
This commit is contained in:
6
src/libraries/j6/init.s
Normal file
6
src/libraries/j6/init.s
Normal file
@@ -0,0 +1,6 @@
|
||||
extern driver_main
|
||||
global main:function weak (main.end - main)
|
||||
main:
|
||||
jmp driver_main
|
||||
main.end:
|
||||
|
||||
@@ -5,6 +5,7 @@ j6 = module("j6",
|
||||
deps = [ "util" ],
|
||||
sources = [
|
||||
"init.cpp",
|
||||
"init.s",
|
||||
"protocol_ids.cpp",
|
||||
"syscalls.s.cog",
|
||||
"sysconf.cpp.cog",
|
||||
|
||||
@@ -16,6 +16,9 @@ struct j6_init_args
|
||||
/// Find the first handle of the given type held by this process
|
||||
j6_handle_t j6_find_first_handle(j6_object_type obj_type);
|
||||
|
||||
/// Drivers may use driver_main instead of main
|
||||
int driver_main(unsigned, const char **, const char **, const j6_init_args *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
@@ -3,8 +3,11 @@ extern exit
|
||||
extern __init_libj6
|
||||
extern __init_libc
|
||||
|
||||
global _start:function (_start.end - _start)
|
||||
global _start:function weak (_libc_crt0_start.end - _libc_crt0_start)
|
||||
global _libc_crt0_start:function (_libc_crt0_start.end - _libc_crt0_start)
|
||||
|
||||
_start:
|
||||
_libc_crt0_start:
|
||||
push 0 ; Add null frame
|
||||
push 0
|
||||
mov rbp, rsp
|
||||
|
||||
Reference in New Issue
Block a user