summaryrefslogtreecommitdiff
path: root/arch/i386/include/kernel/idt.h
diff options
context:
space:
mode:
authorDanny Holman <dholman@gymli.xyz>2021-09-28 09:08:38 -0500
committerDanny Holman <dholman@gymli.xyz>2021-09-28 09:28:33 -0500
commitc0019e9d0bd2059351dc7d0274ee0479a71192fc (patch)
tree99a9ee22a5e8a102e719d6710226b9c181fae74a /arch/i386/include/kernel/idt.h
parent0ec9e9824e32d3d54d2ad43c3f2743d52127aa92 (diff)
arch: i386: fix IDT exception handler
Fix the i386's general exception handler to actually work. Fix provided by Jon Sanderson (jjs295356@gmail.com). Signed-off-by: Danny Holman <dholman@gymli.xyz>
Diffstat (limited to 'arch/i386/include/kernel/idt.h')
-rw-r--r--arch/i386/include/kernel/idt.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/arch/i386/include/kernel/idt.h b/arch/i386/include/kernel/idt.h
new file mode 100644
index 0000000..7ccad30
--- /dev/null
+++ b/arch/i386/include/kernel/idt.h
@@ -0,0 +1,35 @@
+#ifndef I386_IDT_H
+#define I386_IDT_H
+
+#include <stdint.h>
+
+// IDT Flags
+#define SEGMENT_PRESENT 0x8
+#define SEGMENT_RING0 0x0
+#define SEGMENT_STORAGE 0x0
+#define SEGMENT_GATE 0xE
+#define SEGMENT_DPL 0x8
+
+#define SEGMENT_FLAG SEGMENT_PRESENT | SEGMENT_RING0 | SEGMENT_STORAGE |\
+ SEGMENT_GATE | SEGMENT_DPL;
+
+struct idt_entry {
+ uint16_t isr_low;
+ uint16_t kernel_cs;
+ uint8_t reserved;
+ uint8_t flags;
+ uint16_t isr_high;
+} __attribute__((packed));
+
+struct idt_ptr {
+ uint16_t limit;
+ uint32_t base;
+} __attribute__((packed));
+
+extern struct idt_entry idt[256];
+extern struct idt_ptr idtr;
+
+extern void idt_set_gate(uint8_t num, void(*handler)(void), uint16_t cs, uint8_t flags);
+extern void exception_handler(int num);
+
+#endif \ No newline at end of file