mirror of
https://github.com/justinian/jsix.git
synced 2025-12-09 16:04:32 -08:00
[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:
@@ -87,11 +87,16 @@ _libc_crt0_start:
|
|||||||
|
|
||||||
call __run_global_ctors
|
call __run_global_ctors
|
||||||
|
|
||||||
|
; argc
|
||||||
mov rdi, [r15]
|
mov rdi, [r15]
|
||||||
|
|
||||||
|
; argv
|
||||||
mov rsi, r15
|
mov rsi, r15
|
||||||
add rsi, 8
|
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
|
lookup_GOT main
|
||||||
call rax
|
call rax
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
#include "serial.h"
|
#include "serial.h"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
int main(int, const char **);
|
int main(int, const char **, const char **envp);
|
||||||
}
|
}
|
||||||
|
|
||||||
j6_handle_t g_handle_sys = j6_handle_invalid;
|
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;
|
constexpr uintptr_t stack_top = 0xf80000000;
|
||||||
|
|
||||||
int
|
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");
|
j6::syslog(j6::logs::srv, j6::log_level::info, "uart driver starting");
|
||||||
|
|
||||||
|
|||||||
@@ -71,6 +71,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void build() {
|
void build() {
|
||||||
|
*push<uint64_t, 16>() = 0;
|
||||||
|
|
||||||
if ((m_argv.count() + m_envp.count()) % 2 == 0)
|
if ((m_argv.count() + m_envp.count()) % 2 == 0)
|
||||||
*push<uint64_t>() = 0; // Pad for 16-byte alignment
|
*push<uint64_t>() = 0; // Pad for 16-byte alignment
|
||||||
|
|
||||||
@@ -268,6 +270,9 @@ load_program(
|
|||||||
stack_top,
|
stack_top,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
stack.add_arg(path);
|
||||||
|
stack.add_env("jsix_version", GIT_VERSION);
|
||||||
|
|
||||||
static constexpr size_t nhandles = 3;
|
static constexpr size_t nhandles = 3;
|
||||||
static constexpr size_t handles_extra = 3 * sizeof(j6_arg_handle_entry);
|
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);
|
j6_arg_handles *handles_arg = stack.add_aux_data<j6_arg_handles>(j6_aux_handles, handles_extra);
|
||||||
|
|||||||
Reference in New Issue
Block a user