summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2012-11-17 18:12:48 +0100
committerRichard Braun <rbraun@sceen.net>2012-11-17 18:12:48 +0100
commit19d64b4177f7720c6e2aab520436af14db0ffa54 (patch)
treea5e19dd2f200de60656e8241fd055bc76bc62124
parent4df93453244a5fdb0ecaf4f2c87101d675ff36f5 (diff)
x86/trap: rework the default handler
Include the default handler in the handlers array.
-rw-r--r--arch/x86/machine/trap.c24
-rw-r--r--arch/x86/machine/trap.h5
-rw-r--r--arch/x86/machine/trap_asm.S5
3 files changed, 23 insertions, 11 deletions
diff --git a/arch/x86/machine/trap.c b/arch/x86/machine/trap.c
index 4b450ecf..9810d0a6 100644
--- a/arch/x86/machine/trap.c
+++ b/arch/x86/machine/trap.c
@@ -69,16 +69,22 @@ void trap_isr_lapic_spurious(void);
/*
* Array of trap handlers.
*
- * Entries in this table match the content of the IDT.
+ * The additional entry is the default entry used for unhandled traps.
*/
-static struct trap_handler trap_handlers[CPU_IDT_SIZE];
+static struct trap_handler trap_handlers[CPU_IDT_SIZE + 1];
+
+static void __init
+trap_handler_init(struct trap_handler *handler, trap_handler_fn_t fn)
+{
+ handler->fn = fn;
+}
static void __init
trap_install(unsigned int vector, trap_isr_fn_t isr, trap_handler_fn_t fn)
{
- assert(vector < ARRAY_SIZE(trap_handlers));
+ assert(vector < CPU_IDT_SIZE);
- trap_handlers[vector].fn = fn;
+ trap_handler_init(&trap_handlers[vector], fn);
cpu_idt_set_gate(vector, isr);
}
@@ -99,7 +105,7 @@ trap_setup(void)
{
size_t i;
- for (i = 0; i < ARRAY_SIZE(trap_handlers); i++)
+ for (i = 0; i < CPU_IDT_SIZE; i++)
trap_install(i, trap_isr_default, trap_default);
/* Architecture defined traps */
@@ -131,15 +137,15 @@ trap_setup(void)
trap_install(TRAP_LAPIC_ERROR, trap_isr_lapic_error, lapic_intr_error);
trap_install(TRAP_LAPIC_SPURIOUS, trap_isr_lapic_spurious,
lapic_intr_spurious);
+
+ trap_handler_init(&trap_handlers[TRAP_DEFAULT], trap_default);
}
void
trap_main(struct trap_frame *frame)
{
- if (frame->vector < ARRAY_SIZE(trap_handlers))
- trap_handlers[frame->vector].fn(frame);
- else
- trap_default(frame);
+ assert(frame->vector < ARRAY_SIZE(trap_handlers));
+ trap_handlers[frame->vector].fn(frame);
}
#ifdef __LP64__
diff --git a/arch/x86/machine/trap.h b/arch/x86/machine/trap.h
index 06275c4a..aa2e09a5 100644
--- a/arch/x86/machine/trap.h
+++ b/arch/x86/machine/trap.h
@@ -55,6 +55,11 @@
#define TRAP_LAPIC_ERROR 254
#define TRAP_LAPIC_SPURIOUS 255
+/*
+ * Vector identifying an unhandled trap.
+ */
+#define TRAP_DEFAULT 256
+
#ifndef __ASSEMBLER__
#include <kern/macros.h>
diff --git a/arch/x86/machine/trap_asm.S b/arch/x86/machine/trap_asm.S
index a30a697e..255cabde 100644
--- a/arch/x86/machine/trap_asm.S
+++ b/arch/x86/machine/trap_asm.S
@@ -144,8 +144,6 @@ ASM_END(trap_load)
.text
-TRAP(-1, default)
-
/* Architecture defined traps */
TRAP(TRAP_DE, divide_error)
TRAP(TRAP_DB, debug)
@@ -174,3 +172,6 @@ TRAP(TRAP_PIC_BASE + 15, pic_int15)
TRAP(TRAP_LAPIC_TIMER, lapic_timer)
TRAP(TRAP_LAPIC_ERROR, lapic_error)
TRAP(TRAP_LAPIC_SPURIOUS, lapic_spurious)
+
+/* Unhandled traps */
+TRAP(TRAP_DEFAULT, default)