aboutsummaryrefslogtreecommitdiff
path: root/kernel/inc
diff options
context:
space:
mode:
authorMarvin Borner2021-06-02 22:27:59 +0200
committerMarvin Borner2021-06-02 22:27:59 +0200
commit98e15f73f090c32b5197ecec0845c408d4a54608 (patch)
tree31490731c74b45e2450de56c0c4ea4abd3f3b54d /kernel/inc
parent91ba8d02037cc27c7b44f1bfd492c42ccd0af042 (diff)
Huge scheduler rewrite and other things
Diffstat (limited to 'kernel/inc')
-rw-r--r--kernel/inc/drivers/cpu.h9
-rw-r--r--kernel/inc/drivers/int.h52
-rw-r--r--kernel/inc/drivers/interrupts.h95
-rw-r--r--kernel/inc/drivers/pic.h11
-rw-r--r--kernel/inc/drivers/timer.h5
-rw-r--r--kernel/inc/io.h2
-rw-r--r--kernel/inc/mm.h3
-rw-r--r--kernel/inc/proc.h23
8 files changed, 83 insertions, 117 deletions
diff --git a/kernel/inc/drivers/cpu.h b/kernel/inc/drivers/cpu.h
index 75e0495..36b8928 100644
--- a/kernel/inc/drivers/cpu.h
+++ b/kernel/inc/drivers/cpu.h
@@ -4,6 +4,7 @@
#define CPU_H
#include <def.h>
+#include <proc.h>
UNUSED_FUNC static inline void spinlock(u32 *ptr)
{
@@ -21,9 +22,12 @@ void outb(u16 port, u8 data);
void outw(u16 port, u16 data);
void outl(u16 port, u32 data);
+void fpu_init(struct proc *proc);
+void fpu_save(struct proc *proc);
+void fpu_restore(struct proc *proc);
+
void cpu_print(void);
void cpu_enable_features(void);
-void fpu_restore(void);
u32 cr0_get(void);
void cr0_set(u32 cr0);
@@ -35,9 +39,6 @@ void cr4_set(u32 cr4);
void clac(void);
void stac(void);
-void cli(void);
-void sti(void);
-
struct cpuid {
u32 eax;
u32 ebx;
diff --git a/kernel/inc/drivers/int.h b/kernel/inc/drivers/int.h
new file mode 100644
index 0000000..8146898
--- /dev/null
+++ b/kernel/inc/drivers/int.h
@@ -0,0 +1,52 @@
+// MIT License, Copyright (c) 2020 Marvin Borner
+
+#ifndef IDT_H
+#define IDT_H
+
+#include <def.h>
+
+#define INT_GATE 0x8e
+#define INT_TRAP 0xef
+#define INT_USER 0x60
+#define IDT_ENTRY(offset, selector, type) \
+ (struct idt_entry) \
+ { \
+ .base_low = (u16)((offset)&0xffff), .sel = (selector), .zero = 0, .flags = (type), \
+ .base_high = (u16)(((offset) >> 16) & 0xffff), \
+ }
+
+struct int_frame {
+ u32 gs, fs, es, ds;
+ u32 edi, esi, ebp, esp, ebx, edx, ecx, eax;
+ u32 int_no, err_code;
+ u32 eip, cs, eflags;
+} PACKED;
+
+struct int_frame_user {
+ u32 gs, fs, es, ds;
+ u32 edi, esi, ebp, esp, ebx, edx, ecx, eax;
+ u32 int_no, err_code;
+ u32 eip, cs, eflags;
+ u32 useresp, ss;
+} PACKED;
+
+struct idt_entry {
+ u16 base_low;
+ u16 sel; // Kernel segment
+ u8 zero; // Always 0
+ u8 flags;
+ u16 base_high;
+} PACKED;
+
+struct idt_ptr {
+ u16 size;
+ void *base;
+} PACKED;
+
+void idt_install(void);
+
+void int_trap_handler_add(u32 int_no, void (*handler)(u32 esp));
+void int_event_handler_add(u32 int_no, void (*handler)(void));
+void int_special_handler_add(u32 int_no, u32 (*handler)(u32 esp));
+
+#endif
diff --git a/kernel/inc/drivers/interrupts.h b/kernel/inc/drivers/interrupts.h
deleted file mode 100644
index 7c0c1e7..0000000
--- a/kernel/inc/drivers/interrupts.h
+++ /dev/null
@@ -1,95 +0,0 @@
-// MIT License, Copyright (c) 2020 Marvin Borner
-
-#ifndef IDT_H
-#define IDT_H
-
-#include <def.h>
-
-struct regs {
- u32 gs, fs, es, ds;
- u32 edi, esi, ebp, esp, ebx, edx, ecx, eax;
- u32 int_no, err_code;
- u32 eip, cs, eflags, useresp, ss;
-};
-
-struct idt_entry {
- u16 base_low;
- u16 sel; // Kernel segment
- u8 always0; // Always 0
- u8 flags;
- u16 base_high;
-} PACKED;
-
-struct idt_ptr {
- u16 limit;
- void *base;
-} PACKED;
-
-void idt_set_gate(u8 num, u32 base, u16 sel, u8 flags);
-
-void irq_install_handler(int irq, void (*handler)(struct regs *r)) NONNULL;
-void irq_uninstall_handler(int irq);
-
-void isr_install_handler(int isr, void (*handler)(struct regs *r)) NONNULL;
-void isr_uninstall_handler(int isr);
-void isr_panic(struct regs *r) NONNULL;
-
-void interrupts_install(void);
-
-// External handlers (ASM)
-
-extern void isr0(struct regs *r);
-extern void isr1(struct regs *r);
-extern void isr2(struct regs *r);
-extern void isr3(struct regs *r);
-extern void isr4(struct regs *r);
-extern void isr5(struct regs *r);
-extern void isr6(struct regs *r);
-extern void isr7(struct regs *r);
-extern void isr8(struct regs *r);
-extern void isr9(struct regs *r);
-extern void isr10(struct regs *r);
-extern void isr11(struct regs *r);
-extern void isr12(struct regs *r);
-extern void isr13(struct regs *r);
-extern void isr14(struct regs *r);
-extern void isr15(struct regs *r);
-extern void isr16(struct regs *r);
-extern void isr17(struct regs *r);
-extern void isr18(struct regs *r);
-extern void isr19(struct regs *r);
-extern void isr20(struct regs *r);
-extern void isr21(struct regs *r);
-extern void isr22(struct regs *r);
-extern void isr23(struct regs *r);
-extern void isr24(struct regs *r);
-extern void isr25(struct regs *r);
-extern void isr26(struct regs *r);
-extern void isr27(struct regs *r);
-extern void isr28(struct regs *r);
-extern void isr29(struct regs *r);
-extern void isr30(struct regs *r);
-extern void isr31(struct regs *r);
-extern void isr127(struct regs *r);
-extern void isr128(struct regs *r);
-
-extern void irq0(struct regs *r);
-extern void irq1(struct regs *r);
-extern void irq2(struct regs *r);
-extern void irq3(struct regs *r);
-extern void irq4(struct regs *r);
-extern void irq5(struct regs *r);
-extern void irq6(struct regs *r);
-extern void irq7(struct regs *r);
-extern void irq8(struct regs *r);
-extern void irq9(struct regs *r);
-extern void irq10(struct regs *r);
-extern void irq11(struct regs *r);
-extern void irq12(struct regs *r);
-extern void irq13(struct regs *r);
-extern void irq14(struct regs *r);
-extern void irq15(struct regs *r);
-extern void irq127(struct regs *r);
-extern void irq128(struct regs *r);
-
-#endif
diff --git a/kernel/inc/drivers/pic.h b/kernel/inc/drivers/pic.h
new file mode 100644
index 0000000..c2a7d87
--- /dev/null
+++ b/kernel/inc/drivers/pic.h
@@ -0,0 +1,11 @@
+// MIT License, Copyright (c) 2021 Marvin Borner
+
+#ifndef PIC_H
+#define PIC_H
+
+#include <def.h>
+
+void pic_install(void);
+void pic_ack(u32 int_no);
+
+#endif
diff --git a/kernel/inc/drivers/timer.h b/kernel/inc/drivers/timer.h
index 9ff23f8..ea1643b 100644
--- a/kernel/inc/drivers/timer.h
+++ b/kernel/inc/drivers/timer.h
@@ -4,14 +4,9 @@
#define TIMER_H
#include <def.h>
-#include <drivers/interrupts.h>
u32 timer_get(void);
void timer_wait(u32 ticks);
void timer_install(void);
-void timer_handler(struct regs *r) NONNULL;
-
-void scheduler_enable(void);
-void scheduler_disable(void);
#endif
diff --git a/kernel/inc/io.h b/kernel/inc/io.h
index 275fcae..c20a6f7 100644
--- a/kernel/inc/io.h
+++ b/kernel/inc/io.h
@@ -4,7 +4,7 @@
#define IO_H
#include <def.h>
-#include <drivers/interrupts.h>
+#include <drivers/int.h>
#include <proc.h>
#include <sys.h>
diff --git a/kernel/inc/mm.h b/kernel/inc/mm.h
index 0a2bb81..4f3f537 100644
--- a/kernel/inc/mm.h
+++ b/kernel/inc/mm.h
@@ -4,7 +4,7 @@
#define PAGING_H
#include <def.h>
-#include <drivers/interrupts.h>
+#include <drivers/int.h>
#include <errno.h>
struct memory_range {
@@ -18,7 +18,6 @@ struct memory_range {
void paging_disable(void);
void paging_enable(void);
-void page_fault_handler(struct regs *r) NONNULL;
/**
* Physical
diff --git a/kernel/inc/proc.h b/kernel/inc/proc.h
index 1144782..b8310d1 100644
--- a/kernel/inc/proc.h
+++ b/kernel/inc/proc.h
@@ -4,12 +4,12 @@
#define PROC_H
#include <def.h>
-#include <drivers/interrupts.h>
+#include <drivers/int.h>
#include <list.h>
#include <stack.h>
#include <sys.h>
-#define PROC_QUANTUM 42 // Milliseconds or something // TODO
+#define PROC_QUANTUM 15 // Milliseconds or something // TODO
#define PROC_STACK_SIZE 0x4000 // 16KiB
#define EFLAGS_ALWAYS 0x2 // Always one
@@ -26,8 +26,8 @@ struct proc {
char name[64];
char dir[64];
+ u8 fpu[512];
struct page_dir *page_dir;
- struct regs regs;
enum proc_priv priv;
enum proc_state state;
struct stack *messages;
@@ -37,7 +37,9 @@ struct proc {
struct {
u32 user;
+ u32 user_ptr;
u32 kernel;
+ u32 kernel_ptr;
} stack;
struct {
@@ -51,20 +53,21 @@ struct proc {
} quantum;
};
-void scheduler(struct regs *regs) NONNULL;
+u32 scheduler(u32 esp);
NORETURN void proc_init(void);
void proc_print(void);
struct proc *proc_current(void);
u8 proc_super(void);
u8 proc_idle(void);
struct proc *proc_from_pid(u32 pid);
-void proc_exit(struct proc *proc, struct regs *r, s32 status) NONNULL;
+void proc_exit(struct proc *proc, s32 status) NONNULL;
void proc_yield(void);
-void proc_yield_regs(struct regs *r) NONNULL;
-void proc_set_quantum(struct proc *proc, u32 value);
-void proc_reset_quantum(struct proc *proc);
-void proc_state(struct proc *proc, enum proc_state state);
+void proc_set_quantum(struct proc *proc, u32 value) NONNULL;
+void proc_reset_quantum(struct proc *proc) NONNULL;
+void proc_state(struct proc *proc, enum proc_state state) NONNULL;
struct proc *proc_make(enum proc_priv priv);
-void proc_stack_push(struct proc *proc, u32 data) NONNULL;
+void proc_make_regs(struct proc *proc);
+void proc_stack_user_push(struct proc *proc, const void *data, u32 size) NONNULL;
+void proc_stack_kernel_push(struct proc *proc, const void *data, u32 size) NONNULL;
#endif