direct-io.hg

changeset 8498:07306e35a5fc

Fix up x86 emulator header docs and ensure callers use
the X86EMUL_MODE enumeration.

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Thu Jan 05 12:19:12 2006 +0100 (2006-01-05)
parents 9efe7eb108e1
children 84cf56328ce0
files tools/tests/test_x86_emulator.c xen/arch/x86/mm.c xen/include/asm-x86/x86_emulate.h
line diff
     1.1 --- a/tools/tests/test_x86_emulator.c	Wed Jan 04 18:51:38 2006 +0100
     1.2 +++ b/tools/tests/test_x86_emulator.c	Thu Jan 05 12:19:12 2006 +0100
     1.3 @@ -92,7 +92,7 @@ int main(int argc, char **argv)
     1.4      regs.ecx    = 0x12345678;
     1.5      cr2         = (unsigned long)&res;
     1.6      res         = 0x7FFFFFFF;
     1.7 -    rc = x86_emulate_memop(&regs, cr2, &emulops, 4);
     1.8 +    rc = x86_emulate_memop(&regs, cr2, &emulops, X86EMUL_MODE_PROT32);
     1.9      if ( (rc != 0) || 
    1.10           (res != 0x92345677) || 
    1.11           (regs.eflags != 0xa94) ||
    1.12 @@ -110,7 +110,7 @@ int main(int argc, char **argv)
    1.13      regs.ecx    = 0x12345678UL;
    1.14  #endif
    1.15      cr2         = (unsigned long)&res;
    1.16 -    rc = x86_emulate_memop(&regs, cr2, &emulops, 4);
    1.17 +    rc = x86_emulate_memop(&regs, cr2, &emulops, X86EMUL_MODE_PROT32);
    1.18      if ( (rc != 0) || 
    1.19           (res != 0x92345677) || 
    1.20           (regs.ecx != 0x8000000FUL) ||
    1.21 @@ -125,7 +125,7 @@ int main(int argc, char **argv)
    1.22      regs.eax    = 0x92345677UL;
    1.23      regs.ecx    = 0xAA;
    1.24      cr2         = (unsigned long)&res;
    1.25 -    rc = x86_emulate_memop(&regs, cr2, &emulops, 4);    
    1.26 +    rc = x86_emulate_memop(&regs, cr2, &emulops, X86EMUL_MODE_PROT32);    
    1.27      if ( (rc != 0) || 
    1.28           (res != 0x923456AA) || 
    1.29           (regs.eflags != 0x244) ||
    1.30 @@ -141,7 +141,7 @@ int main(int argc, char **argv)
    1.31      regs.eax    = 0xAABBCC77UL;
    1.32      regs.ecx    = 0xFF;
    1.33      cr2         = (unsigned long)&res;
    1.34 -    rc = x86_emulate_memop(&regs, cr2, &emulops, 4);    
    1.35 +    rc = x86_emulate_memop(&regs, cr2, &emulops, X86EMUL_MODE_PROT32);    
    1.36      if ( (rc != 0) || 
    1.37           (res != 0x923456AA) || 
    1.38           ((regs.eflags&0x240) != 0x200) ||
    1.39 @@ -157,7 +157,7 @@ int main(int argc, char **argv)
    1.40      regs.eip    = (unsigned long)&instr[0];
    1.41      regs.ecx    = 0x12345678;
    1.42      cr2         = (unsigned long)&res;
    1.43 -    rc = x86_emulate_memop(&regs, cr2, &emulops, 4);    
    1.44 +    rc = x86_emulate_memop(&regs, cr2, &emulops, X86EMUL_MODE_PROT32);    
    1.45      if ( (rc != 0) || 
    1.46           (res != 0x12345678) || 
    1.47           (regs.eflags != 0x200) ||
    1.48 @@ -174,7 +174,7 @@ int main(int argc, char **argv)
    1.49      regs.eax    = 0x923456AAUL;
    1.50      regs.ecx    = 0xDDEEFF00L;
    1.51      cr2         = (unsigned long)&res;
    1.52 -    rc = x86_emulate_memop(&regs, cr2, &emulops, 4);    
    1.53 +    rc = x86_emulate_memop(&regs, cr2, &emulops, X86EMUL_MODE_PROT32);    
    1.54      if ( (rc != 0) || 
    1.55           (res != 0xDDEEFF00) || 
    1.56           (regs.eflags != 0x244) ||
    1.57 @@ -193,7 +193,7 @@ int main(int argc, char **argv)
    1.58      regs.edi    = (unsigned long)&res + 2;
    1.59      regs.error_code = 0; /* read fault */
    1.60      cr2         = regs.esi;
    1.61 -    rc = x86_emulate_memop(&regs, cr2, &emulops, 4);    
    1.62 +    rc = x86_emulate_memop(&regs, cr2, &emulops, X86EMUL_MODE_PROT32);    
    1.63      if ( (rc != 0) || 
    1.64           (res != 0x44554455) ||
    1.65           (regs.eflags != 0x200) ||
    1.66 @@ -211,7 +211,7 @@ int main(int argc, char **argv)
    1.67      regs.eip    = (unsigned long)&instr[0];
    1.68      regs.edi    = (unsigned long)&res;
    1.69      cr2         = regs.edi;
    1.70 -    rc = x86_emulate_memop(&regs, cr2, &emulops, 4);    
    1.71 +    rc = x86_emulate_memop(&regs, cr2, &emulops, X86EMUL_MODE_PROT32);    
    1.72      if ( (rc != 0) || 
    1.73           (res != 0x2233445D) ||
    1.74           ((regs.eflags&0x201) != 0x201) ||
    1.75 @@ -229,7 +229,7 @@ int main(int argc, char **argv)
    1.76      regs.eip    = (unsigned long)&instr[0];
    1.77      regs.edi    = (unsigned long)cmpxchg8b_res;
    1.78      cr2         = regs.edi;
    1.79 -    rc = x86_emulate_memop(&regs, cr2, &emulops, 4);
    1.80 +    rc = x86_emulate_memop(&regs, cr2, &emulops, X86EMUL_MODE_PROT32);
    1.81      if ( (rc != 0) || 
    1.82           (cmpxchg8b_res[0] != 0x9999AAAA) ||
    1.83           (cmpxchg8b_res[1] != 0xCCCCFFFF) ||
    1.84 @@ -243,7 +243,7 @@ int main(int argc, char **argv)
    1.85      regs.eip    = (unsigned long)&instr[0];
    1.86      regs.edi    = (unsigned long)cmpxchg8b_res;
    1.87      cr2         = regs.edi;
    1.88 -    rc = x86_emulate_memop(&regs, cr2, &emulops, 4);
    1.89 +    rc = x86_emulate_memop(&regs, cr2, &emulops, X86EMUL_MODE_PROT32);
    1.90      if ( (rc != 0) || 
    1.91           (cmpxchg8b_res[0] != 0x9999AAAA) ||
    1.92           (cmpxchg8b_res[1] != 0xCCCCFFFF) ||
    1.93 @@ -260,7 +260,7 @@ int main(int argc, char **argv)
    1.94      regs.ecx    = 0x12345678;
    1.95      cr2         = (unsigned long)&res;
    1.96      res         = 0x82;
    1.97 -    rc = x86_emulate_memop(&regs, cr2, &emulops, 4);
    1.98 +    rc = x86_emulate_memop(&regs, cr2, &emulops, X86EMUL_MODE_PROT32);
    1.99      if ( (rc != 0) ||
   1.100           (res != 0x82) ||
   1.101           (regs.ecx != 0xFFFFFF82) ||
   1.102 @@ -275,7 +275,7 @@ int main(int argc, char **argv)
   1.103      regs.ecx    = 0x12345678;
   1.104      cr2         = (unsigned long)&res;
   1.105      res         = 0x1234aa82;
   1.106 -    rc = x86_emulate_memop(&regs, cr2, &emulops, 4);
   1.107 +    rc = x86_emulate_memop(&regs, cr2, &emulops, X86EMUL_MODE_PROT32);
   1.108      if ( (rc != 0) ||
   1.109           (res != 0x1234aa82) ||
   1.110           (regs.ecx != 0xaa82) ||
     2.1 --- a/xen/arch/x86/mm.c	Wed Jan 04 18:51:38 2006 +0100
     2.2 +++ b/xen/arch/x86/mm.c	Thu Jan 05 12:19:12 2006 +0100
     2.3 @@ -3369,7 +3369,7 @@ int ptwr_do_page_fault(struct domain *d,
     2.4  
     2.5   emulate:
     2.6      if ( x86_emulate_memop(guest_cpu_user_regs(), addr,
     2.7 -                           &ptwr_mem_emulator, BITS_PER_LONG/8) )
     2.8 +                           &ptwr_mem_emulator, X86EMUL_MODE_HOST) )
     2.9          return 0;
    2.10      perfc_incrc(ptwr_emulations);
    2.11      return EXCRET_fault_fixed;
     3.1 --- a/xen/include/asm-x86/x86_emulate.h	Wed Jan 04 18:51:38 2006 +0100
     3.2 +++ b/xen/include/asm-x86/x86_emulate.h	Thu Jan 05 12:19:12 2006 +0100
     3.3 @@ -18,10 +18,11 @@
     3.4   * special treatment or emulation (*_emulated).
     3.5   * 
     3.6   * The emulator assumes that an instruction accesses only one 'emulated memory'
     3.7 - * location, and that this is one of its data operands. Instruction fetches and
     3.8 + * location, that this location is the given linear faulting address (cr2), and
     3.9 + * that this is one of the instruction's data operands. Instruction fetches and
    3.10   * stack operations are assumed never to access emulated memory. The emulator
    3.11   * automatically deduces which operand of a string-move operation is accessing
    3.12 - * emulated memory, and requires that the other operand accesses normal memory.
    3.13 + * emulated memory, and assumes that the other operand accesses normal memory.
    3.14   * 
    3.15   * NOTES:
    3.16   *  1. The emulator isn't very smart about emulated vs. standard memory.
    3.17 @@ -36,6 +37,7 @@
    3.18   *     then immediately bail.
    3.19   *  3. Valid access sizes are 1, 2, 4 and 8 bytes. On x86/32 systems only
    3.20   *     cmpxchg8b_emulated need support 8-byte accesses.
    3.21 + *  4. The emulator cannot handle 64-bit mode emulation on an x86/32 system.
    3.22   */
    3.23  /* Access completed successfully: continue emulation as normal. */
    3.24  #define X86EMUL_CONTINUE        0
    3.25 @@ -141,22 +143,27 @@ x86_emulate_write_std(
    3.26  
    3.27  struct cpu_user_regs;
    3.28  
    3.29 -/* Current execution mode, passed to the emulator. */
    3.30 -#define X86EMUL_MODE_REAL     0
    3.31 -#define X86EMUL_MODE_PROT16   2
    3.32 -#define X86EMUL_MODE_PROT32   4
    3.33 -#define X86EMUL_MODE_PROT64   8
    3.34 +/* Execution mode, passed to the emulator. */
    3.35 +#define X86EMUL_MODE_REAL     0 /* Real mode.             */
    3.36 +#define X86EMUL_MODE_PROT16   2 /* 16-bit protected mode. */
    3.37 +#define X86EMUL_MODE_PROT32   4 /* 32-bit protected mode. */
    3.38 +#define X86EMUL_MODE_PROT64   8 /* 64-bit (long) mode.    */
    3.39 +
    3.40 +/* Host execution mode. */
    3.41 +#if defined(__i386__)
    3.42 +#define X86EMUL_MODE_HOST X86EMUL_MODE_PROT32
    3.43 +#elif defined(__x86_64__)
    3.44 +#define X86EMUL_MODE_HOST X86EMUL_MODE_PROT64
    3.45 +#endif
    3.46  
    3.47  /*
    3.48   * x86_emulate_memop: Emulate an instruction that faulted attempting to
    3.49   *                    read/write a 'special' memory area.
    3.50   *  @regs: Register state at time of fault.
    3.51 - *  @cr2:  Linear faulting address.
    3.52 + *  @cr2:  Linear faulting address within an emulated/special memory area.
    3.53   *  @ops:  Interface to access special memory.
    3.54 - *  @mode: Current execution mode, represented by the default size of memory
    3.55 - *         addresses, in bytes. Valid values are 2, 4 and 8 (x86/64 only).
    3.56 - *         Alternatively use the appropriate X86EMUL_MODE value (which also
    3.57 - *         includes a value for emulating real mode).
    3.58 + *  @mode: Emulated execution mode, represented by an X86EMUL_MODE value.
    3.59 + * Returns -1 on failure, 0 on success.
    3.60   */
    3.61  extern int
    3.62  x86_emulate_memop(