From patchwork Tue Oct 11 10:26:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 614185 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2553106pvb; Tue, 11 Oct 2022 04:17:04 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6BCZEUxnP/k2ZDq1LM+ZqjQ1QjpBErAjZ8LUYnsHKINnt542uNPzaQIw2FGRTuvpjwncwz X-Received: by 2002:a05:622a:2cf:b0:390:f120:cd93 with SMTP id a15-20020a05622a02cf00b00390f120cd93mr18768311qtx.307.1665487024186; Tue, 11 Oct 2022 04:17:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665487024; cv=none; d=google.com; s=arc-20160816; b=CNZAP+dSeBhGlZTXzVwFmPpqSejYRXheUumT8ND0MzWvwMBPn2sXClX4PuzTtZGW90 IX95OoVYKW3mQlZ/OoXY7TmOQ5KMzeaG38CMB2BsPzXSuNYqdQBepCv9qMpqqhjMm4Cw qSAAKWgV0GuQHoQbJ8Sel6G2zavg4jxltGgTpMZwNKwSaY7WUBrsrqwD7wSZUsyonQWD cwKQHI7BldUIGDHL51eBlwwMoLjGPQ2Bgi/U9dg5AvS/aEN9gdNLM8Gc5q70miyUyLQo qCaf51Lq1YSF1IXkugVJdWdGFVl+00GiOKhRtIcHSGTkDqVCAd+qvXasi0LHUsyLUieB i23g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=8EkHY0WoWXhFfht/JJLtepwJCD/svE3cJ5Ov63qiC58=; b=ZKsIpR3BRBS5fzko1gRTi6GIcMoTlSXoeYBtdN0LG2muQU3/bzAgdAq9ssDJGCDnDp 7OjaWfWY3qRaTtESjNutBrmLkLeXXiBlKXtWdAiKuGTqgQ2zzTqfNNUrjmgUWsXTrpXH H5lLWCZdtqa+QnocrVvrkRsVXguEnUpp8sDqB1aaLXAQhTyVfuiqxX1nxH7VXQKZYGDQ 7lUg4x/eCKPSSthsyce8sJSaAcm/lAtIx91UU8HB47d6d/QmXLdqoh4GIEBCMs7bUDeO eNGiZ7VqV5B9c0ZVi4JamNqcFeYgaP3ozpjjO7eEyFRQCT/OIdywYKKavqVTXQfKF1bT UG/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Y8sVAGaG; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id y125-20020a379683000000b006e61831c5fasi5999672qkd.402.2022.10.11.04.17.04 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 11 Oct 2022 04:17:04 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Y8sVAGaG; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1]:39234 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oiDFu-0005pl-Lm for patch@linaro.org; Tue, 11 Oct 2022 07:17:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53124) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oiCUe-0002WM-FK for qemu-devel@nongnu.org; Tue, 11 Oct 2022 06:28:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:27728) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oiCUb-0004b5-PO for qemu-devel@nongnu.org; Tue, 11 Oct 2022 06:28:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665484089; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8EkHY0WoWXhFfht/JJLtepwJCD/svE3cJ5Ov63qiC58=; b=Y8sVAGaGpFCLL2gaGk/Gzp0kRBQnADVbmFyJcU408BkCN2Qwtt6gxJcxGz4P66v74kguWR bslmOsE4JQmiVUE4pw+U/8a6GX47Cn1h9Gt1djC8oS4h584X/Z9JTpqlcuPvb09+6IFIBz +BmdTXzGBAWsmHtVu+SUA+L+HrWKgL0= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-29-FNCXTdXePOq-sTtUnbmwSA-1; Tue, 11 Oct 2022 06:28:08 -0400 X-MC-Unique: FNCXTdXePOq-sTtUnbmwSA-1 Received: by mail-ed1-f70.google.com with SMTP id x4-20020a05640226c400b0045c09fc1bd4so4278120edd.7 for ; Tue, 11 Oct 2022 03:28:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8EkHY0WoWXhFfht/JJLtepwJCD/svE3cJ5Ov63qiC58=; b=42Uw4IWbbtOz/q90F8mydWQSqetkVIItjD6a+OghZKQCygaSVtJpIENCJ/6y3nNjwF M5JBMqwqsZk/KYiBQHuushcCVQtQH8HKQH0bCf7ttndRJYUZZUvXqCGTmjG2O1MAKBV2 oRnE5+84HMiv3YlUVxKdDkwrtEqMGJM36UgLQa/CSEZI3bG0Q/VtQR6souW0eAuz6Sbh pwoCUpi54f/hSJ2g00TZN5mMPgP8X59yOn0QVfbgq59T6wWcgC10GwKeN8QUrCHZ+Jbt LvlhskmJ+JPCR4WFz5iK74zSF6Muy/RfGxRUguzJs7K8g0Trhg8vJ3GX1mWDA0cru7h0 hqvg== X-Gm-Message-State: ACrzQf0D3Rlty2kDtNny53hsi8/9fHVG1U9y3rfTg2eXmBbYjtqIIVMC tnUUjpoxNByhHVA58TusT1heqdSJ3tXnMgKWp31zv0BRSlTz61NnYufmBq3z3Y691/J4+fytS38 hGcWHUqh97lHpkc3RVyORe+7DOKHrEQwmkcegshMahLvZj9aidWRG+sPprZENPs+wlqs= X-Received: by 2002:aa7:cc8a:0:b0:45b:f851:2943 with SMTP id p10-20020aa7cc8a000000b0045bf8512943mr12101519edt.103.1665484086379; Tue, 11 Oct 2022 03:28:06 -0700 (PDT) X-Received: by 2002:aa7:cc8a:0:b0:45b:f851:2943 with SMTP id p10-20020aa7cc8a000000b0045bf8512943mr12101499edt.103.1665484086136; Tue, 11 Oct 2022 03:28:06 -0700 (PDT) Received: from avogadro.local ([2001:b07:6468:f312:aad8:f393:e009:e014]) by smtp.gmail.com with ESMTPSA id jw13-20020a17090776ad00b00731803d4d04sm6718907ejc.82.2022.10.11.03.28.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Oct 2022 03:28:05 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Richard Henderson Subject: [PULL 22/37] target/i386: Create gen_jmp_rel Date: Tue, 11 Oct 2022 12:26:45 +0200 Message-Id: <20221011102700.319178-23-pbonzini@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221011102700.319178-1-pbonzini@redhat.com> References: <20221011102700.319178-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Create a common helper for pc-relative branches. The jmp jb insn was missing a mask for CODE32. In all cases the CODE64 check was incorrectly placed, allowing PREFIX_DATA to truncate %rip to 16 bits. Signed-off-by: Richard Henderson Reviewed-by: Paolo Bonzini Message-Id: <20221001140935.465607-18-richard.henderson@linaro.org> Signed-off-by: Paolo Bonzini --- target/i386/tcg/translate.c | 58 ++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 11aaba8a65..ba1bd7c707 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -226,6 +226,7 @@ static void gen_eob(DisasContext *s); static void gen_jr(DisasContext *s); static void gen_jmp(DisasContext *s, target_ulong eip); static void gen_jmp_tb(DisasContext *s, target_ulong eip, int tb_num); +static void gen_jmp_rel(DisasContext *s, MemOp ot, int diff, int tb_num); static void gen_op(DisasContext *s1, int op, MemOp ot, int d); static void gen_exception_gpf(DisasContext *s); @@ -2792,6 +2793,21 @@ static void gen_jmp_tb(DisasContext *s, target_ulong eip, int tb_num) } } +static void gen_jmp_rel(DisasContext *s, MemOp ot, int diff, int tb_num) +{ + target_ulong dest = s->pc - s->cs_base + diff; + + /* In 64-bit mode, operand size is fixed at 64 bits. */ + if (!CODE64(s)) { + if (ot == MO_16) { + dest &= 0xffff; + } else { + dest &= 0xffffffff; + } + } + gen_jmp_tb(s, dest, tb_num); +} + static void gen_jmp(DisasContext *s, target_ulong eip) { gen_jmp_tb(s, eip, 0); @@ -6862,20 +6878,12 @@ static bool disas_insn(DisasContext *s, CPUState *cpu) break; case 0xe8: /* call im */ { - if (dflag != MO_16) { - tval = (int32_t)insn_get(env, s, MO_32); - } else { - tval = (int16_t)insn_get(env, s, MO_16); - } - tval += s->pc - s->cs_base; - if (dflag == MO_16) { - tval &= 0xffff; - } else if (!CODE64(s)) { - tval &= 0xffffffff; - } + int diff = (dflag != MO_16 + ? (int32_t)insn_get(env, s, MO_32) + : (int16_t)insn_get(env, s, MO_16)); gen_push_v(s, eip_next_tl(s)); gen_bnd_jmp(s); - gen_jmp(s, tval); + gen_jmp_rel(s, dflag, diff, 0); } break; case 0x9a: /* lcall im */ @@ -6893,19 +6901,13 @@ static bool disas_insn(DisasContext *s, CPUState *cpu) } goto do_lcall; case 0xe9: /* jmp im */ - if (dflag != MO_16) { - tval = (int32_t)insn_get(env, s, MO_32); - } else { - tval = (int16_t)insn_get(env, s, MO_16); + { + int diff = (dflag != MO_16 + ? (int32_t)insn_get(env, s, MO_32) + : (int16_t)insn_get(env, s, MO_16)); + gen_bnd_jmp(s); + gen_jmp_rel(s, dflag, diff, 0); } - tval += s->pc - s->cs_base; - if (dflag == MO_16) { - tval &= 0xffff; - } else if (!CODE64(s)) { - tval &= 0xffffffff; - } - gen_bnd_jmp(s); - gen_jmp(s, tval); break; case 0xea: /* ljmp im */ { @@ -6922,12 +6924,10 @@ static bool disas_insn(DisasContext *s, CPUState *cpu) } goto do_ljmp; case 0xeb: /* jmp Jb */ - tval = (int8_t)insn_get(env, s, MO_8); - tval += s->pc - s->cs_base; - if (dflag == MO_16) { - tval &= 0xffff; + { + int diff = (int8_t)insn_get(env, s, MO_8); + gen_jmp_rel(s, dflag, diff, 0); } - gen_jmp(s, tval); break; case 0x70 ... 0x7f: /* jcc Jb */ tval = (int8_t)insn_get(env, s, MO_8);