|
|
@@ -27,6 +27,7 @@
|
|
|
|
|
|
#include <arch/archinfo.h>
|
|
|
#include <arch/mm.h>
|
|
|
+#include <arch/asm.h>
|
|
|
#include <arch/int.h>
|
|
|
#include <arch/string.h>
|
|
|
|
|
|
@@ -44,7 +45,7 @@
|
|
|
extern struct idt_entry idt[256];
|
|
|
|
|
|
extern void ret_intr(void);
|
|
|
-int do_trap(int nr);
|
|
|
+int do_trap(int nr, __archptr_t sp);
|
|
|
static int set_gate(struct idt_entry *, void (*) (void), int attr);
|
|
|
|
|
|
#define set_int_gate(nr, handler) set_gate(idt + nr, handler, 0x8e)
|
|
|
@@ -55,31 +56,156 @@ static int set_gate(struct idt_entry *, void (*) (void), int attr);
|
|
|
|
|
|
/* errcodes later */
|
|
|
|
|
|
-#define build_trap_entry(nr) \
|
|
|
+__asm__ (
|
|
|
+ ".globl common_trap\n\t"
|
|
|
+ "common_trap:\n\t"
|
|
|
+ /* rax already saved */
|
|
|
+ "pushq %rcx\n\t"
|
|
|
+ "pushq %rbx\n\t"
|
|
|
+ "pushq %rdx\n\t"
|
|
|
+ "pushq %rbp\n\t"
|
|
|
+ "pushq %rsi\n\t"
|
|
|
+ "pushq %rdi\n\t"
|
|
|
+ "pushq %r8\n\t"
|
|
|
+ "pushq %r9\n\t"
|
|
|
+ "pushq %r10\n\t"
|
|
|
+ "pushq %r11\n\t"
|
|
|
+ "pushq %r12\n\t"
|
|
|
+ "pushq %r13\n\t"
|
|
|
+ "pushq %r14\n\t"
|
|
|
+ "pushq %r15\n\t"
|
|
|
+ "movq %rax, %rdi\n\t"
|
|
|
+
|
|
|
+ "movq %ds, %rax\n\t"
|
|
|
+ "pushq %rax\n\t"
|
|
|
+ "movq %es, %rax\n\t"
|
|
|
+ "pushq %rax\n\t"
|
|
|
+ "movq %fs, %rax\n\t"
|
|
|
+ "pushq %rax\n\t"
|
|
|
+ "movq %gs, %rax\n\t"
|
|
|
+ "pushq %rax\n\t"
|
|
|
+
|
|
|
+ "movq $0x10, %rax\n\t"
|
|
|
+ "movq %rax, %ds\n\t"
|
|
|
+ "movq %rax, %es\n\t"
|
|
|
+ "movq %rax, %fs\n\t"
|
|
|
+ "movq %rax, %gs\n\t"
|
|
|
+ "movq %rax, %ss\n\t"
|
|
|
+
|
|
|
+ "movq %rsp, %rsi\n\t"
|
|
|
+ "pushq ret_intr(%rip)\n\t"
|
|
|
+ "jmp do_trap\n\t"
|
|
|
+);
|
|
|
+
|
|
|
+#define build_trap_entry_errcode(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" \
|
|
|
+ "cli\n\t" \
|
|
|
+ "pushq %rax\n\t" \
|
|
|
+ "movq $"#nr", %rax\n\t" \
|
|
|
+ "jmp common_trap\n\t" \
|
|
|
);
|
|
|
+
|
|
|
+#define build_trap_entry_nerrcode(nr) \
|
|
|
+ void trap_##nr##_entry(void); \
|
|
|
+ __asm__ ( \
|
|
|
+ ".globl trap_"#nr"_entry\n\t" \
|
|
|
+ "trap_"#nr"_entry:\n\t" \
|
|
|
+ "cli\n\t" \
|
|
|
+ "pushq $0\n\t" \
|
|
|
+ "pushq %rax\n\t" \
|
|
|
+ "movq $"#nr", %rax\n\t" \
|
|
|
+ "jmp common_trap\n\t" \
|
|
|
+ )
|
|
|
#else
|
|
|
|
|
|
-#define build_trap_entry(nr) \
|
|
|
+__asm__ (
|
|
|
+ ".globl common_trap\n\t"
|
|
|
+ "common_trap:\n\t"
|
|
|
+ "pushl %ecx\n\t"
|
|
|
+ "pushl %ebx\n\t"
|
|
|
+ "pushl %edx\n\t"
|
|
|
+ "pushl %ebp\n\t"
|
|
|
+ "pushl %esi\n\t"
|
|
|
+ "pushl %edi\n\t"
|
|
|
+
|
|
|
+ "movl %eax, %edi\n\t"
|
|
|
+ "movl %ds, %eax\n\t"
|
|
|
+ "pushl %eax\n\t"
|
|
|
+ "movl %es, %eax\n\t"
|
|
|
+ "pushl %eax\n\t"
|
|
|
+ "movl %fs, %eax\n\t"
|
|
|
+ "pushl %eax\n\t"
|
|
|
+ "movl %gs, %eax\n\t"
|
|
|
+ "pushl %eax\n\t"
|
|
|
+
|
|
|
+ "movl $0x10, %eax\n\t"
|
|
|
+ "movl %eax, %ds\n\t"
|
|
|
+ "movl %eax, %es\n\t"
|
|
|
+ "movl %eax, %fs\n\t"
|
|
|
+ "movl %eax, %gs\n\t"
|
|
|
+ "movl %eax, %ss\n\t"
|
|
|
+
|
|
|
+ "movl %esp, %esi\n\t"
|
|
|
+ "pushl %esi\n\t"
|
|
|
+ "pushl %edi\n\t"
|
|
|
+ "call do_trap\n\t"
|
|
|
+ "addl $8, %esp\n\t"
|
|
|
+ "jmp ret_intr\n\t"
|
|
|
+);
|
|
|
+
|
|
|
+
|
|
|
+#define build_trap_entry_errcode(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" \
|
|
|
+ "cli\n\t" \
|
|
|
+ "pushl %eax\n\t" \
|
|
|
+ "movl $"#nr", %eax\n\t" \
|
|
|
+ "jmp common_trap\n\t" \
|
|
|
);
|
|
|
+
|
|
|
+#define build_trap_entry_nerrcode(nr) \
|
|
|
+ void trap_##nr##_entry(void); \
|
|
|
+ __asm__ ( \
|
|
|
+ ".globl trap_"#nr"_entry\n\t" \
|
|
|
+ "trap_"#nr"_entry:\n\t" \
|
|
|
+ "cli\n\t" \
|
|
|
+ "pushl $0\n\t" \
|
|
|
+ "pushl %eax\n\t" \
|
|
|
+ "movl $"#nr", %eax\n\t" \
|
|
|
+ "jmp common_trap\n\t" \
|
|
|
+ )
|
|
|
+
|
|
|
#endif
|
|
|
|
|
|
-#include "__build_traps_generated.c"
|
|
|
+
|
|
|
+build_trap_entry_nerrcode(0);
|
|
|
+build_trap_entry_nerrcode(1);
|
|
|
+build_trap_entry_nerrcode(2);
|
|
|
+build_trap_entry_nerrcode(3);
|
|
|
+build_trap_entry_nerrcode(4);
|
|
|
+build_trap_entry_nerrcode(5);
|
|
|
+build_trap_entry_nerrcode(6);
|
|
|
+build_trap_entry_nerrcode(7);
|
|
|
+build_trap_entry_errcode(8);
|
|
|
+build_trap_entry_nerrcode(9);
|
|
|
+build_trap_entry_errcode(10);
|
|
|
+build_trap_entry_errcode(11);
|
|
|
+build_trap_entry_errcode(12);
|
|
|
+build_trap_entry_errcode(13);
|
|
|
+build_trap_entry_errcode(14);
|
|
|
+build_trap_entry_nerrcode(15);
|
|
|
+build_trap_entry_nerrcode(16);
|
|
|
+build_trap_entry_errcode(17);
|
|
|
+build_trap_entry_nerrcode(18);
|
|
|
+build_trap_entry_nerrcode(19);
|
|
|
+build_trap_entry_nerrcode(20);
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
/* set the handlers for traps, 0 - 31 */
|
|
|
@@ -120,11 +246,40 @@ const static char *trap_msg[32] = {
|
|
|
"reserved"
|
|
|
};
|
|
|
|
|
|
-int do_trap(int nr) {
|
|
|
- kmlog("Oops! trap %d: %s\n", nr, trap_msg[nr]);
|
|
|
+
|
|
|
+int do_trap(int nr, __archptr_t sp) {
|
|
|
+ struct registers *regs = (struct registers *) sp;
|
|
|
+
|
|
|
+ kmlog(KERN_ABANDON "Oops! trap %d: %s\n", nr, trap_msg[nr]);
|
|
|
+ kmlog(KERN_ABANDON "sp at %p\n", sp);
|
|
|
+
|
|
|
+ /* okay, we use wrong tabs in protected-mode but i think that's ok :-) */
|
|
|
+ kmlog(KERN_ABANDON "ax\t\t\tcx\t\t\tbx\n");
|
|
|
+ kmlog(KERN_ABANDON "%p\t%p\t%p\n", regs->ax, regs->cx, regs->bx);
|
|
|
+ kmlog(KERN_ABANDON "dx\t\t\tbp\t\t\tsp\n");
|
|
|
+ kmlog(KERN_ABANDON "%p\t%p\t%p\n", regs->dx, regs->bp, regs->sp);
|
|
|
+
|
|
|
+#if CONFIG_64BIT
|
|
|
+ kmlog(KERN_ABANDON "si\t\t\tdi\t\t\tr8\n");
|
|
|
+ kmlog(KERN_ABANDON "%p\t%p\t%p\n", regs->si, regs->di, regs->r8);
|
|
|
+
|
|
|
+ kmlog(KERN_ABANDON "r9\t\t\tr10\t\t\tr11\n");
|
|
|
+ kmlog(KERN_ABANDON "%p\t%p\t%p\n", regs->r9, regs->r10, regs->r11);
|
|
|
+ kmlog(KERN_ABANDON "r12\t\t\tr13\t\t\tr14\n");
|
|
|
+ kmlog(KERN_ABANDON "%p\t%p\t%p\n", regs->r12, regs->r13, regs->r14);
|
|
|
+ kmlog(KERN_ABANDON "r15\n%d\n", regs->r15);
|
|
|
+
|
|
|
+#else
|
|
|
+ kmlog(KERN_ABANDON "si\t\t\tdi\n");
|
|
|
+ kmlog(KERN_ABANDON "%p\t%p\n", regs->si, regs->di);
|
|
|
+#endif
|
|
|
+ kmlog(KERN_ABANDON "ds: \t\t%p\n", regs->ds);
|
|
|
+ kmlog(KERN_ABANDON "ss: \t\t%p\n", regs->ss);
|
|
|
+ kmlog(KERN_ABANDON "flags: \t\t%p\n", regs->flags);
|
|
|
+ kmlog(KERN_ABANDON "cs:ip: \t\t%d:%p\n", regs->cs, regs->ip);
|
|
|
|
|
|
for (;;)
|
|
|
- ;
|
|
|
+ cpu_relax();
|
|
|
|
|
|
return 0;
|
|
|
}
|