diff options
author | Richard Henderson <rth@twiddle.net> | 2015-12-17 11:19:19 -0800 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2016-02-09 15:45:27 +0100 |
commit | d6a2914984c89fa0a3125b9842e0cbf68de79a3d (patch) | |
tree | 10cb617739aea3c7521c293a56d22b038fc3a37e /target-i386/translate.c | |
parent | 64ae256c2450262e27f07657c5734d3197458d95 (diff) |
target-i386: Use gen_lea_v_seg in gen_lea_modrm
Centralize handling of segment bases.
Signed-off-by: Richard Henderson <rth@twiddle.net>
Message-Id: <1450379966-28198-4-git-send-email-rth@twiddle.net>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'target-i386/translate.c')
-rw-r--r-- | target-i386/translate.c | 82 |
1 files changed, 23 insertions, 59 deletions
diff --git a/target-i386/translate.c b/target-i386/translate.c index 836ef1c101..282f4a1c7f 100644 --- a/target-i386/translate.c +++ b/target-i386/translate.c @@ -1841,17 +1841,12 @@ static void gen_shifti(DisasContext *s1, int op, TCGMemOp ot, int d, int c) static void gen_lea_modrm(CPUX86State *env, DisasContext *s, int modrm) { target_long disp; - int havesib; - int base; - int index; - int scale; - int mod, rm, code, override, must_add_seg; + int havesib, base, index, scale; + int mod, rm, code, def_seg, ovr_seg; TCGv sum; - override = s->override; - must_add_seg = s->addseg; - if (override >= 0) - must_add_seg = 1; + def_seg = R_DS; + ovr_seg = s->override; mod = (modrm >> 6) & 3; rm = modrm & 7; @@ -1921,61 +1916,34 @@ static void gen_lea_modrm(CPUX86State *env, DisasContext *s, int modrm) } if (TCGV_IS_UNUSED(sum)) { tcg_gen_movi_tl(cpu_A0, disp); - } else { + sum = cpu_A0; + } else if (disp != 0) { tcg_gen_addi_tl(cpu_A0, sum, disp); + sum = cpu_A0; } - if (must_add_seg) { - if (override < 0) { - if (base == R_EBP || base == R_ESP) { - override = R_SS; - } else { - override = R_DS; - } - } - - tcg_gen_ld_tl(cpu_tmp0, cpu_env, - offsetof(CPUX86State, segs[override].base)); - if (CODE64(s)) { - if (s->aflag == MO_32) { - tcg_gen_ext32u_tl(cpu_A0, cpu_A0); - } - tcg_gen_add_tl(cpu_A0, cpu_A0, cpu_tmp0); - return; - } - - tcg_gen_add_tl(cpu_A0, cpu_A0, cpu_tmp0); - } - - if (s->aflag == MO_32) { - tcg_gen_ext32u_tl(cpu_A0, cpu_A0); + if (base == R_EBP || base == R_ESP) { + def_seg = R_SS; } break; case MO_16: - switch (mod) { - case 0: + sum = cpu_A0; + if (mod == 0) { if (rm == 6) { disp = cpu_lduw_code(env, s->pc); s->pc += 2; tcg_gen_movi_tl(cpu_A0, disp); - rm = 0; /* avoid SS override */ - goto no_rm; - } else { - disp = 0; + break; } - break; - case 1: + disp = 0; + } else if (mod == 1) { disp = (int8_t)cpu_ldub_code(env, s->pc++); - break; - default: - case 2: + } else { disp = (int16_t)cpu_lduw_code(env, s->pc); s->pc += 2; - break; } - sum = cpu_A0; switch (rm) { case 0: tcg_gen_add_tl(cpu_A0, cpu_regs[R_EBX], cpu_regs[R_ESI]); @@ -1985,9 +1953,11 @@ static void gen_lea_modrm(CPUX86State *env, DisasContext *s, int modrm) break; case 2: tcg_gen_add_tl(cpu_A0, cpu_regs[R_EBP], cpu_regs[R_ESI]); + def_seg = R_SS; break; case 3: tcg_gen_add_tl(cpu_A0, cpu_regs[R_EBP], cpu_regs[R_EDI]); + def_seg = R_SS; break; case 4: sum = cpu_regs[R_ESI]; @@ -1997,30 +1967,24 @@ static void gen_lea_modrm(CPUX86State *env, DisasContext *s, int modrm) break; case 6: sum = cpu_regs[R_EBP]; + def_seg = R_SS; break; default: case 7: sum = cpu_regs[R_EBX]; break; } - tcg_gen_addi_tl(cpu_A0, sum, disp); - tcg_gen_ext16u_tl(cpu_A0, cpu_A0); - no_rm: - if (must_add_seg) { - if (override < 0) { - if (rm == 2 || rm == 3 || rm == 6) { - override = R_SS; - } else { - override = R_DS; - } - } - gen_op_addl_A0_seg(s, override); + if (disp != 0) { + tcg_gen_addi_tl(cpu_A0, sum, disp); + sum = cpu_A0; } break; default: tcg_abort(); } + + gen_lea_v_seg(s, sum, def_seg, ovr_seg); } static void gen_nop_modrm(CPUX86State *env, DisasContext *s, int modrm) |