summaryrefslogtreecommitdiff
path: root/kernel/gdt.c
diff options
context:
space:
mode:
authordzwdz2021-06-25 16:22:43 +0200
committerdzwdz2021-06-25 16:22:43 +0200
commitf60d40f3bf4dfe8ed6f63a27367d323319a4ef97 (patch)
tree1cde54eb600106d0d1fc11927f55d5a03eb2b4aa /kernel/gdt.c
parent376325d08388d9103ca2f57aceb60c4a507a42aa (diff)
ring3
Diffstat (limited to 'kernel/gdt.c')
-rw-r--r--kernel/gdt.c20
1 files changed, 7 insertions, 13 deletions
diff --git a/kernel/gdt.c b/kernel/gdt.c
index 8d1ac65..8a29032 100644
--- a/kernel/gdt.c
+++ b/kernel/gdt.c
@@ -1,4 +1,6 @@
+#include <kernel/gdt.h>
#include <kernel/tty.h>
+#include <kernel/util.h>
#include <stdint.h>
extern void stack_top; // platform/boot.s
@@ -36,16 +38,6 @@ struct lgdt_arg {
uint32_t base;
} __attribute__((packed));
-enum {
- SEG_null,
- SEG_r0data,
- SEG_r0code,
- SEG_r3data,
- SEG_r3code,
- SEG_TSS,
-
- SEG_end
-};
static struct gdt_entry GDT[SEG_end];
static struct tss_entry TSS;
static struct lgdt_arg lgdt_arg; // probably doesn't need to be global
@@ -84,7 +76,7 @@ static void gdt_prepare() {
GDT[SEG_r3data].ring = 3;
// tss
- // TODO memset(&TSS, 0, sizeof(TSS));
+ memset(&TSS, 0, sizeof(TSS));
TSS.ss0 = SEG_r0data << SEG_r3data; // kernel data segment
TSS.esp0 = (uint32_t) &stack_top;
@@ -108,13 +100,15 @@ static void gdt_prepare() {
static void gdt_load() {
lgdt_arg.limit = sizeof(GDT) - 1;
lgdt_arg.base = (uint32_t) &GDT;
- asm("lgdt (%0)" : : "b" (&lgdt_arg));
+ asm("lgdt (%0)" : : "r" (&lgdt_arg) : "memory");
+
+ asm("ltr %%ax" : : "a" (SEG_TSS << 3 | 3) : "memory");
}
static void gdt_check() {
tty_write("checking gdt...", 15);
asm("mov %0, %%ds;"
- : : "r" (SEG_r0data << 3));
+ : : "r" (SEG_r0data << 3) : "memory");
tty_write("ok", 2);
}