From 7d947ac220c8b227ab97c5997c0c010e609b3cc6 Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Thu, 5 Jan 2006 12:19:12 +0100 Subject: Fix up x86 emulator header docs and ensure callers use the X86EMUL_MODE enumeration. Signed-off-by: Keir Fraser --- tools/tests/test_x86_emulator.c | 24 ++++++++++++------------ xen/arch/x86/mm.c | 2 +- xen/include/asm-x86/x86_emulate.h | 31 +++++++++++++++++++------------ 3 files changed, 32 insertions(+), 25 deletions(-) diff --git a/tools/tests/test_x86_emulator.c b/tools/tests/test_x86_emulator.c index f1c1a51583..46c98d1b1e 100644 --- a/tools/tests/test_x86_emulator.c +++ b/tools/tests/test_x86_emulator.c @@ -92,7 +92,7 @@ int main(int argc, char **argv) regs.ecx = 0x12345678; cr2 = (unsigned long)&res; res = 0x7FFFFFFF; - rc = x86_emulate_memop(®s, cr2, &emulops, 4); + rc = x86_emulate_memop(®s, cr2, &emulops, X86EMUL_MODE_PROT32); if ( (rc != 0) || (res != 0x92345677) || (regs.eflags != 0xa94) || @@ -110,7 +110,7 @@ int main(int argc, char **argv) regs.ecx = 0x12345678UL; #endif cr2 = (unsigned long)&res; - rc = x86_emulate_memop(®s, cr2, &emulops, 4); + rc = x86_emulate_memop(®s, cr2, &emulops, X86EMUL_MODE_PROT32); if ( (rc != 0) || (res != 0x92345677) || (regs.ecx != 0x8000000FUL) || @@ -125,7 +125,7 @@ int main(int argc, char **argv) regs.eax = 0x92345677UL; regs.ecx = 0xAA; cr2 = (unsigned long)&res; - rc = x86_emulate_memop(®s, cr2, &emulops, 4); + rc = x86_emulate_memop(®s, cr2, &emulops, X86EMUL_MODE_PROT32); if ( (rc != 0) || (res != 0x923456AA) || (regs.eflags != 0x244) || @@ -141,7 +141,7 @@ int main(int argc, char **argv) regs.eax = 0xAABBCC77UL; regs.ecx = 0xFF; cr2 = (unsigned long)&res; - rc = x86_emulate_memop(®s, cr2, &emulops, 4); + rc = x86_emulate_memop(®s, cr2, &emulops, X86EMUL_MODE_PROT32); if ( (rc != 0) || (res != 0x923456AA) || ((regs.eflags&0x240) != 0x200) || @@ -157,7 +157,7 @@ int main(int argc, char **argv) regs.eip = (unsigned long)&instr[0]; regs.ecx = 0x12345678; cr2 = (unsigned long)&res; - rc = x86_emulate_memop(®s, cr2, &emulops, 4); + rc = x86_emulate_memop(®s, cr2, &emulops, X86EMUL_MODE_PROT32); if ( (rc != 0) || (res != 0x12345678) || (regs.eflags != 0x200) || @@ -174,7 +174,7 @@ int main(int argc, char **argv) regs.eax = 0x923456AAUL; regs.ecx = 0xDDEEFF00L; cr2 = (unsigned long)&res; - rc = x86_emulate_memop(®s, cr2, &emulops, 4); + rc = x86_emulate_memop(®s, cr2, &emulops, X86EMUL_MODE_PROT32); if ( (rc != 0) || (res != 0xDDEEFF00) || (regs.eflags != 0x244) || @@ -193,7 +193,7 @@ int main(int argc, char **argv) regs.edi = (unsigned long)&res + 2; regs.error_code = 0; /* read fault */ cr2 = regs.esi; - rc = x86_emulate_memop(®s, cr2, &emulops, 4); + rc = x86_emulate_memop(®s, cr2, &emulops, X86EMUL_MODE_PROT32); if ( (rc != 0) || (res != 0x44554455) || (regs.eflags != 0x200) || @@ -211,7 +211,7 @@ int main(int argc, char **argv) regs.eip = (unsigned long)&instr[0]; regs.edi = (unsigned long)&res; cr2 = regs.edi; - rc = x86_emulate_memop(®s, cr2, &emulops, 4); + rc = x86_emulate_memop(®s, cr2, &emulops, X86EMUL_MODE_PROT32); if ( (rc != 0) || (res != 0x2233445D) || ((regs.eflags&0x201) != 0x201) || @@ -229,7 +229,7 @@ int main(int argc, char **argv) regs.eip = (unsigned long)&instr[0]; regs.edi = (unsigned long)cmpxchg8b_res; cr2 = regs.edi; - rc = x86_emulate_memop(®s, cr2, &emulops, 4); + rc = x86_emulate_memop(®s, cr2, &emulops, X86EMUL_MODE_PROT32); if ( (rc != 0) || (cmpxchg8b_res[0] != 0x9999AAAA) || (cmpxchg8b_res[1] != 0xCCCCFFFF) || @@ -243,7 +243,7 @@ int main(int argc, char **argv) regs.eip = (unsigned long)&instr[0]; regs.edi = (unsigned long)cmpxchg8b_res; cr2 = regs.edi; - rc = x86_emulate_memop(®s, cr2, &emulops, 4); + rc = x86_emulate_memop(®s, cr2, &emulops, X86EMUL_MODE_PROT32); if ( (rc != 0) || (cmpxchg8b_res[0] != 0x9999AAAA) || (cmpxchg8b_res[1] != 0xCCCCFFFF) || @@ -260,7 +260,7 @@ int main(int argc, char **argv) regs.ecx = 0x12345678; cr2 = (unsigned long)&res; res = 0x82; - rc = x86_emulate_memop(®s, cr2, &emulops, 4); + rc = x86_emulate_memop(®s, cr2, &emulops, X86EMUL_MODE_PROT32); if ( (rc != 0) || (res != 0x82) || (regs.ecx != 0xFFFFFF82) || @@ -275,7 +275,7 @@ int main(int argc, char **argv) regs.ecx = 0x12345678; cr2 = (unsigned long)&res; res = 0x1234aa82; - rc = x86_emulate_memop(®s, cr2, &emulops, 4); + rc = x86_emulate_memop(®s, cr2, &emulops, X86EMUL_MODE_PROT32); if ( (rc != 0) || (res != 0x1234aa82) || (regs.ecx != 0xaa82) || diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 683c4b7534..d94b9afc6f 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -3369,7 +3369,7 @@ int ptwr_do_page_fault(struct domain *d, unsigned long addr, emulate: if ( x86_emulate_memop(guest_cpu_user_regs(), addr, - &ptwr_mem_emulator, BITS_PER_LONG/8) ) + &ptwr_mem_emulator, X86EMUL_MODE_HOST) ) return 0; perfc_incrc(ptwr_emulations); return EXCRET_fault_fixed; diff --git a/xen/include/asm-x86/x86_emulate.h b/xen/include/asm-x86/x86_emulate.h index 19482c1538..d87d33f06c 100644 --- a/xen/include/asm-x86/x86_emulate.h +++ b/xen/include/asm-x86/x86_emulate.h @@ -18,10 +18,11 @@ * 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 + * location, that this location is the given linear faulting address (cr2), and + * that this is one of the instruction's 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. + * emulated memory, and assumes that the other operand accesses normal memory. * * NOTES: * 1. The emulator isn't very smart about emulated vs. standard memory. @@ -36,6 +37,7 @@ * then immediately bail. * 3. Valid access sizes are 1, 2, 4 and 8 bytes. On x86/32 systems only * cmpxchg8b_emulated need support 8-byte accesses. + * 4. The emulator cannot handle 64-bit mode emulation on an x86/32 system. */ /* Access completed successfully: continue emulation as normal. */ #define X86EMUL_CONTINUE 0 @@ -141,22 +143,27 @@ x86_emulate_write_std( struct cpu_user_regs; -/* Current execution mode, passed to the emulator. */ -#define X86EMUL_MODE_REAL 0 -#define X86EMUL_MODE_PROT16 2 -#define X86EMUL_MODE_PROT32 4 -#define X86EMUL_MODE_PROT64 8 +/* Execution mode, passed to the emulator. */ +#define X86EMUL_MODE_REAL 0 /* Real mode. */ +#define X86EMUL_MODE_PROT16 2 /* 16-bit protected mode. */ +#define X86EMUL_MODE_PROT32 4 /* 32-bit protected mode. */ +#define X86EMUL_MODE_PROT64 8 /* 64-bit (long) mode. */ + +/* Host execution mode. */ +#if defined(__i386__) +#define X86EMUL_MODE_HOST X86EMUL_MODE_PROT32 +#elif defined(__x86_64__) +#define X86EMUL_MODE_HOST X86EMUL_MODE_PROT64 +#endif /* * 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. + * @cr2: Linear faulting address within an emulated/special memory area. * @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). - * Alternatively use the appropriate X86EMUL_MODE value (which also - * includes a value for emulating real mode). + * @mode: Emulated execution mode, represented by an X86EMUL_MODE value. + * Returns -1 on failure, 0 on success. */ extern int x86_emulate_memop( -- cgit v1.2.3