target/i386: Create cur_insn_len, cur_insn_len_i32

Create common routines for computing the length of the insn.
Use tcg_constant_i32 in the new function, while we're at it.

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20221001140935.465607-12-richard.henderson@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Richard Henderson 2022-10-01 07:09:20 -07:00 committed by Paolo Bonzini
parent 6424ac8eec
commit ad1d6f072d
1 changed files with 19 additions and 12 deletions

View File

@ -530,6 +530,16 @@ static void gen_update_eip_next(DisasContext *s)
gen_jmp_im(s, s->pc - s->cs_base); gen_jmp_im(s, s->pc - s->cs_base);
} }
static int cur_insn_len(DisasContext *s)
{
return s->pc - s->base.pc_next;
}
static TCGv_i32 cur_insn_len_i32(DisasContext *s)
{
return tcg_constant_i32(cur_insn_len(s));
}
/* Compute SEG:REG into A0. SEG is selected from the override segment /* Compute SEG:REG into A0. SEG is selected from the override segment
(OVR_SEG) and the default segment (DEF_SEG). OVR_SEG may be -1 to (OVR_SEG) and the default segment (DEF_SEG). OVR_SEG may be -1 to
indicate no override. */ indicate no override. */
@ -712,9 +722,6 @@ static bool gen_check_io(DisasContext *s, MemOp ot, TCGv_i32 port,
gen_helper_check_io(cpu_env, port, tcg_constant_i32(1 << ot)); gen_helper_check_io(cpu_env, port, tcg_constant_i32(1 << ot));
} }
if (GUEST(s)) { if (GUEST(s)) {
target_ulong cur_eip = s->base.pc_next - s->cs_base;
target_ulong next_eip = s->pc - s->cs_base;
gen_update_cc_op(s); gen_update_cc_op(s);
gen_update_eip_cur(s); gen_update_eip_cur(s);
if (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ)) { if (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ)) {
@ -723,7 +730,7 @@ static bool gen_check_io(DisasContext *s, MemOp ot, TCGv_i32 port,
svm_flags |= 1 << (SVM_IOIO_SIZE_SHIFT + ot); svm_flags |= 1 << (SVM_IOIO_SIZE_SHIFT + ot);
gen_helper_svm_check_io(cpu_env, port, gen_helper_svm_check_io(cpu_env, port,
tcg_constant_i32(svm_flags), tcg_constant_i32(svm_flags),
tcg_constant_i32(next_eip - cur_eip)); cur_insn_len_i32(s));
} }
return true; return true;
#endif #endif
@ -2028,7 +2035,7 @@ static uint64_t advance_pc(CPUX86State *env, DisasContext *s, int num_bytes)
} }
s->pc += num_bytes; s->pc += num_bytes;
if (unlikely(s->pc - s->base.pc_next > X86_MAX_INSN_LENGTH)) { if (unlikely(cur_insn_len(s) > X86_MAX_INSN_LENGTH)) {
/* If the instruction's 16th byte is on a different page than the 1st, a /* If the instruction's 16th byte is on a different page than the 1st, a
* page fault on the second page wins over the general protection fault * page fault on the second page wins over the general protection fault
* caused by the instruction being too long. * caused by the instruction being too long.
@ -2647,7 +2654,7 @@ static void gen_interrupt(DisasContext *s, int intno)
gen_update_cc_op(s); gen_update_cc_op(s);
gen_update_eip_cur(s); gen_update_eip_cur(s);
gen_helper_raise_interrupt(cpu_env, tcg_constant_i32(intno), gen_helper_raise_interrupt(cpu_env, tcg_constant_i32(intno),
tcg_constant_i32(s->pc - s->base.pc_next)); cur_insn_len_i32(s));
s->base.is_jmp = DISAS_NORETURN; s->base.is_jmp = DISAS_NORETURN;
} }
@ -7314,7 +7321,7 @@ static bool disas_insn(DisasContext *s, CPUState *cpu)
if (prefixes & PREFIX_REPZ) { if (prefixes & PREFIX_REPZ) {
gen_update_cc_op(s); gen_update_cc_op(s);
gen_update_eip_cur(s); gen_update_eip_cur(s);
gen_helper_pause(cpu_env, tcg_const_i32(s->pc - s->base.pc_next)); gen_helper_pause(cpu_env, cur_insn_len_i32(s));
s->base.is_jmp = DISAS_NORETURN; s->base.is_jmp = DISAS_NORETURN;
} }
break; break;
@ -7340,7 +7347,7 @@ static bool disas_insn(DisasContext *s, CPUState *cpu)
goto illegal_op; goto illegal_op;
gen_update_cc_op(s); gen_update_cc_op(s);
gen_update_eip_cur(s); gen_update_eip_cur(s);
gen_helper_into(cpu_env, tcg_const_i32(s->pc - s->base.pc_next)); gen_helper_into(cpu_env, cur_insn_len_i32(s));
break; break;
#ifdef WANT_ICEBP #ifdef WANT_ICEBP
case 0xf1: /* icebp (undocumented, exits to external debugger) */ case 0xf1: /* icebp (undocumented, exits to external debugger) */
@ -7499,7 +7506,7 @@ static bool disas_insn(DisasContext *s, CPUState *cpu)
/* XXX: is it usable in real mode ? */ /* XXX: is it usable in real mode ? */
gen_update_cc_op(s); gen_update_cc_op(s);
gen_update_eip_cur(s); gen_update_eip_cur(s);
gen_helper_syscall(cpu_env, tcg_const_i32(s->pc - s->base.pc_next)); gen_helper_syscall(cpu_env, cur_insn_len_i32(s));
/* TF handling for the syscall insn is different. The TF bit is checked /* TF handling for the syscall insn is different. The TF bit is checked
after the syscall insn completes. This allows #DB to not be after the syscall insn completes. This allows #DB to not be
generated after one has entered CPL0 if TF is set in FMASK. */ generated after one has entered CPL0 if TF is set in FMASK. */
@ -7531,7 +7538,7 @@ static bool disas_insn(DisasContext *s, CPUState *cpu)
if (check_cpl0(s)) { if (check_cpl0(s)) {
gen_update_cc_op(s); gen_update_cc_op(s);
gen_update_eip_cur(s); gen_update_eip_cur(s);
gen_helper_hlt(cpu_env, tcg_const_i32(s->pc - s->base.pc_next)); gen_helper_hlt(cpu_env, cur_insn_len_i32(s));
s->base.is_jmp = DISAS_NORETURN; s->base.is_jmp = DISAS_NORETURN;
} }
break; break;
@ -7640,7 +7647,7 @@ static bool disas_insn(DisasContext *s, CPUState *cpu)
} }
gen_update_cc_op(s); gen_update_cc_op(s);
gen_update_eip_cur(s); gen_update_eip_cur(s);
gen_helper_mwait(cpu_env, tcg_const_i32(s->pc - s->base.pc_next)); gen_helper_mwait(cpu_env, cur_insn_len_i32(s));
s->base.is_jmp = DISAS_NORETURN; s->base.is_jmp = DISAS_NORETURN;
break; break;
@ -7716,7 +7723,7 @@ static bool disas_insn(DisasContext *s, CPUState *cpu)
gen_update_cc_op(s); gen_update_cc_op(s);
gen_update_eip_cur(s); gen_update_eip_cur(s);
gen_helper_vmrun(cpu_env, tcg_const_i32(s->aflag - 1), gen_helper_vmrun(cpu_env, tcg_const_i32(s->aflag - 1),
tcg_const_i32(s->pc - s->base.pc_next)); cur_insn_len_i32(s));
tcg_gen_exit_tb(NULL, 0); tcg_gen_exit_tb(NULL, 0);
s->base.is_jmp = DISAS_NORETURN; s->base.is_jmp = DISAS_NORETURN;
break; break;