From cf9135829836c85735b383f7c50f34232bea94f9 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Tue, 2 Jun 2020 23:10:27 +0200 Subject: Much work on the ELF parser and userspace jumping --- src/kernel/tasks/process.c | 62 ++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 29 deletions(-) (limited to 'src/kernel/tasks/process.c') diff --git a/src/kernel/tasks/process.c b/src/kernel/tasks/process.c index 0b13b6b..a4c1c79 100644 --- a/src/kernel/tasks/process.c +++ b/src/kernel/tasks/process.c @@ -8,7 +8,6 @@ #include #include #include -#include #include u32 pid = 0; @@ -36,7 +35,7 @@ void scheduler(struct regs *regs) } serial_put('+'); - memcpy(¤t_proc->registers, regs, sizeof(struct regs)); + memcpy(¤t_proc->regs, regs, sizeof(struct regs)); timer_handler(regs); @@ -55,10 +54,18 @@ void scheduler(struct regs *regs) } } - memcpy(regs, ¤t_proc->registers, sizeof(struct regs)); - paging_switch_directory(current_proc->cr3); + memcpy(regs, ¤t_proc->regs, sizeof(struct regs)); + paging_switch_dir(current_proc->cr3); + if (regs->cs != 0x1B) { + regs->gs = 0x23; + regs->fs = 0x23; + regs->es = 0x23; + regs->ds = 0x23; + regs->cs = 0x1B; + regs->ss = 0x23; + } + locked = 0; - cli(); } void process_force_switch() @@ -68,6 +75,9 @@ void process_force_switch() //scheduler(regs); } +u32 hl_cr3; +u32 hl_eip; +u32 hl_esp; void process_init(struct process *proc) { log("Initializing process %d", pid); @@ -78,7 +88,15 @@ void process_init(struct process *proc) current_proc = root; irq_install_handler(0, scheduler); - userspace_enter(proc); + + hl_eip = proc->regs.eip; + hl_esp = proc->regs.esp; + //paging_switch_dir(proc->cr3); + + debug("Jumping to userspace!"); + extern void userspace_jump(); + userspace_jump(); + panic("This should not happen!"); } // Only for debugging purposes @@ -113,25 +131,6 @@ u32 process_spawn(struct process *process) return process->pid; } -u32 process_wait_pid(u32 pid, u32 *status) -{ - struct process *i = current_proc->next; - - while (i != NULL) { - if (i->pid == pid) { - if (i->state == PROC_ASLEEP) { - *status = i->registers.ebx; - return i->pid; - } else { - return WAIT_OKAY; - } - } - i = i->next; - } - - return WAIT_ERROR; -} - void process_suspend(u32 pid) { debug("Suspending process %d", pid); @@ -175,15 +174,20 @@ struct process *process_from_pid(u32 pid) return PID_NOT_FOUND; } +void no_entry() +{ + panic("No entry point given!"); +} + struct process *process_make_new() { debug("Making new process %d", pid); struct process *proc = (struct process *)valloc(sizeof(struct process)); - proc->registers.cs = 0x1B; - proc->registers.ds = 0x23; - proc->registers.ss = 0x23; + proc->regs.cs = 0x1B; + proc->regs.ds = 0x23; + proc->regs.ss = 0x23; + proc->regs.eip = no_entry; proc->cr3 = paging_make_dir(); - proc->brk = 0x50000000; proc->pid = pid++; return proc; } -- cgit v1.2.3