aboutsummaryrefslogtreecommitdiff
path: root/src/features
diff options
context:
space:
mode:
authorMarvin Borner2020-08-06 20:02:44 +0200
committerMarvin Borner2020-08-06 20:02:44 +0200
commit9dbf8131d6aaff1617ef2bc7ebf54838f808688d (patch)
treed578b3a54a509b840a753c9c29a37dd37b2b3f5d /src/features
parent1272295d0c611f04128f9e388d5a0468dc64dae0 (diff)
Fixed messed up registers
Diffstat (limited to 'src/features')
-rw-r--r--src/features/load.c8
-rw-r--r--src/features/proc.c27
-rw-r--r--src/features/syscall.c4
3 files changed, 22 insertions, 17 deletions
diff --git a/src/features/load.c b/src/features/load.c
index bc56235..36548bb 100644
--- a/src/features/load.c
+++ b/src/features/load.c
@@ -2,6 +2,7 @@
#include <def.h>
#include <fs.h>
+#include <load.h>
#include <mem.h>
#include <print.h>
#include <proc.h>
@@ -14,4 +15,11 @@ void bin_load(char *path, struct proc *proc)
proc->regs.ebp = (u32)stack;
proc->regs.esp = (u32)stack;
proc->regs.eip = (u32)data;
+
+ proc->regs.ds = GDT_DATA_OFFSET;
+ proc->regs.es = GDT_DATA_OFFSET;
+ proc->regs.fs = GDT_DATA_OFFSET;
+ proc->regs.gs = GDT_DATA_OFFSET;
+ proc->regs.cs = GDT_CODE_OFFSET;
+ proc->regs.eflags = EFLAGS_ALWAYS | EFLAGS_INTERRUPTS;
}
diff --git a/src/features/proc.c b/src/features/proc.c
index 0378183..594e9ec 100644
--- a/src/features/proc.c
+++ b/src/features/proc.c
@@ -15,12 +15,14 @@ struct proc *last;
void scheduler(struct regs *regs)
{
- printf("%d", current->pid);
- memcpy(&current->regs, regs, sizeof(struct regs));
+ if (current) {
+ printf("%d", current->pid);
+ memcpy(&current->regs, regs, sizeof(struct regs));
+ }
timer_handler();
- if (current->next)
+ if (current && current->next)
current = current->next;
else
current = root;
@@ -38,6 +40,7 @@ void proc_print()
{
struct proc *proc = root;
+ printf("\n");
while (proc) {
printf("Process %d [%s]\n", proc->pid,
proc->state == PROC_RUNNING ? "running" : "sleeping");
@@ -60,6 +63,8 @@ void proc_attach(struct proc *proc)
struct proc *proc_make()
{
+ /* if (current) */
+ /* current->state = PROC_ASLEEP; */
struct proc *proc = malloc(sizeof(*proc));
proc->pid = pid++;
proc->state = PROC_RUNNING;
@@ -69,24 +74,14 @@ struct proc *proc_make()
return proc;
}
-void proc_jump(struct proc *proc)
-{
- void (*entry)();
- *(void **)(&entry) = (u32 *)proc->regs.eip;
- __asm__ volatile("movl %%eax, %%ebp" ::"a"(proc->regs.ebp));
- __asm__ volatile("movl %%eax, %%esp" ::"a"(proc->regs.esp));
- current = proc;
- sti();
- entry();
-}
-
void proc_init()
{
cli();
irq_install_handler(0, scheduler);
- current = root = proc_make();
+ root = proc_make();
bin_load("/init", root);
proc_print();
- proc_jump(root);
+ sti();
+ hlt();
}
diff --git a/src/features/syscall.c b/src/features/syscall.c
index ebfff59..2279429 100644
--- a/src/features/syscall.c
+++ b/src/features/syscall.c
@@ -1,5 +1,6 @@
// MIT License, Copyright (c) 2020 Marvin Borner
+#include <cpu.h>
#include <interrupts.h>
#include <load.h>
#include <print.h>
@@ -11,7 +12,8 @@ void syscall_handler(struct regs *r)
struct proc *a = proc_make();
bin_load("/a", a);
- proc_jump(a);
+ sti();
+ hlt();
}
void syscall_init()