summaryrefslogtreecommitdiff
path: root/arch/i386/boot/tss.c
diff options
context:
space:
mode:
authorDanny Holman <dholman@gymli.org>2022-01-15 16:20:52 -0600
committerDanny Holman <dholman@gymli.org>2022-01-15 16:22:58 -0600
commitacc73186bc3de78ceb0a54cbf2605dff1b9a6d62 (patch)
tree0b2b930e1e9ad4f96d6b91ff7400a14f7d0335c6 /arch/i386/boot/tss.c
parent5db084e3b478be1c9aa9caeeea94b949264aa853 (diff)
arch: i386: simplifiy GDT setup
Simplify the setup and definitions of GDT/TSS entries. Signed-off-by: Danny Holman <dholman@gymli.org>
Diffstat (limited to 'arch/i386/boot/tss.c')
-rw-r--r--arch/i386/boot/tss.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/arch/i386/boot/tss.c b/arch/i386/boot/tss.c
new file mode 100644
index 0000000..2edfa76
--- /dev/null
+++ b/arch/i386/boot/tss.c
@@ -0,0 +1,26 @@
+#include "tss.h"
+#include <kernel/string.h>
+
+struct tss tss_entry;
+
+uint64_t create_tss_entry(uint16_t ss0, uint32_t esp0) {
+ uint32_t base = (uint32_t)&tss_entry;
+ uint32_t limit = base + sizeof(&tss_entry);
+ uint64_t ret = create_gdt_entry(base, limit, 0xE9);
+
+ memset(&tss_entry, 0, sizeof(struct tss));
+ tss_entry.ss0 = ss0;
+ tss_entry.esp0 = esp0;
+ tss_entry.cs = 0x08;
+ tss_entry.ss = 0x13;
+ tss_entry.ds = 0x13;
+ tss_entry.es = 0x13;
+ tss_entry.fs = 0x13;
+ tss_entry.gs = 0x13;
+ tss_entry.io_offset = sizeof(struct tss) & 0xFFFF;
+ return ret;
+}
+
+void set_kernel_stack(uint32_t stack) {
+ tss_entry.esp0 = stack;
+}