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>
--- /dev/null
+#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:
+ */
--- /dev/null
+#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:
+ */
#include <arch/x86/desc.h>
#include <arch/x86/mm.h>
+#include <arch/x86/traps.h>
uint8_t boot_stack[PAGE_SIZE] __aligned(PAGE_SIZE);
register_console_callback(xen_console_write);
+ arch_init_traps();
+
init_hypercalls();
setup_pv_console();
+#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");
}
/*
# 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)
#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 */