[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:
@@ -1,25 +1,16 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "j6/types.h"
|
||||
#include "j6/init.h"
|
||||
#include "j6/errors.h"
|
||||
#include "j6/signals.h"
|
||||
#include "j6/types.h"
|
||||
|
||||
#include <j6libc/syscalls.h>
|
||||
|
||||
extern "C" {
|
||||
void _init_libc(j6_process_init *);
|
||||
int main(int, const char **);
|
||||
}
|
||||
|
||||
j6_handle_t sys = j6_handle_invalid;
|
||||
size_t size = 0;
|
||||
|
||||
void
|
||||
_init_libc(j6_process_init *init)
|
||||
{
|
||||
sys = init->handles[0];
|
||||
size = reinterpret_cast<size_t>(init->handles[1]);
|
||||
void _get_init(size_t *initc, struct j6_init_value **initv);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -27,12 +18,25 @@ main(int argc, const char **argv)
|
||||
{
|
||||
_syscall_system_log("fb driver starting");
|
||||
|
||||
if (size == 0)
|
||||
size_t initc = 0;
|
||||
j6_init_value *initv = nullptr;
|
||||
_get_init(&initc, &initv);
|
||||
|
||||
j6_init_framebuffer *fb = nullptr;
|
||||
for (unsigned i = 0; i < initc; ++i) {
|
||||
if (initv[i].type == j6_init_desc_framebuffer) {
|
||||
fb = reinterpret_cast<j6_init_framebuffer*>(initv[i].value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!fb)
|
||||
return 1;
|
||||
|
||||
uint32_t *fb = reinterpret_cast<uint32_t*>(0x100000000);
|
||||
uint32_t *fbp = reinterpret_cast<uint32_t*>(fb->addr);
|
||||
size_t size = fb->size;
|
||||
for (size_t i=0; i < size/4; ++i) {
|
||||
fb[i] = 0xff;
|
||||
fbp[i] = 0xff;
|
||||
}
|
||||
|
||||
_syscall_system_log("fb driver done, exiting");
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
section .bss
|
||||
mymessage:
|
||||
resq 1024
|
||||
|
||||
extern main
|
||||
extern _init_libc
|
||||
extern exit
|
||||
|
||||
section .text
|
||||
|
||||
global _start
|
||||
_start:
|
||||
mov rbp, rsp
|
||||
|
||||
mov rdi, rsp
|
||||
call _init_libc
|
||||
|
||||
mov rdi, 0
|
||||
mov rsi, 0
|
||||
|
||||
call main
|
||||
|
||||
mov rdi, rax
|
||||
call exit
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "serial.h"
|
||||
|
||||
char inbuf[1024];
|
||||
j6_handle_t sys = j6_handle_invalid;
|
||||
extern j6_handle_t __handle_sys;
|
||||
j6_handle_t endp = j6_handle_invalid;
|
||||
|
||||
extern "C" {
|
||||
@@ -51,12 +51,6 @@ thread_proc()
|
||||
_syscall_thread_exit(0);
|
||||
}
|
||||
|
||||
void
|
||||
_init_libc(j6_process_init *init)
|
||||
{
|
||||
sys = init->handles[0];
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, const char **argv)
|
||||
{
|
||||
@@ -65,6 +59,9 @@ main(int argc, const char **argv)
|
||||
|
||||
_syscall_system_log("main thread starting");
|
||||
|
||||
for (int i = 0; i < argc; ++i)
|
||||
_syscall_system_log(argv[i]);
|
||||
|
||||
void *base = malloc(0x1000);
|
||||
if (!base)
|
||||
return 1;
|
||||
@@ -97,7 +94,7 @@ main(int argc, const char **argv)
|
||||
if (tag != 17)
|
||||
_syscall_system_log("GOT WRONG TAG FROM SENDRECV");
|
||||
|
||||
result = _syscall_system_bind_irq(sys, endp, 3);
|
||||
result = _syscall_system_bind_irq(__handle_sys, endp, 3);
|
||||
if (result != j6_status_ok)
|
||||
return result;
|
||||
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
section .bss
|
||||
mymessage:
|
||||
resq 1024
|
||||
|
||||
extern main
|
||||
extern _init_libc
|
||||
extern exit
|
||||
|
||||
section .text
|
||||
|
||||
global _start
|
||||
_start:
|
||||
mov rbp, rsp
|
||||
|
||||
mov rdi, rsp
|
||||
call _init_libc
|
||||
|
||||
mov rdi, 0
|
||||
mov rsi, 0
|
||||
|
||||
call main
|
||||
|
||||
mov rdi, rax
|
||||
call exit
|
||||
Reference in New Issue
Block a user