From patchwork Fri Jun 17 09:38:57 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Egger X-Patchwork-Id: 100810 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 448D3B6FD5 for ; Sat, 18 Jun 2011 00:28:32 +1000 (EST) Received: from localhost ([::1]:36398 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QXa29-0006aD-Lh for incoming@patchwork.ozlabs.org; Fri, 17 Jun 2011 10:28:29 -0400 Received: from eggs.gnu.org ([140.186.70.92]:54642) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QXZY2-0006uI-3m for qemu-devel@nongnu.org; Fri, 17 Jun 2011 09:57:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QXZXv-0006s6-QR for qemu-devel@nongnu.org; Fri, 17 Jun 2011 09:57:21 -0400 Received: from am1ehsobe004.messaging.microsoft.com ([213.199.154.207]:16175 helo=AM1EHSOBE004.bigfish.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QXZXu-0006r0-WA for qemu-devel@nongnu.org; Fri, 17 Jun 2011 09:57:15 -0400 Received: from mail58-am1-R.bigfish.com (10.3.201.244) by AM1EHSOBE004.bigfish.com (10.3.204.24) with Microsoft SMTP Server id 14.1.225.22; Fri, 17 Jun 2011 09:39:01 +0000 Received: from mail58-am1 (localhost.localdomain [127.0.0.1]) by mail58-am1-R.bigfish.com (Postfix) with ESMTP id 860771C200ED for ; Fri, 17 Jun 2011 09:39:01 +0000 (UTC) X-SpamScore: 25 X-BigFish: VPS25(z3cfcs329eq6celzzz1202hzz8275bh8275dhz32i668h839h64h) X-Forefront-Antispam-Report: CIP:163.181.249.108; KIP:(null); UIP:(null); IPVD:NLI; H:ausb3twp01.amd.com; RD:none; EFVD:NLI Received: from mail58-am1 (localhost.localdomain [127.0.0.1]) by mail58-am1 (MessageSwitch) id 1308303541329911_19903; Fri, 17 Jun 2011 09:39:01 +0000 (UTC) Received: from AM1EHSMHS011.bigfish.com (unknown [10.3.201.244]) by mail58-am1.bigfish.com (Postfix) with ESMTP id 4CAE91C4004B for ; Fri, 17 Jun 2011 09:39:01 +0000 (UTC) Received: from ausb3twp01.amd.com (163.181.249.108) by AM1EHSMHS011.bigfish.com (10.3.207.111) with Microsoft SMTP Server id 14.1.225.22; Fri, 17 Jun 2011 09:39:01 +0000 X-WSS-ID: 0LMXHGY-01-CHV-02 X-M-MSG: Received: from sausexedgep01.amd.com (sausexedgep01-ext.amd.com [163.181.249.72]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by ausb3twp01.amd.com (Axway MailGate 3.8.1) with ESMTP id 2E01810282B2 for ; Fri, 17 Jun 2011 04:38:58 -0500 (CDT) Received: from sausexhtp01.amd.com (163.181.3.165) by sausexedgep01.amd.com (163.181.36.54) with Microsoft SMTP Server (TLS) id 8.3.106.1; Fri, 17 Jun 2011 04:39:28 -0500 Received: from storexhtp01.amd.com (172.24.4.3) by sausexhtp01.amd.com (163.181.3.165) with Microsoft SMTP Server (TLS) id 8.3.83.0; Fri, 17 Jun 2011 04:38:59 -0500 Received: from rhodium.osrc.amd.com (165.204.15.173) by storexhtp01.amd.com (172.24.4.3) with Microsoft SMTP Server id 8.3.83.0; Fri, 17 Jun 2011 05:38:58 -0400 Message-ID: <4DFB20B1.8070409@amd.com> Date: Fri, 17 Jun 2011 11:38:57 +0200 From: Christoph Egger User-Agent: Mozilla/5.0 (X11; U; NetBSD amd64; en-US; rv:1.9.2.17) Gecko/20110523 Lightning/1.0b3pre Thunderbird/3.1.10 MIME-Version: 1.0 To: "qemu-devel@nongnu.org" X-OriginatorOrg: amd.com X-detected-operating-system: by eggs.gnu.org: Windows 2000 SP2+, XP SP1+ (seldom 98) X-Received-From: 213.199.154.207 Subject: [Qemu-devel] [PATCH] target-i386: fix cmpxchg X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@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 Signed-off-by: Christoph Egger s->cc_op = CC_OP_SUBB + ot; 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);