From patchwork Tue Sep 6 10:09:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 602994 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:4388:0:0:0:0 with SMTP id w8csp4406346mae; Tue, 6 Sep 2022 03:46:45 -0700 (PDT) X-Google-Smtp-Source: AA6agR47s77+6Wrk5EHZV8pQgBIdYZiI7Cs6ipAz3PYznKTyNULUTo6LHuU3Fqn2GWJ0Dn15llrm X-Received: by 2002:a05:6214:19ee:b0:499:1129:d34b with SMTP id q14-20020a05621419ee00b004991129d34bmr31500829qvc.39.1662461204959; Tue, 06 Sep 2022 03:46:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662461204; cv=none; d=google.com; s=arc-20160816; b=p8uPj7kh4ggj3mKQ38A3Ri4iMa/Em+foseh71o+U2aNZeZimxKriqfmUhz5uEd7j/k ef/xfiomnG9JGs9kUSNGxJX4Pqh9XM+lqRXrCwyG1zyRz+t0i31DfTOrzu2S5e3vGUqk v3MkRZqYSBYvommRUAM/oZ6z/NdjNqtyJTgL5zbBLYrahaER4F4nRBUPaBHjd/7Sz2sx whjIekEXbtj0XnyU1WmQ6WfhdwvGchihL3X8/mkjLP9JZjMzhT1/CaJMrJJoS+TKb/KE pkVwGB5KFHcaJBJLWpsClUfz/BQ4gyqWLpQNYP0M/jmLcoJhT0CmMBNTsdRdWqF4udKt MCbg== 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=AHR0afnmw1Pzr7GboZG/SeqWvqBzQ1hpArBDHCu8T8o=; b=rSxLu07cUOA2yJdJQ07KZYLjHApeKNVy/kJIM3jsHoOlJFQ75f6zRYQla6sBzH9gOc wi0+QOZqlojfkGjQveN0iqmyhnxYx7oZWXKvlVNTuMGNdDucvyXXh4LvU7UKSHErWN6i jIsDTBPitm1HO+sIo15cwz8X7vzTdNYF7/sqnWba5P0PyISJE311GWcW8kKKUIryWsr4 ayZxvbFLxdpG5/jTF2AqoT7dkh+kyfV86c0OPcRGEKS5/vjVDI4b+h0GKH/gQgiYmeFZ Tx3cyvycDCuJFp6Aavu5c2+AUtM61UCzd6J61Klz0PDpYv85ut84o+aCEzfAQkZydnjU 50+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Gceews2i; 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=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id jv1-20020a05621429e100b00496d4a5cdc9si6124693qvb.522.2022.09.06.03.46.44 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Sep 2022 03:46:44 -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=@linaro.org header.s=google header.b=Gceews2i; 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=linaro.org Received: from localhost ([::1]:37752 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVW6O-0004nm-GV for patch@linaro.org; Tue, 06 Sep 2022 06:46:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52452) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVVWk-0000GD-DL for qemu-devel@nongnu.org; Tue, 06 Sep 2022 06:09:57 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]:34720) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oVVWi-0003bj-1N for qemu-devel@nongnu.org; Tue, 06 Sep 2022 06:09:54 -0400 Received: by mail-wm1-x32b.google.com with SMTP id z14-20020a7bc7ce000000b003a5db0388a8so7847575wmk.1 for ; Tue, 06 Sep 2022 03:09:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=AHR0afnmw1Pzr7GboZG/SeqWvqBzQ1hpArBDHCu8T8o=; b=Gceews2iVIYGKJuL5vKj6wphX3SUN4tG5bFkdomRhfjS4QZUBk6wxcshZQSQtNkElC OSaXENk4DLl88GVLlX2wr4XSxrpG/SBtr/a82eRmvTvk9mswtkb5VSDpW2W7ABn7Ghjl UZ0os7Kpma8snjBrH4Yqw5XCqBl3pzg8hQ8W/vccuGb0LTiAWqOQWIdDBu2yMyw1JEVX FLltUN37DWJc/qygZz/NC5PGqoUNTqHJjA9H2VvGTwpzSAKJyWGWheeyoAh4GrVG8oHG E9iByLQFzcXeCzE0n9BEhbEcZcg1FIRolfsm5pXnWTqmeJtXPluufJqshYPgHF2rHad3 CQpg== 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; bh=AHR0afnmw1Pzr7GboZG/SeqWvqBzQ1hpArBDHCu8T8o=; b=ZhZeCLF3KdSATos4jDF5QX5e5NFjcSvp73Fy975LVAg1rSSuFmS8vtQ9DkNZlyJxx0 pCArXMXh05nYOyJ4HadxH75ll8M2TTSp+JCiyOEe22rb6oWAKfqmoFdx48JTwjw8pr8S 5q6j16L3WmdP/PatTy/IOi9E9U6fVWtcJ1pBJCUJeenypZGAHqS1BWvvCrI3azRlKn9B 3lEalHGvMIGGzanyzdN0choYYaHZ/uMzH3np9mtPxjcdzya+hVLzPemCrKSUydg8Dv7X pxe7VjA91NU7pxAq+ij2NtApB7xAVbMzCLKGLXsD2CQOFUQo01Fb3dJm3csYD8yp/iOU Lkog== X-Gm-Message-State: ACgBeo1v4g69qUvvDjhxTZFS2jPp6lwlJjggl1Z2xAT+37UM0HfaImY2 2xhqWjR9RAUbQrSwpaEeKNPu+BenRz0dXM6p X-Received: by 2002:a05:600c:4f53:b0:3a6:9d3c:47e9 with SMTP id m19-20020a05600c4f5300b003a69d3c47e9mr13668898wmq.116.1662458990676; Tue, 06 Sep 2022 03:09:50 -0700 (PDT) Received: from localhost.localdomain ([2a02:8084:a5c0:5a80:ba98:3a71:8524:e0b1]) by smtp.gmail.com with ESMTPSA id f25-20020a1c6a19000000b003a840690609sm23125014wmc.36.2022.09.06.03.09.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 03:09:50 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com Subject: [PATCH v2 17/23] target/i386: Create gen_jmp_rel Date: Tue, 6 Sep 2022 11:09:26 +0100 Message-Id: <20220906100932.343523-18-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220906100932.343523-1-richard.henderson@linaro.org> References: <20220906100932.343523-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x32b.google.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, 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, T_SCC_BODY_TEXT_LINE=-0.01 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" Create a common helper for pc-relative branches. The jmp jb insn was missing a mask for CODE32. Signed-off-by: Richard Henderson --- target/i386/tcg/translate.c | 57 ++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index cedc195837..07c7764649 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); @@ -1173,7 +1174,7 @@ static TCGLabel *gen_jz_ecx_string(DisasContext *s) TCGLabel *l2 = gen_new_label(); gen_op_jnz_ecx(s, s->aflag, l1); gen_set_label(l2); - gen_jmp_tb(s, s->pc - s->cs_base, 1); + gen_jmp_rel(s, MO_32, 0, 1); gen_set_label(l1); return l2; } @@ -2756,6 +2757,18 @@ 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; + + if (ot == MO_16) { + dest &= 0xffff; + } else if (!CODE64(s)) { + dest &= 0xffffffff; + } + gen_jmp_tb(s, dest, tb_num); +} + static void gen_jmp(DisasContext *s, target_ulong eip) { gen_jmp_tb(s, eip, 0); @@ -6816,20 +6829,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 */ @@ -6847,19 +6852,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 */ { @@ -6876,12 +6875,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);