diff options
author | Danny Holman <dholman@gymli.org> | 2024-06-25 12:49:40 -0500 |
---|---|---|
committer | Danny Holman <dholman@gymli.org> | 2024-06-25 12:49:40 -0500 |
commit | 0dc4d97e70c17df56a260d31a1cb44881cf64520 (patch) | |
tree | 8fc93c709d334be836e3b896e2ed5f5320292169 /kernel | |
parent | 3851af792ca7b4bb7fc998337c4aec05627cfa8f (diff) |
kernel: interrupt: create a generic interrupt API
Create a generic interface for drivers to make use of interrupt vectors.
This API should be platform-agnostic enough to allow any driver to make
use of virtually any interrupt vector on any CPU. On x86, the first 32
interrupts are set aside for CPU exceptions, and interrupt 128 is set
aside for system calls.
Signed-off-by: Danny Holman <dholman@gymli.org>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/interrupt.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/kernel/interrupt.c b/kernel/interrupt.c new file mode 100644 index 0000000..9639aea --- /dev/null +++ b/kernel/interrupt.c @@ -0,0 +1,20 @@ +#include <kernel/interrupt.h> +#include <kernel/asm.h> + +static void (*isr_handlers[MAX_ISR])(struct isr_frame *frame); + +void register_isr_handler(unsigned int isr, void (*handler)(struct isr_frame *frame)) { + if (isr > MAX_ISR) + panic("Attempted to set non-existant interrupt vector"); + isr_handlers[isr] = handler; +} + +void clear_isr_handler(unsigned int isr) { + if (isr > MAX_ISR) + panic("Attempted to clear non-existant interrupt vector"); + isr_handlers[isr] = NULL; +} + +void isr_dispatch(struct isr_frame frame) { + (*isr_handlers[frame.isr_vector])(&frame); +} |