From patchwork Thu Jul 9 07:15:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 493282 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id D65701401CB for ; Thu, 9 Jul 2015 17:20:10 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=NshIUGhr; dkim-atps=neutral Received: from localhost ([::1]:38153 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZD67s-0000mP-UK for incoming@patchwork.ozlabs.org; Thu, 09 Jul 2015 03:20:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39263) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZD64d-00035W-DE for qemu-devel@nongnu.org; Thu, 09 Jul 2015 03:16:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZD64c-0000VZ-Jq for qemu-devel@nongnu.org; Thu, 09 Jul 2015 03:16:47 -0400 Received: from mail-wg0-x229.google.com ([2a00:1450:400c:c00::229]:35769) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZD64c-0000VN-CX for qemu-devel@nongnu.org; Thu, 09 Jul 2015 03:16:46 -0400 Received: by wgjx7 with SMTP id x7so214916023wgj.2 for ; Thu, 09 Jul 2015 00:16:45 -0700 (PDT) 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=frcqonrFfj8mavESPtuAohaP8ZwEPAtk+J8giNRtM/w=; b=NshIUGhrJ02mMLWSioJDmSxi0DYh37pMSYjyfh+VD4EIzvRznU+mjOdCY7DpQEm37H kEw7yA2Aocr9YK9u9lYRtBvZj51dAvtl8IP2pPXkGWNWziRabfDg1urfxzTQOwN88GvS v4ETNvDmNEssdJeY726ZfE04PESBlh2KeQn+GlmRmcf64/XNa2ufs9dW76IbwCAHTkVL zjn3d/rZBWOF5enWD4xQpPmZanR19ycjgThiLFP1Z82ZThUv3EOC7trlZJb1EGAOre1O x6xIcp0xTTDv5UBEwfDJjGw236qjiYVsui6Tpr/7wIbHyO4FIWcNDZLl1nq6l7o1V5YH FiGA== X-Received: by 10.194.95.41 with SMTP id dh9mr27690565wjb.55.1436426205777; Thu, 09 Jul 2015 00:16:45 -0700 (PDT) Received: from bigtime.twiddle.net (host86-177-156-52.range86-177.btcentralplus.com. [86.177.156.52]) by smtp.gmail.com with ESMTPSA id lq9sm7205575wjb.35.2015.07.09.00.16.38 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Jul 2015 00:16:44 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 9 Jul 2015 08:15:20 +0100 Message-Id: <1436426122-12276-9-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1436426122-12276-1-git-send-email-rth@twiddle.net> References: <1436426122-12276-1-git-send-email-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c00::229 Cc: Paolo Bonzini Subject: [Qemu-devel] [PATCH 08/10] 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Unify the code across stack pointer widths. Fix the note about not updating ESP before the potential exception. Signed-off-by: Richard Henderson --- 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 896e42c..17d3aa6 100644 --- a/target-i386/translate.c +++ b/target-i386/translate.c @@ -2361,6 +2361,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); @@ -5133,20 +5147,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 */