From patchwork Tue Jul 3 05:57:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gibson X-Patchwork-Id: 140897 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp765487ljj; Mon, 2 Jul 2018 23:06:23 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfU3H+K4g8zMhPM/MZnhEOIKJCi91+hDLu1L1qV8tDQKsPIP2cH9GN/x6ar9WgxBeyQJI6A X-Received: by 2002:a37:7c6:: with SMTP id 189-v6mr16197776qkh.15.1530597982892; Mon, 02 Jul 2018 23:06:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530597982; cv=none; d=google.com; s=arc-20160816; b=xf76wXxwRc3OfgCG93pOklWTsbBMWvE50ZvP7eMp9PYtc5RrSzdsbK/SMJXg2PAIso sI3YetKP5qJguEJesPTfjzz840HAZI50MtFD9OebbbXsuKhDlv8XQpq7kwWHbKf1r5Hy 5iR1+mf2pe5xW2Ziv8J3GVLWaHzKL9nFNKWo/UyCiprojqeE0YjPtAOX/h7eEj5LBDs8 C1oYFNSHUPBe3gg8hcrz+w9bALS+0ELf7owg6jkXzmRXqyr4zdvf3GXNyyNGj2pKhUWv tBZ59vK6rSahzMHWrqOCLwWxU9A9wWdFARPXQUHuN+bSO1HVKaxND8/eSIIk3gwGiVUO I12w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=89BjUrFOXUP96RNHzUQS4+21FyUqbcHnhG5H7AonNik=; b=DZS7MqTVBxT6x0nMKB6ALBlUs1/pG+rc0Qo64cJh5jVlUT8LRdhCgPoqj5lQE44Zdv CMmNlI8h+1J4bNemQkmtN55CN23jdP9FLcKbLWWbd4Brw9Bd4MX9PBBJWv6dUz4chHf+ LFlf3KmT2sDaSJq333ZsxKHApKaXAHxf2HLDPm9Uc41qFa8ooeU1GXGxFMvwo7BdZ+jT 5ssZavAY347J8LZrCzoqfHRePBfuZrBBWdS/KTvEq2jOvZblOmH3mJ6yp9J1eP497tfA /g9tpvaukLGRd23EAdnJzZEMpp62aiEIFn3MXef9kbKKLgfw+1A/kNwqbtcMJd65gzgB 0Ccw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gibson.dropbear.id.au header.s=201602 header.b=bKJl9wGC; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 61-v6si325003qtf.322.2018.07.02.23.06.22 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 02 Jul 2018 23:06:22 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@gibson.dropbear.id.au header.s=201602 header.b=bKJl9wGC; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:37974 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1faESE-0000ZR-8M for patch@linaro.org; Tue, 03 Jul 2018 02:06:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39881) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1faEKY-0002sV-2w for qemu-devel@nongnu.org; Tue, 03 Jul 2018 01:58:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1faEKV-00071s-OZ for qemu-devel@nongnu.org; Tue, 03 Jul 2018 01:58:26 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:32831) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1faEKU-0006xx-RN; Tue, 03 Jul 2018 01:58:23 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 41KYMB634yz9sBs; Tue, 3 Jul 2018 15:58:13 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1530597494; bh=kcbHI7VcKyE/gHvFWADW0Ha5EEQDj1GjzAloZ1A66+8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bKJl9wGCrpK10Bu4U+74/gkjflrifElgT2bGO6L8OGX57rRfp3eT6uDZTSvcNP8pf gGs3zGsqO3pK1duLOr3aJRdxd/26xszLHluqby9JvWQGejcfk74xE+TgkXsz8nnuHM 6eHD35q/+ISLTmqXNt6zCFzfs1DFdH0GtOfeh84I= From: David Gibson To: peter.maydell@linaro.org Date: Tue, 3 Jul 2018 15:57:51 +1000 Message-Id: <20180703055804.13449-23-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180703055804.13449-1-david@gibson.dropbear.id.au> References: <20180703055804.13449-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2401:3900:2:1::2 Subject: [Qemu-devel] [PULL 22/35] target/ppc: Implement the rest of gen_ld_atomic X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org, Richard Henderson , mdroth@linux.vnet.ibm.com, agraf@suse.de, aik@ozlabs.ru, groug@kaod.org, qemu-ppc@nongnu.org, clg@kaod.org, David Gibson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson These cases were stubbed out. For now, implement them only within a serial context, forcing parallel execution to synchronize. It would be possible to implement these with cmpxchg loops, if we care. Signed-off-by: Richard Henderson Signed-off-by: David Gibson --- target/ppc/translate.c | 83 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 79 insertions(+), 4 deletions(-) -- 2.17.1 diff --git a/target/ppc/translate.c b/target/ppc/translate.c index 79285b6698..597a37d3ec 100644 --- a/target/ppc/translate.c +++ b/target/ppc/translate.c @@ -3078,16 +3078,45 @@ LARX(lbarx, DEF_MEMOP(MO_UB)) LARX(lharx, DEF_MEMOP(MO_UW)) LARX(lwarx, DEF_MEMOP(MO_UL)) +static void gen_fetch_inc_conditional(DisasContext *ctx, TCGMemOp memop, + TCGv EA, TCGCond cond, int addend) +{ + TCGv t = tcg_temp_new(); + TCGv t2 = tcg_temp_new(); + TCGv u = tcg_temp_new(); + + tcg_gen_qemu_ld_tl(t, EA, ctx->mem_idx, memop); + tcg_gen_addi_tl(t2, EA, MEMOP_GET_SIZE(memop)); + tcg_gen_qemu_ld_tl(t2, t2, ctx->mem_idx, memop); + tcg_gen_addi_tl(u, t, addend); + + /* E.g. for fetch and increment bounded... */ + /* mem(EA,s) = (t != t2 ? u = t + 1 : t) */ + tcg_gen_movcond_tl(cond, u, t, t2, u, t); + tcg_gen_qemu_st_tl(u, EA, ctx->mem_idx, memop); + + /* RT = (t != t2 ? t : u = 1<<(s*8-1)) */ + tcg_gen_movi_tl(u, 1 << (MEMOP_GET_SIZE(memop) * 8 - 1)); + tcg_gen_movcond_tl(cond, cpu_gpr[rD(ctx->opcode)], t, t2, t, u); + + tcg_temp_free(t); + tcg_temp_free(t2); + tcg_temp_free(u); +} + static void gen_ld_atomic(DisasContext *ctx, TCGMemOp memop) { uint32_t gpr_FC = FC(ctx->opcode); TCGv EA = tcg_temp_new(); + int rt = rD(ctx->opcode); + bool need_serial; TCGv src, dst; gen_addr_register(ctx, EA); - dst = cpu_gpr[rD(ctx->opcode)]; - src = cpu_gpr[rD(ctx->opcode) + 1]; + dst = cpu_gpr[rt]; + src = cpu_gpr[(rt + 1) & 31]; + need_serial = false; memop |= MO_ALIGN; switch (gpr_FC) { case 0: /* Fetch and add */ @@ -3117,17 +3146,63 @@ static void gen_ld_atomic(DisasContext *ctx, TCGMemOp memop) case 8: /* Swap */ tcg_gen_atomic_xchg_tl(dst, EA, src, ctx->mem_idx, memop); break; - case 16: /* compare and swap not equal */ + + case 16: /* Compare and swap not equal */ + if (tb_cflags(ctx->base.tb) & CF_PARALLEL) { + need_serial = true; + } else { + TCGv t0 = tcg_temp_new(); + TCGv t1 = tcg_temp_new(); + + tcg_gen_qemu_ld_tl(t0, EA, ctx->mem_idx, memop); + if ((memop & MO_SIZE) == MO_64 || TARGET_LONG_BITS == 32) { + tcg_gen_mov_tl(t1, src); + } else { + tcg_gen_ext32u_tl(t1, src); + } + tcg_gen_movcond_tl(TCG_COND_NE, t1, t0, t1, + cpu_gpr[(rt + 2) & 31], t0); + tcg_gen_qemu_st_tl(t1, EA, ctx->mem_idx, memop); + tcg_gen_mov_tl(dst, t0); + + tcg_temp_free(t0); + tcg_temp_free(t1); + } + break; + case 24: /* Fetch and increment bounded */ + if (tb_cflags(ctx->base.tb) & CF_PARALLEL) { + need_serial = true; + } else { + gen_fetch_inc_conditional(ctx, memop, EA, TCG_COND_NE, 1); + } + break; case 25: /* Fetch and increment equal */ + if (tb_cflags(ctx->base.tb) & CF_PARALLEL) { + need_serial = true; + } else { + gen_fetch_inc_conditional(ctx, memop, EA, TCG_COND_EQ, 1); + } + break; case 28: /* Fetch and decrement bounded */ - gen_invalid(ctx); + if (tb_cflags(ctx->base.tb) & CF_PARALLEL) { + need_serial = true; + } else { + gen_fetch_inc_conditional(ctx, memop, EA, TCG_COND_NE, -1); + } break; + default: /* invoke data storage error handler */ gen_exception_err(ctx, POWERPC_EXCP_DSI, POWERPC_EXCP_INVAL); } tcg_temp_free(EA); + + if (need_serial) { + /* Restart with exclusive lock. */ + gen_helper_exit_atomic(cpu_env); + ctx->base.is_jmp = DISAS_NORETURN; + } } static void gen_lwat(DisasContext *ctx)