From 82585d70771bbac69f95127b003446486623c07a Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Sun, 27 Jul 2025 16:53:54 +0200 Subject: Tweaks to the interrupt handler mechanism --- src/interrupt.c | 115 ++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 83 insertions(+), 32 deletions(-) (limited to 'src/interrupt.c') diff --git a/src/interrupt.c b/src/interrupt.c index 97bc921..54f9947 100644 --- a/src/interrupt.c +++ b/src/interrupt.c @@ -1,41 +1,92 @@ #include "aplos.h" -static char8_t *descriptions[256] = { - [0] = u8"divide-by-zero-error", - [1] = u8"debug", - [2] = u8"non-maskable-interrupt", - [3] = u8"breakpoint", - [4] = u8"overflow", - [5] = u8"bound-range", - [6] = u8"invalid-opcode", - [7] = u8"device-not-available", - [8] = u8"double-fault", - [9] = u8"coprocessor-segment-overrun", - [10] = u8"invalid-tss", - [11] = u8"segment-not-present", - [12] = u8"stack", - [13] = u8"general-protection", - [14] = u8"page-fault", - [16] = u8"x87 floating-point exception-pending", - [17] = u8"alignment-check", - [18] = u8"machine-check", - [19] = u8"simd floating-point", - [21] = u8"control protection", - [28] = u8"hypervisor injection exception", - [29] = u8"vmm communication exception", - [30] = u8"security exception", +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) +interrupt_handler(uint8_t n, uint32_t code) { - char8_t *desc = descriptions[n]; - - print(u8"Got interrupt: %u8", n); - if(desc) - print(u8" (%s)", desc); - print(u8"\n"); - panic(); + 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(); + } } -- cgit v1.2.3