From patchwork Sat Oct 1 14:09:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 611357 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp219699pvb; Sat, 1 Oct 2022 07:18:38 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4RgH5fbge4cbmbCo31Y6dCiAAv2SuVe4kScWvIR3/zGSFsr8Uki76w55bHljw2mGSXGdbw X-Received: by 2002:a05:6214:20a6:b0:4ac:ba17:e20f with SMTP id 6-20020a05621420a600b004acba17e20fmr10981451qvd.101.1664633918280; Sat, 01 Oct 2022 07:18:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664633918; cv=none; d=google.com; s=arc-20160816; b=F+hTP6EiGizxlaP20ZAUXdqamU7k8WVt0SpccqmeG2me0I/x5FjeRDfC/71LWqkPjP qAS5PWrelORrUx+GdIQn3WC6/Lcm56IM3xfYJwJphuOZ5O6muN1unRK52LLq7SmA0ak+ uERCTsB0fUsfQzlz8GC/zMnRA5cPDLmHoZ/rKjWQtClI6GoxSm/xbiVmwTAI/0ciRvDr C6WTJHcb18nRbcscAczguHzaUYMK73Ibc/NyP2kfc1PVgRtpF82qdX62dl7OiuwgFfbe 9bvQk2YhNjHUz2kBfv2yrOIOS13H9lcDzFg08BCKU3sc3SfNixNBLY14yhThlgsne/Dx BRmw== 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=DTJJ71t7R1eHc1HKaFy+ccZJ8BDGeOHfxDTw9ANJp2I=; b=D6eG84YwZCQbbtYM/Jqci2fExN4tL57ksoFQmGZnS6h1agrKGnN7Gmirq2zLIa0P3p uaRNiZBO6rpX0yQ0u+bVLEGy+wAAngdmlbZzImV1WzLabTi4gosH1hTsLQ6ZuqaBSEry RZJE1g2rDHm8SEJdGV4W2EMNMjD8WEgVy6OOETZqi8E6xj19KqIbOACFU30QnWzHa4Kx c6a3x5kG0Xtg+Nm4t3sCFl6B0f7XpKLALhYN+VxiD1P6bzOa32RsmLsNjZDjKpXk2yJ/ c6hHNY8PYM3iaDC5cPIT3h92NhBw0XU9Eaq2MtzZyB+fsADXwBsT6jR+sDv3cC0nRjcz Lhnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=G35ehc9s; 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 v3-20020a05620a440300b006ce54bf3feesi3084737qkp.57.2022.10.01.07.18.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 01 Oct 2022 07:18:38 -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=G35ehc9s; 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]:52866 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oedK9-0001yZ-Os for patch@linaro.org; Sat, 01 Oct 2022 10:18:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55304) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oedBx-0002kL-DJ for qemu-devel@nongnu.org; Sat, 01 Oct 2022 10:10:09 -0400 Received: from mail-qt1-x82d.google.com ([2607:f8b0:4864:20::82d]:40665) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oedBv-0004CP-Bh for qemu-devel@nongnu.org; Sat, 01 Oct 2022 10:10:09 -0400 Received: by mail-qt1-x82d.google.com with SMTP id cj27so4214564qtb.7 for ; Sat, 01 Oct 2022 07:10:06 -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=DTJJ71t7R1eHc1HKaFy+ccZJ8BDGeOHfxDTw9ANJp2I=; b=G35ehc9sfpLzSry3OR0MsQteGdRRXq50T2euKRm+XGO5kZE6rd2CWenf6kg69uV/0C p6hf/sRvW4eIaxNzziZopqgB+j5l1pbHreYNhnkaVXleMVbhbVJJOEFkRwMsZXb9P6PZ LEeUYecsXHbbJamLjnTBPEgq9xc7+yz77wv4DIZSMNuccy3IuJb6+BnSi0hI6GvZU3al YVzJaq8A1sROEhhnNgvZriNNK8uvL4znQVeGaSgMa6Odb4s1T69ZYe2k1u4HfCl5cQzX RTC+GlwRtSGN7yUpoqrhFe2WPchdvN2sX4cAvJwy7ObcFVl6FkV0wIcdFEKBDaL5gCFz YC7A== 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=DTJJ71t7R1eHc1HKaFy+ccZJ8BDGeOHfxDTw9ANJp2I=; b=XYftrFqu88B5AtufPrXcH97GaJI+lY3vYq+Rmy0OavgpTmquW2kRI3ZITAPIyNmhyT 4AjwV5+tttPJ6xEps1lUdXKVRJIxlOrrxPI0Txh7wERazD/XHcCnEEp+Arq8dhKf/EHv OB9sic3Fk6LOeTtqGTNxvhv7XsuKuBn0bHXQnu7ogJ/H6QofLADsOJII4roAhICFQprz UGJ2huugZ1WE+WB18YBesz4hfHLeHii3TTzoSpvib0HkkYMgm4OJL3AtK44/r+U5HX2j oPKpDql0vUyt80qqQ7Rrl5+SAYa0BztoorFm555PpQ0hRBJahN56skjZ9FzQa+jGcW/s ppsQ== X-Gm-Message-State: ACrzQf3/BBBVARAzuu6V6Rzkg7ykDBW83a9zu5l5V/K++Cp/AOP3QW6y m0+bIvvE8FNU8RbJ09rKP2poiqZbpx/enxxO X-Received: by 2002:a05:622a:14cc:b0:35d:1214:99e8 with SMTP id u12-20020a05622a14cc00b0035d121499e8mr10543201qtx.205.1664633406361; Sat, 01 Oct 2022 07:10:06 -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.10.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Oct 2022 07:10:05 -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 11/26] target/i386: Create cur_insn_len, cur_insn_len_i32 Date: Sat, 1 Oct 2022 07:09:20 -0700 Message-Id: <20221001140935.465607-12-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::82d; envelope-from=richard.henderson@linaro.org; helo=mail-qt1-x82d.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" Create common routines for computing the length of the insn. Use tcg_constant_i32 in the new function, while we're at it. Reviewed-by: Paolo Bonzini Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- target/i386/tcg/translate.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 6b16c0b62c..fe99c4361c 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -530,6 +530,16 @@ static void gen_update_eip_next(DisasContext *s) gen_jmp_im(s, s->pc - s->cs_base); } +static int cur_insn_len(DisasContext *s) +{ + return s->pc - s->base.pc_next; +} + +static TCGv_i32 cur_insn_len_i32(DisasContext *s) +{ + return tcg_constant_i32(cur_insn_len(s)); +} + /* Compute SEG:REG into A0. SEG is selected from the override segment (OVR_SEG) and the default segment (DEF_SEG). OVR_SEG may be -1 to indicate no override. */ @@ -712,9 +722,6 @@ static bool gen_check_io(DisasContext *s, MemOp ot, TCGv_i32 port, gen_helper_check_io(cpu_env, port, tcg_constant_i32(1 << ot)); } if (GUEST(s)) { - target_ulong cur_eip = s->base.pc_next - s->cs_base; - target_ulong next_eip = s->pc - s->cs_base; - gen_update_cc_op(s); gen_update_eip_cur(s); if (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ)) { @@ -723,7 +730,7 @@ static bool gen_check_io(DisasContext *s, MemOp ot, TCGv_i32 port, svm_flags |= 1 << (SVM_IOIO_SIZE_SHIFT + ot); gen_helper_svm_check_io(cpu_env, port, tcg_constant_i32(svm_flags), - tcg_constant_i32(next_eip - cur_eip)); + cur_insn_len_i32(s)); } return true; #endif @@ -2028,7 +2035,7 @@ static uint64_t advance_pc(CPUX86State *env, DisasContext *s, int num_bytes) } s->pc += num_bytes; - if (unlikely(s->pc - s->base.pc_next > X86_MAX_INSN_LENGTH)) { + if (unlikely(cur_insn_len(s) > X86_MAX_INSN_LENGTH)) { /* If the instruction's 16th byte is on a different page than the 1st, a * page fault on the second page wins over the general protection fault * caused by the instruction being too long. @@ -2647,7 +2654,7 @@ static void gen_interrupt(DisasContext *s, int intno) gen_update_cc_op(s); gen_update_eip_cur(s); gen_helper_raise_interrupt(cpu_env, tcg_constant_i32(intno), - tcg_constant_i32(s->pc - s->base.pc_next)); + cur_insn_len_i32(s)); s->base.is_jmp = DISAS_NORETURN; } @@ -7314,7 +7321,7 @@ static bool disas_insn(DisasContext *s, CPUState *cpu) if (prefixes & PREFIX_REPZ) { gen_update_cc_op(s); gen_update_eip_cur(s); - gen_helper_pause(cpu_env, tcg_const_i32(s->pc - s->base.pc_next)); + gen_helper_pause(cpu_env, cur_insn_len_i32(s)); s->base.is_jmp = DISAS_NORETURN; } break; @@ -7340,7 +7347,7 @@ static bool disas_insn(DisasContext *s, CPUState *cpu) goto illegal_op; gen_update_cc_op(s); gen_update_eip_cur(s); - gen_helper_into(cpu_env, tcg_const_i32(s->pc - s->base.pc_next)); + gen_helper_into(cpu_env, cur_insn_len_i32(s)); break; #ifdef WANT_ICEBP case 0xf1: /* icebp (undocumented, exits to external debugger) */ @@ -7499,7 +7506,7 @@ static bool disas_insn(DisasContext *s, CPUState *cpu) /* XXX: is it usable in real mode ? */ gen_update_cc_op(s); gen_update_eip_cur(s); - gen_helper_syscall(cpu_env, tcg_const_i32(s->pc - s->base.pc_next)); + gen_helper_syscall(cpu_env, cur_insn_len_i32(s)); /* TF handling for the syscall insn is different. The TF bit is checked after the syscall insn completes. This allows #DB to not be generated after one has entered CPL0 if TF is set in FMASK. */ @@ -7531,7 +7538,7 @@ static bool disas_insn(DisasContext *s, CPUState *cpu) if (check_cpl0(s)) { gen_update_cc_op(s); gen_update_eip_cur(s); - gen_helper_hlt(cpu_env, tcg_const_i32(s->pc - s->base.pc_next)); + gen_helper_hlt(cpu_env, cur_insn_len_i32(s)); s->base.is_jmp = DISAS_NORETURN; } break; @@ -7640,7 +7647,7 @@ static bool disas_insn(DisasContext *s, CPUState *cpu) } gen_update_cc_op(s); gen_update_eip_cur(s); - gen_helper_mwait(cpu_env, tcg_const_i32(s->pc - s->base.pc_next)); + gen_helper_mwait(cpu_env, cur_insn_len_i32(s)); s->base.is_jmp = DISAS_NORETURN; break; @@ -7716,7 +7723,7 @@ static bool disas_insn(DisasContext *s, CPUState *cpu) gen_update_cc_op(s); gen_update_eip_cur(s); gen_helper_vmrun(cpu_env, tcg_const_i32(s->aflag - 1), - tcg_const_i32(s->pc - s->base.pc_next)); + cur_insn_len_i32(s)); tcg_gen_exit_tb(NULL, 0); s->base.is_jmp = DISAS_NORETURN; break;