[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:
Justin C. Miller
2023-02-20 11:05:53 -08:00
parent abe7fe37d0
commit c092e07832
7 changed files with 17 additions and 12 deletions

View File

@@ -18,8 +18,8 @@ extern "C" {
void _get_init(size_t *initc, struct j6_init_value **initv);
}
extern "C" int
driver_main(int argc, const char **argv, const char **env, const j6_init_args *init)
int
driver_main(unsigned argc, const char **argv, const char **env, const j6_init_args *init)
{
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");
return 0;
}
int main () __attribute__ ((weak, alias ("driver_main")));

View File

@@ -1,6 +1,6 @@
# vim: ft=python
fb = module("drv.uefi_fb",
module("drv.uefi_fb",
targets = [ "user" ],
deps = [ "libc", "bootproto" ],
description = "UEFI framebuffer driver",
@@ -11,5 +11,3 @@ fb = module("drv.uefi_fb",
"screen.cpp",
"scrollback.cpp",
])
fb.variables['asflags'] = ["${asflags}", "-dmain_func=driver_main"]

View File

@@ -11,10 +11,6 @@ char inbuf[1024];
extern j6_handle_t __handle_sys;
j6_handle_t endp = j6_handle_invalid;
extern "C" {
int main(int, const char **);
}
extern j6_handle_t __handle_self;
constexpr uintptr_t stack_top = 0xf80000000;