summaryrefslogtreecommitdiff
path: root/payloads/libpayload/arch/x86/exception.c
diff options
context:
space:
mode:
Diffstat (limited to 'payloads/libpayload/arch/x86/exception.c')
-rw-r--r--payloads/libpayload/arch/x86/exception.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/payloads/libpayload/arch/x86/exception.c b/payloads/libpayload/arch/x86/exception.c
index fe50d09c51..d70d942a05 100644
--- a/payloads/libpayload/arch/x86/exception.c
+++ b/payloads/libpayload/arch/x86/exception.c
@@ -37,6 +37,9 @@
u32 exception_stack[0x400] __attribute__((aligned(8)));
static exception_hook hook;
+
+static interrupt_handler handlers[256];
+
static const char *names[EXC_COUNT] = {
[EXC_DE] = "Divide by Zero",
[EXC_DB] = "Debug",
@@ -163,7 +166,16 @@ static void dump_exception_state(void)
void exception_dispatch(void)
{
u32 vec = exception_state->vector;
- die_if(vec >= EXC_COUNT || !names[vec], "Bad exception vector %u", vec);
+
+ die_if(vec >= ARRAY_SIZE(handlers), "Invalid vector %u\n", vec);
+
+ if (handlers[vec]) {
+ handlers[vec](vec);
+ return;
+ }
+
+ die_if(vec >= EXC_COUNT || !names[vec], "Bad exception vector %u\n",
+ vec);
if (hook && hook(vec))
return;
@@ -185,6 +197,11 @@ void exception_install_hook(exception_hook h)
hook = h;
}
+void set_interrupt_handler(u8 vector, interrupt_handler handler)
+{
+ handlers[vector] = handler;
+}
+
static uint32_t eflags(void)
{
uint32_t eflags;