Skip to contentSkip to conversation

x86: use enum instead of literals for trap values

PATCH Superseded Kees Cook 1 participant 1 message Mar 9, 2012 x86

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH v2 1/1 x86: use enum instead of literals for trap values

The traps are referred to by their numbers and it can be difficult to understand them while reading the code without context. This patch adds enumeration of the trap numbers and replaces the numbers with the correct enum for x86.

---
v2:
- drop IRQ 13 confusions, change enum naming (Ingo Molnar).
v1:
- updated Aditya Kali's earlier patch: https://lkml.org/lkml/2011/4/22/328

---
 arch/x86/include/asm/traps.h |   25 +++++++++
 arch/x86/kernel/irqinit.c    |    2 +-
 arch/x86/kernel/traps.c      |  123 +++++++++++++++++++++++-------------------
 3 files changed, 94 insertions(+), 56 deletions(-)
arch/x86/include/asm/traps.h +25 -0
index 0012d09..9fbecc0 100644
@@ -89,4 +89,29 @@ asmlinkage void smp_thermal_interrupt(void);
 asmlinkage void mce_threshold_interrupt(void);
 #endif
 
+/* Processor Fault Vectors */
+enum {
+	X86_DIV_BY_ZERO_FAULT_VEC = 0,	/*  0 */
+	X86_DEBUG_FAULT_VEC,		/*  1 */
+	X86_NMI_FAULT_VEC,		/*  2 */
+	X86_BREAKPOINT_FAULT_VEC,	/*  3 */
+	X86_OVERFLOW_FAULT_VEC,		/*  4 */
+	X86_BOUNDS_CHECK_FAULT_VEC,	/*  5 */
+	X86_INVALID_OP_FAULT_VEC,	/*  6 */
+	X86_NO_DEV_FAULT_VEC,		/*  7 */
+	X86_DOUBLE_FAULT_VEC,		/*  8 */
+	X86_SEG_OVERRUN_FAULT_VEC,	/*  9 */
+	X86_INVALID_TSS_FAULT_VEC,	/* 10 */
+	X86_NO_SEG_FAULT_VEC,		/* 11 */
+	X86_STACK_FAULT_VEC,		/* 12 */
+	X86_GPF_FAULT_VEC,		/* 13 */
+	X86_PAGE_FAULT_VEC,		/* 14 */
+	X86_SPURIOUS_FAULT_VEC,		/* 15 */
+	X86_COPROCESSOR_FAULT_VEC,	/* 16 */
+	X86_ALIGNMENT_FAULT_VEC,	/* 17 */
+	X86_MCE_FAULT_VEC,		/* 18 */
+	X86_SIMD_COPROCESSOR_FAULT_VEC,	/* 19 */
+	X86_IRET_FAULT_VEC = 32,	/* 32 */
+};
+
 #endif /* _ASM_X86_TRAPS_H */
arch/x86/kernel/irqinit.c +1 -1
index 313fb5c..b7d9525 100644
@@ -61,7 +61,7 @@ static irqreturn_t math_error_irq(int cpl, void *dev_id)
 	outb(0, 0xF0);
 	if (ignore_fpu_irq || !boot_cpu_data.hard_math)
 		return IRQ_NONE;
-	math_error(get_irq_regs(), 0, 16);
+	math_error(get_irq_regs(), 0, X86_COPROCESSOR_FAULT_VEC);
 	return IRQ_HANDLED;
 }
 
arch/x86/kernel/traps.c +68 -55

246 lines not on this page · raw message

Signature · 5 lines
1.7.0.4

-- 
Kees Cook
ChromeOS Security