From patchwork Mon Feb 8 17:03:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 8252851 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 4194FBEEE5 for ; Mon, 8 Feb 2016 17:18:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 96227203DC for ; Mon, 8 Feb 2016 17:18:05 +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 CE0D0203DB for ; Mon, 8 Feb 2016 17:18:04 +0000 (UTC) Received: from localhost ([::1]:46982 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSpRs-0003VP-2f for patchwork-qemu-devel@patchwork.kernel.org; Mon, 08 Feb 2016 12:18:04 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43677) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSpEB-0003oj-Ot for qemu-devel@nongnu.org; Mon, 08 Feb 2016 12:03:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aSpE7-0006sT-Ls for qemu-devel@nongnu.org; Mon, 08 Feb 2016 12:03:55 -0500 Received: from mail-wm0-x235.google.com ([2a00:1450:400c:c09::235]:35490) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSpE7-0006sM-FT for qemu-devel@nongnu.org; Mon, 08 Feb 2016 12:03:51 -0500 Received: by mail-wm0-x235.google.com with SMTP id c200so25255597wme.0 for ; Mon, 08 Feb 2016 09:03:51 -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=jY65gfRo5rxxeWvm21TbG2g1dG3uuzw7kqifQPECv6k=; b=FXDdl2Ax6s8yWLMQJboVDf5HUirjLu/F23sf2VuDqa+ynmHGG2MZKOMkQreenLZtBS pdgDZyzc8cebWkGPXef3KAXkql2KCehIzSttNbLzuGNmDJlTBdpOBtf0u15Cnxx7GkX5 AiiGY1D7kI5SCOFQzzZ7k2vlKZSbs8n5aLUz8LgtUjv/eI2WntO46y+8t9gjLCcXwgKY BDJ8hs4XfLoLhrnpIHxTVtDKlJIiJjCb0cODdm27npkhrU50gGBXOfH3UvpMhUI+cetK wtvGIYpvyF+R6LEPBioFAS4vVyOSRVnHrr+q7TOY64B52VnGWgvlHat75cZjwZuqU2TC A6Eg== 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=jY65gfRo5rxxeWvm21TbG2g1dG3uuzw7kqifQPECv6k=; b=Ni5GRLW7HcDhQm+rmHx32xPlLFnXycHMWNIdxf3N2sh6oIu2NzQIf/fJzZo9ORqXDF zOWk3v+Ip2Ykb7Im4sWBHoo9I7Z11tScKibiXFVNtnTOj2NtpU9XJ8mdVJpeYSgbyvJa iP+OIU1PpygSUaOOeeJzmvg7QP101jAmk1eS4xQgse2UJMMkUbwlbaj50zbobcla5jUg fVooZIDlDsROa5jrQr1DPJX9VeXyGkuXdZGPjmCq+JwVl7Rzx+vqso+fLq57WM5qXK7L 6hBBF3s52BsOoIJLBZ6Fkhi/htVi0ypOuZwOk5rIiHAd15/rpqWvgZA5h6nH+nQmV+NQ 90Eg== X-Gm-Message-State: AG10YORJhOOSOiu2nt6xsDUwF0lOMPev7cBvtlaS82wy+ISHSp9A8Pi0RP2InoyGYCVM+Q== X-Received: by 10.194.109.2 with SMTP id ho2mr33884836wjb.66.1454951030859; Mon, 08 Feb 2016 09:03:50 -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.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Feb 2016 09:03:50 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 8 Feb 2016 18:03:14 +0100 Message-Id: <1454950999-64128-24-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 23/28] target-i386: Rewrite leave 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 Unify the code across stack pointer widths. Fix the note about not updating ESP before the potential exception. Signed-off-by: Richard Henderson Message-Id: <1450379966-28198-9-git-send-email-rth@twiddle.net> Signed-off-by: Paolo Bonzini --- target-i386/translate.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/target-i386/translate.c b/target-i386/translate.c index b2f8790..6b901b1 100644 --- a/target-i386/translate.c +++ b/target-i386/translate.c @@ -2359,6 +2359,20 @@ static void gen_enter(DisasContext *s, int esp_addend, int level) gen_op_mov_reg_v(a_ot, R_ESP, cpu_T[1]); } +static void gen_leave(DisasContext *s) +{ + TCGMemOp d_ot = mo_pushpop(s, s->dflag); + TCGMemOp a_ot = mo_stacksize(s); + + gen_lea_v_seg(s, a_ot, cpu_regs[R_EBP], R_SS, -1); + gen_op_ld_v(s, d_ot, cpu_T[0], cpu_A0); + + tcg_gen_addi_tl(cpu_T[1], cpu_regs[R_EBP], 1 << d_ot); + + gen_op_mov_reg_v(d_ot, R_EBP, cpu_T[0]); + gen_op_mov_reg_v(a_ot, R_ESP, cpu_T[1]); +} + static void gen_exception(DisasContext *s, int trapno, target_ulong cur_eip) { gen_update_cc_op(s); @@ -5114,20 +5128,7 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s, } break; case 0xc9: /* leave */ - /* XXX: exception not precise (ESP is updated before potential exception) */ - if (CODE64(s)) { - gen_op_mov_v_reg(MO_64, cpu_T[0], R_EBP); - gen_op_mov_reg_v(MO_64, R_ESP, cpu_T[0]); - } else if (s->ss32) { - gen_op_mov_v_reg(MO_32, cpu_T[0], R_EBP); - gen_op_mov_reg_v(MO_32, R_ESP, cpu_T[0]); - } else { - gen_op_mov_v_reg(MO_16, cpu_T[0], R_EBP); - gen_op_mov_reg_v(MO_16, R_ESP, cpu_T[0]); - } - ot = gen_pop_T0(s); - gen_op_mov_reg_v(ot, R_EBP, cpu_T[0]); - gen_pop_update(s, ot); + gen_leave(s); break; case 0x06: /* push es */ case 0x0e: /* push cs */