ia64/xen-unstable

changeset 13268:344c8ae3cecb

[XEN] Add LEA to the Xen x86 emulator. Rename x86_emulate_memop() to
x86_emulate(), as the emulator now does more than emulation of
'special' memory accesses.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Fri Jan 05 10:55:55 2007 +0000 (2007-01-05)
parents d04ff58bbe18
children 10a6d7eff555
files tools/tests/test_x86_emulator.c xen/arch/x86/mm.c xen/arch/x86/mm/shadow/multi.c xen/arch/x86/x86_emulate.c xen/include/asm-x86/x86_emulate.h
line diff
     1.1 --- a/tools/tests/test_x86_emulator.c	Fri Jan 05 10:40:19 2007 +0000
     1.2 +++ b/tools/tests/test_x86_emulator.c	Fri Jan 05 10:55:55 2007 +0000
     1.3 @@ -119,7 +119,7 @@ int main(int argc, char **argv)
     1.4      regs.ecx    = 0x12345678;
     1.5      regs.eax    = (unsigned long)res;
     1.6      *res        = 0x7FFFFFFF;
     1.7 -    rc = x86_emulate_memop(&ctxt, &emulops);
     1.8 +    rc = x86_emulate(&ctxt, &emulops);
     1.9      if ( (rc != 0) || 
    1.10           (*res != 0x92345677) || 
    1.11           (regs.eflags != 0xa94) ||
    1.12 @@ -133,7 +133,7 @@ int main(int argc, char **argv)
    1.13      regs.eip    = (unsigned long)&instr[0];
    1.14      regs.ecx    = 0x12345678;
    1.15      regs.eax    = 0x7FFFFFFF;
    1.16 -    rc = x86_emulate_memop(&ctxt, &emulops);
    1.17 +    rc = x86_emulate(&ctxt, &emulops);
    1.18      if ( (rc != 0) || 
    1.19           (regs.ecx != 0x12345678) ||
    1.20           (regs.eax != 0x92345677) ||
    1.21 @@ -152,7 +152,7 @@ int main(int argc, char **argv)
    1.22      regs.ecx    = 0x12345678UL;
    1.23  #endif
    1.24      regs.eax    = (unsigned long)res;
    1.25 -    rc = x86_emulate_memop(&ctxt, &emulops);
    1.26 +    rc = x86_emulate(&ctxt, &emulops);
    1.27      if ( (rc != 0) || 
    1.28           (*res != 0x92345677) || 
    1.29           (regs.ecx != 0x8000000FUL) ||
    1.30 @@ -166,7 +166,7 @@ int main(int argc, char **argv)
    1.31      regs.eip    = (unsigned long)&instr[0];
    1.32      regs.ecx    = ~0UL;
    1.33      regs.eax    = (unsigned long)res;
    1.34 -    rc = x86_emulate_memop(&ctxt, &emulops);
    1.35 +    rc = x86_emulate(&ctxt, &emulops);
    1.36      if ( (rc != 0) || 
    1.37           (*res != 0x92345677) || 
    1.38           (regs.ecx != 0x92345677UL) ||
    1.39 @@ -181,7 +181,7 @@ int main(int argc, char **argv)
    1.40      regs.eax    = 0x92345677UL;
    1.41      regs.ecx    = 0xAA;
    1.42      regs.ebx    = (unsigned long)res;
    1.43 -    rc = x86_emulate_memop(&ctxt, &emulops);
    1.44 +    rc = x86_emulate(&ctxt, &emulops);
    1.45      if ( (rc != 0) || 
    1.46           (*res != 0x923456AA) || 
    1.47           (regs.eflags != 0x244) ||
    1.48 @@ -197,7 +197,7 @@ int main(int argc, char **argv)
    1.49      regs.eax    = 0xAABBCC77UL;
    1.50      regs.ecx    = 0xFF;
    1.51      regs.ebx    = (unsigned long)res;
    1.52 -    rc = x86_emulate_memop(&ctxt, &emulops);
    1.53 +    rc = x86_emulate(&ctxt, &emulops);
    1.54      if ( (rc != 0) || 
    1.55           (*res != 0x923456AA) || 
    1.56           ((regs.eflags&0x240) != 0x200) ||
    1.57 @@ -213,7 +213,7 @@ int main(int argc, char **argv)
    1.58      regs.eip    = (unsigned long)&instr[0];
    1.59      regs.ecx    = 0x12345678;
    1.60      regs.eax    = (unsigned long)res;
    1.61 -    rc = x86_emulate_memop(&ctxt, &emulops);
    1.62 +    rc = x86_emulate(&ctxt, &emulops);
    1.63      if ( (rc != 0) || 
    1.64           (*res != 0x12345678) || 
    1.65           (regs.eflags != 0x200) ||
    1.66 @@ -230,7 +230,7 @@ int main(int argc, char **argv)
    1.67      regs.eax    = 0x923456AAUL;
    1.68      regs.ecx    = 0xDDEEFF00L;
    1.69      regs.ebx    = (unsigned long)res;
    1.70 -    rc = x86_emulate_memop(&ctxt, &emulops);
    1.71 +    rc = x86_emulate(&ctxt, &emulops);
    1.72      if ( (rc != 0) || 
    1.73           (*res != 0xDDEEFF00) || 
    1.74           (regs.eflags != 0x244) ||
    1.75 @@ -247,7 +247,7 @@ int main(int argc, char **argv)
    1.76      regs.eip    = (unsigned long)&instr[0];
    1.77      regs.esi    = (unsigned long)res + 0;
    1.78      regs.edi    = (unsigned long)res + 2;
    1.79 -    rc = x86_emulate_memop(&ctxt, &emulops);
    1.80 +    rc = x86_emulate(&ctxt, &emulops);
    1.81      if ( (rc != 0) || 
    1.82           (*res != 0x44554455) ||
    1.83           (regs.eflags != 0x200) ||
    1.84 @@ -264,7 +264,7 @@ int main(int argc, char **argv)
    1.85      regs.eflags = 0x200;
    1.86      regs.eip    = (unsigned long)&instr[0];
    1.87      regs.edi    = (unsigned long)res;
    1.88 -    rc = x86_emulate_memop(&ctxt, &emulops);
    1.89 +    rc = x86_emulate(&ctxt, &emulops);
    1.90      if ( (rc != 0) ||
    1.91           (*res != 0x2233445D) ||
    1.92           ((regs.eflags&0x201) != 0x201) ||
    1.93 @@ -279,7 +279,7 @@ int main(int argc, char **argv)
    1.94      regs.eip    = (unsigned long)&instr[0];
    1.95      regs.eax    = -32;
    1.96      regs.edi    = (unsigned long)(res+1);
    1.97 -    rc = x86_emulate_memop(&ctxt, &emulops);
    1.98 +    rc = x86_emulate(&ctxt, &emulops);
    1.99      if ( (rc != 0) ||
   1.100           (*res != 0x2233445E) ||
   1.101           ((regs.eflags&0x201) != 0x201) ||
   1.102 @@ -299,7 +299,7 @@ int main(int argc, char **argv)
   1.103      regs.ecx    = 0xCCCCFFFF;
   1.104      regs.eip    = (unsigned long)&instr[0];
   1.105      regs.edi    = (unsigned long)res;
   1.106 -    rc = x86_emulate_memop(&ctxt, &emulops);
   1.107 +    rc = x86_emulate(&ctxt, &emulops);
   1.108      if ( (rc != 0) ||
   1.109           (res[0] != 0x9999AAAA) ||
   1.110           (res[1] != 0xCCCCFFFF) ||
   1.111 @@ -313,7 +313,7 @@ int main(int argc, char **argv)
   1.112      regs.eflags = 0x200;
   1.113      regs.eip    = (unsigned long)&instr[0];
   1.114      regs.edi    = (unsigned long)res;
   1.115 -    rc = x86_emulate_memop(&ctxt, &emulops);
   1.116 +    rc = x86_emulate(&ctxt, &emulops);
   1.117      if ( (rc != 0) || 
   1.118           (res[0] != 0x9999AAAA) ||
   1.119           (res[1] != 0xCCCCFFFF) ||
   1.120 @@ -331,7 +331,7 @@ int main(int argc, char **argv)
   1.121      regs.ecx    = 0x12345678;
   1.122      regs.eax    = (unsigned long)res;
   1.123      *res        = 0x82;
   1.124 -    rc = x86_emulate_memop(&ctxt, &emulops);
   1.125 +    rc = x86_emulate(&ctxt, &emulops);
   1.126      if ( (rc != 0) ||
   1.127           (*res != 0x82) ||
   1.128           (regs.ecx != 0xFFFFFF82) ||
   1.129 @@ -347,7 +347,7 @@ int main(int argc, char **argv)
   1.130      regs.ecx    = 0x12345678;
   1.131      regs.eax    = (unsigned long)res;
   1.132      *res        = 0x1234aa82;
   1.133 -    rc = x86_emulate_memop(&ctxt, &emulops);
   1.134 +    rc = x86_emulate(&ctxt, &emulops);
   1.135      if ( (rc != 0) ||
   1.136           (*res != 0x1234aa82) ||
   1.137           (regs.ecx != 0xaa82) ||
   1.138 @@ -363,7 +363,7 @@ int main(int argc, char **argv)
   1.139      regs.ecx    = (unsigned long)res;
   1.140      regs.eax    = 0x12345678;
   1.141      *res        = 0x11111111;
   1.142 -    rc = x86_emulate_memop(&ctxt, &emulops);
   1.143 +    rc = x86_emulate(&ctxt, &emulops);
   1.144      if ( (rc != 0) ||
   1.145           (*res != 0x11116789) ||
   1.146           (regs.eax != 0x12341111) ||
   1.147 @@ -372,6 +372,33 @@ int main(int argc, char **argv)
   1.148          goto fail;
   1.149      printf("okay\n");
   1.150  
   1.151 +    printf("%-40s", "Testing dec %%ax...");
   1.152 +    instr[0] = 0x66; instr[1] = 0x48;
   1.153 +    regs.eflags = 0x200;
   1.154 +    regs.eip    = (unsigned long)&instr[0];
   1.155 +    regs.eax    = 0x00000000;
   1.156 +    rc = x86_emulate(&ctxt, &emulops);
   1.157 +    if ( (rc != 0) ||
   1.158 +         (regs.eax != 0x0000ffff) ||
   1.159 +         ((regs.eflags&0x240) != 0x200) ||
   1.160 +         (regs.eip != (unsigned long)&instr[2]) )
   1.161 +        goto fail;
   1.162 +    printf("okay\n");
   1.163 +
   1.164 +    printf("%-40s", "Testing lea 8(%%ebp),%%eax...");
   1.165 +    instr[0] = 0x8d; instr[1] = 0x45; instr[2] = 0x08;
   1.166 +    regs.eflags = 0x200;
   1.167 +    regs.eip    = (unsigned long)&instr[0];
   1.168 +    regs.eax    = 0x12345678;
   1.169 +    regs.ebp    = 0xaaaaaaaa;
   1.170 +    rc = x86_emulate(&ctxt, &emulops);
   1.171 +    if ( (rc != 0) ||
   1.172 +         (regs.eax != 0xaaaaaab2) ||
   1.173 +         ((regs.eflags&0x240) != 0x200) ||
   1.174 +         (regs.eip != (unsigned long)&instr[3]) )
   1.175 +        goto fail;
   1.176 +    printf("okay\n");
   1.177 +
   1.178      return 0;
   1.179  
   1.180   fail:
     2.1 --- a/xen/arch/x86/mm.c	Fri Jan 05 10:40:19 2007 +0000
     2.2 +++ b/xen/arch/x86/mm.c	Fri Jan 05 10:55:55 2007 +0000
     2.3 @@ -3297,7 +3297,7 @@ int ptwr_do_page_fault(struct vcpu *v, u
     2.4      ptwr_ctxt.ctxt.mode = X86EMUL_MODE_HOST;
     2.5      ptwr_ctxt.cr2       = addr;
     2.6      ptwr_ctxt.pte       = pte;
     2.7 -    if ( x86_emulate_memop(&ptwr_ctxt.ctxt, &ptwr_emulate_ops) )
     2.8 +    if ( x86_emulate(&ptwr_ctxt.ctxt, &ptwr_emulate_ops) )
     2.9          goto bail;
    2.10  
    2.11      UNLOCK_BIGLOCK(d);
     3.1 --- a/xen/arch/x86/mm/shadow/multi.c	Fri Jan 05 10:40:19 2007 +0000
     3.2 +++ b/xen/arch/x86/mm/shadow/multi.c	Fri Jan 05 10:55:55 2007 +0000
     3.3 @@ -2836,7 +2836,7 @@ static int sh_page_fault(struct vcpu *v,
     3.4       * it seems very unlikely that any OS grants user access to page tables.
     3.5       */
     3.6      if ( (regs->error_code & PFEC_user_mode) ||
     3.7 -         x86_emulate_memop(&emul_ctxt.ctxt, emul_ops) )
     3.8 +         x86_emulate(&emul_ctxt.ctxt, emul_ops) )
     3.9      {
    3.10          SHADOW_PRINTK("emulator failure, unshadowing mfn %#lx\n", 
    3.11                         mfn_x(gmfn));
     4.1 --- a/xen/arch/x86/x86_emulate.c	Fri Jan 05 10:40:19 2007 +0000
     4.2 +++ b/xen/arch/x86/x86_emulate.c	Fri Jan 05 10:55:55 2007 +0000
     4.3 @@ -107,7 +107,7 @@ static uint8_t opcode_table[256] = {
     4.4      /* 0x88 - 0x8F */
     4.5      ByteOp|DstMem|SrcReg|ModRM|Mov, DstMem|SrcReg|ModRM|Mov,
     4.6      ByteOp|DstReg|SrcMem|ModRM|Mov, DstReg|SrcMem|ModRM|Mov,
     4.7 -    0, 0, 0, DstMem|SrcNone|ModRM|Mov,
     4.8 +    0, DstReg|SrcNone|ModRM, 0, DstMem|SrcNone|ModRM|Mov,
     4.9      /* 0x90 - 0x9F */
    4.10      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    4.11      /* 0xA0 - 0xA7 */
    4.12 @@ -447,7 +447,7 @@ decode_register(
    4.13  }
    4.14  
    4.15  int
    4.16 -x86_emulate_memop(
    4.17 +x86_emulate(
    4.18      struct x86_emulate_ctxt *ctxt,
    4.19      struct x86_emulate_ops  *ops)
    4.20  {
    4.21 @@ -869,6 +869,9 @@ x86_emulate_memop(
    4.22      case 0xc6 ... 0xc7: /* mov (sole member of Grp11) */
    4.23          dst.val = src.val;
    4.24          break;
    4.25 +    case 0x8d: /* lea */
    4.26 +        dst.val = ea.mem.off;
    4.27 +        break;
    4.28      case 0x8f: /* pop (sole member of Grp1a) */
    4.29          /* 64-bit mode: POP defaults to a 64-bit operand. */
    4.30          if ( (mode == X86EMUL_MODE_PROT64) && (dst.bytes == 4) )
     5.1 --- a/xen/include/asm-x86/x86_emulate.h	Fri Jan 05 10:40:19 2007 +0000
     5.2 +++ b/xen/include/asm-x86/x86_emulate.h	Fri Jan 05 10:55:55 2007 +0000
     5.3 @@ -154,12 +154,11 @@ struct x86_emulate_ctxt
     5.4  #endif
     5.5  
     5.6  /*
     5.7 - * x86_emulate_memop: Emulate an instruction that faulted attempting to
     5.8 - *                    read/write a 'special' memory area.
     5.9 + * x86_emulate: Emulate an instruction.
    5.10   * Returns -1 on failure, 0 on success.
    5.11   */
    5.12  int
    5.13 -x86_emulate_memop(
    5.14 +x86_emulate(
    5.15      struct x86_emulate_ctxt *ctxt,
    5.16      struct x86_emulate_ops  *ops);
    5.17