#define EFER_LMA (1 << 10)
#define BUG() abort()
-#define ASSERT assert
#define ASSERT_UNREACHABLE() assert(!__LINE__)
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
#define __init
#define __maybe_unused __attribute__((__unused__))
+#define likely(x) __builtin_expect(!!(x), true)
+#define unlikely(x) __builtin_expect(!!(x), false)
+
#include "x86_emulate/x86_emulate.c"
#ifndef __X86_EMULATE_H__
#define __X86_EMULATE_H__
+#if !defined(__XEN__) && !defined(ASSERT)
+#define ASSERT assert
+#endif
+
#define MAX_INST_LEN 15
struct x86_emulate_ctxt;
/*
* x86_emulate: Emulate an instruction.
- * Returns -1 on failure, 0 on success.
+ * Returns X86EMUL_* constants.
*/
int
x86_emulate(
struct x86_emulate_ctxt *ctxt,
const struct x86_emulate_ops *ops);
+#ifndef NDEBUG
+/*
+ * In debug builds, wrap x86_emulate() with some assertions about its expected
+ * behaviour.
+ */
+static inline int x86_emulate_wrapper(
+ struct x86_emulate_ctxt *ctxt,
+ const struct x86_emulate_ops *ops)
+{
+ int rc = x86_emulate(ctxt, ops);
+
+ /* Retire flags should only be set for successful instruction emulation. */
+ if ( rc != X86EMUL_OKAY )
+ ASSERT(ctxt->retire.raw == 0);
+
+ return rc;
+}
+
+#define x86_emulate x86_emulate_wrapper
+#endif
+
/*
* Given the 'reg' portion of a ModRM byte, and a register block, return a
* pointer into the block that addresses the relevant register.