]> xenbits.xensource.com Git - people/royger/xen-test-framework.git/commitdiff
Refactor architectural trap setup
authorAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 11 Dec 2015 15:35:12 +0000 (15:35 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 18 Dec 2015 18:31:11 +0000 (18:31 +0000)
The setup of entry points is very different between PV and HVM guests.
Introduce two new traps.c to accommodate, a stub arch_init_traps(), and a stub
do_trap() as the C entry point for traps.

Adjust the single arch_crash_hard() into the relevant arch traps.c to reduce
the #ifdef'ary

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
arch/x86/hvm/traps.c [new file with mode: 0644]
arch/x86/pv/traps.c [new file with mode: 0644]
arch/x86/setup.c
arch/x86/traps.c
build/files.mk
include/arch/x86/traps.h

diff --git a/arch/x86/hvm/traps.c b/arch/x86/hvm/traps.c
new file mode 100644 (file)
index 0000000..a6d81c7
--- /dev/null
@@ -0,0 +1,29 @@
+#include <xtf/traps.h>
+
+void arch_init_traps(void)
+{
+}
+
+void __noreturn arch_crash_hard(void)
+{
+    /*
+     * Clear interrupts and halt.  Xen should catch this condition and shut
+     * the VM down.  If that fails, sit in a loop.
+     */
+    asm volatile("cli;"
+                 "1: hlt;"
+                 "pause;"
+                 "jmp 1b"
+                 ::: "memory");
+    unreachable();
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/arch/x86/pv/traps.c b/arch/x86/pv/traps.c
new file mode 100644 (file)
index 0000000..f8f9c85
--- /dev/null
@@ -0,0 +1,47 @@
+#include <xtf/traps.h>
+
+void arch_init_traps(void)
+{
+}
+
+void __noreturn arch_crash_hard(void)
+{
+    /*
+     * For both architectures, put the stack pointer into an invalid place and
+     * attempt to use it.  Xen should fail to create a bounce frame and crash
+     * the domain.
+     */
+    asm volatile(
+#ifdef __i386__
+        "mov %0, %%esp;"
+#else
+        "movabs %0, %%rsp;"
+#endif
+        "pushf"
+        ::
+#ifdef __i386__
+         "i" (0xfbadc0deUL)         /* 32bit: In the read-only M2P mapping. */
+#else
+         "i" (0x800000000badc0deUL) /* 64bit: Non-canonical region. */
+#endif
+        : "memory" );
+
+    /*
+     * Attempt to crash failed.  Give up and sit in a loop.
+     */
+    asm volatile("1: hlt;"
+                 "pause;"
+                 "jmp 1b"
+                 ::: "memory");
+    unreachable();
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
index bc9553a0fe04539e4433882e9f177a0e47484b9f..773bcd9ba6b6825222031df1bca8739965d7f7a3 100644 (file)
@@ -4,6 +4,7 @@
 
 #include <arch/x86/desc.h>
 #include <arch/x86/mm.h>
+#include <arch/x86/traps.h>
 
 uint8_t boot_stack[PAGE_SIZE] __aligned(PAGE_SIZE);
 
@@ -116,6 +117,8 @@ void arch_setup(void)
 
     register_console_callback(xen_console_write);
 
+    arch_init_traps();
+
     init_hypercalls();
 
     setup_pv_console();
index 3879ad75af457ceec0688f796b325761a25fe71b..710003bab9cca6188a3448daff481698dfe07f99 100644 (file)
@@ -1,42 +1,13 @@
+#include <xtf/lib.h>
 #include <xtf/traps.h>
 
 /*
- * Getting called means that a shutdown(crash) hypercall has not succeeded.
- * Attempt more extreme measures to try and force a crash, and fall into an
- * infinite loop if all else fails.
+ * C entry-point for exceptions, after the per-environment stubs have suitably
+ * adjusted the stack.
  */
-void __noreturn arch_crash_hard(void)
+void do_exception(void)
 {
-#if defined(CONFIG_ENV_pv32)
-    /*
-     * 32bit PV - put the stack in the Xen read-only M2P mappings and attempt
-     * to use it.
-     */
-    asm volatile("mov %0, %%esp; pushf"
-                 :: "i" (0xfbadc0deUL) : "memory");
-
-#elif defined(CONFIG_ENV_pv64)
-    /*
-     * 64bit PV - put the stack in the middle of the non-canonical region, and
-     * attempt to use it.
-     */
-    asm volatile("movabs %0, %%rsp; pushf"
-                 :: "i" (0x800000000badc0deUL) : "memory");
-
-#elif defined(CONFIG_ENV_hvm)
-    /*
-     * HVM - clear interrupts and halt.  Xen should catch this condition and
-     * shut the VM down.
-     */
-    asm volatile("cli; hlt");
-
-#endif
-
-    /*
-     * Attempt to crash failed.  Give up and sit in a loop.
-     */
-    asm volatile("1: hlt; rep; nop; jmp 1b" ::: "memory");
-    unreachable();
+    panic("Unhandled exception\n");
 }
 
 /*
index 49302f3edb9e0fbf7d5eb6b014f2cc8c867cf46b..cc3094902f4d411abeb03d6ea686a922af890339 100644 (file)
@@ -20,6 +20,13 @@ obj-perenv += $(ROOT)/arch/x86/hypercall_page.o
 
 # HVM specific objects
 obj-hvm += $(ROOT)/arch/x86/hvm_pagetables.o
+obj-hvm += $(ROOT)/arch/x86/hvm/traps.o
 
 obj-hvm32 += $(obj-hvm)
 obj-hvm64 += $(obj-hvm)
+
+# PV specific objects
+obj-pv  += $(ROOT)/arch/x86/pv/traps.o
+
+obj-pv32 += $(obj-pv)
+obj-pv64 += $(obj-pv)
index fc89d17af9dc68bb7dadeac53edb7ab7eccce66f..0a88cec7135b799d0bd10e37089fe38305d0d849 100644 (file)
@@ -3,6 +3,15 @@
 
 #include <xtf/compiler.h>
 
+/*
+ * Arch-specific function to initialise the exception entry points, etc.
+ */
+void arch_init_traps(void);
+
+/*
+ * Arch-specific function to quiesce the domain, in the event that a
+ * shutdown(crash) hypercall has not succeeded.
+ */
 void __noreturn arch_crash_hard(void);
 
 #endif /* XTF_X86_TRAPS_H */