diff --git a/src/kernel/loader.s b/src/kernel/loader.s index eb58d8f..e9310eb 100644 --- a/src/kernel/loader.s +++ b/src/kernel/loader.s @@ -4,18 +4,15 @@ extern load_process global ramdisk_process_loader ramdisk_process_loader: - ; create_process already pushed a cpu_state onto the stack for us, this ; acts both as the cpu_state parameter to load_process, and the saved ; state for the following iretq ; ; Additional parameters: - ; rax - the address of the program image - ; rbx - the size of the program image - ; rcx - the address of this process' process structure - mov rdi, rax - mov rsi, rbx - mov rdx, rcx + ; rdi - the address of the program image + ; rsi - the size of the program image + ; rdx - the address of this process' process structure + ; rcx - the stack pointer, which points at the cpu_state call load_process swapgs diff --git a/src/kernel/scheduler.cpp b/src/kernel/scheduler.cpp index b837847..c164548 100644 --- a/src/kernel/scheduler.cpp +++ b/src/kernel/scheduler.cpp @@ -24,7 +24,7 @@ const uint64_t rflags_int = 0x202; extern "C" { void ramdisk_process_loader(); - void load_process(const void *image_start, size_t bytes, process *proc, cpu_state state); + void load_process(const void *image_start, size_t bytes, process *proc, cpu_state *state); }; struct cpu_data @@ -60,7 +60,7 @@ scheduler::scheduler(lapic *apic) : } void -load_process(const void *image_start, size_t bytes, process *proc, cpu_state state) +load_process(const void *image_start, size_t bytes, process *proc, cpu_state *state) { // We're now in the process space for this process, allocate memory for the // process code and load it @@ -111,10 +111,10 @@ load_process(const void *image_start, size_t bytes, process *proc, cpu_state sta kutil::memcpy(dest, src, header->size); } - state.rip = image.entrypoint(); + state->rip = image.entrypoint(); proc->flags &= ~process_flags::loading; - log::debug(logs::task, " Loaded! New process rip: %016lx", state.rip); + log::debug(logs::task, " Loaded! New process rip: %016lx", state->rip); } process_node * @@ -167,8 +167,11 @@ scheduler::load_process(const char *name, const void *data, size_t size) loader_state->rip = reinterpret_cast(ramdisk_process_loader); loader_state->user_rsp = reinterpret_cast(state); - loader_state->rax = reinterpret_cast(data); - loader_state->rbx = size; + // Set up the registers to have the arguments to the load_process call + loader_state->rdi = reinterpret_cast(data); // arg 1 + loader_state->rsi = size; // arg 2 + loader_state->rdx = reinterpret_cast(proc); // arg 3 + loader_state->rcx = loader_state->user_rsp; // arg 4 proc->rsp = reinterpret_cast(loader_state); proc->pml4 = pml4; @@ -180,7 +183,6 @@ scheduler::load_process(const char *name, const void *data, size_t size) m_runlists[default_priority].push_back(proc); - loader_state->rcx = reinterpret_cast(proc); log::debug(logs::task, "Creating process %s: pid %d pri %d", name, proc->pid, proc->priority); log::debug(logs::task, " RSP0 %016lx", state);