Signed-off-by: Richard Henderson <r...@twiddle.net> --- target-i386/helper.h | 2 ++ target-i386/mpx_helper.c | 8 ++++++++ target-i386/translate.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 55 insertions(+), 1 deletion(-)
diff --git a/target-i386/helper.h b/target-i386/helper.h index 0c957bf..331457f 100644 --- a/target-i386/helper.h +++ b/target-i386/helper.h @@ -16,6 +16,8 @@ DEF_HELPER_2(divq_EAX, void, env, tl) DEF_HELPER_2(idivq_EAX, void, env, tl) #endif +DEF_HELPER_FLAGS_2(bndck, TCG_CALL_NO_WG, void, env, i32) + DEF_HELPER_2(aam, void, env, int) DEF_HELPER_2(aad, void, env, int) DEF_HELPER_1(aaa, void, env) diff --git a/target-i386/mpx_helper.c b/target-i386/mpx_helper.c index decb2ea..172a4d2 100644 --- a/target-i386/mpx_helper.c +++ b/target-i386/mpx_helper.c @@ -49,3 +49,11 @@ void cpu_sync_bndcs_hf(CPUX86State *env) env->hflags = hflags; } + +void helper_bndck(CPUX86State *env, uint32_t fail) +{ + if (unlikely(fail)) { + env->bndcs_regs.sts = 1; + raise_exception(env, EXCP05_BOUND); + } +} diff --git a/target-i386/translate.c b/target-i386/translate.c index fcafa81..05796cc 100644 --- a/target-i386/translate.c +++ b/target-i386/translate.c @@ -1988,6 +1988,23 @@ static void gen_nop_modrm(CPUX86State *env, DisasContext *s, int modrm) (void)gen_lea_modrm_0(env, s, modrm); } +/* Used for BNDCL, BNDCU, BNDCN. */ +static void gen_bndck(CPUX86State *env, DisasContext *s, int modrm, + TCGCond cond, TCGv_i64 bndv, target_ulong pc_start) +{ + TCGv ea = gen_lea_modrm_1(gen_lea_modrm_0(env, s, modrm)); + + tcg_gen_extu_tl_i64(cpu_tmp1_i64, ea); + if (!CODE64(s)) { + tcg_gen_ext32u_i64(cpu_tmp1_i64, cpu_tmp1_i64); + } + tcg_gen_setcond_i64(cond, cpu_tmp1_i64, cpu_tmp1_i64, bndv); + tcg_gen_trunc_i64_i32(cpu_tmp2_i32, cpu_tmp1_i64); + gen_update_cc_op(s); + gen_jmp_im(pc_start - s->cs_base); + gen_helper_bndck(cpu_env, cpu_tmp2_i32); +} + /* used for LEA and MOV AX, mem */ static void gen_add_A0_ds_seg(DisasContext *s) { @@ -7521,7 +7538,26 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s, if (s->flags & HF_MPX_EN_MASK) { mod = (modrm >> 6) & 3; reg = ((modrm >> 3) & 7) | rex_r; - if (prefixes & PREFIX_DATA) { + if (prefixes & PREFIX_REPZ) { + /* bndcl */ + if (reg >= 4 + || (prefixes & PREFIX_LOCK) + || s->aflag == MO_16) { + goto illegal_op; + } + gen_bndck(env, s, modrm, TCG_COND_LTU, cpu_bndl[reg], pc_start); + } else if (prefixes & PREFIX_REPNZ) { + /* bndcu */ + if (reg >= 4 + || (prefixes & PREFIX_LOCK) + || s->aflag == MO_16) { + goto illegal_op; + } + TCGv_i64 notu = tcg_temp_new_i64(); + tcg_gen_not_i64(notu, cpu_bndu[reg]); + gen_bndck(env, s, modrm, TCG_COND_GTU, notu, pc_start); + tcg_temp_free_i64(notu); + } else if (prefixes & PREFIX_DATA) { /* bndmov -- from reg/mem */ if (reg >= 4 || s->aflag == MO_16) { goto illegal_op; @@ -7587,6 +7623,14 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s, /* bnd registers are now in-use */ gen_set_hflag(s, HF_MPX_IU_MASK); break; + } else if (prefixes & PREFIX_REPNZ) { + /* bndcn */ + if (reg >= 4 + || (prefixes & PREFIX_LOCK) + || s->aflag == MO_16) { + goto illegal_op; + } + gen_bndck(env, s, modrm, TCG_COND_GTU, cpu_bndu[reg], pc_start); } else if (prefixes & PREFIX_DATA) { /* bndmov -- to reg/mem */ if (reg >= 4 || s->aflag == MO_16) { -- 2.4.3