summaryrefslogtreecommitdiff
path: root/kernel/idt.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/idt.c')
-rw-r--r--kernel/idt.c122
1 files changed, 87 insertions, 35 deletions
diff --git a/kernel/idt.c b/kernel/idt.c
index 3fdc3dc..5633c61 100644
--- a/kernel/idt.c
+++ b/kernel/idt.c
@@ -1,40 +1,5 @@
#include "idt.h"
-#define outb(port, value) asm volatile("out %b0,%w1" : : "a" (value), "d" (port));
-
-#define isr_panic(num) void isr_ ## num(); \
-asm( \
- ".globl isr_" #num "\n" \
- "isr_" #num ":\n" \
- "push $" #num "\n" \
- "call panic\n" \
- "iret\n" \
-)
-
-char* panic_msg[] = {
- [0] = "Divide error.",
- [8] = "Double fault.",
- [14] = "Page fault."
-};
-
-isr_panic(0);
-isr_panic(8);
-isr_panic(14);
-
-void panic(uint32_t num) {
- char* str = panic_msg[num];
- while(*str) {
- outb(0x3f8, *str++);
- }
- outb(0x3f8, '\r');
- outb(0x3f8, '\n');
- asm volatile(
- "cli\n"
- "hlt\n"
- );
- while(1);
-}
-
idt_entry idt[] = {
{.base_low = 1}, // Keep IDT in .data.
[1 ... 255] = idt_entry_null
@@ -52,10 +17,97 @@ void idt_set_gate(uint8_t num, uint32_t base, uint16_t segment, uint16_t flags)
idt[num].flags = flags;
}
+#define isr_panic(num) void isr_ ## num(); \
+asm( \
+ ".globl isr_" #num "\n" \
+ "isr_" #num ":\n" \
+ "push $0\n" \
+ "push $" #num "\n" \
+ "pusha\n" \
+ "push %ds\n" \
+ "push %ss\n" \
+ "call panic\n" \
+)
+
+#define isr_panic_e(num) void isr_ ## num(); \
+asm( \
+ ".globl isr_" #num "\n" \
+ "isr_" #num ":\n" \
+ "push $" #num "\n" \
+ "pusha\n" \
+ "push %ds\n" \
+ "push %ss\n" \
+ "call panic\n" \
+)
+
+isr_panic(0);
+isr_panic(1);
+isr_panic(2);
+isr_panic(3);
+isr_panic(4);
+isr_panic(5);
+isr_panic(6);
+isr_panic(7);
+isr_panic_e(8);
+isr_panic(9);
+isr_panic_e(10);
+isr_panic_e(11);
+isr_panic_e(12);
+isr_panic_e(13);
+isr_panic_e(14);
+isr_panic(15);
+isr_panic(16);
+isr_panic_e(17);
+isr_panic(18);
+isr_panic(19);
+isr_panic(20);
+isr_panic(21);
+isr_panic(22);
+isr_panic(23);
+isr_panic(24);
+isr_panic(25);
+isr_panic(26);
+isr_panic(27);
+isr_panic(28);
+isr_panic(29);
+isr_panic(30);
+isr_panic(31);
+
+
void idt_init() {
idt_set_gate(0, (uint32_t)isr_0, 0x08, 0x8e00);
+ idt_set_gate(1, (uint32_t)isr_1, 0x08, 0x8e00);
+ idt_set_gate(2, (uint32_t)isr_2, 0x08, 0x8e00);
+ idt_set_gate(3, (uint32_t)isr_3, 0x08, 0x8e00);
+ idt_set_gate(4, (uint32_t)isr_4, 0x08, 0x8e00);
+ idt_set_gate(5, (uint32_t)isr_5, 0x08, 0x8e00);
+ idt_set_gate(6, (uint32_t)isr_6, 0x08, 0x8e00);
+ idt_set_gate(7, (uint32_t)isr_7, 0x08, 0x8e00);
idt_set_gate(8, (uint32_t)isr_8, 0x08, 0x8e00);
+ idt_set_gate(9, (uint32_t)isr_9, 0x08, 0x8e00);
+ idt_set_gate(10, (uint32_t)isr_10, 0x08, 0x8e00);
+ idt_set_gate(11, (uint32_t)isr_11, 0x08, 0x8e00);
+ idt_set_gate(12, (uint32_t)isr_12, 0x08, 0x8e00);
+ idt_set_gate(13, (uint32_t)isr_13, 0x08, 0x8e00);
idt_set_gate(14, (uint32_t)isr_14, 0x08, 0x8e00);
+ idt_set_gate(15, (uint32_t)isr_15, 0x08, 0x8e00);
+ idt_set_gate(16, (uint32_t)isr_16, 0x08, 0x8e00);
+ idt_set_gate(17, (uint32_t)isr_17, 0x08, 0x8e00);
+ idt_set_gate(18, (uint32_t)isr_18, 0x08, 0x8e00);
+ idt_set_gate(19, (uint32_t)isr_19, 0x08, 0x8e00);
+ idt_set_gate(10, (uint32_t)isr_20, 0x08, 0x8e00);
+ idt_set_gate(21, (uint32_t)isr_21, 0x08, 0x8e00);
+ idt_set_gate(22, (uint32_t)isr_22, 0x08, 0x8e00);
+ idt_set_gate(23, (uint32_t)isr_23, 0x08, 0x8e00);
+ idt_set_gate(24, (uint32_t)isr_24, 0x08, 0x8e00);
+ idt_set_gate(25, (uint32_t)isr_25, 0x08, 0x8e00);
+ idt_set_gate(26, (uint32_t)isr_26, 0x08, 0x8e00);
+ idt_set_gate(27, (uint32_t)isr_27, 0x08, 0x8e00);
+ idt_set_gate(28, (uint32_t)isr_28, 0x08, 0x8e00);
+ idt_set_gate(29, (uint32_t)isr_29, 0x08, 0x8e00);
+ idt_set_gate(30, (uint32_t)isr_30, 0x08, 0x8e00);
+ idt_set_gate(31, (uint32_t)isr_31, 0x08, 0x8e00);
+
asm volatile(
"lidt (%0)\n"
: : "r" (&idtr)