[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 10/22] target/i386: Create cur_insn_len, cur_insn_len_i32
From: |
Richard Henderson |
Subject: |
[PATCH 10/22] target/i386: Create cur_insn_len, cur_insn_len_i32 |
Date: |
Mon, 22 Aug 2022 16:33:06 -0700 |
Create common routines for computing the length of the insn.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
target/i386/tcg/translate.c | 31 +++++++++++++++++++------------
1 file changed, 19 insertions(+), 12 deletions(-)
diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c
index 1dc3ff67ae..ee8e87a617 100644
--- a/target/i386/tcg/translate.c
+++ b/target/i386/tcg/translate.c
@@ -530,6 +530,16 @@ static void gen_update_eip_next(DisasContext *s)
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
(OVR_SEG) and the default segment (DEF_SEG). OVR_SEG may be -1 to
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));
}
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_eip_cur(s);
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);
gen_helper_svm_check_io(cpu_env, port,
tcg_constant_i32(svm_flags),
- tcg_constant_i32(next_eip - cur_eip));
+ cur_insn_len_i32(s));
}
return true;
#endif
@@ -2028,7 +2035,7 @@ static uint64_t advance_pc(CPUX86State *env, DisasContext
*s, int 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
* page fault on the second page wins over the general protection fault
* caused by the instruction being too long.
@@ -2622,7 +2629,7 @@ static void gen_interrupt(DisasContext *s, int intno)
gen_update_cc_op(s);
gen_update_eip_cur(s);
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;
}
@@ -7166,7 +7173,7 @@ static bool disas_insn(DisasContext *s, CPUState *cpu)
if (prefixes & PREFIX_REPZ) {
gen_update_cc_op(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;
}
break;
@@ -7192,7 +7199,7 @@ static bool disas_insn(DisasContext *s, CPUState *cpu)
goto illegal_op;
gen_update_cc_op(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;
#ifdef WANT_ICEBP
case 0xf1: /* icebp (undocumented, exits to external debugger) */
@@ -7351,7 +7358,7 @@ static bool disas_insn(DisasContext *s, CPUState *cpu)
/* XXX: is it usable in real mode ? */
gen_update_cc_op(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
after the syscall insn completes. This allows #DB to not be
generated after one has entered CPL0 if TF is set in FMASK. */
@@ -7383,7 +7390,7 @@ static bool disas_insn(DisasContext *s, CPUState *cpu)
if (check_cpl0(s)) {
gen_update_cc_op(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;
}
break;
@@ -7492,7 +7499,7 @@ static bool disas_insn(DisasContext *s, CPUState *cpu)
}
gen_update_cc_op(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;
break;
@@ -7568,7 +7575,7 @@ static bool disas_insn(DisasContext *s, CPUState *cpu)
gen_update_cc_op(s);
gen_update_eip_cur(s);
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);
s->base.is_jmp = DISAS_NORETURN;
break;
--
2.34.1
- [PATCH 00/22] target/i386: pc-relative translation, Richard Henderson, 2022/08/22
- [PATCH 01/22] target/i386: Return bool from disas_insn, Richard Henderson, 2022/08/22
- [PATCH 03/22] target/i386: Remove cur_eip, next_eip arguments to gen_interrupt, Richard Henderson, 2022/08/22
- [PATCH 02/22] target/i386: Remove cur_eip argument to gen_exception, Richard Henderson, 2022/08/22
- [PATCH 04/22] target/i386: Create gen_update_eip_cur, Richard Henderson, 2022/08/22
- [PATCH 05/22] target/i386: Create gen_update_eip_next, Richard Henderson, 2022/08/22
- [PATCH 06/22] target/i386: Introduce DISAS_EOB*, Richard Henderson, 2022/08/22
- [PATCH 07/22] target/i386: Use DISAS_EOB* in gen_movl_seg_T0, Richard Henderson, 2022/08/22
- [PATCH 08/22] target/i386: Use DISAS_EOB_NEXT, Richard Henderson, 2022/08/22
- [PATCH 10/22] target/i386: Create cur_insn_len, cur_insn_len_i32,
Richard Henderson <=
- [PATCH 09/22] target/i386: USe DISAS_EOB_ONLY, Richard Henderson, 2022/08/22
- [PATCH 13/22] target/i386: Truncate values for lcall_real to i32, Richard Henderson, 2022/08/22
- [PATCH 15/22] target/i386: Use DISAS_TOO_MANY to exit after gen_io_start, Richard Henderson, 2022/08/22
- [PATCH 16/22] target/i386: Create gen_jmp_rel, Richard Henderson, 2022/08/22
- [PATCH 17/22] target/i386: Use gen_jmp_rel for loop and jecxz insns, Richard Henderson, 2022/08/22
- [PATCH 11/22] target/i386: Remove cur_eip, next_eip arguments to gen_repz*, Richard Henderson, 2022/08/22
- [PATCH 20/22] target/i386: Use gen_jmp_rel for DISAS_TOO_MANY, Richard Henderson, 2022/08/22
- [PATCH 12/22] target/i386: Introduce DISAS_JUMP, Richard Henderson, 2022/08/22
- [PATCH 19/22] target/i386: Use gen_jmp_rel for gen_repz*, Richard Henderson, 2022/08/22
- [PATCH 18/22] target/i386: Use gen_jmp_rel for gen_jcc, Richard Henderson, 2022/08/22