Newer
Older
tree-os / src / interrupts / exceptions.c
#include <exceptions.h>
#include <interrupts.h>
#include <task.h>
#include <_stdio.h>

#define exception(exceptionNR, name) void exception##exceptionNR##Handler () {printf("exception "#name" happend!"); yields();}
#define setExceptionHandler(exceptionNR) setInterrupt(exceptionNR, &exception##exceptionNR##Handler);

exception(0, DIVIDE_BY_ZERO);
exception(1, DEBUG);
exception(2, NON_MASKABLE_INTERRUPT);
exception(3, BREAKPOINT);
exception(4, OVERFLOW);
exception(5, BOUND_RANGE_EXCEEDED);
exception(6, INVALID_OPCODE);
exception(7, DEVIVE_NOT_AVAILABLE);
exception(8, DOUBLE_FAULT);
exception(10, INVALID_TSS);
exception(11, SEGMENT_NOT_PRESENT);
exception(12, STACK_SEGMENT_FAULT);
exception(13, GENERAL_PROTECTION_FAULT);
exception(14, PAGE_FAULT);
exception(16, X87_FLOATING_POINT_EXCEPTION);
exception(17, ALIGNMENT_CHECK);
exception(18, MACHINE_CHECK);
exception(19, SMID_FLOATING_POINT_EXCEPTION);
exception(20, VIRTUALIZATION_EXCEPTION);
exception(30, SECURITy_EXCEPTION);


void setupExceptions() {
    printf("setting exceptions\n");
    setExceptionHandler(0);
    setExceptionHandler(1);
    setExceptionHandler(2);
    setExceptionHandler(3);
    setExceptionHandler(4);
    setExceptionHandler(5);
    setExceptionHandler(6);
    setExceptionHandler(7);
    setExceptionHandler(8);
    setExceptionHandler(10);
    setExceptionHandler(11);
    setExceptionHandler(12);
    setExceptionHandler(13);
    setExceptionHandler(14);
    setExceptionHandler(16);
    setExceptionHandler(17);
    setExceptionHandler(18);
    setExceptionHandler(19);
    setExceptionHandler(20);
    setExceptionHandler(30);
}