aboutsummaryrefslogtreecommitdiffstats
path: root/xen/include/asm-x86/x86_emulate.h
diff options
context:
space:
mode:
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>2005-03-09 16:43:53 +0000
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>2005-03-09 16:43:53 +0000
commit4c5eeec983495e347c6ab3d40a4a70cdbdfce9af (patch)
tree97f1a2efc1e3a4435009a5b3c3293195ddbb34c0 /xen/include/asm-x86/x86_emulate.h
parentd9109bda544f877da56e2c9823e19486a1b229d6 (diff)
downloadxen-4c5eeec983495e347c6ab3d40a4a70cdbdfce9af.tar.gz
xen-4c5eeec983495e347c6ab3d40a4a70cdbdfce9af.tar.bz2
xen-4c5eeec983495e347c6ab3d40a4a70cdbdfce9af.zip
bitkeeper revision 1.1236.18.1 (422f27c9EveZXnXhkLBg8iYwaAffoQ)
Begin integrating new instruction decoder and emulator. Signed-off-by: Keir Fraser <keir@xensource.com>
Diffstat (limited to 'xen/include/asm-x86/x86_emulate.h')
-rw-r--r--xen/include/asm-x86/x86_emulate.h131
1 files changed, 131 insertions, 0 deletions
diff --git a/xen/include/asm-x86/x86_emulate.h b/xen/include/asm-x86/x86_emulate.h
new file mode 100644
index 0000000000..fc2301d376
--- /dev/null
+++ b/xen/include/asm-x86/x86_emulate.h
@@ -0,0 +1,131 @@
+/******************************************************************************
+ * x86_emulate.h
+ *
+ * Generic x86 (32-bit and 64-bit) instruction decoder and emulator.
+ *
+ * Copyright (c) 2005 Keir Fraser
+ */
+
+#ifndef __X86_EMULATE_H__
+#define __X86_EMULATE_H__
+
+/*
+ * x86_mem_emulator:
+ *
+ * These operations represent the instruction emulator's interface to memory.
+ * There are two categories of operation: those that act on ordinary memory
+ * regions (*_std), and those that act on memory regions known to require
+ * special treatment or emulation (*_emulated).
+ *
+ * The emulator assumes that an instruction accesses only one 'emulated memory'
+ * location, and that this is one of its data operands. Instruction fetches and
+ * stack operations are assumed never to access emulated memory. The emulator
+ * automatically deduces which operand of a string-move operation is accessing
+ * emulated memory, and requires that the other operand accesses normal memory.
+ *
+ * NOTES:
+ * 1. The emulator isn't very smart about emulated vs. standard memory.
+ * 'Emulated memory' access addresses should be checked for sanity.
+ * 'Normal memory' accesses may fault, and the caller must arrange to
+ * detect and handle reentrancy into the emulator via recursive faults.
+ * Accesses may be unaligned and may cross page boundaries.
+ * 2. If the access fails (cannot emulate, or a standard access faults) then
+ * it is up to the memop to propagate the fault to the guest VM via
+ * some out-of-band mechanism, unknown to the emulator. The memop signals
+ * failure by returning a non-zero value to the emulator, which will then
+ * immediately bail.
+ */
+struct x86_mem_emulator
+{
+ /*
+ * read_std: Read bytes of standard (non-emulated/special) memory.
+ * Used for instruction fetch, stack operations, and others.
+ * @addr: [IN ] Linear address from which to read.
+ * @val: [OUT] Value read from memory, zero-extended to 'u_long'.
+ * @bytes: [IN ] Number of bytes to read from memory.
+ */
+ int (*read_std)(
+ unsigned long addr,
+ unsigned long *val,
+ unsigned int bytes);
+
+ /*
+ * write_std: Write bytes of standard (non-emulated/special) memory.
+ * Used for stack operations, and others.
+ * @addr: [IN ] Linear address to which to write.
+ * @val: [IN ] Value to write to memory (low-order bytes used as req'd).
+ * @bytes: [IN ] Number of bytes to write to memory.
+ */
+ int (*write_std)(
+ unsigned long addr,
+ unsigned long val,
+ unsigned int bytes);
+
+ /*
+ * read_emulated: Read bytes from emulated/special memory area.
+ * @addr: [IN ] Linear address from which to read.
+ * @val: [OUT] Value read from memory, zero-extended to 'u_long'.
+ * @bytes: [IN ] Number of bytes to read from memory.
+ */
+ int (*read_emulated)(
+ unsigned long addr,
+ unsigned long *val,
+ unsigned int bytes);
+
+ /*
+ * write_emulated: Read bytes from emulated/special memory area.
+ * @addr: [IN ] Linear address to which to write.
+ * @val: [IN ] Value to write to memory (low-order bytes used as req'd).
+ * @bytes: [IN ] Number of bytes to write to memory.
+ */
+ int (*write_emulated)(
+ unsigned long addr,
+ unsigned long val,
+ unsigned int bytes);
+
+ /*
+ * cmpxchg_emulated: Emulate an atomic (LOCKed) CMPXCHG operation on an
+ * emulated/special memory area.
+ * @addr: [IN ] Linear address to access.
+ * @old: [IN ] Value expected to be current at @addr.
+ * @new: [IN ] Value to write to @addr.
+ * @seen: [OUT] Value actually seen at @addr, zero-extended to 'u_long'.
+ * @bytes: [IN ] Number of bytes to access using CMPXCHG.
+ */
+ int (*cmpxchg_emulated)(
+ unsigned long addr,
+ unsigned long old,
+ unsigned long new,
+ unsigned long *seen,
+ unsigned int bytes);
+};
+
+
+struct xen_regs;
+
+/*
+ * x86_emulate_memop: Emulate an instruction that faulted attempting to
+ * read/write a 'special' memory area.
+ * @regs: Register state at time of fault.
+ * @cr2: Linear faulting address.
+ * @ops: Interface to access special memory.
+ * @mode: Current execution mode, represented by the default size of memory
+ * addresses, in bytes. Valid values are 2, 4 and 8 (x86/64 only).
+ */
+extern int
+x86_emulate_memop(
+ struct xen_regs *regs,
+ unsigned long cr2,
+ struct x86_mem_emulator *ops,
+ int mode);
+
+/*
+ * Given the 'reg' portion of a ModRM byte, and a register block, return a
+ * pointer into the block that addresses the relevant register.
+ * @highbyte_regs specifies whether to decode AH,CH,DH,BH.
+ */
+extern void *
+decode_register(
+ u8 modrm_reg, struct xen_regs *regs, int highbyte_regs);
+
+#endif /* __X86_EMULATE_H__ */