Clean up process loader

- cpu_state was being passed 'by value' to modify outer stack frame
- don't pass loader args as rax, rbx, etc - pass in ABI order
This commit is contained in:
Justin C. Miller
2019-03-15 01:05:45 -07:00
parent bf8286d15f
commit 33374ab257
2 changed files with 13 additions and 14 deletions

View File

@@ -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

View File

@@ -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<uint64_t>(ramdisk_process_loader);
loader_state->user_rsp = reinterpret_cast<uint64_t>(state);
loader_state->rax = reinterpret_cast<uint64_t>(data);
loader_state->rbx = size;
// Set up the registers to have the arguments to the load_process call
loader_state->rdi = reinterpret_cast<uint64_t>(data); // arg 1
loader_state->rsi = size; // arg 2
loader_state->rdx = reinterpret_cast<uint64_t>(proc); // arg 3
loader_state->rcx = loader_state->user_rsp; // arg 4
proc->rsp = reinterpret_cast<uintptr_t>(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<uint64_t>(proc);
log::debug(logs::task, "Creating process %s: pid %d pri %d", name, proc->pid, proc->priority);
log::debug(logs::task, " RSP0 %016lx", state);