From patchwork Sat Oct 1 14:09:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 611356 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp218942pvb; Sat, 1 Oct 2022 07:17:07 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7qT7Y9f3DI23NWaDwTWPFXhyHy3y9OrViHk5RGOt1kXaP9Ovs8WSW6858EJ6wpu6dZ4sJo X-Received: by 2002:a05:6214:e41:b0:496:ac31:4a4b with SMTP id o1-20020a0562140e4100b00496ac314a4bmr10940749qvc.101.1664633827159; Sat, 01 Oct 2022 07:17:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664633827; cv=none; d=google.com; s=arc-20160816; b=maZPSIViWANCJssjWyhKO7Of8dtJTutmEuiLRehxBohVqVzjO76eX3GKgXxbwaMj5g 7Ski77yEvdd1C6c8nXIKWFFEy5ulFnRRCWHy+Phvwd+knLU0fzfFV35KvPWg3ROxMmzs jY0ApikpXfqESZUjZoGOVAmQqLP22dlnMpcBc1w2IJjueTDRpw8SYPIsu0dYElQkjTDj twgjPp0YbBS14rPlNKNrP1UMQmXSsUFCu00lWjq0450rjARCB/IBlIdfMaywqrCtePrl /tjaQGPOE2CdStV4ESSndf4npgS2ZPAxHJjkHfRNbyAqSitdAm99eX4GM5kkKc2PW6J0 5WKQ== 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=j8Fqn52emtrc8wfKNsJ8wDq4Kg/BHk/sdQJpywsNASo=; b=W2LzLC5jQuSrAQuj+3ZJMna1U4/awc2EIEHrwJfiu7DheMt6MePf+G46EGr+SzhFD4 vwn+kf1n9cUGPkxpoIMzg88ovqLPXnVKzBtIX4ADfIUfhhdhDoRW6O1HLhZ7OHgb/8Bv pwH3PaQ024fOe+DFrpE1W3tdz36DyV15qgmaa18L4uLCy8iotIWiSWNKCREd9OlWDLpp gbjhx+FWGRdq8QFEhtMnipak/tS41ldF3yKbTucKOFNDn1keQ2RrKAECvw3m/K+vextF djzvhxLbPjINhWKSm13MtRkNu7Slh1ABZa9r3eNq19EVvGJPgOU2XKX2Bjx4VQWkia10 F6TQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FywkiZyD; 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 y23-20020a37f617000000b006cf982c28absi2317994qkj.687.2022.10.01.07.17.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 01 Oct 2022 07:17:07 -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=FywkiZyD; 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]:49540 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oedIg-0000FP-Jv for patch@linaro.org; Sat, 01 Oct 2022 10:17:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55294) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oedBu-0002cg-IZ for qemu-devel@nongnu.org; Sat, 01 Oct 2022 10:10:06 -0400 Received: from mail-qv1-xf30.google.com ([2607:f8b0:4864:20::f30]:40839) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oedBq-0003zX-Tc for qemu-devel@nongnu.org; Sat, 01 Oct 2022 10:10:06 -0400 Received: by mail-qv1-xf30.google.com with SMTP id h10so2804609qvq.7 for ; Sat, 01 Oct 2022 07:09:45 -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=j8Fqn52emtrc8wfKNsJ8wDq4Kg/BHk/sdQJpywsNASo=; b=FywkiZyDRT77Uw4bCcV5Q3LuTBgSSOpF2Kay84HRVaTrKJQH3mPsdGTHhfg4vDgvHU srdTqiBt+M6ZWkNZKqApx8s3pTJKDYqPEayZGF9eSrb8oEiD0D7ORnSIExXrBqWdIwtK 9RvqdLdR4jsyNwUmqCjkdnxpu2P/m5kvqa7K0Z9SZyUwmCterzbOJcVB0F1bavffYhDa zaOpbLwg2rV8ugiVbdPxIpkpyW+LHR7QbzEC8SqprmskFR3BXzrzB8jEcVxJx1OncROQ jEO59rWyD5vFEUM6wNMLCski6QoKPacK1SCiD8iRI/w55Uz2IXOF9VXWafbC8yZe38VW Smjg== 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=j8Fqn52emtrc8wfKNsJ8wDq4Kg/BHk/sdQJpywsNASo=; b=dX9J6LhEwGf3QuXKezAsJErm4sL1bwsxkiAVsQsaLi2LrOR4/Fz3AnfDRJ4/ltA5cx dTSWH48+dzoyEqZ0G6//mM5SoEu3aeuogVN8sdbEVs0Sy0qPsnDxN9aocjgWKVk7nyHz i9EzBQt/M//56z1mCDfYnZILkcTG7Pma3/sf+FMWWaBz6+bHipjXevshyeXjipgaRA9P Rc+WnUexxPE9RvdSCO9EeBIs3Udal9xXyRPnISzrrggd3Kr+9nsC/SRIAkeVXkqwWL95 b4odJK+iEluaqGHCpDdY+Lxt6WBLwbgmA3wH07iVXPe9vhxQ/AC/ZWjAf2k3InmgVmAM 2lrg== X-Gm-Message-State: ACrzQf0hul8F7zZ0DcXQT0y0LfFMoP8Se5057rQgS6zoQbhdRXjk3QDN 1Sl/TxC0da3bY2A16BquCc0Epfj0BybL64y4 X-Received: by 2002:a05:6214:c21:b0:4ad:75e:93bb with SMTP id a1-20020a0562140c2100b004ad075e93bbmr11069848qvd.27.1664633385235; Sat, 01 Oct 2022 07:09:45 -0700 (PDT) Received: from stoup.. ([2605:ef80:8080:8162:afc7:8362:2616:ac15]) by smtp.gmail.com with ESMTPSA id j16-20020a05620a289000b006b615cd8c13sm6075914qkp.106.2022.10.01.07.09.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Oct 2022 07:09:44 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v3 02/26] target/i386: Return bool from disas_insn Date: Sat, 1 Oct 2022 07:09:11 -0700 Message-Id: <20221001140935.465607-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221001140935.465607-1-richard.henderson@linaro.org> References: <20221001140935.465607-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::f30; envelope-from=richard.henderson@linaro.org; helo=mail-qv1-xf30.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 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" Instead of returning the new pc, which is present in DisasContext, return true if an insn was translated. This is false when we detect a page crossing and must undo the insn under translation. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- target/i386/tcg/translate.c | 44 +++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 16bf56dbc7..3f3e79c096 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -4707,7 +4707,7 @@ static void gen_sse(CPUX86State *env, DisasContext *s, int b) /* convert one instruction. s->base.is_jmp is set if the translation must be stopped. Return the next pc value */ -static target_ulong disas_insn(DisasContext *s, CPUState *cpu) +static bool disas_insn(DisasContext *s, CPUState *cpu) { CPUX86State *env = cpu->env_ptr; int b, prefixes; @@ -4734,15 +4734,16 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) break; case 1: gen_exception_gpf(s); - return s->pc; + return true; case 2: /* Restore state that may affect the next instruction. */ + s->pc = s->base.pc_next; s->cc_op_dirty = orig_cc_op_dirty; s->cc_op = orig_cc_op; s->base.num_insns--; tcg_remove_ops_after(s->prev_insn_end); s->base.is_jmp = DISAS_TOO_MANY; - return s->base.pc_next; + return false; default: g_assert_not_reached(); } @@ -8644,13 +8645,13 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) default: goto unknown_op; } - return s->pc; + return true; illegal_op: gen_illegal_opcode(s); - return s->pc; + return true; unknown_op: gen_unknown_opcode(env, s); - return s->pc; + return true; } void tcg_x86_init(void) @@ -8815,7 +8816,6 @@ static void i386_tr_insn_start(DisasContextBase *dcbase, CPUState *cpu) static void i386_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) { DisasContext *dc = container_of(dcbase, DisasContext, base); - target_ulong pc_next; #ifdef TARGET_VSYSCALL_PAGE /* @@ -8828,21 +8828,23 @@ static void i386_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) } #endif - pc_next = disas_insn(dc, cpu); - dc->base.pc_next = pc_next; + if (disas_insn(dc, cpu)) { + target_ulong pc_next = dc->pc; + dc->base.pc_next = pc_next; - if (dc->base.is_jmp == DISAS_NEXT) { - if (dc->flags & (HF_TF_MASK | HF_INHIBIT_IRQ_MASK)) { - /* - * If single step mode, we generate only one instruction and - * generate an exception. - * If irq were inhibited with HF_INHIBIT_IRQ_MASK, we clear - * the flag and abort the translation to give the irqs a - * chance to happen. - */ - dc->base.is_jmp = DISAS_TOO_MANY; - } else if (!is_same_page(&dc->base, pc_next)) { - dc->base.is_jmp = DISAS_TOO_MANY; + if (dc->base.is_jmp == DISAS_NEXT) { + if (dc->flags & (HF_TF_MASK | HF_INHIBIT_IRQ_MASK)) { + /* + * If single step mode, we generate only one instruction and + * generate an exception. + * If irq were inhibited with HF_INHIBIT_IRQ_MASK, we clear + * the flag and abort the translation to give the irqs a + * chance to happen. + */ + dc->base.is_jmp = DISAS_TOO_MANY; + } else if (!is_same_page(&dc->base, pc_next)) { + dc->base.is_jmp = DISAS_TOO_MANY; + } } } }