summaryrefslogtreecommitdiff
path: root/payloads/libpayload
diff options
context:
space:
mode:
Diffstat (limited to 'payloads/libpayload')
-rw-r--r--payloads/libpayload/arch/x86/exception.c19
-rw-r--r--payloads/libpayload/arch/x86/exception_asm.S25
-rw-r--r--payloads/libpayload/include/exception.h4
3 files changed, 47 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;
diff --git a/payloads/libpayload/arch/x86/exception_asm.S b/payloads/libpayload/arch/x86/exception_asm.S
index a8f9a1d254..00dc888207 100644
--- a/payloads/libpayload/arch/x86/exception_asm.S
+++ b/payloads/libpayload/arch/x86/exception_asm.S
@@ -68,6 +68,14 @@ exception_stub_\num:
jmp exception_common
.endm
+ .altmacro
+ .macro user_defined_stubs from, to
+ stub \from
+ .if \to-\from
+ user_defined_stubs %(from+1),\to
+ .endif
+ .endm
+
stub 0
stub 1
stub 2
@@ -100,6 +108,11 @@ exception_stub_\num:
stub 29
stub_err 30
stub 31
+ /* Split the macro so we avoid a stack overflow. */
+ user_defined_stubs 32, 63
+ user_defined_stubs 64, 127
+ user_defined_stubs 128, 191
+ user_defined_stubs 192, 255
exception_common:
/*
@@ -215,6 +228,14 @@ gdt_ptr:
.long \target
.endm
+ .altmacro
+ .macro user_defined_gates from, to
+ interrupt_gate exception_stub_\from
+ .if \to-\from
+ user_defined_gates %(from+1),\to
+ .endif
+ .endm
+
.align 8
.global idt
idt:
@@ -250,6 +271,10 @@ idt:
interrupt_gate exception_stub_29
interrupt_gate exception_stub_30
interrupt_gate exception_stub_31
+ user_defined_gates 32, 63
+ user_defined_gates 64, 127
+ user_defined_gates 128, 191
+ user_defined_gates 192, 255
idt_end:
/* IDT pointer for use with lidt */
diff --git a/payloads/libpayload/include/exception.h b/payloads/libpayload/include/exception.h
index 67923ea9af..7a7bc46d26 100644
--- a/payloads/libpayload/include/exception.h
+++ b/payloads/libpayload/include/exception.h
@@ -36,6 +36,10 @@
typedef int (*exception_hook)(u32 type);
void exception_init(void);
+/* Deprecated, use set_interrupt_handler. */
void exception_install_hook(exception_hook h);
+typedef void (*interrupt_handler)(u8 vector);
+void set_interrupt_handler(u8 vector, interrupt_handler handler);
+
#endif