]> xenbits.xensource.com Git - people/royger/xen-test-framework.git/commitdiff
Represent exception frames in C
authorAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 14 Dec 2015 09:00:02 +0000 (09:00 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 18 Dec 2015 18:31:11 +0000 (18:31 +0000)
Introduce struct cpu_regs, and make the entry points create the expected
layout.

As part of this, split the very x86 bits of asm_macros.h into a new header
file.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
arch/x86/entry_32.S
arch/x86/entry_64.S
arch/x86/traps.c
include/arch/x86/asm_macros.h [new file with mode: 0644]
include/arch/x86/regs.h [new file with mode: 0644]
include/arch/x86/traps.h
include/xtf/asm_macros.h
include/xtf/numbers.h

index c904257be251c1e06c2efb092875b8eb7710bf0e..e46057eefca0ba0cc4c2431d7259159552356451 100644 (file)
@@ -60,5 +60,9 @@ exception_entry VE  X86_EXC_VE
         .align 16
 handle_exception:
 
+        SAVE_ALL
+
+        push %esp               /* struct cpu_regs * */
         call do_exception
+        add $4, %esp
         ud2a
index b0229f3827c0cc5f71fecdab820ec3b0573ab07a..826bfd7780cdf0834e1611388ce227dd86a4d351 100644 (file)
@@ -71,5 +71,8 @@ exception_entry VE  X86_EXC_VE
         .align 16
 handle_exception:
 
+        SAVE_ALL
+
+        mov %rsp, %rdi          /* struct cpu_regs * */
         call do_exception
         ud2a
index 710003bab9cca6188a3448daff481698dfe07f99..f46190e7738f75126acca6705aaa61339879fc0b 100644 (file)
@@ -5,9 +5,10 @@
  * 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));
 }
 
 /*
diff --git a/include/arch/x86/asm_macros.h b/include/arch/x86/asm_macros.h
new file mode 100644 (file)
index 0000000..f0da23d
--- /dev/null
@@ -0,0 +1,89 @@
+/**
+ * @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:
+ */
diff --git a/include/arch/x86/regs.h b/include/arch/x86/regs.h
new file mode 100644 (file)
index 0000000..1fb5340
--- /dev/null
@@ -0,0 +1,78 @@
+#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:
+ */
index 0a88cec7135b799d0bd10e37089fe38305d0d849..53eabb7b779fc7e95f9eb4a127ff20013160875b 100644 (file)
@@ -2,6 +2,7 @@
 #define XTF_X86_TRAPS_H
 
 #include <xtf/compiler.h>
+#include <arch/x86/regs.h>
 
 /*
  * Arch-specific function to initialise the exception entry points, etc.
index 5b41fc5fe6c793db4f12d37e6da76de8d88e242a..96a5fecd0c9f606ac6031e337943d57a7dcb2848 100644 (file)
@@ -8,14 +8,7 @@
 
 #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.
index aa36f40f309139e7a0734bcce4316ddf78df4567..c237900b075629056565ed5bbf17ce18c11da285 100644 (file)
@@ -22,6 +22,8 @@
 #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 */
 
 /*