]> xenbits.xensource.com Git - people/andrewcoop/xen-test-framework.git/commitdiff
Introduce common extable helper functions
authorAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 23 Aug 2016 14:55:22 +0000 (15:55 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 29 Sep 2016 17:41:09 +0000 (18:41 +0100)
It is turning out to be a common pattern to use extable handlers to catch a
fault at an instruction under test.  Introduce a common extable handler to
return fault information in %eax.

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

diff --git a/arch/x86/extable.c b/arch/x86/extable.c
new file mode 100644 (file)
index 0000000..3505e25
--- /dev/null
@@ -0,0 +1,37 @@
+/**
+ * @file arch/x86/extable.c
+ *
+ * Common x86 exception table helper functions.
+ */
+#include <xtf/lib.h>
+#include <xtf/extable.h>
+
+#include <arch/x86/regs.h>
+
+/**
+ * Record the current fault in @%eax
+ *
+ * Sample usage:
+ * <pre>
+ *   asm volatile ("1: $INSN; 2:"
+ *                 _ASM_EXTABLE_HANDLER(1b, 2b, ex_record_fault)
+ *                 : "=a" (fault) : "0" (0));
+ * </pre>
+ */
+bool ex_record_fault(struct cpu_regs *regs, const struct extable_entry *ex)
+{
+    regs->ax = (uint32_t)(regs->entry_vector << 16) | regs->error_code;
+    regs->ip = ex->fixup;
+
+    return true;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
index 4c05a49b04840c9f4b026f7f5d9fbf15872d95f6..64f43430d2ae4f3e680627cc0cde8b131e4882e4 100644 (file)
@@ -16,6 +16,7 @@ obj-perarch += $(ROOT)/common/setup.o
 
 obj-perenv += $(ROOT)/arch/x86/decode.o
 obj-perenv += $(ROOT)/arch/x86/desc.o
+obj-perenv += $(ROOT)/arch/x86/extable.o
 obj-perenv += $(ROOT)/arch/x86/hypercall_page.o
 obj-perenv += $(ROOT)/arch/x86/setup.o
 obj-perenv += $(ROOT)/arch/x86/traps.o