mirror of
https://github.com/justinian/jsix.git
synced 2025-12-09 16:04: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" ],
|
deps = [ "util" ],
|
||||||
sources = [
|
sources = [
|
||||||
"init.cpp",
|
"init.cpp",
|
||||||
|
"init.s",
|
||||||
"protocol_ids.cpp",
|
"protocol_ids.cpp",
|
||||||
"syscalls.s.cog",
|
"syscalls.s.cog",
|
||||||
"sysconf.cpp.cog",
|
"sysconf.cpp.cog",
|
||||||
|
|||||||
@@ -16,6 +16,9 @@ struct j6_init_args
|
|||||||
/// Find the first handle of the given type held by this process
|
/// Find the first handle of the given type held by this process
|
||||||
j6_handle_t j6_find_first_handle(j6_object_type obj_type);
|
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
|
#ifdef __cplusplus
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -3,8 +3,11 @@ extern exit
|
|||||||
extern __init_libj6
|
extern __init_libj6
|
||||||
extern __init_libc
|
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:
|
_start:
|
||||||
|
_libc_crt0_start:
|
||||||
push 0 ; Add null frame
|
push 0 ; Add null frame
|
||||||
push 0
|
push 0
|
||||||
mov rbp, rsp
|
mov rbp, rsp
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ extern "C" {
|
|||||||
void _get_init(size_t *initc, struct j6_init_value **initv);
|
void _get_init(size_t *initc, struct j6_init_value **initv);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" int
|
int
|
||||||
driver_main(int argc, const char **argv, const char **env, const j6_init_args *init)
|
driver_main(unsigned argc, const char **argv, const char **env, const j6_init_args *init)
|
||||||
{
|
{
|
||||||
j6_log("fb driver starting");
|
j6_log("fb driver starting");
|
||||||
|
|
||||||
@@ -130,5 +130,3 @@ driver_main(int argc, const char **argv, const char **env, const j6_init_args *i
|
|||||||
j6_log("fb driver done, exiting");
|
j6_log("fb driver done, exiting");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main () __attribute__ ((weak, alias ("driver_main")));
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# vim: ft=python
|
# vim: ft=python
|
||||||
|
|
||||||
fb = module("drv.uefi_fb",
|
module("drv.uefi_fb",
|
||||||
targets = [ "user" ],
|
targets = [ "user" ],
|
||||||
deps = [ "libc", "bootproto" ],
|
deps = [ "libc", "bootproto" ],
|
||||||
description = "UEFI framebuffer driver",
|
description = "UEFI framebuffer driver",
|
||||||
@@ -11,5 +11,3 @@ fb = module("drv.uefi_fb",
|
|||||||
"screen.cpp",
|
"screen.cpp",
|
||||||
"scrollback.cpp",
|
"scrollback.cpp",
|
||||||
])
|
])
|
||||||
|
|
||||||
fb.variables['asflags'] = ["${asflags}", "-dmain_func=driver_main"]
|
|
||||||
|
|||||||
@@ -11,10 +11,6 @@ char inbuf[1024];
|
|||||||
extern j6_handle_t __handle_sys;
|
extern j6_handle_t __handle_sys;
|
||||||
j6_handle_t endp = j6_handle_invalid;
|
j6_handle_t endp = j6_handle_invalid;
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
int main(int, const char **);
|
|
||||||
}
|
|
||||||
|
|
||||||
extern j6_handle_t __handle_self;
|
extern j6_handle_t __handle_self;
|
||||||
|
|
||||||
constexpr uintptr_t stack_top = 0xf80000000;
|
constexpr uintptr_t stack_top = 0xf80000000;
|
||||||
|
|||||||
Reference in New Issue
Block a user