aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/tasks
diff options
context:
space:
mode:
authorMarvin Borner2020-06-02 23:10:27 +0200
committerMarvin Borner2020-06-02 23:10:27 +0200
commitcf9135829836c85735b383f7c50f34232bea94f9 (patch)
treec6385aae76407504f34f371b799e03aa53c63e5c /src/kernel/tasks
parent0b3b63ffdedb2e37e0732c09eb0e967e256f0d71 (diff)
Much work on the ELF parser and userspace jumping
Diffstat (limited to 'src/kernel/tasks')
-rw-r--r--src/kernel/tasks/process.c62
-rw-r--r--src/kernel/tasks/process.h5
-rw-r--r--src/kernel/tasks/userspace.asm4
-rw-r--r--src/kernel/tasks/userspace.c59
-rw-r--r--src/kernel/tasks/userspace.h17
5 files changed, 36 insertions, 111 deletions
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 <stdint.h>
#include <system.h>
#include <tasks/process.h>
-#include <tasks/userspace.h>
#include <timer/timer.h>
u32 pid = 0;
@@ -36,7 +35,7 @@ void scheduler(struct regs *regs)
}
serial_put('+');
- memcpy(&current_proc->registers, regs, sizeof(struct regs));
+ memcpy(&current_proc->regs, regs, sizeof(struct regs));
timer_handler(regs);
@@ -55,10 +54,18 @@ void scheduler(struct regs *regs)
}
}
- memcpy(regs, &current_proc->registers, sizeof(struct regs));
- paging_switch_directory(current_proc->cr3);
+ memcpy(regs, &current_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;
}
diff --git a/src/kernel/tasks/process.h b/src/kernel/tasks/process.h
index 5c72e64..493dbe5 100644
--- a/src/kernel/tasks/process.h
+++ b/src/kernel/tasks/process.h
@@ -14,7 +14,7 @@ struct mmap {
struct process {
u32 cr3;
- struct regs registers;
+ struct regs regs;
u32 pid;
char name[256];
@@ -35,9 +35,6 @@ u32 process_spawn(struct process *process);
void process_suspend(u32 pid);
void process_wake(u32 pid);
-u32 process_wait_gid(u32 gid, u32 *status);
-u32 process_wait_pid(u32 pid, u32 *status);
-
struct process *process_from_pid(u32 pid);
void process_init(struct process *proc);
diff --git a/src/kernel/tasks/userspace.asm b/src/kernel/tasks/userspace.asm
index ebdcf26..6881bdf 100644
--- a/src/kernel/tasks/userspace.asm
+++ b/src/kernel/tasks/userspace.asm
@@ -1,9 +1,9 @@
-global jump_userspace
+global userspace_jump
extern hl_cr3
extern hl_esp
extern hl_eip
-jump_userspace:
+userspace_jump:
mov ax, 0x23
mov ds, ax
mov es, ax
diff --git a/src/kernel/tasks/userspace.c b/src/kernel/tasks/userspace.c
deleted file mode 100644
index 3164965..0000000
--- a/src/kernel/tasks/userspace.c
+++ /dev/null
@@ -1,59 +0,0 @@
-#include <interrupts/interrupts.h>
-#include <io/io.h>
-#include <lib/lib.h>
-#include <memory/paging.h>
-#include <stddef.h>
-#include <stdint.h>
-#include <system.h>
-#include <tasks/process.h>
-#include <tasks/userspace.h>
-
-struct process *proc_bottom = NULL;
-
-u32 hl_cr3;
-u32 hl_eip;
-u32 hl_esp;
-
-u32 spawn_child(struct process *child)
-{
- return (u32)-1;
-}
-
-void userspace_enter(struct process *proc)
-{
- proc_bottom = proc;
- hl_eip = proc->registers.eip;
- hl_esp = proc->registers.esp;
- paging_switch_directory(proc->cr3);
-
- //debug("Jumping to userspace!");
- jump_userspace();
-}
-
-void single_yield(struct process *proc, struct regs *regs)
-{
- memcpy(&proc_bottom->registers, regs, sizeof(struct regs));
-
- if (proc == proc_bottom)
- panic("Can't return from parent process");
-
- proc->next = proc_bottom;
- proc_bottom = proc;
-
- memcpy(regs, &proc->registers, sizeof(struct regs));
- paging_switch_directory(proc->cr3);
-}
-
-u32 single_exit(struct regs *regs)
-{
- u32 hold = regs->ebx;
- proc_bottom = proc_bottom->next;
-
- if (proc_bottom == NULL)
- panic("Return from process with no parent");
-
- memcpy(regs, &proc_bottom->registers, sizeof(struct regs));
- paging_switch_directory(proc_bottom->cr3);
-
- return hold;
-} \ No newline at end of file
diff --git a/src/kernel/tasks/userspace.h b/src/kernel/tasks/userspace.h
deleted file mode 100644
index d66ba54..0000000
--- a/src/kernel/tasks/userspace.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#ifndef MELVIX_USERSPACE_H
-#define MELVIX_USERSPACE_H
-
-#include <interrupts/interrupts.h>
-#include <stdint.h>
-#include <tasks/process.h>
-
-u32 spawn_child(struct process *child);
-
-void userspace_enter(struct process *proc);
-
-void single_yield(struct process *proc, struct regs *regs);
-u32 single_exit(struct regs *regs);
-
-extern void jump_userspace();
-
-#endif \ No newline at end of file