mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-11 03:24:58 -06:00
target/i386: Remove cur_eip, next_eip arguments to gen_repz*
All callers pass s->base.pc_next and s->pc, which we can just as well compute within the functions. Pull out common helpers and reduce the amount of code under macros. Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <20221001140935.465607-13-richard.henderson@linaro.org> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
ad1d6f072d
commit
122e6d7b4a
1 changed files with 57 additions and 59 deletions
|
@ -736,7 +736,7 @@ static bool gen_check_io(DisasContext *s, MemOp ot, TCGv_i32 port,
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void gen_movs(DisasContext *s, MemOp ot)
|
static void gen_movs(DisasContext *s, MemOp ot)
|
||||||
{
|
{
|
||||||
gen_string_movl_A0_ESI(s);
|
gen_string_movl_A0_ESI(s);
|
||||||
gen_op_ld_v(s, ot, s->T0, s->A0);
|
gen_op_ld_v(s, ot, s->T0, s->A0);
|
||||||
|
@ -1156,18 +1156,18 @@ static inline void gen_jcc1(DisasContext *s, int b, TCGLabel *l1)
|
||||||
|
|
||||||
/* XXX: does not work with gdbstub "ice" single step - not a
|
/* XXX: does not work with gdbstub "ice" single step - not a
|
||||||
serious problem */
|
serious problem */
|
||||||
static TCGLabel *gen_jz_ecx_string(DisasContext *s, target_ulong next_eip)
|
static TCGLabel *gen_jz_ecx_string(DisasContext *s)
|
||||||
{
|
{
|
||||||
TCGLabel *l1 = gen_new_label();
|
TCGLabel *l1 = gen_new_label();
|
||||||
TCGLabel *l2 = gen_new_label();
|
TCGLabel *l2 = gen_new_label();
|
||||||
gen_op_jnz_ecx(s, s->aflag, l1);
|
gen_op_jnz_ecx(s, s->aflag, l1);
|
||||||
gen_set_label(l2);
|
gen_set_label(l2);
|
||||||
gen_jmp_tb(s, next_eip, 1);
|
gen_jmp_tb(s, s->pc - s->cs_base, 1);
|
||||||
gen_set_label(l1);
|
gen_set_label(l1);
|
||||||
return l2;
|
return l2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void gen_stos(DisasContext *s, MemOp ot)
|
static void gen_stos(DisasContext *s, MemOp ot)
|
||||||
{
|
{
|
||||||
gen_op_mov_v_reg(s, MO_32, s->T0, R_EAX);
|
gen_op_mov_v_reg(s, MO_32, s->T0, R_EAX);
|
||||||
gen_string_movl_A0_EDI(s);
|
gen_string_movl_A0_EDI(s);
|
||||||
|
@ -1176,7 +1176,7 @@ static inline void gen_stos(DisasContext *s, MemOp ot)
|
||||||
gen_op_add_reg_T0(s, s->aflag, R_EDI);
|
gen_op_add_reg_T0(s, s->aflag, R_EDI);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void gen_lods(DisasContext *s, MemOp ot)
|
static void gen_lods(DisasContext *s, MemOp ot)
|
||||||
{
|
{
|
||||||
gen_string_movl_A0_ESI(s);
|
gen_string_movl_A0_ESI(s);
|
||||||
gen_op_ld_v(s, ot, s->T0, s->A0);
|
gen_op_ld_v(s, ot, s->T0, s->A0);
|
||||||
|
@ -1185,7 +1185,7 @@ static inline void gen_lods(DisasContext *s, MemOp ot)
|
||||||
gen_op_add_reg_T0(s, s->aflag, R_ESI);
|
gen_op_add_reg_T0(s, s->aflag, R_ESI);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void gen_scas(DisasContext *s, MemOp ot)
|
static void gen_scas(DisasContext *s, MemOp ot)
|
||||||
{
|
{
|
||||||
gen_string_movl_A0_EDI(s);
|
gen_string_movl_A0_EDI(s);
|
||||||
gen_op_ld_v(s, ot, s->T1, s->A0);
|
gen_op_ld_v(s, ot, s->T1, s->A0);
|
||||||
|
@ -1194,7 +1194,7 @@ static inline void gen_scas(DisasContext *s, MemOp ot)
|
||||||
gen_op_add_reg_T0(s, s->aflag, R_EDI);
|
gen_op_add_reg_T0(s, s->aflag, R_EDI);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void gen_cmps(DisasContext *s, MemOp ot)
|
static void gen_cmps(DisasContext *s, MemOp ot)
|
||||||
{
|
{
|
||||||
gen_string_movl_A0_EDI(s);
|
gen_string_movl_A0_EDI(s);
|
||||||
gen_op_ld_v(s, ot, s->T1, s->A0);
|
gen_op_ld_v(s, ot, s->T1, s->A0);
|
||||||
|
@ -1222,7 +1222,7 @@ static void gen_bpt_io(DisasContext *s, TCGv_i32 t_port, int ot)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void gen_ins(DisasContext *s, MemOp ot)
|
static void gen_ins(DisasContext *s, MemOp ot)
|
||||||
{
|
{
|
||||||
gen_string_movl_A0_EDI(s);
|
gen_string_movl_A0_EDI(s);
|
||||||
/* Note: we must do this dummy write first to be restartable in
|
/* Note: we must do this dummy write first to be restartable in
|
||||||
|
@ -1238,7 +1238,7 @@ static inline void gen_ins(DisasContext *s, MemOp ot)
|
||||||
gen_bpt_io(s, s->tmp2_i32, ot);
|
gen_bpt_io(s, s->tmp2_i32, ot);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void gen_outs(DisasContext *s, MemOp ot)
|
static void gen_outs(DisasContext *s, MemOp ot)
|
||||||
{
|
{
|
||||||
gen_string_movl_A0_ESI(s);
|
gen_string_movl_A0_ESI(s);
|
||||||
gen_op_ld_v(s, ot, s->T0, s->A0);
|
gen_op_ld_v(s, ot, s->T0, s->A0);
|
||||||
|
@ -1252,42 +1252,49 @@ static inline void gen_outs(DisasContext *s, MemOp ot)
|
||||||
gen_bpt_io(s, s->tmp2_i32, ot);
|
gen_bpt_io(s, s->tmp2_i32, ot);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* same method as Valgrind : we generate jumps to current or next
|
/* Generate jumps to current or next instruction */
|
||||||
instruction */
|
static void gen_repz(DisasContext *s, MemOp ot,
|
||||||
#define GEN_REPZ(op) \
|
void (*fn)(DisasContext *s, MemOp ot))
|
||||||
static inline void gen_repz_ ## op(DisasContext *s, MemOp ot, \
|
{
|
||||||
target_ulong cur_eip, target_ulong next_eip) \
|
TCGLabel *l2;
|
||||||
{ \
|
gen_update_cc_op(s);
|
||||||
TCGLabel *l2; \
|
l2 = gen_jz_ecx_string(s);
|
||||||
gen_update_cc_op(s); \
|
fn(s, ot);
|
||||||
l2 = gen_jz_ecx_string(s, next_eip); \
|
gen_op_add_reg_im(s, s->aflag, R_ECX, -1);
|
||||||
gen_ ## op(s, ot); \
|
/*
|
||||||
gen_op_add_reg_im(s, s->aflag, R_ECX, -1); \
|
* A loop would cause two single step exceptions if ECX = 1
|
||||||
/* a loop would cause two single step exceptions if ECX = 1 \
|
* before rep string_insn
|
||||||
before rep string_insn */ \
|
*/
|
||||||
if (s->repz_opt) \
|
if (s->repz_opt) {
|
||||||
gen_op_jz_ecx(s, s->aflag, l2); \
|
gen_op_jz_ecx(s, s->aflag, l2);
|
||||||
gen_jmp(s, cur_eip); \
|
}
|
||||||
|
gen_jmp(s, s->base.pc_next - s->cs_base);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define GEN_REPZ2(op) \
|
#define GEN_REPZ(op) \
|
||||||
static inline void gen_repz_ ## op(DisasContext *s, MemOp ot, \
|
static inline void gen_repz_ ## op(DisasContext *s, MemOp ot) \
|
||||||
target_ulong cur_eip, \
|
{ gen_repz(s, ot, gen_##op); }
|
||||||
target_ulong next_eip, \
|
|
||||||
int nz) \
|
static void gen_repz2(DisasContext *s, MemOp ot, int nz,
|
||||||
{ \
|
void (*fn)(DisasContext *s, MemOp ot))
|
||||||
TCGLabel *l2; \
|
{
|
||||||
gen_update_cc_op(s); \
|
TCGLabel *l2;
|
||||||
l2 = gen_jz_ecx_string(s, next_eip); \
|
gen_update_cc_op(s);
|
||||||
gen_ ## op(s, ot); \
|
l2 = gen_jz_ecx_string(s);
|
||||||
gen_op_add_reg_im(s, s->aflag, R_ECX, -1); \
|
fn(s, ot);
|
||||||
gen_update_cc_op(s); \
|
gen_op_add_reg_im(s, s->aflag, R_ECX, -1);
|
||||||
gen_jcc1(s, (JCC_Z << 1) | (nz ^ 1), l2); \
|
gen_update_cc_op(s);
|
||||||
if (s->repz_opt) \
|
gen_jcc1(s, (JCC_Z << 1) | (nz ^ 1), l2);
|
||||||
gen_op_jz_ecx(s, s->aflag, l2); \
|
if (s->repz_opt) {
|
||||||
gen_jmp(s, cur_eip); \
|
gen_op_jz_ecx(s, s->aflag, l2);
|
||||||
|
}
|
||||||
|
gen_jmp(s, s->base.pc_next - s->cs_base);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define GEN_REPZ2(op) \
|
||||||
|
static inline void gen_repz_ ## op(DisasContext *s, MemOp ot, int nz) \
|
||||||
|
{ gen_repz2(s, ot, nz, gen_##op); }
|
||||||
|
|
||||||
GEN_REPZ(movs)
|
GEN_REPZ(movs)
|
||||||
GEN_REPZ(stos)
|
GEN_REPZ(stos)
|
||||||
GEN_REPZ(lods)
|
GEN_REPZ(lods)
|
||||||
|
@ -6623,8 +6630,7 @@ static bool disas_insn(DisasContext *s, CPUState *cpu)
|
||||||
case 0xa5:
|
case 0xa5:
|
||||||
ot = mo_b_d(b, dflag);
|
ot = mo_b_d(b, dflag);
|
||||||
if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ)) {
|
if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ)) {
|
||||||
gen_repz_movs(s, ot, s->base.pc_next - s->cs_base,
|
gen_repz_movs(s, ot);
|
||||||
s->pc - s->cs_base);
|
|
||||||
} else {
|
} else {
|
||||||
gen_movs(s, ot);
|
gen_movs(s, ot);
|
||||||
}
|
}
|
||||||
|
@ -6634,8 +6640,7 @@ static bool disas_insn(DisasContext *s, CPUState *cpu)
|
||||||
case 0xab:
|
case 0xab:
|
||||||
ot = mo_b_d(b, dflag);
|
ot = mo_b_d(b, dflag);
|
||||||
if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ)) {
|
if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ)) {
|
||||||
gen_repz_stos(s, ot, s->base.pc_next - s->cs_base,
|
gen_repz_stos(s, ot);
|
||||||
s->pc - s->cs_base);
|
|
||||||
} else {
|
} else {
|
||||||
gen_stos(s, ot);
|
gen_stos(s, ot);
|
||||||
}
|
}
|
||||||
|
@ -6644,8 +6649,7 @@ static bool disas_insn(DisasContext *s, CPUState *cpu)
|
||||||
case 0xad:
|
case 0xad:
|
||||||
ot = mo_b_d(b, dflag);
|
ot = mo_b_d(b, dflag);
|
||||||
if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ)) {
|
if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ)) {
|
||||||
gen_repz_lods(s, ot, s->base.pc_next - s->cs_base,
|
gen_repz_lods(s, ot);
|
||||||
s->pc - s->cs_base);
|
|
||||||
} else {
|
} else {
|
||||||
gen_lods(s, ot);
|
gen_lods(s, ot);
|
||||||
}
|
}
|
||||||
|
@ -6654,11 +6658,9 @@ static bool disas_insn(DisasContext *s, CPUState *cpu)
|
||||||
case 0xaf:
|
case 0xaf:
|
||||||
ot = mo_b_d(b, dflag);
|
ot = mo_b_d(b, dflag);
|
||||||
if (prefixes & PREFIX_REPNZ) {
|
if (prefixes & PREFIX_REPNZ) {
|
||||||
gen_repz_scas(s, ot, s->base.pc_next - s->cs_base,
|
gen_repz_scas(s, ot, 1);
|
||||||
s->pc - s->cs_base, 1);
|
|
||||||
} else if (prefixes & PREFIX_REPZ) {
|
} else if (prefixes & PREFIX_REPZ) {
|
||||||
gen_repz_scas(s, ot, s->base.pc_next - s->cs_base,
|
gen_repz_scas(s, ot, 0);
|
||||||
s->pc - s->cs_base, 0);
|
|
||||||
} else {
|
} else {
|
||||||
gen_scas(s, ot);
|
gen_scas(s, ot);
|
||||||
}
|
}
|
||||||
|
@ -6668,11 +6670,9 @@ static bool disas_insn(DisasContext *s, CPUState *cpu)
|
||||||
case 0xa7:
|
case 0xa7:
|
||||||
ot = mo_b_d(b, dflag);
|
ot = mo_b_d(b, dflag);
|
||||||
if (prefixes & PREFIX_REPNZ) {
|
if (prefixes & PREFIX_REPNZ) {
|
||||||
gen_repz_cmps(s, ot, s->base.pc_next - s->cs_base,
|
gen_repz_cmps(s, ot, 1);
|
||||||
s->pc - s->cs_base, 1);
|
|
||||||
} else if (prefixes & PREFIX_REPZ) {
|
} else if (prefixes & PREFIX_REPZ) {
|
||||||
gen_repz_cmps(s, ot, s->base.pc_next - s->cs_base,
|
gen_repz_cmps(s, ot, 0);
|
||||||
s->pc - s->cs_base, 0);
|
|
||||||
} else {
|
} else {
|
||||||
gen_cmps(s, ot);
|
gen_cmps(s, ot);
|
||||||
}
|
}
|
||||||
|
@ -6690,8 +6690,7 @@ static bool disas_insn(DisasContext *s, CPUState *cpu)
|
||||||
gen_io_start();
|
gen_io_start();
|
||||||
}
|
}
|
||||||
if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ)) {
|
if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ)) {
|
||||||
gen_repz_ins(s, ot, s->base.pc_next - s->cs_base,
|
gen_repz_ins(s, ot);
|
||||||
s->pc - s->cs_base);
|
|
||||||
/* jump generated by gen_repz_ins */
|
/* jump generated by gen_repz_ins */
|
||||||
} else {
|
} else {
|
||||||
gen_ins(s, ot);
|
gen_ins(s, ot);
|
||||||
|
@ -6712,8 +6711,7 @@ static bool disas_insn(DisasContext *s, CPUState *cpu)
|
||||||
gen_io_start();
|
gen_io_start();
|
||||||
}
|
}
|
||||||
if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ)) {
|
if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ)) {
|
||||||
gen_repz_outs(s, ot, s->base.pc_next - s->cs_base,
|
gen_repz_outs(s, ot);
|
||||||
s->pc - s->cs_base);
|
|
||||||
/* jump generated by gen_repz_outs */
|
/* jump generated by gen_repz_outs */
|
||||||
} else {
|
} else {
|
||||||
gen_outs(s, ot);
|
gen_outs(s, ot);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue