From patchwork Mon Feb 8 17:03:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 8252701 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 37B019F1C1 for ; Mon, 8 Feb 2016 17:13:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 76AF720145 for ; Mon, 8 Feb 2016 17:13:56 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A530520107 for ; Mon, 8 Feb 2016 17:13:55 +0000 (UTC) Received: from localhost ([::1]:46937 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSpNr-0004Lz-0M for patchwork-qemu-devel@patchwork.kernel.org; Mon, 08 Feb 2016 12:13:55 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43548) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSpE3-0003aO-RF for qemu-devel@nongnu.org; Mon, 08 Feb 2016 12:03:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aSpE2-0006ph-Ph for qemu-devel@nongnu.org; Mon, 08 Feb 2016 12:03:47 -0500 Received: from mail-wm0-x235.google.com ([2a00:1450:400c:c09::235]:38142) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSpE2-0006pR-Fm for qemu-devel@nongnu.org; Mon, 08 Feb 2016 12:03:46 -0500 Received: by mail-wm0-x235.google.com with SMTP id p63so124738863wmp.1 for ; Mon, 08 Feb 2016 09:03:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=/AMRd4+pTqe9ZdPn7hLHKBL1WaTEr6DvtRvK56IipI8=; b=hQV7WVjp1Phi8PVIx4bcPMSPdstp3tu+YzN1R5E+HEaiA8+YUGgbtTX67Z8IurBOhG VFOqsfxAQg9IpVVtesxmgjZEnmRuJc+rNoqGGcfeLPtVswM/QVNe4PYNziMge7x3qugO rlui0ERkKQAx1yQRCCGXCUzOh9iMgThYTFlui/HaFPs7fv7WMd8vdHfWVv4v9fmdaQqa pvlpFeks8MUUhuxI6FpB7g4vT0Go2ChXLG2QbUK02SJR0TMnnL/LdzKONz6NOYXVnQGQ Oang7azSbWQjaQ34ah6bZMpM8HxQov4cQqy0X+e547DHxwqkFiak6S4ky/Fof/ankn/H JrWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=/AMRd4+pTqe9ZdPn7hLHKBL1WaTEr6DvtRvK56IipI8=; b=hMz5pOb67MQAuzWhe9nUmFxy+IOJ1ZL+smdKEQKlnb0PErNWahJ6xB7CjdkGGdBv0r aZlf75Et4zRwsgofqpd099jYc+Q9gixA1ejcq/YEZlw0bJBD6DfZJ1dzmw4RCmglFwOr K80S5+u/Y8BaH9z0fwiuzxNIhXCDZ/9nmyVuFIXtSRdKdj3tVWST/kqyja1cSSOw/JcN 9uEU1xvygC1+kqqmPwidhMcTTcFlnJB7YH/1qAAaOeW34ZgaBsL66ATsjJtFm4pXZELP K5wW50p1Kh54fQEKHtbmXkH5hf/qmGFp4Zr01Ecjs4L7lKq76r8pXXcIA7B2Bp8YKmGs VT5A== X-Gm-Message-State: AG10YOSs04PG6arwSgyYUKmMbQpQyuponx7WTb+0B4OCpgO6zFzVdDc/Ht+aYuiD5FrBnQ== X-Received: by 10.28.180.84 with SMTP id d81mr20810156wmf.42.1454951025815; Mon, 08 Feb 2016 09:03:45 -0800 (PST) Received: from 640k.lan (94-39-141-130.adsl-ull.clienti.tiscali.it. [94.39.141.130]) by smtp.gmail.com with ESMTPSA id b1sm30651442wjy.0.2016.02.08.09.03.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Feb 2016 09:03:44 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 8 Feb 2016 18:03:09 +0100 Message-Id: <1454950999-64128-19-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1454950999-64128-1-git-send-email-pbonzini@redhat.com> References: <1454950999-64128-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::235 Cc: Richard Henderson Subject: [Qemu-devel] [PULL 18/28] target-i386: Use gen_lea_v_seg in gen_lea_modrm X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Richard Henderson Centralize handling of segment bases. Signed-off-by: Richard Henderson Message-Id: <1450379966-28198-4-git-send-email-rth@twiddle.net> Signed-off-by: Paolo Bonzini --- 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)