All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] x86_emulate: fix emulation of CMPXCHG
@ 2015-04-29  0:52 Eugene Korenevsky
  2015-05-01 11:45 ` Jan Beulich
  0 siblings, 1 reply; 2+ messages in thread
From: Eugene Korenevsky @ 2015-04-29  0:52 UTC (permalink / raw)
  To: xen-devel

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@gmail.com>
---
 xen/arch/x86/x86_emulate/x86_emulate.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/xen/arch/x86/x86_emulate/x86_emulate.c b/xen/arch/x86/x86_emulate/x86_emulate.c
index ae32c82..7532734 100644
--- a/xen/arch/x86/x86_emulate/x86_emulate.c
+++ b/xen/arch/x86/x86_emulate/x86_emulate.c
@@ -4343,7 +4343,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);
+        /* EAX must be a minuend, dst must be a subtrahend. */
+        emulate_2op_SrcV("cmp", dst, src, _regs.eflags);
         if ( _regs.eflags & EFLG_ZF )
         {
             /* Success: write back to memory. */
-- 
2.0.5

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 1/2] x86_emulate: fix emulation of CMPXCHG
  2015-04-29  0:52 [PATCH 1/2] x86_emulate: fix emulation of CMPXCHG Eugene Korenevsky
@ 2015-05-01 11:45 ` Jan Beulich
  0 siblings, 0 replies; 2+ messages in thread
From: Jan Beulich @ 2015-05-01 11:45 UTC (permalink / raw)
  To: ekorenevsky; +Cc: xen-devel

>>> Eugene Korenevsky <ekorenevsky@gmail.com> 04/28/15 11:54 PM >>>
>--- a/xen/arch/x86/x86_emulate/x86_emulate.c
>+++ b/xen/arch/x86/x86_emulate/x86_emulate.c
>@@ -4343,7 +4343,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);
>+        /* EAX must be a minuend, dst must be a subtrahend. */
>+        emulate_2op_SrcV("cmp", dst, src, _regs.eflags);

Thanks, operands indeed need to be the other way around. The comment,
however, doesn't really look that helpful to me, and hence I intend to alter
it before committing (also getting it closer to what CMPS and SCAS have).

Should you submit further patches in the future, please also remember to
Cc relevant maintainers.

Jan

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-05-01 11:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-29  0:52 [PATCH 1/2] x86_emulate: fix emulation of CMPXCHG Eugene Korenevsky
2015-05-01 11:45 ` Jan Beulich

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.