#include #include #include "isrs.h" #include "../idt/idt.h" // Assembly coded extern void i86_isr0(); extern void i86_isr1(); extern void i86_isr2(); extern void i86_isr3(); extern void i86_isr4(); extern void i86_isr5(); extern void i86_isr6(); extern void i86_isr7(); extern void i86_isr8(); extern void i86_isr9(); extern void i86_isr10(); extern void i86_isr11(); extern void i86_isr12(); extern void i86_isr13(); extern void i86_isr14(); extern void i86_isr15(); extern void i86_isr16(); extern void i86_isr17(); extern void i86_isr18(); extern void i86_isr19(); extern void i86_isr20(); extern void i86_isr21(); extern void i86_isr22(); extern void i86_isr23(); extern void i86_isr24(); extern void i86_isr25(); extern void i86_isr26(); extern void i86_isr27(); extern void i86_isr28(); extern void i86_isr29(); extern void i86_isr30(); extern void i86_isr31(); void* IdtFaultHandlers[32] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; void i86_IsrsInstall() { i86_IdtSetGate(0, (unsigned)i86_isr0, 0x08, 0x8E); i86_IdtSetGate(1, (unsigned)i86_isr1, 0x08, 0x8E); i86_IdtSetGate(2, (unsigned)i86_isr2, 0x08, 0x8E); i86_IdtSetGate(3, (unsigned)i86_isr3, 0x08, 0x8E); i86_IdtSetGate(4, (unsigned)i86_isr4, 0x08, 0x8E); i86_IdtSetGate(5, (unsigned)i86_isr5, 0x08, 0x8E); i86_IdtSetGate(6, (unsigned)i86_isr6, 0x08, 0x8E); i86_IdtSetGate(7, (unsigned)i86_isr7, 0x08, 0x8E); i86_IdtSetGate(8, (unsigned)i86_isr8, 0x08, 0x8E); i86_IdtSetGate(9, (unsigned)i86_isr9, 0x08, 0x8E); i86_IdtSetGate(10, (unsigned)i86_isr10, 0x08, 0x8E); i86_IdtSetGate(11, (unsigned)i86_isr11, 0x08, 0x8E); i86_IdtSetGate(12, (unsigned)i86_isr12, 0x08, 0x8E); i86_IdtSetGate(13, (unsigned)i86_isr13, 0x08, 0x8E); i86_IdtSetGate(14, (unsigned)i86_isr14, 0x08, 0x8E); i86_IdtSetGate(15, (unsigned)i86_isr15, 0x08, 0x8E); i86_IdtSetGate(16, (unsigned)i86_isr16, 0x08, 0x8E); i86_IdtSetGate(17, (unsigned)i86_isr17, 0x08, 0x8E); i86_IdtSetGate(18, (unsigned)i86_isr18, 0x08, 0x8E); i86_IdtSetGate(19, (unsigned)i86_isr19, 0x08, 0x8E); i86_IdtSetGate(20, (unsigned)i86_isr20, 0x08, 0x8E); i86_IdtSetGate(21, (unsigned)i86_isr21, 0x08, 0x8E); i86_IdtSetGate(22, (unsigned)i86_isr22, 0x08, 0x8E); i86_IdtSetGate(23, (unsigned)i86_isr23, 0x08, 0x8E); i86_IdtSetGate(24, (unsigned)i86_isr24, 0x08, 0x8E); i86_IdtSetGate(25, (unsigned)i86_isr25, 0x08, 0x8E); i86_IdtSetGate(26, (unsigned)i86_isr26, 0x08, 0x8E); i86_IdtSetGate(27, (unsigned)i86_isr27, 0x08, 0x8E); i86_IdtSetGate(28, (unsigned)i86_isr28, 0x08, 0x8E); i86_IdtSetGate(29, (unsigned)i86_isr29, 0x08, 0x8E); i86_IdtSetGate(30, (unsigned)i86_isr30, 0x08, 0x8E); i86_IdtSetGate(31, (unsigned)i86_isr31, 0x08, 0x8E); } void i86_IsrsInstallHandler(int interr, void (*function)(ISR_stack_regs *r)) { if (interr < 32) IdtFaultHandlers[interr] = function; } void i86_IsrsUninstallHandler(int interr) { if (interr < 32) IdtFaultHandlers[interr] = 0; } /* All of our Exception handling Interrupt Service Routines will * point to this function. This will tell us what exception has * happened! Right now, we simply halt the system by hitting an * endless loop. All ISRs disable interrupts while they are being * serviced as a 'locking' mechanism to prevent an IRQ from * happening and messing up kernel data structures */ void i86_FaultHandler(ISR_stack_regs *r) { /* Is this a fault whose number is from 0 to 31? */ if (r->int_no < 32) { void (*func)(ISR_stack_regs *r); func = IdtFaultHandlers[r->int_no]; // Halt system if unhandled if (!func) { cprintf("%#0C*** %#0EFatal error: Unhandled interrupt (INT%u)", r->int_no); for(;;); } else (*func)(r); } }