[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 18/28] target-i386: Use gen_lea_v_seg in gen_lea_modr
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 18/28] target-i386: Use gen_lea_v_seg in gen_lea_modrm |
Date: |
Mon, 8 Feb 2016 18:03:09 +0100 |
From: Richard Henderson <address@hidden>
Centralize handling of segment bases.
Signed-off-by: Richard Henderson <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
target-i386/translate.c | 82 ++++++++++++++-----------------------------------
1 file changed, 23 insertions(+), 59 deletions(-)
diff --git a/target-i386/translate.c b/target-i386/translate.c
index 57dfec8..86a6aa1 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)
--
1.8.3.1
- [Qemu-devel] [PULL 02/28] memory: RCU ram_list.dirty_memory[] for safe RAM hotplug, (continued)
- [Qemu-devel] [PULL 02/28] memory: RCU ram_list.dirty_memory[] for safe RAM hotplug, Paolo Bonzini, 2016/02/08
- [Qemu-devel] [PULL 06/28] scsi: push WWN fields up to SCSIDevice, Paolo Bonzini, 2016/02/08
- [Qemu-devel] [PULL 07/28] scsi-generic: grab device and port SAS addresses from backend, Paolo Bonzini, 2016/02/08
- [Qemu-devel] [PULL 05/28] include/qemu/atomic.h: default to __atomic functions, Paolo Bonzini, 2016/02/08
- [Qemu-devel] [PULL 04/28] configure: sanity check the glib library that pkg-config finds, Paolo Bonzini, 2016/02/08
- [Qemu-devel] [PULL 09/28] qemu-nbd: Fix unintended texi verbatim formatting, Paolo Bonzini, 2016/02/08
- [Qemu-devel] [PULL 12/28] scripts/kvm/kvm_stat: Fix tracefs access checking, Paolo Bonzini, 2016/02/08
- [Qemu-devel] [PULL 14/28] kvm-all: trace: strerror fixup, Paolo Bonzini, 2016/02/08
- [Qemu-devel] [PULL 17/28] target-i386: Introduce mo_stacksize, Paolo Bonzini, 2016/02/08
- [Qemu-devel] [PULL 15/28] char: fix repeated registration of tcp chardev I/O handlers, Paolo Bonzini, 2016/02/08
- [Qemu-devel] [PULL 18/28] target-i386: Use gen_lea_v_seg in gen_lea_modrm,
Paolo Bonzini <=
- [Qemu-devel] [PULL 19/28] target-i386: Use gen_lea_v_seg in stack subroutines, Paolo Bonzini, 2016/02/08
- [Qemu-devel] [PULL 10/28] qemu-nbd: Minor texi updates, Paolo Bonzini, 2016/02/08
- [Qemu-devel] [PULL 11/28] qemu-nbd: Fix texi sentence capitalisation, Paolo Bonzini, 2016/02/08
- [Qemu-devel] [PULL 13/28] nbd: avoid unaligned uint64_t store, Paolo Bonzini, 2016/02/08
- [Qemu-devel] [PULL 16/28] target-i386: Create gen_lea_v_seg, Paolo Bonzini, 2016/02/08
- [Qemu-devel] [PULL 08/28] hw: Add support for LSI SAS1068 (mptsas) device, Paolo Bonzini, 2016/02/08
- [Qemu-devel] [PULL 20/28] target-i386: Access segs via TCG registers, Paolo Bonzini, 2016/02/08
- [Qemu-devel] [PULL 22/28] target-i386: Rewrite gen_enter inline, Paolo Bonzini, 2016/02/08
- [Qemu-devel] [PULL 21/28] target-i386: Use gen_lea_v_seg in pusha/popa, Paolo Bonzini, 2016/02/08
- [Qemu-devel] [PULL 27/28] ipmi_bmc_sim: Fix off by one in check., Paolo Bonzini, 2016/02/08