summaryrefslogtreecommitdiff
path: root/src/kernel/mem
diff options
context:
space:
mode:
authorAlexis211 <alexis211@gmail.com>2010-02-09 12:44:06 +0100
committerAlexis211 <alexis211@gmail.com>2010-02-09 12:44:06 +0100
commit4886faa3dce410543eda2139221e03959e73a747 (patch)
treee74cedd7b8a89005c802ddd3ce38f7ab5b8c4fb4 /src/kernel/mem
parent6a52d123672b7a00af6e22b4c138205be2042a94 (diff)
downloadTCE-4886faa3dce410543eda2139221e03959e73a747.tar.gz
TCE-4886faa3dce410543eda2139221e03959e73a747.zip
Added user mode support and monitor_writeDec
Diffstat (limited to 'src/kernel/mem')
-rw-r--r--src/kernel/mem/gdt.c24
-rw-r--r--src/kernel/mem/gdt.h31
-rw-r--r--src/kernel/mem/paging.c2
3 files changed, 55 insertions, 2 deletions
diff --git a/src/kernel/mem/gdt.c b/src/kernel/mem/gdt.c
index 5aaad41..18a5fa7 100644
--- a/src/kernel/mem/gdt.c
+++ b/src/kernel/mem/gdt.c
@@ -3,12 +3,18 @@
#include <core/monitor.h>
extern void gdt_flush(uint32_t); //ASM (idt_.asm)
+extern void tss_flush();
-#define GDT_ENTRIES 5
+#define GDT_ENTRIES 6
+static struct tss_entry tss_entry;
static struct gdt_entry gdt_entries[GDT_ENTRIES];
static struct gdt_ptr gdt_ptr;
+void gdt_setKernelStack(uint32_t esp0) {
+ tss_entry.esp0 = esp0;
+}
+
static void gdt_setGate(int num, uint32_t base, uint32_t limit, uint8_t access, uint8_t gran) {
gdt_entries[num].base_low = (base & 0xFFFF);
gdt_entries[num].base_middle = (base >> 16) & 0xFF;
@@ -20,6 +26,20 @@ static void gdt_setGate(int num, uint32_t base, uint32_t limit, uint8_t access,
gdt_entries[num].access = access;
}
+static void gdt_writeTss(int num, uint32_t ss0, uint32_t esp0) {
+ uint32_t base = (uint32_t)&tss_entry;
+ uint32_t limit = base + sizeof(struct tss_entry);
+
+ gdt_setGate(num, base, limit, 0xE9, 0);
+
+ memset(&tss_entry, 0, sizeof(struct tss_entry));
+
+ tss_entry.ss0 = ss0; tss_entry.esp0 = esp0;
+
+ tss_entry.cs = 0x0b;
+ tss_entry.ss = tss_entry.ds = tss_entry.es = tss_entry.fs = tss_entry.gs = 0x13;
+}
+
void gdt_init() {
gdt_ptr.limit = (sizeof(struct gdt_entry) * GDT_ENTRIES) - 1;
gdt_ptr.base = (uint32_t)&gdt_entries;
@@ -29,8 +49,10 @@ void gdt_init() {
gdt_setGate(2, 0, 0xFFFFFFFF, 0x92, 0xCF); //Kernel data segment
gdt_setGate(3, 0, 0xFFFFFFFF, 0xFA, 0xCF); //User code segment
gdt_setGate(4, 0, 0xFFFFFFFF, 0xF2, 0xCF); //User data segment
+ gdt_writeTss(5, 0x10, 0);
gdt_flush((uint32_t)&gdt_ptr);
+ tss_flush();
monitor_write("GDT ok\n");
}
diff --git a/src/kernel/mem/gdt.h b/src/kernel/mem/gdt.h
index aac16bb..485002b 100644
--- a/src/kernel/mem/gdt.h
+++ b/src/kernel/mem/gdt.h
@@ -17,7 +17,38 @@ struct gdt_ptr {
uint32_t base;
} __attribute__((packed));
+struct tss_entry {
+ uint32_t prev_tss; // The previous TSS - if we used hardware task switching this would form a linked list.
+ uint32_t esp0; // The stack pointer to load when we change to kernel mode.
+ uint32_t ss0; // The stack segment to load when we change to kernel mode.
+ uint32_t esp1; // Unused...
+ uint32_t ss1;
+ uint32_t esp2;
+ uint32_t ss2;
+ uint32_t cr3;
+ uint32_t eip;
+ uint32_t eflags;
+ uint32_t eax;
+ uint32_t ecx;
+ uint32_t edx;
+ uint32_t ebx;
+ uint32_t esp;
+ uint32_t ebp;
+ uint32_t esi;
+ uint32_t edi;
+ uint32_t es; // The value to load into ES when we change to kernel mode.
+ uint32_t cs; // The value to load into CS when we change to kernel mode.
+ uint32_t ss; // The value to load into SS when we change to kernel mode.
+ uint32_t ds; // The value to load into DS when we change to kernel mode.
+ uint32_t fs; // The value to load into FS when we change to kernel mode.
+ uint32_t gs; // The value to load into GS when we change to kernel mode.
+ uint32_t ldt; // Unused...
+ uint16_t trap;
+ uint16_t iomap_base;
+} __attribute__((packed));
+
void gdt_init();
+void gdt_setKernelStack(uint32_t esp0);
#endif
diff --git a/src/kernel/mem/paging.c b/src/kernel/mem/paging.c
index 27ce043..d478e05 100644
--- a/src/kernel/mem/paging.c
+++ b/src/kernel/mem/paging.c
@@ -116,7 +116,7 @@ uint32_t paging_fault(struct registers *regs) {
}
if (seg == 0) {
- monitor_write("(paging.c:119) Unhandled Page Fault ");
+ WHERE; monitor_write("Unhandled Page Fault ");
if (regs->err_code & 0x1) monitor_write("present ");
if (regs->err_code & 0x2) monitor_write("write ");
if (regs->err_code & 0x4) monitor_write("user ");