qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] target-i386: fix cmpxchg
@ 2011-06-17  9:38 Christoph Egger
  2011-06-17 14:40 ` malc
  0 siblings, 1 reply; 2+ messages in thread
From: Christoph Egger @ 2011-06-17  9:38 UTC (permalink / raw)
  To: qemu-devel@nongnu.org

Correct emulation of i386 cmpxchg instruction in the case where the
comparison outcome is unequal and the memory write causes a page
fault.

From: Andreas Gustafsson <gson@netbsd.org>
Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>

diff --git a/target-i386/translate.c b/target-i386/translate.c
index 10bd72a..69a878f 100644
--- a/target-i386/translate.c
+++ b/target-i386/translate.c
@@ -4857,20 +4857,23 @@ static target_ulong disas_insn(DisasContext *s, 
target_ulong pc_start)
              tcg_gen_sub_tl(t2, cpu_regs[R_EAX], t0);
              gen_extu(ot, t2);
              tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, label1);
+            label2 = gen_new_label();
              if (mod == 3) {
-                label2 = gen_new_label();
                  gen_op_mov_reg_v(ot, R_EAX, t0);
                  tcg_gen_br(label2);
                  gen_set_label(label1);
                  gen_op_mov_reg_v(ot, rm, t1);
-                gen_set_label(label2);
              } else {
-                tcg_gen_mov_tl(t1, t0);
+                /* perform no-op store cycle like physical cpu; must be
+                 * before changing accumulator to ensure idempotency if
+                 * the store faults and the instruction is restarted */
+                gen_op_st_v(ot + s->mem_index, t0, a0);
                  gen_op_mov_reg_v(ot, R_EAX, t0);
+                tcg_gen_br(label2);
                  gen_set_label(label1);
-                /* always store */
                  gen_op_st_v(ot + s->mem_index, t1, a0);
              }
+            gen_set_label(label2);
              tcg_gen_mov_tl(cpu_cc_src, t0);
              tcg_gen_mov_tl(cpu_cc_dst, t2);
              s->cc_op = CC_OP_SUBB + ot;



-- 
---to satisfy European Law for business letters:
Advanced Micro Devices GmbH
Einsteinring 24, 85689 Dornach b. Muenchen
Geschaeftsfuehrer: Alberto Bozzo, Andrew Bowd
Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632

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

* Re: [Qemu-devel] [PATCH] target-i386: fix cmpxchg
  2011-06-17  9:38 [Qemu-devel] [PATCH] target-i386: fix cmpxchg Christoph Egger
@ 2011-06-17 14:40 ` malc
  0 siblings, 0 replies; 2+ messages in thread
From: malc @ 2011-06-17 14:40 UTC (permalink / raw)
  To: Christoph Egger; +Cc: qemu-devel@nongnu.org

On Fri, 17 Jun 2011, Christoph Egger wrote:

> Correct emulation of i386 cmpxchg instruction in the case where the
> comparison outcome is unequal and the memory write causes a page
> fault.
> 
> From: Andreas Gustafsson <gson@netbsd.org>
> Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>

We've been through this a couple of times already:
http://www.mail-archive.com/qemu-devel@nongnu.org/msg50159.html

[..snip..]

-- 
mailto:av1474@comtv.ru

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

end of thread, other threads:[~2011-06-17 14:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-17  9:38 [Qemu-devel] [PATCH] target-i386: fix cmpxchg Christoph Egger
2011-06-17 14:40 ` malc

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).