[kernel] Give threads initial arguments
This commit changes the add_user_thunk to point to a new routine, initialize_user_cpu, which sets all the registers that were previously unset when starting a new user thread. The values for rdi and rsi are popped off the initial stack values that add_user_thunk sets up, so that user thread procs can take up to two arguments. To suppor this, j6_thread_create gained two new arguments, which are passed on to the thread. This also let me finally get rid of the hack of passing an argument in rsp when starting init.
This commit is contained in:
@@ -135,7 +135,7 @@ load_program(
|
||||
}
|
||||
|
||||
j6_handle_t thread = j6_handle_invalid;
|
||||
res = j6_thread_create(&thread, proc, stack_top - 6*sizeof(uint64_t), progelf.entrypoint());
|
||||
res = j6_thread_create(&thread, proc, stack_top - 6*sizeof(uint64_t), progelf.entrypoint(), 0, 0);
|
||||
if (res != j6_status_ok) {
|
||||
sprintf(err_msg, " ** error loading program '%s': creating thread: %lx", name, res);
|
||||
return false;
|
||||
|
||||
@@ -7,34 +7,29 @@ extern _arg_modules_phys
|
||||
section .bss
|
||||
align 0x100
|
||||
init_stack_start:
|
||||
resb 0x8000 ; 16KiB stack space
|
||||
resb 0x8000 ; 16KiB stack space
|
||||
init_stack_top:
|
||||
|
||||
section .text
|
||||
|
||||
global _start:function (_start.end - _start)
|
||||
_start:
|
||||
; No parent process exists to have created init's stack, so we create a
|
||||
; stack in BSS and assign that to be init's first stack
|
||||
mov [_arg_modules_phys], rdi
|
||||
mov rsp, init_stack_top
|
||||
push 0
|
||||
push 0
|
||||
|
||||
; No parent process exists to have created init's stack, so we override
|
||||
; _start to deal with that in two ways:
|
||||
mov rbp, rsp
|
||||
mov rdi, rsp
|
||||
call __init_libj6
|
||||
call __init_libc
|
||||
|
||||
; 1. We create a stack in BSS and assign that to be init's first stack
|
||||
; 2. We take advantage of the fact that rsp is useless here as a way
|
||||
; for the kernel to tell init where its initial modules page is.
|
||||
mov [_arg_modules_phys], rsp
|
||||
mov rsp, init_stack_top
|
||||
push 0
|
||||
push 0
|
||||
pop rdi
|
||||
mov rsi, rsp
|
||||
call main
|
||||
|
||||
mov rbp, rsp
|
||||
mov rdi, rsp
|
||||
call __init_libj6
|
||||
call __init_libc
|
||||
|
||||
pop rdi
|
||||
mov rsi, rsp
|
||||
call main
|
||||
|
||||
mov rdi, rax
|
||||
call exit
|
||||
mov rdi, rax
|
||||
call exit
|
||||
.end:
|
||||
|
||||
Reference in New Issue
Block a user