71 lines
3.7 KiB
C
71 lines
3.7 KiB
C
#include "exception.h"
|
|
#include "idt.h"
|
|
#include "interrupt.h"
|
|
#include "irq.h"
|
|
|
|
exception_handler exception_handler_array[EXCEPTION_NUM] = {
|
|
NULL,
|
|
};
|
|
|
|
int exceptionSetRoutine(int exception, exception_handler handler)
|
|
{
|
|
uint32_t flags;
|
|
if ((exception < 0) || exception >= EXCEPTION_NUM)
|
|
return -1;
|
|
|
|
disable_IRQs(flags);
|
|
|
|
exception_handler_array[exception] = handler;
|
|
|
|
idt_set_handler(EXCEPTION_INTERRUPT_BASE_ADDRESS + exception, (unsigned int)handler, 0);
|
|
restore_IRQs(flags);
|
|
return 0;
|
|
}
|
|
|
|
int exceptionSetup()
|
|
{
|
|
exceptionSetRoutine(EXCEPTION_DOUBLE_FAULT, ACCESS_INTERRUPT(EXCEPTION_DOUBLE_FAULT));
|
|
exceptionSetRoutine(EXCEPTION_DIVIDE_ZERO, ACCESS_INTERRUPT(EXCEPTION_DIVIDE_ZERO));
|
|
// Used by the DBG
|
|
// exceptionSetRoutine(EXCEPTION_DEBUG, ACCESS_INTERRUPT(EXCEPTION_DEBUG));
|
|
exceptionSetRoutine(EXCEPTION_NMI, ACCESS_INTERRUPT(EXCEPTION_NMI));
|
|
exceptionSetRoutine(EXCEPTION_BREAKPOINT, ACCESS_INTERRUPT(EXCEPTION_BREAKPOINT));
|
|
exceptionSetRoutine(EXCEPTION_OVERFLOW, ACCESS_INTERRUPT(EXCEPTION_OVERFLOW));
|
|
exceptionSetRoutine(EXCEPTION_BOUND_RANGE_EXCEEDED,
|
|
ACCESS_INTERRUPT(EXCEPTION_BOUND_RANGE_EXCEEDED));
|
|
exceptionSetRoutine(EXCEPTION_INVALID_OPCODE, ACCESS_INTERRUPT(EXCEPTION_INVALID_OPCODE));
|
|
exceptionSetRoutine(EXCEPTION_DEVICE_NOT_AVAILABLE,
|
|
ACCESS_INTERRUPT(EXCEPTION_DEVICE_NOT_AVAILABLE));
|
|
exceptionSetRoutine(EXCEPTION_COPRO_OVERRUN, ACCESS_INTERRUPT(EXCEPTION_COPRO_OVERRUN));
|
|
exceptionSetRoutine(EXCEPTION_INVALID_TSS, ACCESS_INTERRUPT(EXCEPTION_INVALID_TSS));
|
|
exceptionSetRoutine(EXCEPTION_SEGMENT_NOT_PRESENT,
|
|
ACCESS_INTERRUPT(EXCEPTION_SEGMENT_NOT_PRESENT));
|
|
exceptionSetRoutine(EXCEPTION_STACK_SEGMENT_FAULT,
|
|
ACCESS_INTERRUPT(EXCEPTION_STACK_SEGMENT_FAULT));
|
|
exceptionSetRoutine(EXCEPTION_GENERAL_PROTECTION_FAULT,
|
|
ACCESS_INTERRUPT(EXCEPTION_GENERAL_PROTECTION_FAULT));
|
|
exceptionSetRoutine(EXCEPTION_PAGE_FAULT, ACCESS_INTERRUPT(EXCEPTION_PAGE_FAULT));
|
|
exceptionSetRoutine(EXCEPTION_RESERVED_1, ACCESS_INTERRUPT(EXCEPTION_RESERVED_1));
|
|
exceptionSetRoutine(EXCEPTION_X87_FP_EXCEPTION,
|
|
ACCESS_INTERRUPT(EXCEPTION_X87_FP_EXCEPTION));
|
|
exceptionSetRoutine(EXCEPTION_ALIGNMENT_CHECK,
|
|
ACCESS_INTERRUPT(EXCEPTION_ALIGNMENT_CHECK));
|
|
exceptionSetRoutine(EXCEPTION_MACHINE_CHECK, ACCESS_INTERRUPT(EXCEPTION_MACHINE_CHECK));
|
|
exceptionSetRoutine(EXCEPTION_SIMD_FP, ACCESS_INTERRUPT(EXCEPTION_SIMD_FP));
|
|
exceptionSetRoutine(EXCEPTION_VIRTUALIZATION, ACCESS_INTERRUPT(EXCEPTION_VIRTUALIZATION));
|
|
exceptionSetRoutine(EXCEPTION_RESERVED_2, ACCESS_INTERRUPT(EXCEPTION_RESERVED_2));
|
|
exceptionSetRoutine(EXCEPTION_RESERVED_3, ACCESS_INTERRUPT(EXCEPTION_RESERVED_3));
|
|
exceptionSetRoutine(EXCEPTION_RESERVED_4, ACCESS_INTERRUPT(EXCEPTION_RESERVED_4));
|
|
exceptionSetRoutine(EXCEPTION_RESERVED_5, ACCESS_INTERRUPT(EXCEPTION_RESERVED_5));
|
|
exceptionSetRoutine(EXCEPTION_RESERVED_6, ACCESS_INTERRUPT(EXCEPTION_RESERVED_6));
|
|
exceptionSetRoutine(EXCEPTION_RESERVED_7, ACCESS_INTERRUPT(EXCEPTION_RESERVED_7));
|
|
exceptionSetRoutine(EXCEPTION_RESERVED_8, ACCESS_INTERRUPT(EXCEPTION_RESERVED_8));
|
|
exceptionSetRoutine(EXCEPTION_RESERVED_9, ACCESS_INTERRUPT(EXCEPTION_RESERVED_9));
|
|
exceptionSetRoutine(EXCEPTION_RESERVED_10, ACCESS_INTERRUPT(EXCEPTION_RESERVED_10));
|
|
exceptionSetRoutine(EXCEPTION_SECURITY, ACCESS_INTERRUPT(EXCEPTION_SECURITY));
|
|
exceptionSetRoutine(EXCEPTION_RESERVED_11, ACCESS_INTERRUPT(EXCEPTION_RESERVED_11));
|
|
|
|
exceptionSetRoutine(EXCEPTION_PAGE_FAULT, pagefault_handler);
|
|
return 0;
|
|
}
|