From f9ed728f2724677b467bf8c4cfb26900ba881e20 Mon Sep 17 00:00:00 2001 From: "Emilio G. Cota" Date: Tue, 27 Feb 2018 23:03:26 -0500 Subject: [PATCH] target-i386: emulate LOCK'ed NEG using cmpxchg helper Backports commit 8eb8c7385608b99bed6055a22d897ff727a6cb8e from qemu --- qemu/target-i386/translate.c | 38 ++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/qemu/target-i386/translate.c b/qemu/target-i386/translate.c index a424a434..2dde92be 100644 --- a/qemu/target-i386/translate.c +++ b/qemu/target-i386/translate.c @@ -5362,11 +5362,41 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s, } break; case 3: /* neg */ - tcg_gen_neg_tl(tcg_ctx, cpu_T0, cpu_T0); - if (mod != 3) { - gen_op_st_v(s, ot, cpu_T0, cpu_A0); + if (s->prefix & PREFIX_LOCK) { + TCGLabel *label1; + TCGv a0, t0, t1, t2; + + if (mod == 3) { + goto illegal_op; + } + a0 = tcg_temp_local_new(tcg_ctx); + t0 = tcg_temp_local_new(tcg_ctx); + label1 = gen_new_label(tcg_ctx); + + tcg_gen_mov_tl(tcg_ctx, a0, cpu_A0); + tcg_gen_mov_tl(tcg_ctx, t0, cpu_T0); + + gen_set_label(tcg_ctx, label1); + t1 = tcg_temp_new(tcg_ctx); + t2 = tcg_temp_new(tcg_ctx); + tcg_gen_mov_tl(tcg_ctx, t2, t0); + tcg_gen_neg_tl(tcg_ctx, t1, t0); + tcg_gen_atomic_cmpxchg_tl(tcg_ctx, t0, a0, t0, t1, + s->mem_index, ot | MO_LE); + tcg_temp_free(tcg_ctx, t1); + tcg_gen_brcond_tl(tcg_ctx, TCG_COND_NE, t0, t2, label1); + + tcg_temp_free(tcg_ctx, t2); + tcg_temp_free(tcg_ctx, a0); + tcg_gen_mov_tl(tcg_ctx, cpu_T0, t0); + tcg_temp_free(tcg_ctx, t0); } else { - gen_op_mov_reg_v(tcg_ctx, ot, rm, cpu_T0); + tcg_gen_neg_tl(tcg_ctx, cpu_T0, cpu_T0); + if (mod != 3) { + gen_op_st_v(s, ot, cpu_T0, cpu_A0); + } else { + gen_op_mov_reg_v(tcg_ctx, ot, rm, cpu_T0); + } } gen_op_update_neg_cc(tcg_ctx); set_cc_op(s, CC_OP_SUBB + ot);