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

[Xen-changelog] [xen stable-4.5] x86_emulate: fix EFLAGS setting of CMPXCHG emulation



commit a824bf9daff246d8b6a269028fb7c391917cad24
Author:     Eugene Korenevsky <ekorenevsky@xxxxxxxxx>
AuthorDate: Tue May 19 11:46:31 2015 +0200
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Tue May 19 11:46:31 2015 +0200

    x86_emulate: fix EFLAGS setting of CMPXCHG emulation
    
    CMPXCHG sets CF, PF, AF, SF, and OF flags according to the results of the
    comparison the rAX with the operand of the instruction.
    rAX must be the first argument of the comparison (a minuend), the operand
    must be the second one (a subtrahend).
    
    Due to improper order of comparison arguments, CF, PF, AF, SF and OF flags 
were
    set incorrectly in the case of inequality. Need to swap them.
    
    Signed-off-by: Eugene Korenevsky <ekorenevsky@xxxxxxxxx>
    
    # Commit 20fd4b70a7647656812b8f276510e09b252db9f7
    # Date 2015-05-04 12:03:19 +0200
    # Author Eugene Korenevsky <ekorenevsky@xxxxxxxxx>
    # Committer Jan Beulich <jbeulich@xxxxxxxx>
    test_x86_emulate: extend EFLAGS check of CMPXCHG test
    
    CMPXCHG: in the case of inequality of the rAX and the operand,
    need to check CF, PF, AF, SF and OF flags as well.
    
    This adjustment covers the fix of incorrect comparison during
    CMPXCHG emulation.
    
    Signed-off-by: Eugene Korenevsky <ekorenevsky@xxxxxxxxx>
    master commit: 2232628ecbab42e7700287204daad71a3ce2208c
    master date: 2015-05-04 11:55:41 +0200
    master commit: 20fd4b70a7647656812b8f276510e09b252db9f7
    master date: 2015-05-04 12:03:19 +0200
---
 tools/tests/x86_emulator/test_x86_emulator.c |    2 +-
 xen/arch/x86/x86_emulate/x86_emulate.c       |    3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/tools/tests/x86_emulator/test_x86_emulator.c 
b/tools/tests/x86_emulator/test_x86_emulator.c
index 6f67fc7..347d5f9 100644
--- a/tools/tests/x86_emulator/test_x86_emulator.c
+++ b/tools/tests/x86_emulator/test_x86_emulator.c
@@ -288,7 +288,7 @@ int main(int argc, char **argv)
     rc = x86_emulate(&ctxt, &emulops);
     if ( (rc != X86EMUL_OKAY) || 
          (*res != 0x923456AA) || 
-         ((regs.eflags&0x240) != 0x200) ||
+         ((regs.eflags&0xad5) != 0xa91) ||
          (regs.eax != 0xAABBCCAA) ||
          (regs.ecx != 0xFF) ||
          (regs.eip != (unsigned long)&instr[4]) )
diff --git a/xen/arch/x86/x86_emulate/x86_emulate.c 
b/xen/arch/x86/x86_emulate/x86_emulate.c
index 656a06f..3e8335e 100644
--- a/xen/arch/x86/x86_emulate/x86_emulate.c
+++ b/xen/arch/x86/x86_emulate/x86_emulate.c
@@ -4346,7 +4346,8 @@ x86_emulate(
         /* Save real source value, then compare EAX against destination. */
         src.orig_val = src.val;
         src.val = _regs.eax;
-        emulate_2op_SrcV("cmp", src, dst, _regs.eflags);
+        /* cmp: %%eax - dst ==> dst and src swapped for macro invocation */
+        emulate_2op_SrcV("cmp", dst, src, _regs.eflags);
         if ( _regs.eflags & EFLG_ZF )
         {
             /* Success: write back to memory. */
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.5

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
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®.