summaryrefslogtreecommitdiff
path: root/payloads/libpayload/arch/x86/exception.c
diff options
context:
space:
mode:
authorRaul E Rangel <rrangel@chromium.org>2018-08-22 10:03:05 -0600
committerPatrick Georgi <pgeorgi@google.com>2018-09-10 15:01:04 +0000
commit80d5c195901d7fa1a442b36d697f9f0f3f063379 (patch)
treeea157434824368d55047d03d5fbe0e84dfe06d2e /payloads/libpayload/arch/x86/exception.c
parent28cee59ca294422056d983fc06d5d8d5800a4390 (diff)
downloadcoreboot-80d5c195901d7fa1a442b36d697f9f0f3f063379.tar.xz
libpayload/x86/exception: Add ability to handle user defined interrupts
I need to setup the APIC timer to fire interrupts. I would like to reuse the existing interrupt table. So I extended it to support user defined interrupts. I just added all 255 vectors so there wouldn't need to be any additional build time configuration. I'm going to deprecate exception_install_hook and remove it in a follow up. It will be replaced with set_interrupt_handler. This way the exception lookup does not have to manage a list of callbacks, or have to worry about the order they are processed. BUG=b:109749762 TEST=Wrote an interrupt handler and fired an APIC timer interrupt and verified that vector 32 was returned. Change-Id: Id9c2583c7c3d9be4a06a25e546e64399f2b0620c Signed-off-by: Raul E Rangel <rrangel@chromium.org> Reviewed-on: https://review.coreboot.org/28100 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Martin Roth <martinroth@google.com>
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;