|
|
@@ -43,12 +43,88 @@
|
|
|
|
|
|
extern struct idt_entry idt[256];
|
|
|
|
|
|
+extern void ret_intr(void);
|
|
|
+int do_trap(int nr);
|
|
|
static int set_gate(struct idt_entry *, void (*) (void), int attr);
|
|
|
|
|
|
+#define set_int_gate(nr, handler) set_gate(idt + nr, handler, 0x8e)
|
|
|
+#define set_trap_gate(nr, handler) set_gate(idt + nr, handler, 0x8f)
|
|
|
+#define set_sys_gate(nr, handler) set_gate(idt + nr, handler, 0xef)
|
|
|
+
|
|
|
+#if CONFIG_64BIT
|
|
|
+
|
|
|
+/* errcodes later */
|
|
|
+
|
|
|
+#define build_trap_entry(nr) \
|
|
|
+ void trap_##nr##_entry(void); \
|
|
|
+ __asm__ ( \
|
|
|
+ ".globl trap_"#nr"_entry\n\t" \
|
|
|
+ "trap_"#nr"_entry:\n\t" \
|
|
|
+ IRQ_SAVE_REGS \
|
|
|
+ "movq $"#nr", %rdi\n\t" \
|
|
|
+ "pushq ret_intr(%rip)\n\t" \
|
|
|
+ "jmp do_trap\n\t" \
|
|
|
+ );
|
|
|
+#else
|
|
|
+
|
|
|
+#define build_trap_entry(nr) \
|
|
|
+ void trap_##nr##_entry(void); \
|
|
|
+ __asm__ ( \
|
|
|
+ ".globl trap_"#nr"_entry\n\t" \
|
|
|
+ "trap_"#nr"_entry:\n\t" \
|
|
|
+ "pushl $"#nr"\n\t" \
|
|
|
+ "call do_trap\n\t" \
|
|
|
+ "addl $4, %esp\n\t" \
|
|
|
+ "jmp ret_intr\n\t" \
|
|
|
+ );
|
|
|
+#endif
|
|
|
+
|
|
|
+#include "__build_traps_generated.c"
|
|
|
+
|
|
|
+
|
|
|
/* set the handlers for traps, 0 - 31 */
|
|
|
|
|
|
int __init arch_traps_init(void) {
|
|
|
- set_gate(idt + 0x80, NULL, 0x8e);
|
|
|
+#include "__arch_traps_generated.c"
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+const static char *trap_msg[32] = {
|
|
|
+ "division by zero",
|
|
|
+ "debug trap",
|
|
|
+ "NMI",
|
|
|
+ "breakpoint",
|
|
|
+ "overflow",
|
|
|
+ "bound",
|
|
|
+ "invalid op-code",
|
|
|
+ "device not avaliable",
|
|
|
+ "double fault",
|
|
|
+ "coprocessor segment overrun",
|
|
|
+ "invalid tss",
|
|
|
+ "segment not present",
|
|
|
+ "stack-segment fault",
|
|
|
+ "general protection",
|
|
|
+ "page fault",
|
|
|
+ "reserved",
|
|
|
+ "x87 floating-point exception",
|
|
|
+ "alignment check",
|
|
|
+ "machine check",
|
|
|
+ "simd floating-point exception",
|
|
|
+ "virtualization exception",
|
|
|
+ "control protection exception",
|
|
|
+ "reserved",
|
|
|
+ "hypervisor injection exception",
|
|
|
+ "vmm communication exception",
|
|
|
+ "security exception",
|
|
|
+ "reserved"
|
|
|
+};
|
|
|
+
|
|
|
+int do_trap(int nr) {
|
|
|
+ kmlog("Oops! trap %d: %s\n", nr, trap_msg[nr]);
|
|
|
+
|
|
|
+ for (;;)
|
|
|
+ ;
|
|
|
|
|
|
return 0;
|
|
|
}
|