#include "aplos.h" struct handler { char8_t *description; bool (*fn)(uint32_t code); } handlers[256] = { [0] = { .description = u8"divide-by-zero-error" }, [1] = { .description = u8"debug" }, [2] = { .description = u8"non-maskable-interrupt" }, [3] = { .description = u8"breakpoint" }, [4] = { .description = u8"overflow" }, [5] = { .description = u8"bound-range" }, [6] = { .description = u8"invalid-opcode" }, [7] = { .description = u8"device-not-available" }, [8] = { .description = u8"double-fault" }, [9] = { .description = u8"coprocessor-segment-overrun" }, [10] = { .description = u8"invalid-tss" }, [11] = { .description = u8"segment-not-present" }, [12] = { .description = u8"stack" }, [13] = { .description = u8"general-protection" }, [14] = { .description = u8"page-fault", .fn = page_fault_handler }, [16] = { .description = u8"x87 floating-point exception-pending" }, [17] = { .description = u8"alignment-check" }, [18] = { .description = u8"machine-check" }, [19] = { .description = u8"simd floating-point" }, [21] = { .description = u8"control protection" }, [28] = { .description = u8"hypervisor injection exception" }, [29] = { .description = u8"vmm communication exception" }, [30] = { .description = u8"security exception" } }; void interrupt_handler(uint8_t n, uint32_t code) { struct handler *h = handlers+n; bool handled; if(h->fn) handled = h->fn(code); if(!handled){ print(u8"Unhandled interrupt: %u8 (%s) with error code %x32\n", n, h->description ? h->description : u8"???", code); panic(); } }