Begin multitasking refactor to support ring-3 TSS
diff --git a/src/kernel/descriptor_tables.c b/src/kernel/descriptor_tables.c
index 211dcb2..339162e 100644
--- a/src/kernel/descriptor_tables.c
+++ b/src/kernel/descriptor_tables.c
@@ -7,6 +7,7 @@
 
 extern void gdt_flush(uint gdt);
 extern void idt_flush(uint idt);
+extern void tss_flush();
 
 static void gdt_set_gate(uint i, uint base, uint limit, uchar access,
 						 uchar gran);
@@ -29,26 +30,7 @@
 
 extern void (*interrupt_handlers[256])(struct registers);
 
-void init_gdt()
-{
-	vga_write("Initializing GDT...\n");
-	gdt_pointer.limit = sizeof(struct gdt_entry) * 5 - 1;
-	gdt_pointer.base = (uint)&gdt_entries;
-
-	gdt_set_gate(0, 0, 0, 0, 0);		// Null segment
-	gdt_set_gate(1, 0, ~0, 0x9a, 0xcf); // Code segment
-	gdt_set_gate(2, 0, ~0, 0x92, 0xcf); // Data segment
-	gdt_set_gate(3, 0, ~0, 0xfa, 0xcf); // User mode code segment
-	gdt_set_gate(4, 0, ~0, 0xf2, 0xcf); // User mode data segment
-
-	for (volatile uint i = 0; i < 0x1000; i++)
-	{
-	} // waste some time, for some reason this helps
-
-	gdt_flush((uint)&gdt_pointer);
-
-	vga_write("GDT Initialized\n");
-}
+struct tss_entry tss_entry;
 
 static void gdt_set_gate(uint i, uint base, uint limit, uchar access,
 						 uchar gran)
@@ -65,6 +47,44 @@
 	e->access = access;
 }
 
+static void init_tss(uint num, uint ss, uint esp)
+{
+	gdt_set_gate(num, (uint)&tss_entry, (uint)&tss_entry+1, 0xe9, 0x00);
+
+	memset(&tss_entry, 0, sizeof(tss_entry));
+
+	tss_entry.ss0 = ss;
+	tss_entry.esp0 = esp;
+	tss_entry.cs = 0x0b;
+	// | 0b11 to make these readable from user-mode. i.e. user mode
+	// can switch to kernel mode using this tss
+	tss_entry.ss = tss_entry.ds = tss_entry.es = tss_entry.fs = tss_entry.gs = 0x13;
+}
+
+void init_gdt()
+{
+	vga_write("Initializing GDT...\n");
+	gdt_pointer.limit = sizeof(struct gdt_entry) * 5 - 1;
+	gdt_pointer.base = (uint)&gdt_entries;
+
+	gdt_set_gate(0, 0, 0, 0, 0);		// Null segment, 0x00
+	gdt_set_gate(1, 0, ~0, 0x9a, 0xcf); // Code segment, 0x08
+	gdt_set_gate(2, 0, ~0, 0x92, 0xcf); // Data segment, 0x10
+	gdt_set_gate(3, 0, ~0, 0xfa, 0xcf); // User mode code segment, 0x18
+	gdt_set_gate(4, 0, ~0, 0xf2, 0xcf); // User mode data segment, 0x20
+	//init_tss(5, 0x10, 0x0); // 0x10 = kernel data segment, 0x28
+
+	for (volatile uint i = 0; i < 0x1000; i++)
+	{
+	} // waste some time, for some reason this helps
+
+	gdt_flush((uint)&gdt_pointer);
+	// For now let's not do this
+	// tss_flush();
+
+	vga_write("GDT Initialized\n");
+}
+
 void init_idt()
 {
 	idt_pointer.limit = sizeof(struct idt_entry) * 256 - 1;
@@ -114,3 +134,8 @@
 	init_gdt();
 	init_idt();
 }
+
+void set_kernel_interrupt_stack(void *stack)
+{
+	tss_entry.esp0 = (uint)stack;
+}