From e1c2fac129b51b8d19e0cf762e1f87dad4e80036 Mon Sep 17 00:00:00 2001 From: Mihail Abakumov Date: Sat, 3 Mar 2018 14:55:57 -0500 Subject: [PATCH] i386: fix read/write cr with icount option Running Windows with icount causes a crash in instruction of write cr. This patch fixes it. Reading and writing cr cause an icount read because there are called cpu_get_apic_tpr and cpu_set_apic_tpr functions. So, there is need gen_io_start()/gen_io_end() calls. Backports commit 5b003a40bb1ab14d0398e91f03393d3c6b9577cd from qemu --- qemu/target/i386/translate.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/qemu/target/i386/translate.c b/qemu/target/i386/translate.c index e0fbcffe..4a2d0fc3 100644 --- a/qemu/target/i386/translate.c +++ b/qemu/target/i386/translate.c @@ -8624,14 +8624,38 @@ case 0x101: gen_update_cc_op(s); gen_jmp_im(s, pc_start - s->cs_base); if (b & 2) { + // Unicorn: if'd out + #if 0 + if (s->tb->cflags & CF_USE_ICOUNT) { + gen_io_start(); + } + #endif gen_op_mov_v_reg(tcg_ctx, ot, cpu_T0, rm); gen_helper_write_crN(tcg_ctx, cpu_env, tcg_const_i32(tcg_ctx, reg), cpu_T0); + + // Unicorn: if'd out + #if 0 + if (s->tb->cflags & CF_USE_ICOUNT) { + gen_io_end(); + } + #endif gen_jmp_im(s, s->pc - s->cs_base); gen_eob(s); } else { + // Unicorn: if'd out + #if 0 + if (s->tb->cflags & CF_USE_ICOUNT) { + gen_io_start(); + } + #endif gen_helper_read_crN(tcg_ctx, cpu_T0, cpu_env, tcg_const_i32(tcg_ctx, reg)); gen_op_mov_reg_v(tcg_ctx, ot, rm, cpu_T0); + #if 0 + if (s->tb->cflags & CF_USE_ICOUNT) { + gen_io_end(); + } + #endif } break; default: