fix: interrupt handler function uses an array
fix: gdt calls cli asm instruction at init
This commit is contained in:
parent
14758ff4ea
commit
d348ac109e
@ -4,6 +4,7 @@
|
||||
.global set_gdt
|
||||
|
||||
set_gdt:
|
||||
cli // disable all interrupts
|
||||
mov eax, [esp+4] // 1st parameter : pointer to the IDT
|
||||
lgdt [eax]
|
||||
mov ax, 0x10 // 0x10 is the offset in the GDT to our data segment
|
||||
|
@ -1,76 +1,48 @@
|
||||
#include "interrupts.h"
|
||||
#include "kpanic.h"
|
||||
#include "kprintf.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
const char *faults[] = {
|
||||
"division by zero",
|
||||
"debugger",
|
||||
"NMI",
|
||||
"breakpoint",
|
||||
"overflow",
|
||||
"bounds",
|
||||
"invalid opcode",
|
||||
"coprocessor not available",
|
||||
"double fault",
|
||||
"coprocessor segement overrun",
|
||||
"invalid task state segment",
|
||||
"segment not present",
|
||||
"stack fault",
|
||||
"general protection fault",
|
||||
"page fault",
|
||||
"reserved",
|
||||
"math fault",
|
||||
"alignment check",
|
||||
"machine check",
|
||||
"SIMD floating point exception",
|
||||
};
|
||||
|
||||
void exception_handler(void)
|
||||
{
|
||||
int8_t index = -1;
|
||||
__asm__ volatile("movb %%bl, %0" ::"m"(index));
|
||||
|
||||
switch (index) {
|
||||
case 0:
|
||||
kpanic("interrupt: division by zero\n");
|
||||
break;
|
||||
case 1:
|
||||
kpanic("interrupt: debugger\n");
|
||||
break;
|
||||
case 2:
|
||||
kpanic("interrupt: NMI\n");
|
||||
break;
|
||||
case 3:
|
||||
kpanic("interrupt: breakpoint\n");
|
||||
break;
|
||||
case 4:
|
||||
kpanic("interrupt: overflow\n");
|
||||
break;
|
||||
case 5:
|
||||
kpanic("interrupt: bounds\n");
|
||||
break;
|
||||
case 6:
|
||||
kpanic("interrupt: invalid opcode\n");
|
||||
break;
|
||||
case 7:
|
||||
kpanic("interrupt: coprocessor not available\n");
|
||||
break;
|
||||
case 8:
|
||||
kpanic("interrupt: double fault\n");
|
||||
break;
|
||||
case 9:
|
||||
kpanic("interrupt: coprocessor segement overrun\n");
|
||||
break;
|
||||
case 10:
|
||||
kpanic("interrupt: invalid task state segment\n");
|
||||
break;
|
||||
case 11:
|
||||
kpanic("interrupt: segment not present\n");
|
||||
break;
|
||||
case 12:
|
||||
kpanic("interrupt: stack fault\n");
|
||||
break;
|
||||
case 13:
|
||||
kpanic("interrupt: general protection fault\n");
|
||||
break;
|
||||
case 14:
|
||||
kpanic("interrupt: page fault\n");
|
||||
break;
|
||||
case 15:
|
||||
kpanic("interrupt: reserved\n");
|
||||
break;
|
||||
case 16:
|
||||
kpanic("interrupt: math fault\n");
|
||||
break;
|
||||
case 17:
|
||||
kpanic("interrupt: alignment check\n");
|
||||
break;
|
||||
case 18:
|
||||
kpanic("interrupt: machine check\n");
|
||||
break;
|
||||
case 19:
|
||||
kpanic("interrupt: SIMD floating point exception\n");
|
||||
break;
|
||||
default:
|
||||
if (index == -1) {
|
||||
kprintf(KERN_ERR "interrupt triggered without a code\n");
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
uint8_t i = 0;
|
||||
while (i < ARRAY_SIZE(faults)) {
|
||||
if (i == index)
|
||||
kpanic("interrupt: %s\n", faults[i]);
|
||||
i++;
|
||||
}
|
||||
kprintf(KERN_ERR "interrupt triggered with no matching code\n");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user