115 lines
3.6 KiB
C
115 lines
3.6 KiB
C
|
#include <debugio.h>
|
||
|
|
||
|
#include "isrs.h"
|
||
|
#include "idt.h"
|
||
|
|
||
|
// Assembly coded
|
||
|
extern void isr_exception_0();
|
||
|
extern void isr_exception_1();
|
||
|
extern void isr_exception_2();
|
||
|
extern void isr_exception_3();
|
||
|
extern void isr_exception_4();
|
||
|
extern void isr_exception_5();
|
||
|
extern void isr_exception_6();
|
||
|
extern void isr_exception_7();
|
||
|
extern void isr_exception_8();
|
||
|
extern void isr_exception_9();
|
||
|
extern void isr_exception_10();
|
||
|
extern void isr_exception_11();
|
||
|
extern void isr_exception_12();
|
||
|
extern void isr_exception_13();
|
||
|
extern void isr_exception_14();
|
||
|
extern void isr_exception_15();
|
||
|
extern void isr_exception_16();
|
||
|
extern void isr_exception_17();
|
||
|
extern void isr_exception_18();
|
||
|
extern void isr_exception_19();
|
||
|
extern void isr_exception_20();
|
||
|
extern void isr_exception_21();
|
||
|
extern void isr_exception_22();
|
||
|
extern void isr_exception_23();
|
||
|
extern void isr_exception_24();
|
||
|
extern void isr_exception_25();
|
||
|
extern void isr_exception_26();
|
||
|
extern void isr_exception_27();
|
||
|
extern void isr_exception_28();
|
||
|
extern void isr_exception_29();
|
||
|
extern void isr_exception_30();
|
||
|
extern void isr_exception_31();
|
||
|
|
||
|
|
||
|
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 IsrsInstall()
|
||
|
{
|
||
|
IdtSetGate(0, (unsigned)isr_exception_0, 0x08, 0x8E);
|
||
|
IdtSetGate(1, (unsigned)isr_exception_1, 0x08, 0x8E);
|
||
|
IdtSetGate(2, (unsigned)isr_exception_2, 0x08, 0x8E);
|
||
|
IdtSetGate(3, (unsigned)isr_exception_3, 0x08, 0x8E);
|
||
|
IdtSetGate(4, (unsigned)isr_exception_4, 0x08, 0x8E);
|
||
|
IdtSetGate(5, (unsigned)isr_exception_5, 0x08, 0x8E);
|
||
|
IdtSetGate(6, (unsigned)isr_exception_6, 0x08, 0x8E);
|
||
|
IdtSetGate(7, (unsigned)isr_exception_7, 0x08, 0x8E);
|
||
|
IdtSetGate(8, (unsigned)isr_exception_8, 0x08, 0x8E);
|
||
|
IdtSetGate(9, (unsigned)isr_exception_9, 0x08, 0x8E);
|
||
|
IdtSetGate(10, (unsigned)isr_exception_10, 0x08, 0x8E);
|
||
|
IdtSetGate(11, (unsigned)isr_exception_11, 0x08, 0x8E);
|
||
|
IdtSetGate(12, (unsigned)isr_exception_12, 0x08, 0x8E);
|
||
|
IdtSetGate(13, (unsigned)isr_exception_13, 0x08, 0x8E);
|
||
|
IdtSetGate(14, (unsigned)isr_exception_14, 0x08, 0x8E);
|
||
|
IdtSetGate(15, (unsigned)isr_exception_15, 0x08, 0x8E);
|
||
|
IdtSetGate(16, (unsigned)isr_exception_16, 0x08, 0x8E);
|
||
|
IdtSetGate(17, (unsigned)isr_exception_17, 0x08, 0x8E);
|
||
|
IdtSetGate(18, (unsigned)isr_exception_18, 0x08, 0x8E);
|
||
|
IdtSetGate(19, (unsigned)isr_exception_19, 0x08, 0x8E);
|
||
|
IdtSetGate(20, (unsigned)isr_exception_20, 0x08, 0x8E);
|
||
|
IdtSetGate(21, (unsigned)isr_exception_21, 0x08, 0x8E);
|
||
|
IdtSetGate(22, (unsigned)isr_exception_22, 0x08, 0x8E);
|
||
|
IdtSetGate(23, (unsigned)isr_exception_23, 0x08, 0x8E);
|
||
|
IdtSetGate(24, (unsigned)isr_exception_24, 0x08, 0x8E);
|
||
|
IdtSetGate(25, (unsigned)isr_exception_25, 0x08, 0x8E);
|
||
|
IdtSetGate(26, (unsigned)isr_exception_26, 0x08, 0x8E);
|
||
|
IdtSetGate(27, (unsigned)isr_exception_27, 0x08, 0x8E);
|
||
|
IdtSetGate(28, (unsigned)isr_exception_28, 0x08, 0x8E);
|
||
|
IdtSetGate(29, (unsigned)isr_exception_29, 0x08, 0x8E);
|
||
|
IdtSetGate(30, (unsigned)isr_exception_30, 0x08, 0x8E);
|
||
|
IdtSetGate(31, (unsigned)isr_exception_31, 0x08, 0x8E);
|
||
|
}
|
||
|
|
||
|
|
||
|
void IsrsInstallHandler(int interr, void (*function)(_RegsStack32 *r))
|
||
|
{
|
||
|
if (interr < 32) IdtFaultHandlers[interr] = function;
|
||
|
}
|
||
|
|
||
|
|
||
|
void IsrsUninstallHandler(int interr)
|
||
|
{
|
||
|
if (interr < 32) IdtFaultHandlers[interr] = 0;
|
||
|
}
|
||
|
|
||
|
|
||
|
extern void CrashMessage(_RegsStack32 *r);
|
||
|
// Default fault handler; calls other handlers, or displays error message.
|
||
|
void IsrsFaultHandler(_RegsStack32 *r)
|
||
|
{
|
||
|
/* Is this a fault whose number is from 0 to 31? */
|
||
|
if (r->int_no < 32)
|
||
|
{
|
||
|
void (*func)(_RegsStack32 *r);
|
||
|
func = IdtFaultHandlers[r->int_no];
|
||
|
|
||
|
// Halt system if unhandled
|
||
|
if (!func) {
|
||
|
CrashMessage(r);
|
||
|
asm ("cli");
|
||
|
asm ("hlt");
|
||
|
}
|
||
|
|
||
|
else (*func)(r);
|
||
|
}
|
||
|
}
|