target-i386: emulate LOCK'ed INC using atomic helper

Backports commit 60e573462fcdb83aa1a41e66a9f31dc8a4364399 from qemu
This commit is contained in:
Emilio G. Cota 2018-02-27 22:55:56 -05:00 committed by Lioncash
parent 7c7b0fe746
commit 05c94546d5
No known key found for this signature in database
GPG Key ID: 4E3C3CC1031BA9C7

View File

@ -1562,21 +1562,23 @@ static void gen_inc(DisasContext *s, TCGMemOp ot, int d, int c)
TCGv cpu_cc_src = tcg_ctx->cpu_cc_src;
TCGv cpu_T0 = tcg_ctx->cpu_T0;
if (s->prefix & PREFIX_LOCK) {
tcg_gen_movi_tl(tcg_ctx, cpu_T0, c > 0 ? 1 : -1);
tcg_gen_atomic_add_fetch_tl(tcg_ctx, cpu_T0, cpu_A0, cpu_T0,
s->mem_index, ot | MO_LE);
} else {
if (d != OR_TMP0) {
gen_op_mov_v_reg(tcg_ctx, ot, cpu_T0, d);
} else {
gen_op_ld_v(s, ot, cpu_T0, cpu_A0);
}
gen_compute_eflags_c(s, cpu_cc_src);
if (c > 0) {
tcg_gen_addi_tl(tcg_ctx, cpu_T0, cpu_T0, 1);
set_cc_op(s, CC_OP_INCB + ot);
} else {
tcg_gen_addi_tl(tcg_ctx, cpu_T0, cpu_T0, -1);
set_cc_op(s, CC_OP_DECB + ot);
}
tcg_gen_addi_tl(tcg_ctx, cpu_T0, cpu_T0, (c > 0 ? 1 : -1));
gen_op_st_rm_T0_A0(s, ot, d);
}
gen_compute_eflags_c(s, cpu_cc_src);
tcg_gen_mov_tl(tcg_ctx, cpu_cc_dst, cpu_T0);
set_cc_op(s, (c > 0 ? CC_OP_INCB : CC_OP_DECB) + ot);
}
static void gen_shift_flags(DisasContext *s, TCGMemOp ot, TCGv result,