[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] [XEN] Add LEA to the Xen x86 emulator. Rename x86_emulate_memop() to



# HG changeset patch
# User kfraser@xxxxxxxxxxxxxxxxxxxxx
# Date 1167994555 0
# Node ID 344c8ae3cecb3eda0757f8f33088ec765a12eba8
# Parent  d04ff58bbe18b40807c1f4fe0c29843333573f05
[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@xxxxxxxxxxxxx>
---
 tools/tests/test_x86_emulator.c   |   59 +++++++++++++++++++++++++++-----------
 xen/arch/x86/mm.c                 |    2 -
 xen/arch/x86/mm/shadow/multi.c    |    2 -
 xen/arch/x86/x86_emulate.c        |    7 +++-
 xen/include/asm-x86/x86_emulate.h |    5 +--
 5 files changed, 52 insertions(+), 23 deletions(-)

diff -r d04ff58bbe18 -r 344c8ae3cecb tools/tests/test_x86_emulator.c
--- a/tools/tests/test_x86_emulator.c   Fri Jan 05 10:40:19 2007 +0000
+++ b/tools/tests/test_x86_emulator.c   Fri Jan 05 10:55:55 2007 +0000
@@ -119,7 +119,7 @@ int main(int argc, char **argv)
     regs.ecx    = 0x12345678;
     regs.eax    = (unsigned long)res;
     *res        = 0x7FFFFFFF;
-    rc = x86_emulate_memop(&ctxt, &emulops);
+    rc = x86_emulate(&ctxt, &emulops);
     if ( (rc != 0) || 
          (*res != 0x92345677) || 
          (regs.eflags != 0xa94) ||
@@ -133,7 +133,7 @@ int main(int argc, char **argv)
     regs.eip    = (unsigned long)&instr[0];
     regs.ecx    = 0x12345678;
     regs.eax    = 0x7FFFFFFF;
-    rc = x86_emulate_memop(&ctxt, &emulops);
+    rc = x86_emulate(&ctxt, &emulops);
     if ( (rc != 0) || 
          (regs.ecx != 0x12345678) ||
          (regs.eax != 0x92345677) ||
@@ -152,7 +152,7 @@ int main(int argc, char **argv)
     regs.ecx    = 0x12345678UL;
 #endif
     regs.eax    = (unsigned long)res;
-    rc = x86_emulate_memop(&ctxt, &emulops);
+    rc = x86_emulate(&ctxt, &emulops);
     if ( (rc != 0) || 
          (*res != 0x92345677) || 
          (regs.ecx != 0x8000000FUL) ||
@@ -166,7 +166,7 @@ int main(int argc, char **argv)
     regs.eip    = (unsigned long)&instr[0];
     regs.ecx    = ~0UL;
     regs.eax    = (unsigned long)res;
-    rc = x86_emulate_memop(&ctxt, &emulops);
+    rc = x86_emulate(&ctxt, &emulops);
     if ( (rc != 0) || 
          (*res != 0x92345677) || 
          (regs.ecx != 0x92345677UL) ||
@@ -181,7 +181,7 @@ int main(int argc, char **argv)
     regs.eax    = 0x92345677UL;
     regs.ecx    = 0xAA;
     regs.ebx    = (unsigned long)res;
-    rc = x86_emulate_memop(&ctxt, &emulops);
+    rc = x86_emulate(&ctxt, &emulops);
     if ( (rc != 0) || 
          (*res != 0x923456AA) || 
          (regs.eflags != 0x244) ||
@@ -197,7 +197,7 @@ int main(int argc, char **argv)
     regs.eax    = 0xAABBCC77UL;
     regs.ecx    = 0xFF;
     regs.ebx    = (unsigned long)res;
-    rc = x86_emulate_memop(&ctxt, &emulops);
+    rc = x86_emulate(&ctxt, &emulops);
     if ( (rc != 0) || 
          (*res != 0x923456AA) || 
          ((regs.eflags&0x240) != 0x200) ||
@@ -213,7 +213,7 @@ int main(int argc, char **argv)
     regs.eip    = (unsigned long)&instr[0];
     regs.ecx    = 0x12345678;
     regs.eax    = (unsigned long)res;
-    rc = x86_emulate_memop(&ctxt, &emulops);
+    rc = x86_emulate(&ctxt, &emulops);
     if ( (rc != 0) || 
          (*res != 0x12345678) || 
          (regs.eflags != 0x200) ||
@@ -230,7 +230,7 @@ int main(int argc, char **argv)
     regs.eax    = 0x923456AAUL;
     regs.ecx    = 0xDDEEFF00L;
     regs.ebx    = (unsigned long)res;
-    rc = x86_emulate_memop(&ctxt, &emulops);
+    rc = x86_emulate(&ctxt, &emulops);
     if ( (rc != 0) || 
          (*res != 0xDDEEFF00) || 
          (regs.eflags != 0x244) ||
@@ -247,7 +247,7 @@ int main(int argc, char **argv)
     regs.eip    = (unsigned long)&instr[0];
     regs.esi    = (unsigned long)res + 0;
     regs.edi    = (unsigned long)res + 2;
-    rc = x86_emulate_memop(&ctxt, &emulops);
+    rc = x86_emulate(&ctxt, &emulops);
     if ( (rc != 0) || 
          (*res != 0x44554455) ||
          (regs.eflags != 0x200) ||
@@ -264,7 +264,7 @@ int main(int argc, char **argv)
     regs.eflags = 0x200;
     regs.eip    = (unsigned long)&instr[0];
     regs.edi    = (unsigned long)res;
-    rc = x86_emulate_memop(&ctxt, &emulops);
+    rc = x86_emulate(&ctxt, &emulops);
     if ( (rc != 0) ||
          (*res != 0x2233445D) ||
          ((regs.eflags&0x201) != 0x201) ||
@@ -279,7 +279,7 @@ int main(int argc, char **argv)
     regs.eip    = (unsigned long)&instr[0];
     regs.eax    = -32;
     regs.edi    = (unsigned long)(res+1);
-    rc = x86_emulate_memop(&ctxt, &emulops);
+    rc = x86_emulate(&ctxt, &emulops);
     if ( (rc != 0) ||
          (*res != 0x2233445E) ||
          ((regs.eflags&0x201) != 0x201) ||
@@ -299,7 +299,7 @@ int main(int argc, char **argv)
     regs.ecx    = 0xCCCCFFFF;
     regs.eip    = (unsigned long)&instr[0];
     regs.edi    = (unsigned long)res;
-    rc = x86_emulate_memop(&ctxt, &emulops);
+    rc = x86_emulate(&ctxt, &emulops);
     if ( (rc != 0) ||
          (res[0] != 0x9999AAAA) ||
          (res[1] != 0xCCCCFFFF) ||
@@ -313,7 +313,7 @@ int main(int argc, char **argv)
     regs.eflags = 0x200;
     regs.eip    = (unsigned long)&instr[0];
     regs.edi    = (unsigned long)res;
-    rc = x86_emulate_memop(&ctxt, &emulops);
+    rc = x86_emulate(&ctxt, &emulops);
     if ( (rc != 0) || 
          (res[0] != 0x9999AAAA) ||
          (res[1] != 0xCCCCFFFF) ||
@@ -331,7 +331,7 @@ int main(int argc, char **argv)
     regs.ecx    = 0x12345678;
     regs.eax    = (unsigned long)res;
     *res        = 0x82;
-    rc = x86_emulate_memop(&ctxt, &emulops);
+    rc = x86_emulate(&ctxt, &emulops);
     if ( (rc != 0) ||
          (*res != 0x82) ||
          (regs.ecx != 0xFFFFFF82) ||
@@ -347,7 +347,7 @@ int main(int argc, char **argv)
     regs.ecx    = 0x12345678;
     regs.eax    = (unsigned long)res;
     *res        = 0x1234aa82;
-    rc = x86_emulate_memop(&ctxt, &emulops);
+    rc = x86_emulate(&ctxt, &emulops);
     if ( (rc != 0) ||
          (*res != 0x1234aa82) ||
          (regs.ecx != 0xaa82) ||
@@ -363,12 +363,39 @@ int main(int argc, char **argv)
     regs.ecx    = (unsigned long)res;
     regs.eax    = 0x12345678;
     *res        = 0x11111111;
-    rc = x86_emulate_memop(&ctxt, &emulops);
+    rc = x86_emulate(&ctxt, &emulops);
     if ( (rc != 0) ||
          (*res != 0x11116789) ||
          (regs.eax != 0x12341111) ||
          ((regs.eflags&0x240) != 0x200) ||
          (regs.eip != (unsigned long)&instr[4]) )
+        goto fail;
+    printf("okay\n");
+
+    printf("%-40s", "Testing dec %%ax...");
+    instr[0] = 0x66; instr[1] = 0x48;
+    regs.eflags = 0x200;
+    regs.eip    = (unsigned long)&instr[0];
+    regs.eax    = 0x00000000;
+    rc = x86_emulate(&ctxt, &emulops);
+    if ( (rc != 0) ||
+         (regs.eax != 0x0000ffff) ||
+         ((regs.eflags&0x240) != 0x200) ||
+         (regs.eip != (unsigned long)&instr[2]) )
+        goto fail;
+    printf("okay\n");
+
+    printf("%-40s", "Testing lea 8(%%ebp),%%eax...");
+    instr[0] = 0x8d; instr[1] = 0x45; instr[2] = 0x08;
+    regs.eflags = 0x200;
+    regs.eip    = (unsigned long)&instr[0];
+    regs.eax    = 0x12345678;
+    regs.ebp    = 0xaaaaaaaa;
+    rc = x86_emulate(&ctxt, &emulops);
+    if ( (rc != 0) ||
+         (regs.eax != 0xaaaaaab2) ||
+         ((regs.eflags&0x240) != 0x200) ||
+         (regs.eip != (unsigned long)&instr[3]) )
         goto fail;
     printf("okay\n");
 
diff -r d04ff58bbe18 -r 344c8ae3cecb xen/arch/x86/mm.c
--- a/xen/arch/x86/mm.c Fri Jan 05 10:40:19 2007 +0000
+++ b/xen/arch/x86/mm.c Fri Jan 05 10:55:55 2007 +0000
@@ -3297,7 +3297,7 @@ int ptwr_do_page_fault(struct vcpu *v, u
     ptwr_ctxt.ctxt.mode = X86EMUL_MODE_HOST;
     ptwr_ctxt.cr2       = addr;
     ptwr_ctxt.pte       = pte;
-    if ( x86_emulate_memop(&ptwr_ctxt.ctxt, &ptwr_emulate_ops) )
+    if ( x86_emulate(&ptwr_ctxt.ctxt, &ptwr_emulate_ops) )
         goto bail;
 
     UNLOCK_BIGLOCK(d);
diff -r d04ff58bbe18 -r 344c8ae3cecb xen/arch/x86/mm/shadow/multi.c
--- a/xen/arch/x86/mm/shadow/multi.c    Fri Jan 05 10:40:19 2007 +0000
+++ b/xen/arch/x86/mm/shadow/multi.c    Fri Jan 05 10:55:55 2007 +0000
@@ -2836,7 +2836,7 @@ static int sh_page_fault(struct vcpu *v,
      * it seems very unlikely that any OS grants user access to page tables.
      */
     if ( (regs->error_code & PFEC_user_mode) ||
-         x86_emulate_memop(&emul_ctxt.ctxt, emul_ops) )
+         x86_emulate(&emul_ctxt.ctxt, emul_ops) )
     {
         SHADOW_PRINTK("emulator failure, unshadowing mfn %#lx\n", 
                        mfn_x(gmfn));
diff -r d04ff58bbe18 -r 344c8ae3cecb xen/arch/x86/x86_emulate.c
--- a/xen/arch/x86/x86_emulate.c        Fri Jan 05 10:40:19 2007 +0000
+++ b/xen/arch/x86/x86_emulate.c        Fri Jan 05 10:55:55 2007 +0000
@@ -107,7 +107,7 @@ static uint8_t opcode_table[256] = {
     /* 0x88 - 0x8F */
     ByteOp|DstMem|SrcReg|ModRM|Mov, DstMem|SrcReg|ModRM|Mov,
     ByteOp|DstReg|SrcMem|ModRM|Mov, DstReg|SrcMem|ModRM|Mov,
-    0, 0, 0, DstMem|SrcNone|ModRM|Mov,
+    0, DstReg|SrcNone|ModRM, 0, DstMem|SrcNone|ModRM|Mov,
     /* 0x90 - 0x9F */
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
     /* 0xA0 - 0xA7 */
@@ -447,7 +447,7 @@ decode_register(
 }
 
 int
-x86_emulate_memop(
+x86_emulate(
     struct x86_emulate_ctxt *ctxt,
     struct x86_emulate_ops  *ops)
 {
@@ -869,6 +869,9 @@ x86_emulate_memop(
     case 0xc6 ... 0xc7: /* mov (sole member of Grp11) */
         dst.val = src.val;
         break;
+    case 0x8d: /* lea */
+        dst.val = ea.mem.off;
+        break;
     case 0x8f: /* pop (sole member of Grp1a) */
         /* 64-bit mode: POP defaults to a 64-bit operand. */
         if ( (mode == X86EMUL_MODE_PROT64) && (dst.bytes == 4) )
diff -r d04ff58bbe18 -r 344c8ae3cecb xen/include/asm-x86/x86_emulate.h
--- a/xen/include/asm-x86/x86_emulate.h Fri Jan 05 10:40:19 2007 +0000
+++ b/xen/include/asm-x86/x86_emulate.h Fri Jan 05 10:55:55 2007 +0000
@@ -154,12 +154,11 @@ struct x86_emulate_ctxt
 #endif
 
 /*
- * x86_emulate_memop: Emulate an instruction that faulted attempting to
- *                    read/write a 'special' memory area.
+ * x86_emulate: Emulate an instruction.
  * Returns -1 on failure, 0 on success.
  */
 int
-x86_emulate_memop(
+x86_emulate(
     struct x86_emulate_ctxt *ctxt,
     struct x86_emulate_ops  *ops);
 

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.