aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Borner2020-08-06 20:02:44 +0200
committerMarvin Borner2020-08-06 20:02:44 +0200
commit9dbf8131d6aaff1617ef2bc7ebf54838f808688d (patch)
treed578b3a54a509b840a753c9c29a37dd37b2b3f5d
parent1272295d0c611f04128f9e388d5a0468dc64dae0 (diff)
Fixed messed up registers
-rw-r--r--apps/init.c2
-rw-r--r--src/drivers/interrupts.asm14
-rw-r--r--src/features/load.c8
-rw-r--r--src/features/proc.c27
-rw-r--r--src/features/syscall.c4
-rw-r--r--src/inc/load.h6
-rw-r--r--src/inc/proc.h1
7 files changed, 43 insertions, 19 deletions
diff --git a/apps/init.c b/apps/init.c
index 859ffe8..1c7540c 100644
--- a/apps/init.c
+++ b/apps/init.c
@@ -43,7 +43,7 @@ void serial_print(const char *data)
void main()
{
serial_print("Init loaded\n");
- __asm__ volatile("int $0x80");
+ /* __asm__ volatile("int $0x80"); */
while (1) {
__asm__ volatile("hlt");
};
diff --git a/src/drivers/interrupts.asm b/src/drivers/interrupts.asm
index 8f8afbb..59c323c 100644
--- a/src/drivers/interrupts.asm
+++ b/src/drivers/interrupts.asm
@@ -37,6 +37,13 @@ irq_common_stub:
push fs
push gs
+ mov ax, 0x10
+ mov ds, ax
+ mov es, ax
+ mov fs, ax
+ mov gs, ax
+ cld
+
push esp
call irq_handler
add esp, 4
@@ -113,6 +120,13 @@ isr_common_stub:
push fs
push gs
+ mov ax, 0x10
+ mov ds, ax
+ mov es, ax
+ mov fs, ax
+ mov gs, ax
+ cld
+
push esp
call isr_handler
add esp, 4
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()
diff --git a/src/inc/load.h b/src/inc/load.h
index 60fecf9..697248e 100644
--- a/src/inc/load.h
+++ b/src/inc/load.h
@@ -5,6 +5,12 @@
#include <proc.h>
+#define EFLAGS_ALWAYS 0x2 // Always one
+#define EFLAGS_INTERRUPTS 0x200 // Enable interrupts
+
+#define GDT_DATA_OFFSET 0x10 // Data segment offset in GDT
+#define GDT_CODE_OFFSET 0x8 // Code segment offset in GDT
+
void bin_load(char *path, struct proc *proc);
#endif
diff --git a/src/inc/proc.h b/src/inc/proc.h
index bc3d115..dc8b9e9 100644
--- a/src/inc/proc.h
+++ b/src/inc/proc.h
@@ -17,7 +17,6 @@ struct proc {
};
void proc_init();
-void proc_jump(struct proc *proc);
struct proc *proc_make();
#endif