[crt0] Actually pass argc, argv, envp to main()s

With the new SysV style process init args, it's a bit easier to finally
parse out argc, argv, and envp from the stack and pass them on to main
functions.
This commit is contained in:
Justin C. Miller
2024-08-10 17:37:34 -07:00
parent fa587060f1
commit d3f5db2479
3 changed files with 14 additions and 4 deletions

View File

@@ -87,11 +87,16 @@ _libc_crt0_start:
call __run_global_ctors
; argc
mov rdi, [r15]
; argv
mov rsi, r15
add rsi, 8
mov rdx, 0 ; TODO: actually parse stack for argc, argv, envp
mov rcx, rbx
; envp
lea rdx, [rsi + rdi*8 + 8]
lookup_GOT main
call rax

View File

@@ -20,7 +20,7 @@
#include "serial.h"
extern "C" {
int main(int, const char **);
int main(int, const char **, const char **envp);
}
j6_handle_t g_handle_sys = j6_handle_invalid;
@@ -36,7 +36,7 @@ uint8_t com2_out[out_buf_size];
constexpr uintptr_t stack_top = 0xf80000000;
int
main(int argc, const char **argv)
main(int argc, const char **argv, const char **envp)
{
j6::syslog(j6::logs::srv, j6::log_level::info, "uart driver starting");

View File

@@ -71,6 +71,8 @@ public:
}
void build() {
*push<uint64_t, 16>() = 0;
if ((m_argv.count() + m_envp.count()) % 2 == 0)
*push<uint64_t>() = 0; // Pad for 16-byte alignment
@@ -268,6 +270,9 @@ load_program(
stack_top,
};
stack.add_arg(path);
stack.add_env("jsix_version", GIT_VERSION);
static constexpr size_t nhandles = 3;
static constexpr size_t handles_extra = 3 * sizeof(j6_arg_handle_entry);
j6_arg_handles *handles_arg = stack.add_aux_data<j6_arg_handles>(j6_aux_handles, handles_extra);