mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 08:24:32 -08:00
[kernel] Improve process init
Move process init from each process needing a main.s with _start to crt0.s in libc. Also change to a sysv-like initial stack with a j6-specific array of initialization values after the program arguments.
This commit is contained in:
19
src/libraries/libc/arch/x86_64/crt0.s
Normal file
19
src/libraries/libc/arch/x86_64/crt0.s
Normal file
@@ -0,0 +1,19 @@
|
||||
extern main
|
||||
extern exit
|
||||
extern _init_libc
|
||||
|
||||
global _start:function (_start.end - _start)
|
||||
_start:
|
||||
mov rbp, rsp
|
||||
mov rdi, rsp
|
||||
|
||||
call _init_libc
|
||||
|
||||
pop rdi
|
||||
mov rsi, rsp
|
||||
|
||||
call main
|
||||
|
||||
mov rdi, rax
|
||||
call exit
|
||||
.end:
|
||||
36
src/libraries/libc/arch/x86_64/init_libc.c
Normal file
36
src/libraries/libc/arch/x86_64/init_libc.c
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <stdint.h>
|
||||
#include <j6/init.h>
|
||||
#include <j6/types.h>
|
||||
|
||||
static size_t __initc = 0;
|
||||
static struct j6_init_value *__initv = 0;
|
||||
|
||||
j6_handle_t __handle_sys = j6_handle_invalid;
|
||||
|
||||
void
|
||||
_get_init(size_t *initc, struct j6_init_value **initv)
|
||||
{
|
||||
if (!initc)
|
||||
return;
|
||||
|
||||
*initc = __initc;
|
||||
if (initv)
|
||||
*initv = __initv;
|
||||
}
|
||||
|
||||
void
|
||||
_init_libc(uint64_t *rsp)
|
||||
{
|
||||
uint64_t argc = *rsp++;
|
||||
rsp += argc;
|
||||
|
||||
__initc = *rsp++;
|
||||
__initv = (struct j6_init_value *)rsp;
|
||||
|
||||
for (unsigned i = 0; i < __initc; ++i) {
|
||||
if (__initv[i].type == j6_init_handle_system) {
|
||||
__handle_sys = __initv[i].value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user