.align 16
handle_exception:
+ SAVE_ALL
+
+ push %esp /* struct cpu_regs * */
call do_exception
+ add $4, %esp
ud2a
.align 16
handle_exception:
+ SAVE_ALL
+
+ mov %rsp, %rdi /* struct cpu_regs * */
call do_exception
ud2a
* C entry-point for exceptions, after the per-environment stubs have suitably
* adjusted the stack.
*/
-void do_exception(void)
+void do_exception(struct cpu_regs *regs)
{
- panic("Unhandled exception\n");
+ panic("Unhandled exception: vec %u at %04x:%p\n",
+ regs->entry_vector, regs->cs, _p(regs->ip));
}
/*
--- /dev/null
+/**
+ * @file include/arch/x86/asm_macros.h
+ *
+ * Macros for use in x86 assembly files.
+ */
+#ifndef XTF_X86_ASM_MACROS_H
+#define XTF_X86_ASM_MACROS_H
+
+/* Declare data at the architectures width. */
+#if defined(__x86_64__)
+# define _WORD .quad
+#elif defined(__i386__)
+# define _WORD .long
+#else
+# error Bad architecture for _WORD
+#endif
+
+.macro SAVE_ALL
+ cld
+#if defined(__x86_64__)
+ push %rdi
+ push %rsi
+ push %rdx
+ push %rcx
+ push %rax
+ push %r8
+ push %r9
+ push %r10
+ push %r11
+ push %rbx
+ push %rbp
+ push %r12
+ push %r13
+ push %r14
+ push %r15
+#elif defined(__i386__)
+ push %edi
+ push %esi
+ push %edx
+ push %ecx
+ push %eax
+ push %ebx
+ push %ebp
+#else
+# error Bad architecture for SAVE_ALL
+#endif
+.endm
+
+.macro RESTORE_ALL
+#if defined(__x86_64__)
+ pop %r15
+ pop %r14
+ pop %r13
+ pop %r12
+ pop %rbp
+ pop %rbx
+ pop %r11
+ pop %r10
+ pop %r9
+ pop %r8
+ pop %rax
+ pop %rcx
+ pop %rdx
+ pop %rsi
+ pop %rdi
+#elif defined(__i386__)
+ pop %ebp
+ pop %ebx
+ pop %eax
+ pop %ecx
+ pop %edx
+ pop %esi
+ pop %edi
+#else
+# error Bad architecture for RESTORE_ALL
+#endif
+.endm
+
+#endif /* XTF_X86_ASM_MACROS_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
--- /dev/null
+#ifndef XTF_X86_REGS_H
+#define XTF_X86_REGS_H
+
+#include <xtf/types.h>
+
+#if defined(__i386__)
+
+#define DECL_REG(n) \
+ union { uint32_t e ## n; unsigned long n; }
+
+struct cpu_regs {
+ DECL_REG(bp);
+ DECL_REG(bx);
+ DECL_REG(ax);
+ DECL_REG(cx);
+ DECL_REG(dx);
+ DECL_REG(si);
+ DECL_REG(di);
+
+ uint32_t entry_vector;
+ uint32_t error_code;
+
+/* Hardware exception frame. */
+ DECL_REG(ip);
+ uint16_t cs, _pad1[1];
+ DECL_REG(flags);
+ DECL_REG(sp); /* Won't be valid if stack */
+ uint16_t ss, _pad0[1]; /* switch didn't occur. */
+/* Top of stack. */
+};
+
+#elif defined(__x86_64__)
+
+#define DECL_REG(n) \
+ union { uint64_t r ## n; uint32_t e ## n; unsigned long n; }
+
+struct cpu_regs {
+ uint64_t r15;
+ uint64_t r14;
+ uint64_t r13;
+ uint64_t r12;
+ DECL_REG(bp);
+ DECL_REG(bx);
+ uint64_t r11;
+ uint64_t r10;
+ uint64_t r9;
+ uint64_t r8;
+ DECL_REG(ax);
+ DECL_REG(cx);
+ DECL_REG(dx);
+ DECL_REG(si);
+ DECL_REG(di);
+
+ uint32_t error_code;
+ uint32_t entry_vector;
+
+/* Hardware exception frame. */
+ DECL_REG(ip);
+ uint16_t cs, _pad1[3];
+ DECL_REG(flags);
+ DECL_REG(sp);
+ uint16_t ss, _pad0[3];
+/* Top of stack. */
+};
+
+#endif /* __i386__ / __x86_64__ */
+
+#endif /* XTF_X86_REGS_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
#define XTF_X86_TRAPS_H
#include <xtf/compiler.h>
+#include <arch/x86/regs.h>
/*
* Arch-specific function to initialise the exception entry points, etc.
#include <xtf/numbers.h>
-/* Declare data at the architectures width. */
-#if defined(__x86_64__)
-# define _WORD .quad
-#elif defined(__i386__)
-# define _WORD .long
-#else
-# error Bad architecture for _WORD
-#endif
+#include <arch/x86/asm_macros.h>
/**
* Declare a global symbol.
#define GB(num) (_AC(num, ULL) << 30)
#define TB(num) (_AC(num, ULL) << 40)
+#define _p(v) ((void*)(unsigned long)(v))
+
#endif /* XTF_NUMBERS_H */
/*