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

[Xen-changelog] [xen-unstable] [XEN] Emulate XADD instruction.



# HG changeset patch
# User kfraser@xxxxxxxxxxxxxxxxxxxxx
# Node ID 43c8cb5a895cd5ee506d6e848049ab66fee54817
# Parent  ef1dadde363179f591543c1283a370578d8dc520
[XEN] Emulate XADD instruction.
Signed-off-by: Keir Fraser <keir@xxxxxxxxxxxxx>
---
 tools/tests/test_x86_emulator.c |   20 ++++++++++++++++++++
 xen/arch/x86/x86_emulate.c      |   17 +++++++++++++++--
 2 files changed, 35 insertions(+), 2 deletions(-)

diff -r ef1dadde3631 -r 43c8cb5a895c tools/tests/test_x86_emulator.c
--- a/tools/tests/test_x86_emulator.c   Fri Dec 01 13:55:28 2006 +0000
+++ b/tools/tests/test_x86_emulator.c   Fri Dec 01 13:57:46 2006 +0000
@@ -304,6 +304,7 @@ int main(int argc, char **argv)
 
     printf("%-40s", "Testing cmpxchg8b (%edi) [failing]...");
     instr[0] = 0x0f; instr[1] = 0xc7; instr[2] = 0x0f;
+    regs.eflags = 0x200;
     regs.eip    = (unsigned long)&instr[0];
     regs.edi    = (unsigned long)res;
     regs.error_code = PFEC_write_access;
@@ -320,6 +321,7 @@ int main(int argc, char **argv)
 
     printf("%-40s", "Testing movsxbd (%%eax),%%ecx...");
     instr[0] = 0x0f; instr[1] = 0xbe; instr[2] = 0x08;
+    regs.eflags = 0x200;
     regs.eip    = (unsigned long)&instr[0];
     regs.ecx    = 0x12345678;
     regs.eax    = (unsigned long)res;
@@ -336,6 +338,7 @@ int main(int argc, char **argv)
 
     printf("%-40s", "Testing movzxwd (%%eax),%%ecx...");
     instr[0] = 0x0f; instr[1] = 0xb7; instr[2] = 0x08;
+    regs.eflags = 0x200;
     regs.eip    = (unsigned long)&instr[0];
     regs.ecx    = 0x12345678;
     regs.eax    = (unsigned long)res;
@@ -350,6 +353,23 @@ int main(int argc, char **argv)
         goto fail;
     printf("okay\n");
 
+    printf("%-40s", "Testing xadd %%ax,(%%ecx)...");
+    instr[0] = 0x66; instr[1] = 0x0f; instr[2] = 0xc1; instr[3] = 0x01;
+    regs.eflags = 0x200;
+    regs.eip    = (unsigned long)&instr[0];
+    regs.ecx    = (unsigned long)res;
+    regs.eax    = 0x12345678;
+    *res        = 0x11111111;
+    regs.error_code = 0;
+    rc = x86_emulate_memop(&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");
+
     return 0;
 
  fail:
diff -r ef1dadde3631 -r 43c8cb5a895c xen/arch/x86/x86_emulate.c
--- a/xen/arch/x86/x86_emulate.c        Fri Dec 01 13:55:28 2006 +0000
+++ b/xen/arch/x86/x86_emulate.c        Fri Dec 01 13:57:46 2006 +0000
@@ -179,8 +179,11 @@ static uint8_t twobyte_table[256] = {
     /* 0xB8 - 0xBF */
     0, 0, DstBitBase|SrcImmByte|ModRM, DstBitBase|SrcReg|ModRM,
     0, 0, ByteOp|DstReg|SrcMem|ModRM|Mov, DstReg|SrcMem16|ModRM|Mov,
-    /* 0xC0 - 0xCF */
-    0, 0, 0, 0, 0, 0, 0, ImplicitOps|ModRM, 0, 0, 0, 0, 0, 0, 0, 0,
+    /* 0xC0 - 0xC7 */
+    ByteOp|DstMem|SrcReg|ModRM, DstMem|SrcReg|ModRM, 0, 0,
+    0, 0, 0, ImplicitOps|ModRM,
+    /* 0xC8 - 0xCF */
+    0, 0, 0, 0, 0, 0, 0, 0,
     /* 0xD0 - 0xDF */
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
     /* 0xE0 - 0xEF */
@@ -1116,6 +1119,16 @@ x86_emulate_memop(
         dst.bytes = op_bytes;
         dst.val = (d & ByteOp) ? (int8_t)src.val : (int16_t)src.val;
         break;
+    case 0xc0 ... 0xc1: /* xadd */
+        /* Write back the register source. */
+        switch ( dst.bytes )
+        {
+        case 1: *(uint8_t  *)src.reg = (uint8_t)dst.val; break;
+        case 2: *(uint16_t *)src.reg = (uint16_t)dst.val; break;
+        case 4: *src.reg = (uint32_t)dst.val; break; /* 64b reg: zero-extend */
+        case 8: *src.reg = dst.val; break;
+        }
+        goto add;
     }
     goto writeback;
 

_______________________________________________
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®.