BarryServer : Git

All the code for all my projects
// BarryServer : Git / Nucleus / commit / c738dbb1e7e7a46a98436326234826eef71083e2 / kernel / idt.c

// Related

Nucleus

Barry CPU specific segment c738dbb (3 years, 2 months ago)
diff --git a/kernel/idt.c b/kernel/idt.c
index a9f7c79..6aceb88 100644
--- a/kernel/idt.c
+++ b/kernel/idt.c
@@ -28,10 +28,14 @@ void (**interrupts)(struct InterruptFrame *);
 static void
 install_idt_entry(uint8_t num, void *addr)
 {
+	uint8_t type = 0x8E; /* Interrupt gate */
+	if (num < 32)
+		type = 0x8F; /* Trap gate for exceptions */
+
 	IDT[num].offsetLower = (uintptr_t) addr & 0xFFFF;
 	IDT[num].selector = 0x08;
 	IDT[num].zero = 0;
-	IDT[num].typeAttr = 0x8E | 0x60; /* Allowed from ring 3 */
+	IDT[num].typeAttr = type | 0x60; /* Allowed from ring 3 */
 	IDT[num].offsetHigher = (uintptr_t) addr >> 16;
 }
 
@@ -41,11 +45,12 @@ isr_handler(struct InterruptFrame frame)
 {
 	if (!exceptions[frame.intnum] && frame.intnum < 32)
 		panic("[CPU#%d] Failed to handle exception %d (%#.8x) @ %#.8x",
-		      CPUID, frame.intnum, frame.err, frame.eip);
+		      cpu->id, frame.intnum, frame.err, frame.eip);
 
 	/* Run registered handler */
-	if (exceptions[frame.intnum])
-		exceptions[frame.intnum](&frame);
+	exc_handler_t handler = exceptions[frame.intnum];
+	if (handler)
+		handler(&frame);
 
 	/* Send EOI */
 	if (frame.intnum >= 40 && frame.intnum < 48)
@@ -62,7 +67,7 @@ isr_handler(struct InterruptFrame frame)
 void
 register_exception(int num, exc_handler_t addr)
 {
-	if ((num >= 0 && num < 32) || num >= 48)
+	if (num >= 0 && num < 256)
 		exceptions[num] = addr;
 }