From nobody Thu May 16 04:45:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1713240429; cv=none; d=zohomail.com; s=zohoarc; b=FDm+KhM6Di2iYM4rLlnKaxZmRhl+4aOTFsZy34Uk54RzyUM8a9kfTM1lL0VSSzUJ2X6Rrqx9sksNdzQ2Azb+8Na8wv1px6fqFyty91JQ5mjvwSoJYM//+lgYGzVkNPwWZZ/A99abAbqW0FTavxTkRdZLhIPv3an64RWG8knGgM4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1713240429; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=q/kvkzaV0z5p/8QW/Fxpj7Ie/nTETi6lfyNRR9fnonw=; b=YxuK4IcbclveeOcd+RIpa7x3EtQ8eXcLWKWpPIq0836RVztxXg3C/oVJ6QMyWEF45FDQv5xp2ST9JNJVKipKQsGKy3P8yjMcA39UI89BkI0lfDUU/32UrUtv1cZsvEbCx8WEvH+W97IL1YCbYvKC0BAT0MgxMfbT1Djd3r053q8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1713240429839685.326300793705; Mon, 15 Apr 2024 21:07:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rwa5J-0007sz-9u; Tue, 16 Apr 2024 00:06:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rwa5H-0007ox-PY for qemu-devel@nongnu.org; Tue, 16 Apr 2024 00:06:15 -0400 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rwa5G-00079c-6j for qemu-devel@nongnu.org; Tue, 16 Apr 2024 00:06:15 -0400 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1e2178b2cf2so36553085ad.0 for ; Mon, 15 Apr 2024 21:06:13 -0700 (PDT) Received: from stoup.. (174-21-72-5.tukw.qwest.net. [174.21.72.5]) by smtp.gmail.com with ESMTPSA id l1-20020a170902f68100b001e3e244e5c0sm8694439plg.78.2024.04.15.21.06.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 21:06:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713240372; x=1713845172; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=q/kvkzaV0z5p/8QW/Fxpj7Ie/nTETi6lfyNRR9fnonw=; b=R87zjJKIxmKNxfeEW385F8KhXvlfNIrfrIX7Mb9PKRcEaXJOcvaRcwGhKdJBKKq8z5 Lnz6L0iDt/mVRAbLBztcQfYMJRV0rEEvs7al4p2GTJLxxymZpON4ayQT0sPOkPlituuT KEE1Du5IPm0BdYfXNNgo+xUwn2PwX+SPVSZTO4X+hvp1OduKZ9TkzcYaM9g/Zdw90bRK B90ZwIMhX7/A8tt0rhPRCxkwCZwcTR+mX1+C9P6T4q4Djivmw8kdBn/zDZ/hWqAd1hJA ITR6yDLeCb+EOoA1tOEaJMomndusyogUL9tFZqr9pBuUTXRknKqpKf76qh3nPm70eu++ I+SQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713240372; x=1713845172; 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=q/kvkzaV0z5p/8QW/Fxpj7Ie/nTETi6lfyNRR9fnonw=; b=NQLMOFhArE3SU3BjMjhlzj8cFmaTzcnUFadfyPt0grqJOH3a7NyFf+AUd1a7ktmSIJ tLk9E74IB0sMuZ+2hPe+gw1hD+qo/NRf3nzYfeFCF/7jcKuvzjdQcgtxV/Qk7aWqh/fP xql+paNVNw+tu2K2ZKgPFyBcWJoFGkm/WW1FCfCCKBVzCSNmhKGUy5/hwh62wE0FJ9GZ ux+POXWAouNT3g6+Fok+Pky1biClEmlsv73bmFs8XUjgNV0rl3rp9T23N2lu+Wx+QPi3 Oi2rAoh2I7ND6SPFglg3DfReED+hZU5mBcNLn/IlYdjcQTO75mMmouxrPS3+Hr8t9Npz lgRw== X-Gm-Message-State: AOJu0YzJybsAojQFvBHRpxZw114aDwxlpAxc/oOkQlyYcKMksNkiNfxE ytQz9iIXMzvyvUTYbbwn6WLuKjcEC6IMAcmxJ+QJqwgPAPK4iSFuUtwrIzmHRVgvV510/2xHTvU J X-Google-Smtp-Source: AGHT+IHxzHiV/wDymWLdsHG5GLpfZDk9LcrGLdoQXOobcc2g3cOPQ+pO/zvhGEF83dLU/Ayrae3QpQ== X-Received: by 2002:a17:903:287:b0:1e5:5be8:15af with SMTP id j7-20020a170903028700b001e55be815afmr16035469plr.17.1713240371908; Mon, 15 Apr 2024 21:06:11 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org Subject: [PATCH 1/7] tcg: Introduce INDEX_op_plugin_pc Date: Mon, 15 Apr 2024 21:06:03 -0700 Message-Id: <20240416040609.1313605-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240416040609.1313605-1-richard.henderson@linaro.org> References: <20240416040609.1313605-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x635.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1713240430717100001 Content-Type: text/plain; charset="utf-8" Add an opcode to find a code address within the current insn, for later use with unwinding. Generate the code generically using tcg_reg_alloc_do_movi. Signed-off-by: Richard Henderson Reviewed-by: Pierrick Bouvier --- include/tcg/tcg-op-common.h | 1 + include/tcg/tcg-opc.h | 1 + tcg/tcg-op.c | 5 +++++ tcg/tcg.c | 10 ++++++++++ 4 files changed, 17 insertions(+) diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h index 009e2778c5..a32c88a182 100644 --- a/include/tcg/tcg-op-common.h +++ b/include/tcg/tcg-op-common.h @@ -76,6 +76,7 @@ void tcg_gen_lookup_and_goto_ptr(void); =20 void tcg_gen_plugin_cb(unsigned from); void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo); +void tcg_gen_plugin_pc(TCGv_ptr); =20 /* 32 bit ops */ =20 diff --git a/include/tcg/tcg-opc.h b/include/tcg/tcg-opc.h index 546eb49c11..087d1b82da 100644 --- a/include/tcg/tcg-opc.h +++ b/include/tcg/tcg-opc.h @@ -199,6 +199,7 @@ DEF(goto_ptr, 0, 1, 0, TCG_OPF_BB_EXIT | TCG_OPF_BB_END) =20 DEF(plugin_cb, 0, 0, 1, TCG_OPF_NOT_PRESENT) DEF(plugin_mem_cb, 0, 1, 1, TCG_OPF_NOT_PRESENT) +DEF(plugin_pc, 1, 0, 0, TCG_OPF_NOT_PRESENT) =20 /* Replicate ld/st ops for 32 and 64-bit guest addresses. */ DEF(qemu_ld_a32_i32, 1, 1, 1, diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c index eff3728622..b8ca78cbe4 100644 --- a/tcg/tcg-op.c +++ b/tcg/tcg-op.c @@ -322,6 +322,11 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned mem= info) tcg_gen_op2(INDEX_op_plugin_mem_cb, tcgv_i64_arg(addr), meminfo); } =20 +void tcg_gen_plugin_pc(TCGv_ptr arg) +{ + tcg_gen_op1(INDEX_op_plugin_pc, tcgv_ptr_arg(arg)); +} + /* 32 bit ops */ =20 void tcg_gen_discard_i32(TCGv_i32 arg) diff --git a/tcg/tcg.c b/tcg/tcg.c index d248c52e96..42e2b53729 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -4701,6 +4701,13 @@ static void tcg_reg_alloc_mov(TCGContext *s, const T= CGOp *op) } } =20 +static void tcg_reg_alloc_plugin_pc(TCGContext *s, const TCGOp *op) +{ + tcg_reg_alloc_do_movi(s, arg_temp(op->args[0]), + (uintptr_t)tcg_splitwx_to_rx(s->code_ptr), + op->life, output_pref(op, 0)); +} + /* * Specialized code generation for INDEX_op_dup_vec. */ @@ -6208,6 +6215,9 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb,= uint64_t pc_start) case INDEX_op_mov_vec: tcg_reg_alloc_mov(s, op); break; + case INDEX_op_plugin_pc: + tcg_reg_alloc_plugin_pc(s, op); + break; case INDEX_op_dup_vec: tcg_reg_alloc_dup(s, op); break; --=20 2.34.1 From nobody Thu May 16 04:45:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1713240404; cv=none; d=zohomail.com; s=zohoarc; b=UfEdyqYzVVAhWkv7qERqQR/YYOKQemCMmmUU/QgPZXLZ29JufqjWN5Mgn+GPgdfmQvJjmWZRBV22wTt8SMzPB6t875MfSRaZjkNzgKIAo5Lnr78OAeW7ykzKMt7OTB91X0p6V11an/lUgNWYIb/xyJ9q+gknCGA7n2EW0ZU3TAA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1713240404; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=3ETaHVvoHKNHLSSeeGS1BiYVkaanEylQv/HH8WSVcLo=; b=WldHmW+xn1d6JNH9L0CthRRyNvV+7D+so9z2CQXPKlrH+mL6azzFIy/XIWckdVNXCoBZCOrAyyFmxmXTTzrfSmOiFhbUlWxUIOjcUyhJ6venzG8xFE1rejpQqnfNr/0SV19/hTAngoppIz4ehLfZDfJTz2Th3fTLPlrfOChXsec= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1713240404122737.8344155557849; Mon, 15 Apr 2024 21:06:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rwa5K-0007xm-ET; Tue, 16 Apr 2024 00:06:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rwa5I-0007rZ-MA for qemu-devel@nongnu.org; Tue, 16 Apr 2024 00:06:16 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rwa5G-00079h-MQ for qemu-devel@nongnu.org; Tue, 16 Apr 2024 00:06:16 -0400 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1e5aa82d1f6so21593665ad.0 for ; Mon, 15 Apr 2024 21:06:14 -0700 (PDT) Received: from stoup.. (174-21-72-5.tukw.qwest.net. [174.21.72.5]) by smtp.gmail.com with ESMTPSA id l1-20020a170902f68100b001e3e244e5c0sm8694439plg.78.2024.04.15.21.06.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 21:06:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713240373; x=1713845173; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3ETaHVvoHKNHLSSeeGS1BiYVkaanEylQv/HH8WSVcLo=; b=EkHcV20Zj/NA54i21wioS079qCAEzd26Ouu+t4j+Z7ZydDaF6JFE79ob5LcCJzspPR sP65/pDSCLPX/bQeKw+x+yAfg3tlI7T4vTM3UFxpqUarbop1NXL2Yfp/QASlsgibCzT6 m355bHJo+93+cqTv3uNg9o6diyenwDwnfY6JdA0nvleHG3qNxRMhlhqJ/I9GzhCpoKVh oe3C0ymyW7SzsTFf4mG7PPXaRsiCxp3iohVZQtmvovzrL0ljdkWMC5BzuHpbdAukjBmJ yCphbzBPfMeuuo/20VIQHQGtUsN2oeCx34pwapQpR+IWzOm0hzJYQjVUQte+EeOwo70d 8qfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713240373; x=1713845173; 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=3ETaHVvoHKNHLSSeeGS1BiYVkaanEylQv/HH8WSVcLo=; b=BFXRRlRAtaakOezLgYdJMGPwZO367iNueLRt+tseHjXtJo0hFIGsE6FHnQuR1IY4DY UaaC1OB2L4h18K3G9iec5H6cu5VZsMfDDwW1ZgPuCVQWCiiX6PiP7lI/ekc1kKuN6YMz 3AmFvv1zU9sKj3XqwKP93AmkcCofhK8zvZp0X5O1/aHOLIQJjUzifsqdn9phBIxz+foP GzgFPI1S2kxq6ijV65fus2WoSJxtUvhEFiifS2F/DPiNlLp+t9TdevqJBjbZHOM2KiG4 fau7Rm3cZIS5YW2YOnpAZeJtCRNV9m+6S1/KLzEX4AjRbPi6sowybDJnPYclvRVgygvY 1FYQ== X-Gm-Message-State: AOJu0YxYOzZmSbrrST5H8YwdC34//7rB3uQJCjgSN0rd2r601a+alO64 pbU8vN8ayiAD3OdZjWz+x1TchdJYbVNHp6o5MyFlVfgj5Vf8+8Qwxs8067K5TJY0wJBXUXM1IEX b X-Google-Smtp-Source: AGHT+IFx3xATxmCsX3o/78sxy3qbg3OcoRGZcv09Ai9H6d+f0z6nFXkOle3KQq6Ow+kPggeWhclFag== X-Received: by 2002:a17:902:e811:b0:1e4:6cd7:30b3 with SMTP id u17-20020a170902e81100b001e46cd730b3mr1246254plg.23.1713240373219; Mon, 15 Apr 2024 21:06:13 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org Subject: [PATCH 2/7] accel/tcg: Set CPUState.plugin_ra before all plugin callbacks Date: Mon, 15 Apr 2024 21:06:04 -0700 Message-Id: <20240416040609.1313605-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240416040609.1313605-1-richard.henderson@linaro.org> References: <20240416040609.1313605-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x632.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1713240404664100002 Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson Reviewed-by: Pierrick Bouvier --- include/hw/core/cpu.h | 1 + accel/tcg/plugin-gen.c | 50 +++++++++++++++++++++++++++++++++++++----- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 10cd492aff..f4af37c13d 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -350,6 +350,7 @@ typedef union IcountDecr { typedef struct CPUNegativeOffsetState { CPUTLB tlb; #ifdef CONFIG_PLUGIN + uintptr_t plugin_ra; GArray *plugin_mem_cbs; #endif IcountDecr icount_decr; diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c index 36e9134a5d..f96b49cce6 100644 --- a/accel/tcg/plugin-gen.c +++ b/accel/tcg/plugin-gen.c @@ -37,6 +37,12 @@ enum plugin_gen_from { PLUGIN_GEN_AFTER_TB, }; =20 +enum plugin_gen_ra { + GEN_RA_DONE, + GEN_RA_FROM_TB, + GEN_RA_FROM_INSN, +}; + /* called before finishing a TB with exit_tb, goto_tb or goto_ptr */ void plugin_gen_disable_mem_helpers(void) { @@ -151,11 +157,38 @@ static void gen_mem_cb(struct qemu_plugin_dyn_cb *cb, tcg_temp_free_i32(cpu_index); } =20 -static void inject_cb(struct qemu_plugin_dyn_cb *cb) +static void inject_ra(enum plugin_gen_ra *gen_ra) +{ + TCGv_ptr ra; + + switch (*gen_ra) { + case GEN_RA_DONE: + return; + case GEN_RA_FROM_TB: + ra =3D tcg_constant_ptr(NULL); + break; + case GEN_RA_FROM_INSN: + ra =3D tcg_temp_ebb_new_ptr(); + tcg_gen_plugin_pc(ra); + break; + default: + g_assert_not_reached(); + } + + tcg_gen_st_ptr(ra, tcg_env, + offsetof(CPUState, neg.plugin_ra) - + offsetof(ArchCPU, env)); + tcg_temp_free_ptr(ra); + *gen_ra =3D GEN_RA_DONE; +} + +static void inject_cb(struct qemu_plugin_dyn_cb *cb, + enum plugin_gen_ra *gen_ra) =20 { switch (cb->type) { case PLUGIN_CB_REGULAR: + inject_ra(gen_ra); gen_udata_cb(cb); break; case PLUGIN_CB_INLINE: @@ -167,16 +200,18 @@ static void inject_cb(struct qemu_plugin_dyn_cb *cb) } =20 static void inject_mem_cb(struct qemu_plugin_dyn_cb *cb, + enum plugin_gen_ra *gen_ra, enum qemu_plugin_mem_rw rw, qemu_plugin_meminfo_t meminfo, TCGv_i64 addr) { if (cb->rw & rw) { switch (cb->type) { case PLUGIN_CB_MEM_REGULAR: + inject_ra(gen_ra); gen_mem_cb(cb, meminfo, addr); break; default: - inject_cb(cb); + inject_cb(cb, gen_ra); break; } } @@ -186,6 +221,7 @@ static void plugin_gen_inject(struct qemu_plugin_tb *pl= ugin_tb) { TCGOp *op, *next; int insn_idx =3D -1; + enum plugin_gen_ra gen_ra; =20 if (unlikely(qemu_loglevel_mask(LOG_TB_OP_PLUGIN) && qemu_log_in_addr_range(plugin_tb->vaddr))) { @@ -205,10 +241,12 @@ static void plugin_gen_inject(struct qemu_plugin_tb *= plugin_tb) */ memset(tcg_ctx->free_temps, 0, sizeof(tcg_ctx->free_temps)); =20 + gen_ra =3D GEN_RA_FROM_TB; QTAILQ_FOREACH_SAFE(op, &tcg_ctx->ops, link, next) { switch (op->opc) { case INDEX_op_insn_start: insn_idx++; + gen_ra =3D GEN_RA_FROM_INSN; break; =20 case INDEX_op_plugin_cb: @@ -244,7 +282,8 @@ static void plugin_gen_inject(struct qemu_plugin_tb *pl= ugin_tb) cbs =3D plugin_tb->cbs; for (i =3D 0, n =3D (cbs ? cbs->len : 0); i < n; i++) { inject_cb( - &g_array_index(cbs, struct qemu_plugin_dyn_cb, i)); + &g_array_index(cbs, struct qemu_plugin_dyn_cb, i), + &gen_ra); } break; =20 @@ -256,7 +295,8 @@ static void plugin_gen_inject(struct qemu_plugin_tb *pl= ugin_tb) cbs =3D insn->insn_cbs; for (i =3D 0, n =3D (cbs ? cbs->len : 0); i < n; i++) { inject_cb( - &g_array_index(cbs, struct qemu_plugin_dyn_cb, i)); + &g_array_index(cbs, struct qemu_plugin_dyn_cb, i), + &gen_ra); } break; =20 @@ -288,7 +328,7 @@ static void plugin_gen_inject(struct qemu_plugin_tb *pl= ugin_tb) cbs =3D insn->mem_cbs; for (i =3D 0, n =3D (cbs ? cbs->len : 0); i < n; i++) { inject_mem_cb(&g_array_index(cbs, struct qemu_plugin_dyn_c= b, i), - rw, meminfo, addr); + &gen_ra, rw, meminfo, addr); } =20 tcg_ctx->emit_before_op =3D NULL; --=20 2.34.1 From nobody Thu May 16 04:45:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1713240444; cv=none; d=zohomail.com; s=zohoarc; b=IUrNBALxXfTZrMATiOBkI2nKIRaCKETI+HCvPHoEaAwINMjgSz+XrEKkCdQw0+bHgWKZcd2aA+BaTy8M2iDSs50qgKIYAx4nDoKtu2/BX0OnHIdlQbUg4y/36A8y6tpcyY1kprJkP2PSTa+kwWq0h6IsR9shlTFpz+g/Lf7kVBg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1713240444; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=aAiLRxdfYErxgfOh0gQk21KRRPoDj9hGg+dmJqqgE+Q=; b=non1K84sjGTBkaWceYIFcehOcBF1o7lg+vn1uO32nhjpHnngsGxr+LJtvSP93gLPPjSqKJiw06QpxaMAJ2tiB0AW69Z/4qOJclV7ty1p/oF2GeRSncrNCnE+XDQBVVK+l+0UTvY6IwQFnrFl1gjUyMXR/DzbjVfOyVGN68VdcqM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1713240444795896.116968869305; Mon, 15 Apr 2024 21:07:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rwa5L-00081Q-6A; Tue, 16 Apr 2024 00:06:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rwa5J-0007t8-5t for qemu-devel@nongnu.org; Tue, 16 Apr 2024 00:06:17 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rwa5H-00079u-8g for qemu-devel@nongnu.org; Tue, 16 Apr 2024 00:06:16 -0400 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1e6723c606dso14272295ad.1 for ; Mon, 15 Apr 2024 21:06:14 -0700 (PDT) Received: from stoup.. (174-21-72-5.tukw.qwest.net. [174.21.72.5]) by smtp.gmail.com with ESMTPSA id l1-20020a170902f68100b001e3e244e5c0sm8694439plg.78.2024.04.15.21.06.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 21:06:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713240374; x=1713845174; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aAiLRxdfYErxgfOh0gQk21KRRPoDj9hGg+dmJqqgE+Q=; b=dmmm1wld2bdTpFmPVDYZi7adYMZi+fk1ubyDMpALGVZS8AuhmDoRjn6dX7hvrCoxdv QpLgzv2tNGr6oFUDljkM66mFhgy0J4E+PExZKzzuMVcg4PvIcW3Bgjnzn4JwipRMISqQ md9WeCWnlqWc4X50XYl6DJrV9hiinGq69eONhxqL5eJrnoXoVfjjl8jE+LsuISN2UBGu Cwp9fZbuaPmrdKJ8v7SfjqAvPRsuiZC7bxFvfvLrCNM/Z0zCoshl+UEsEdPWh3iyYB3r At62ILxfPWredZPsPad/PbEQ+PVyyP8n6uFlzvK3i9fiH1anu/HfHYGEIlqAtWWUqFQc yt6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713240374; x=1713845174; 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=aAiLRxdfYErxgfOh0gQk21KRRPoDj9hGg+dmJqqgE+Q=; b=v6RdAS+4WWRSaSwFkuEqYgFauvzhXzEJcWsdPwGOLojIl64ZZ1bSmyKQMbatFx6Q53 qT0KdDdZMANrSQF0/hDquqb7WOdnG9MfHPBDz1u8QE27EbJ92Rw3iZxr80WTkkJdbkBC X5vmKPfdDe4lGb4SbmNmLGQKMcAOBXRY6RcXpNbJrHyt3Gim7QL9ct3OVseZYh8luI2M 4wfJtEiL/nV0t4gFmYI3kjzKzR0cYZZRb9mEa7jAKaNqducK+JmnhyyOEcySanu+2/gR O8ADow+mItif3D//rmRgcuk18hwseNiz3moujBY83/TTzSFqI1bjpTux+v7Jkt7ZRNSc GyIg== X-Gm-Message-State: AOJu0YyceXigHApE/Kx8+bI0c7XGrnoyW0QxVyoKrut6RIy9FNwVLgDI 2EmPxLf7v4OnlhVkDc/g5B0ngkHujFdBaJAQ8pHIaqvxBCdSxEXVBWJfl/wKA6kMXLEmLr+v4K+ y X-Google-Smtp-Source: AGHT+IEgvbOda4SoTtCo0RS7v5GODFA/XHhXV5nmZafOfpYSGwklwj+wYQHcjgsrMc066qgF/v11iw== X-Received: by 2002:a17:902:ed4c:b0:1dd:e114:121c with SMTP id y12-20020a170902ed4c00b001dde114121cmr13250311plb.56.1713240373959; Mon, 15 Apr 2024 21:06:13 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org Subject: [PATCH 3/7] accel/tcg: Return the TranslationBlock from cpu_unwind_state_data Date: Mon, 15 Apr 2024 21:06:05 -0700 Message-Id: <20240416040609.1313605-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240416040609.1313605-1-richard.henderson@linaro.org> References: <20240416040609.1313605-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x634.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1713240446784100004 Content-Type: text/plain; charset="utf-8" Fix the i386 get_memio_eip function to use tb->cflags instead of cs->tcg_cflags. Signed-off-by: Richard Henderson Reviewed-by: Pierrick Bouvier --- include/exec/cpu-common.h | 9 +++++---- accel/tcg/translate-all.c | 9 +++++---- target/i386/helper.c | 6 ++++-- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h index 6346df17ce..f056132cab 100644 --- a/include/exec/cpu-common.h +++ b/include/exec/cpu-common.h @@ -176,12 +176,13 @@ void list_cpus(void); * @host_pc: the host pc within the translation * @data: output data * - * Attempt to load the the unwind state for a host pc occurring in - * translated code. If @host_pc is not in translated code, the - * function returns false; otherwise @data is loaded. + * Attempt to load the the unwind state for a host pc occurring in transla= ted + * code. If @host_pc is not in translated code, the function returns NULL; + * otherwise @data is loaded and the TranslationBlock is returned. * This is the same unwind info as given to restore_state_to_opc. */ -bool cpu_unwind_state_data(CPUState *cpu, uintptr_t host_pc, uint64_t *dat= a); +const TranslationBlock *cpu_unwind_state_data(CPUState *cpu, uintptr_t hos= t_pc, + uint64_t *data); =20 /** * cpu_restore_state: diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 83cc14fbde..c745bc5b6c 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -243,15 +243,16 @@ bool cpu_restore_state(CPUState *cpu, uintptr_t host_= pc) return false; } =20 -bool cpu_unwind_state_data(CPUState *cpu, uintptr_t host_pc, uint64_t *dat= a) +const TranslationBlock * +cpu_unwind_state_data(CPUState *cpu, uintptr_t host_pc, uint64_t *data) { if (in_code_gen_buffer((const void *)(host_pc - tcg_splitwx_diff))) { TranslationBlock *tb =3D tcg_tb_lookup(host_pc); - if (tb) { - return cpu_unwind_data_from_tb(tb, host_pc, data) >=3D 0; + if (tb && cpu_unwind_data_from_tb(tb, host_pc, data) >=3D 0) { + return tb; } } - return false; + return NULL; } =20 void page_init(void) diff --git a/target/i386/helper.c b/target/i386/helper.c index 23ccb23a5b..eaa691a851 100644 --- a/target/i386/helper.c +++ b/target/i386/helper.c @@ -517,13 +517,15 @@ static inline target_ulong get_memio_eip(CPUX86State = *env) #ifdef CONFIG_TCG uint64_t data[TARGET_INSN_START_WORDS]; CPUState *cs =3D env_cpu(env); + const TranslationBlock *tb; =20 - if (!cpu_unwind_state_data(cs, cs->mem_io_pc, data)) { + tb =3D cpu_unwind_state_data(cs, cs->mem_io_pc, data); + if (!tb) { return env->eip; } =20 /* Per x86_restore_state_to_opc. */ - if (cs->tcg_cflags & CF_PCREL) { + if (tb->cflags & CF_PCREL) { return (env->eip & TARGET_PAGE_MASK) | data[0]; } else { return data[0] - env->segs[R_CS].base; --=20 2.34.1 From nobody Thu May 16 04:45:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1713240395; cv=none; d=zohomail.com; s=zohoarc; b=HE294no/SERBGrfBivhCTahKSnHxAzRRQR2G27yikabqummYUDR7DqL7yM1BD+LG6dHfUiMVrMw0U6dCVYcsOtKb+ktCe/VrKU/ueJHS1YDWPTCgbIH1/+qWcuuMTN3dSz+WoI/fsXFNOsdKO6JLlQ8hUaAX7lt8iMl8vTJZtWk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1713240395; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Zbqcgu18SLn9cjl7+e/QBG9Rh9IFLtqhM10K4KhEsKw=; b=WJpTwDtH4WP3h+Y6h5X049tsaRVYIl3DFATnBwE6Lf0RPGpPfvybl5k4G9yY+xRSQXC0DTM5iTp3dQKYRW/5Q7EG9Eh866LI4qxU5KQid36VOK9qihdMPHBCp2F5xuKjAQ0jl2IovjncAnY/f9NEN3vJBduDIapjB4/OS5vr/YQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1713240395573867.9541954261347; Mon, 15 Apr 2024 21:06:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rwa5M-0008AO-Oq; Tue, 16 Apr 2024 00:06:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rwa5K-0007wS-27 for qemu-devel@nongnu.org; Tue, 16 Apr 2024 00:06:18 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rwa5I-0007A5-3f for qemu-devel@nongnu.org; Tue, 16 Apr 2024 00:06:17 -0400 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1e220e40998so25203965ad.1 for ; Mon, 15 Apr 2024 21:06:15 -0700 (PDT) Received: from stoup.. (174-21-72-5.tukw.qwest.net. [174.21.72.5]) by smtp.gmail.com with ESMTPSA id l1-20020a170902f68100b001e3e244e5c0sm8694439plg.78.2024.04.15.21.06.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 21:06:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713240375; x=1713845175; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Zbqcgu18SLn9cjl7+e/QBG9Rh9IFLtqhM10K4KhEsKw=; b=EQdhEDTUckWVosXGgfbcekjkCjcxtIo0BHjQJcwU6TkcehlWCo3LyQieWGnzBJwR3M XLFnP7VQJoxJp50EFK/Ub+Mb2cCy4wyhM1CyKgDzs753fHVN5A2we5hxajyPi65b9iHg rJBhofBVIvB0dA4tkW9lZpp01aCFy/kfDHgEElJ0hluFrW975+GfC/JGFeYHrdK8nTyL UW0gm+3d4UWYgQFex2toPbH4TrEO0eH5s6s3UtOpaL6sBrlTkyT+KvSwRA5JgdFiIkZC ziBl64Hjgh/OK7lic16V30mAtsi75A2e2qd+LDiVTYML4upQE/cXEnmwu66kmwWHGGPr EHYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713240375; x=1713845175; 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=Zbqcgu18SLn9cjl7+e/QBG9Rh9IFLtqhM10K4KhEsKw=; b=jQwz6nAW1gGze/7fTpBeAtDfQRvRh+S5ujaEz3mHjM6qldSqcv5I1rCzQNf4xIsIn2 Cifx4XMLAeDWtNaKQ4WMHqa2dhddhMJODKqBZBtQcTwbU2HJLnhy/Zk93DjA4ER4iG4p Qkspwo3jgnkyBIQ1ZErcm1YsjReC2Nxbxp4WMun+DfZLEM00JFJj9Xg/Tpc/+wpIBV3M XOmY4aX67fPa6qmH04YETcM/dSgRkVaUwBQDdITEhD/n6DEprhZWYQN0rjgfleBg57X5 XKJxxnfTNBR8BZDDX/DmmguSAAkZWe6bNMkPBZGO7ZaeZR2MSIQxDRwqiBYjEY8+ws01 QeHw== X-Gm-Message-State: AOJu0YzFNg4TeWDaW6QAAwuh3KhvU7VVA0CSRfB0ZhtkSQFDKolnDjtM k1R1LWtk4SNV3XHqPHGWndevoob87s1K18lstMXrmcUW85M7PJ3ULBuf4eC0VREHHvK7SIK8p1p z X-Google-Smtp-Source: AGHT+IFRbQtj+sH6emYDvOVpOSePzRCOpPO5wtjr9NuKJB6G096d6lFKerSUb0BhozPjpFkmzvrQMw== X-Received: by 2002:a17:902:f785:b0:1e5:4f69:15eb with SMTP id q5-20020a170902f78500b001e54f6915ebmr15578523pln.7.1713240374674; Mon, 15 Apr 2024 21:06:14 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org Subject: [PATCH 4/7] plugins: Introduce TCGCPUOps callbacks for mid-tb register reads Date: Mon, 15 Apr 2024 21:06:06 -0700 Message-Id: <20240416040609.1313605-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240416040609.1313605-1-richard.henderson@linaro.org> References: <20240416040609.1313605-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x636.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1713240396627100001 Content-Type: text/plain; charset="utf-8" Certain target registers are not updated continuously within the translation block. For normal exception handling we use unwind info to re-generate the correct value when required. Leverage that same info for reading those registers for plugins. All targets will need updating for these new callbacks. Signed-off-by: Richard Henderson Reviewed-by: Pierrick Bouvier --- include/hw/core/tcg-cpu-ops.h | 13 +++++++++++++ plugins/api.c | 36 +++++++++++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/include/hw/core/tcg-cpu-ops.h b/include/hw/core/tcg-cpu-ops.h index bf8ff8e3ee..e954d83edf 100644 --- a/include/hw/core/tcg-cpu-ops.h +++ b/include/hw/core/tcg-cpu-ops.h @@ -49,6 +49,19 @@ struct TCGCPUOps { /** @debug_excp_handler: Callback for handling debug exceptions */ void (*debug_excp_handler)(CPUState *cpu); =20 + /** + * @plugin_need_unwind_for_reg: + * True if unwind info needed for reading reg. + */ + bool (*plugin_need_unwind_for_reg)(CPUState *cpu, int reg); + /** + * @plugin_unwind_read_reg: + * Like CPUClass.gdb_read_register, but for registers that require + * regeneration using unwind info, like in @restore_state_to_opc. + */ + int (*plugin_unwind_read_reg)(CPUState *cpu, GByteArray *buf, int reg, + const TranslationBlock *tb, + const uint64_t *data); #ifdef NEED_CPU_H #ifdef CONFIG_USER_ONLY /** diff --git a/plugins/api.c b/plugins/api.c index 3912c9cc8f..3543647a89 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -40,10 +40,12 @@ #include "qemu/plugin.h" #include "qemu/log.h" #include "tcg/tcg.h" +#include "tcg/insn-start-words.h" #include "exec/exec-all.h" #include "exec/gdbstub.h" #include "exec/ram_addr.h" #include "disas/disas.h" +#include "hw/core/tcg-cpu-ops.h" #include "plugin.h" #ifndef CONFIG_USER_ONLY #include "qemu/plugin-memory.h" @@ -454,9 +456,39 @@ GArray *qemu_plugin_get_registers(void) =20 int qemu_plugin_read_register(struct qemu_plugin_register *reg, GByteArray= *buf) { - g_assert(current_cpu); + CPUState *cs; + uintptr_t ra; + int regno; =20 - return gdb_read_register(current_cpu, buf, GPOINTER_TO_INT(reg)); + assert(current_cpu); + cs =3D current_cpu; + ra =3D cs->neg.plugin_ra; + regno =3D GPOINTER_TO_INT(reg); + + /* + * When plugin_ra is 0, we have no unwind info. This will be true for + * TB callbacks that happen before any insns of the TB have started. + */ + if (ra) { + const TCGCPUOps *tcg_ops =3D cs->cc->tcg_ops; + + /* + * For plugins in the middle of the TB, we may need to locate + * and use unwind data to reconstruct a register value. + * Usually this required for the PC, but there may be others. + */ + if (tcg_ops->plugin_need_unwind_for_reg && + tcg_ops->plugin_need_unwind_for_reg(cs, regno)) { + uint64_t data[TARGET_INSN_START_WORDS]; + const TranslationBlock *tb; + + tb =3D cpu_unwind_state_data(cs, ra, data); + assert(tb); + return tcg_ops->plugin_unwind_read_reg(cs, buf, regno, tb, dat= a); + } + } + + return gdb_read_register(cs, buf, regno); } =20 struct qemu_plugin_scoreboard *qemu_plugin_scoreboard_new(size_t element_s= ize) --=20 2.34.1 From nobody Thu May 16 04:45:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1713240446; cv=none; d=zohomail.com; s=zohoarc; b=MgfpHlOBWuxC/FrV7PwB2GjA9yhlbXNPmTUEJKyxZFsMTeOt+fGh/QDKUrXbLZUwjhyDaSYliwxzd8LHHXNZG5+/J+v6j7LIw9ED9J+WPQCnid7GziwgfmoyhynClZYnm+U6KITYaExquJqMLQZb1zjNMjN5aOEuySIkbgH9IAI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1713240446; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=cliU8saQcbFVDKE5SoNvV+Ccq9QeWmSvOygbDeWVqyc=; b=eMVIgq8Bf1NVzfZoOVFO6UHeTTEbeTAryaa07brFwK7RSz/gQpItSbannTz5WjLPEmCP+ERQSJzoj16P/waep8viWqa+6afcRIh+HoYL0+AdSEvbzXSUwz2Fjym9HMAnvphYIlte6o6fTJgIKN39SbTWywIT5Wkrsd7PjjYYdbg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1713240446362349.6414073468245; Mon, 15 Apr 2024 21:07:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rwa5O-0008FA-Ni; Tue, 16 Apr 2024 00:06:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rwa5L-00086k-Vk for qemu-devel@nongnu.org; Tue, 16 Apr 2024 00:06:20 -0400 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rwa5K-0007AS-1A for qemu-devel@nongnu.org; Tue, 16 Apr 2024 00:06:19 -0400 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1e2c725e234so35216825ad.1 for ; Mon, 15 Apr 2024 21:06:17 -0700 (PDT) Received: from stoup.. (174-21-72-5.tukw.qwest.net. [174.21.72.5]) by smtp.gmail.com with ESMTPSA id l1-20020a170902f68100b001e3e244e5c0sm8694439plg.78.2024.04.15.21.06.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 21:06:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713240375; x=1713845175; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cliU8saQcbFVDKE5SoNvV+Ccq9QeWmSvOygbDeWVqyc=; b=luzu0gxgEWpKRlZGu5XpCFtm6bU5c27OYDieBqxPoxVX0KE77Z2oL5dTwpC10j14VQ WWvM/jur3wZh1f7J2IPhklnQeCjUp/MOpUNGb6T5zeBsAxFXBxaw3p43wZJW4JTl4zox HW0KBYDfkKuDwrxgxv3aI/M9Th+BtWSpVRhCoXcdmXuF2N8u1anHUr1azZyd3FXurdUR KhNnAYnkm4BQaqGvFrFguPqa+DxaENiX1t6IEdmfCGnHnZpkH19k6aj/53z0mz2hZy6v mVf7oElgr3QfszFtVlb9XytDuu/TPJghoI4+3GRXiwr6mtmtbFNC1aRJhwnlHYLi0A7W 4kBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713240375; x=1713845175; 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=cliU8saQcbFVDKE5SoNvV+Ccq9QeWmSvOygbDeWVqyc=; b=P2bbQIvH1OGu1Pp00FIiipBpHLOq0bYkTfhxAWc/DR8wdYY+kslu0QFQdhXBQvUDW9 5df8xP2NvXyMQd8WiIHAbLguJe2eK3VAjmKrqp41mJzsnaQD8BGN2AxaqmS/OwiLOW0M lmYSGNL3dNmvC1/OnUE35ISd7QyG/5ixByzc0gK83BHI4/1y5RAz0wN5Cu9FoevarFeI uVuXFezEDxVjQfesLG2/sTx745330U7lN9C8GgNxRE5t9DGVxpUDTJSFB2uPhlCdmQG+ BgMtKpdRqHlNQk/68oh+oBhyptzE9fFGN5OboEq+Uc0N1kW+rifnacTWAAYbTI2+uN8g AKDg== X-Gm-Message-State: AOJu0YzeqxsYX1aImKuM+uMG6Rsrald/Nuy5utfuZQJR5sTvjY6DXrsm EP+DZ12CD7sd9nyqzfQRp+44hQLxGHMCsaujRUwDdOp3HWWuFX6I+P73hK1dV40f6rm/3UnFJyG D X-Google-Smtp-Source: AGHT+IEiDeSKLZ9mA/Wsyej7nfMsUEc8eLpN7DAO8H94fQez/TkMsWSx0JvpWbm0goWlwvUOglAMgw== X-Received: by 2002:a17:902:e741:b0:1e5:5c69:fcda with SMTP id p1-20020a170902e74100b001e55c69fcdamr2235414plf.26.1713240375547; Mon, 15 Apr 2024 21:06:15 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org Subject: [PATCH 5/7] target/i386: Split out gdb-internal.h Date: Mon, 15 Apr 2024 21:06:07 -0700 Message-Id: <20240416040609.1313605-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240416040609.1313605-1-richard.henderson@linaro.org> References: <20240416040609.1313605-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62f; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62f.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1713240446784100003 Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson Reviewed-by: Pierrick Bouvier --- target/i386/gdb-internal.h | 65 ++++++++++++++++++++++++++++++++++++++ target/i386/gdbstub.c | 1 + 2 files changed, 66 insertions(+) create mode 100644 target/i386/gdb-internal.h diff --git a/target/i386/gdb-internal.h b/target/i386/gdb-internal.h new file mode 100644 index 0000000000..7cf4c1a656 --- /dev/null +++ b/target/i386/gdb-internal.h @@ -0,0 +1,65 @@ +/* + * x86 gdb server stub + * + * Copyright (c) 2003-2005 Fabrice Bellard + * Copyright (c) 2013 SUSE LINUX Products GmbH + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#ifndef I386_GDB_INTERNAL_H +#define I386_GDB_INTERNAL_H + +/* + * Keep these in sync with assignment to + * gdb_num_core_regs in target/i386/cpu.c + * and with the machine description + */ + +/* + * SEG: 6 segments, plus fs_base, gs_base, kernel_gs_base + */ + +/* + * general regs -----> 8 or 16 + */ +#define IDX_NB_IP 1 +#define IDX_NB_FLAGS 1 +#define IDX_NB_SEG (6 + 3) +#define IDX_NB_CTL 6 +#define IDX_NB_FP 16 +/* + * fpu regs ----------> 8 or 16 + */ +#define IDX_NB_MXCSR 1 +/* + * total ----> 8+1+1+9+6+16+8+1=3D50 or 16+1+1+9+6+16+16+1=3D66 + */ + +#define IDX_IP_REG CPU_NB_REGS +#define IDX_FLAGS_REG (IDX_IP_REG + IDX_NB_IP) +#define IDX_SEG_REGS (IDX_FLAGS_REG + IDX_NB_FLAGS) +#define IDX_CTL_REGS (IDX_SEG_REGS + IDX_NB_SEG) +#define IDX_FP_REGS (IDX_CTL_REGS + IDX_NB_CTL) +#define IDX_XMM_REGS (IDX_FP_REGS + IDX_NB_FP) +#define IDX_MXCSR_REG (IDX_XMM_REGS + CPU_NB_REGS) + +#define IDX_CTL_CR0_REG (IDX_CTL_REGS + 0) +#define IDX_CTL_CR2_REG (IDX_CTL_REGS + 1) +#define IDX_CTL_CR3_REG (IDX_CTL_REGS + 2) +#define IDX_CTL_CR4_REG (IDX_CTL_REGS + 3) +#define IDX_CTL_CR8_REG (IDX_CTL_REGS + 4) +#define IDX_CTL_EFER_REG (IDX_CTL_REGS + 5) + +#endif diff --git a/target/i386/gdbstub.c b/target/i386/gdbstub.c index ebb000df6a..9662509b82 100644 --- a/target/i386/gdbstub.c +++ b/target/i386/gdbstub.c @@ -20,6 +20,7 @@ #include "qemu/osdep.h" #include "cpu.h" #include "include/gdbstub/helpers.h" +#include "gdb-internal.h" =20 #ifdef TARGET_X86_64 static const int gpr_map[16] =3D { --=20 2.34.1 From nobody Thu May 16 04:45:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1713240433; cv=none; d=zohomail.com; s=zohoarc; b=hRZqF+DDee4tkANxe8psi5sl/GkBJR7bXfmOSqc+71XPcf06+dCBl9w2rD2gq1qItZeel0Y4BMHwbO4O1lvt+/3FeYl4g2q21pBq/RjkogijpMeSNILAUAZ/iNLMV3Ccl/tM2FcIAKUnC+NTtcbCu80ObTM/GZNnxReHwlEzAPc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1713240433; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=IZaZlRSWcRP8TIIFtrlkzqwhRaKDjzyacbuo5KubVSI=; b=VDw2SmDeHp22gPo2Z4Z0S/oyAcO9yqxK8M9A7deE1FLRd2MTiCr8OtyBbNGT4EocAFBY58osIgtUkCk4O1ATtDyHAN+E2+MaLFhd3qfw6s6sg5F/V2StvEoITgpACgJcqcaDxaQFQXAnBoDJPt8SVXFbv/ZGIMBRI4ntFfVburY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1713240433740508.7960821819522; Mon, 15 Apr 2024 21:07:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rwa5O-0008Em-4f; Tue, 16 Apr 2024 00:06:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rwa5L-00085B-J6 for qemu-devel@nongnu.org; Tue, 16 Apr 2024 00:06:19 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rwa5J-0007AM-Qe for qemu-devel@nongnu.org; Tue, 16 Apr 2024 00:06:19 -0400 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1e4f341330fso32496925ad.0 for ; Mon, 15 Apr 2024 21:06:17 -0700 (PDT) Received: from stoup.. (174-21-72-5.tukw.qwest.net. [174.21.72.5]) by smtp.gmail.com with ESMTPSA id l1-20020a170902f68100b001e3e244e5c0sm8694439plg.78.2024.04.15.21.06.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 21:06:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713240376; x=1713845176; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IZaZlRSWcRP8TIIFtrlkzqwhRaKDjzyacbuo5KubVSI=; b=TS9yRPrupgnRGUxLgkS1MrwrA1KW3h7M937fpIRazfr5rJq/03hJKWyKs/7NKqB+OW XMAzqduRZWuO1BOfBvG3eGy6pZIU+4N7rRG/MRQmW6/WOvroTcGWfJRavSc0ZZD39bKa JQ7kXEdAB8nzTc618g4aNo42qYecF75DzPwvGZquzWXQ5Tfb3++sK5dU4VqPXV+vqDgi GpEEb+mNDs796AafXKkb7Zs3GjPvAn9iIFpxEdNtEc0HUUPtrQuhvmewVXOQA6nwDerG PB9KGdxA7QOnPDJgNKUaQ/cqjwDLCea5+ez7sefKNL2S31H7FmVEBTTewg8URf9ldnqO xJlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713240376; x=1713845176; 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=IZaZlRSWcRP8TIIFtrlkzqwhRaKDjzyacbuo5KubVSI=; b=LcDuJUXIXlDGCtsCBEc2sYq81DN2DEm0FaWD2cz3hVSQa8QYZpXcLl8hFzIJKn+bqv utZ6zCvCMPGmhewNLsRqkql2zv0UtqIr2+EyudHKkEKCP21hV41lOK7cDFpYVxJCH053 ANfJorONozA1tR9+sHTOXqUuvvZ3jlvSsQKHvmSSJXRCLK/Jv14oF4lO0ZlBUgYovfBD KJ8EoWhrqavLLrbT+PrrAWc//jcDpxTy+pfAoaVTPpfZP84djVYkCnJEjOOQwXqTPfKA 39J6tTsXngl025Mke+8vR0jM2+HMIHTjatQFxoSGM7Mel9BiSXsHB8y3of3MouM636ER pnJw== X-Gm-Message-State: AOJu0Yze3dHi1Ra1vrgSpiMSO4GUvPIisApym7tGoL0TqLPm+sUZYwYm njzWx3y/xu8ElG7wXnzzDLIRqISHlooQXhxSiOvhH+F38EFOK9s+yllqaxDIgr1CZmIIDQ/N3ki c X-Google-Smtp-Source: AGHT+IHxo/yoMjlAGOh3rZc9RZCBljavtyEkWgil3E2pGuVvktyPi8ylV4fViLbmZ+ap6M6c7gDitQ== X-Received: by 2002:a17:902:eacd:b0:1e2:23b9:eb24 with SMTP id p13-20020a170902eacd00b001e223b9eb24mr9864530pld.33.1713240376408; Mon, 15 Apr 2024 21:06:16 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org Subject: [PATCH 6/7] target/i386: Introduce cpu_compute_eflags_ccop Date: Mon, 15 Apr 2024 21:06:08 -0700 Message-Id: <20240416040609.1313605-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240416040609.1313605-1-richard.henderson@linaro.org> References: <20240416040609.1313605-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x636.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1713240434706100001 Content-Type: text/plain; charset="utf-8" This is a generalization of cpu_compute_eflags, with a dynamic value of cc_op, and is thus tcg specific. Signed-off-by: Richard Henderson Reviewed-by: Pierrick Bouvier --- target/i386/cpu.h | 2 ++ target/i386/tcg/cc_helper.c | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 6b05738079..285f26d99d 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2379,6 +2379,8 @@ void cpu_x86_inject_mce(Monitor *mon, X86CPU *cpu, in= t bank, =20 uint32_t cpu_cc_compute_all(CPUX86State *env1); =20 +uint32_t cpu_compute_eflags_ccop(CPUX86State *env, CCOp op); + static inline uint32_t cpu_compute_eflags(CPUX86State *env) { uint32_t eflags =3D env->eflags; diff --git a/target/i386/tcg/cc_helper.c b/target/i386/tcg/cc_helper.c index f76e9cb8cf..8203682ca8 100644 --- a/target/i386/tcg/cc_helper.c +++ b/target/i386/tcg/cc_helper.c @@ -225,6 +225,16 @@ uint32_t cpu_cc_compute_all(CPUX86State *env) return helper_cc_compute_all(CC_DST, CC_SRC, CC_SRC2, CC_OP); } =20 +uint32_t cpu_compute_eflags_ccop(CPUX86State *env, CCOp op) +{ + uint32_t eflags; + + eflags =3D helper_cc_compute_all(CC_DST, CC_SRC, CC_SRC2, op); + eflags |=3D env->df & DF_MASK; + eflags |=3D env->eflags & ~(VM_MASK | RF_MASK); + return eflags; +} + target_ulong helper_cc_compute_c(target_ulong dst, target_ulong src1, target_ulong src2, int op) { --=20 2.34.1 From nobody Thu May 16 04:45:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1713240433; cv=none; d=zohomail.com; s=zohoarc; b=NYAyiP3oKm1dNnbWxArXxGIiCY1v39YxRhm0BKMJwCBryIj5PSKnt5cclvDwScle0oknA3oCh/3huFfTVyOICBV6EVk26dAr7dsAr6ElYk7Cpeu3f3LzBM/SOUVLdM4AO9DaeOCaW9CSPmpmhhRgxbvCJNR/94I+3JL749nLJRI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1713240433; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=SGHcSo147SgN6rnFLSb3VGek6gUZYoiow/EIARfgQaI=; b=gQaoePjhb25a1SB2RHAADlX9//yox7AyNiR78a45swWIl4KLFZAp+fbZFYaBnphqhBl+ZmFadk0sPJo5JGuCNT9HmqjevxWCKGj0C9cTQBJTJEe5RyOMCPmQLH7Mc1wKXzW01bjaZBGQfyZqQE9f/fIwPkDYPEv87VaeTW+c+nU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 171324043371491.82452484276928; Mon, 15 Apr 2024 21:07:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rwa5P-0008Ff-As; Tue, 16 Apr 2024 00:06:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rwa5N-0008C0-5E for qemu-devel@nongnu.org; Tue, 16 Apr 2024 00:06:21 -0400 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rwa5K-0007Aa-St for qemu-devel@nongnu.org; Tue, 16 Apr 2024 00:06:20 -0400 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1e3ff14f249so30376775ad.1 for ; Mon, 15 Apr 2024 21:06:18 -0700 (PDT) Received: from stoup.. (174-21-72-5.tukw.qwest.net. [174.21.72.5]) by smtp.gmail.com with ESMTPSA id l1-20020a170902f68100b001e3e244e5c0sm8694439plg.78.2024.04.15.21.06.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 21:06:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713240377; x=1713845177; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SGHcSo147SgN6rnFLSb3VGek6gUZYoiow/EIARfgQaI=; b=qnvBKeqvUCwKHGbcCgTHflcOR52tZpqyQ3ziHizT+ldJO9Z2Xe72jluHKDGdjStJPX 2lVqogXRpVUiU3Nrl3iVM5AmaS/P7Dl4VKd0GwFBG0xqsDO3Nc/NHy4YPn6GZmYYtPUv ZgUQ8ofPQfp9mFnSzz5huoXWdWzSJUaMVdy5KcKu0PCdpUYDvsL/GggYmkWrQJt9K11y 6Fw7QXaiqWidt6V+HJkx4bg0+rYFk6dm7/rPGNSCwmTJLwH4g1ucFOPezP6NCemyLx19 VtVBQ7iI4TiXU84Z7ng4QblT42b44e0wwkI9DTbjKhuyDbGoa2GFxPhwLyzSWI9+JtY9 v4DQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713240377; x=1713845177; 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=SGHcSo147SgN6rnFLSb3VGek6gUZYoiow/EIARfgQaI=; b=cx9bqepdFcVCV54jYIZnzyIUloNCnf5hbGxXt7F6/AwbxwZKvkwzVUyAfQ/x15usfV tGzFkd0MIYHGmIcuZEFD7JK10a/87HP0INZ7Gziz1dXrG23onB1VxaZWVTlgorx/cJ/W bGyzDBsGJhFfkvexaUmM9P9tWPMY3Kro/g4v8ZOasAinSU1tHefauI5ebThTgLpxQEIi 6d5JEMyHTRZDgaQylw9XDViwqgXEy1i7F8bSoZRuC67CAIjhzEBT5GCnQbU7XK8tp8iW Gcv8WBgNsWXViUzvMSwOzWRbFx0NbI3F/U1sm3XI1BoAN50CRWk04j/XREIwQzVXSwxH V78A== X-Gm-Message-State: AOJu0YzYPeMDB1MdfmF6tAM1g0qbLgsdDBZF8fRY6cp1ZkZU6+t+EyEq cDqJnsGHHP7IxIlBfMqVDwYi0MgDj0I4dsewgpJSUPg/ICYPDRhVPeSw62PpzWjEk9xqzaDNM36 n X-Google-Smtp-Source: AGHT+IFHSl4pIJ3RQk0j5ij5rqS3i2lJqANY3IMNaWQosD3WTiI19+ZfVg5NraQMgWrTXuEhdSsacQ== X-Received: by 2002:a17:903:41c7:b0:1e3:ce12:ef77 with SMTP id u7-20020a17090341c700b001e3ce12ef77mr1256616ple.11.1713240377293; Mon, 15 Apr 2024 21:06:17 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org Subject: [PATCH 7/7] target/i386: Implement TCGCPUOps for plugin register reads Date: Mon, 15 Apr 2024 21:06:09 -0700 Message-Id: <20240416040609.1313605-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240416040609.1313605-1-richard.henderson@linaro.org> References: <20240416040609.1313605-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62d.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1713240434742100002 Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson Reviewed-by: Pierrick Bouvier --- target/i386/tcg/tcg-cpu.c | 72 ++++++++++++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 16 deletions(-) diff --git a/target/i386/tcg/tcg-cpu.c b/target/i386/tcg/tcg-cpu.c index cca19cd40e..2370053df2 100644 --- a/target/i386/tcg/tcg-cpu.c +++ b/target/i386/tcg/tcg-cpu.c @@ -22,9 +22,11 @@ #include "helper-tcg.h" #include "qemu/accel.h" #include "hw/core/accel-cpu.h" - +#include "gdbstub/helpers.h" +#include "gdb-internal.h" #include "tcg-cpu.h" =20 + /* Frob eflags into and out of the CPU temporary format. */ =20 static void x86_cpu_exec_enter(CPUState *cs) @@ -61,38 +63,74 @@ static void x86_cpu_synchronize_from_tb(CPUState *cs, } } =20 -static void x86_restore_state_to_opc(CPUState *cs, - const TranslationBlock *tb, - const uint64_t *data) +static uint64_t eip_from_unwind(CPUX86State *env, const TranslationBlock *= tb, + uint64_t data0) { - X86CPU *cpu =3D X86_CPU(cs); - CPUX86State *env =3D &cpu->env; - int cc_op =3D data[1]; uint64_t new_pc; =20 if (tb_cflags(tb) & CF_PCREL) { /* - * data[0] in PC-relative TBs is also a linear address, i.e. an ad= dress with - * the CS base added, because it is not guaranteed that EIP bits 1= 2 and higher - * stay the same across the translation block. Add the CS base ba= ck before - * replacing the low bits, and subtract it below just like for !CF= _PCREL. + * data[0] in PC-relative TBs is also a linear address, + * i.e. an address with the CS base added, because it is + * not guaranteed that EIP bits 12 and higher stay the + * same across the translation block. Add the CS base + * back before replacing the low bits, and subtract it + * below just like for !CF_PCREL. */ uint64_t pc =3D env->eip + tb->cs_base; - new_pc =3D (pc & TARGET_PAGE_MASK) | data[0]; + new_pc =3D (pc & TARGET_PAGE_MASK) | data0; } else { - new_pc =3D data[0]; + new_pc =3D data0; } if (tb->flags & HF_CS64_MASK) { - env->eip =3D new_pc; - } else { - env->eip =3D (uint32_t)(new_pc - tb->cs_base); + return new_pc; } + return (uint32_t)(new_pc - tb->cs_base); +} =20 +static void x86_restore_state_to_opc(CPUState *cs, + const TranslationBlock *tb, + const uint64_t *data) +{ + CPUX86State *env =3D cpu_env(cs); + CCOp cc_op; + + env->eip =3D eip_from_unwind(env, tb, data[0]); + + cc_op =3D data[1]; if (cc_op !=3D CC_OP_DYNAMIC) { env->cc_op =3D cc_op; } } =20 +static bool x86_plugin_need_unwind_for_reg(CPUState *cs, int reg) +{ + return reg =3D=3D IDX_IP_REG || reg =3D=3D IDX_FLAGS_REG; +} + +static int x86_plugin_unwind_read_reg(CPUState *cs, GByteArray *buf, int r= eg, + const TranslationBlock *tb, + const uint64_t *data) +{ + CPUX86State *env =3D cpu_env(cs); + CCOp cc_op; + + switch (reg) { + case IDX_IP_REG: + return gdb_get_regl(buf, eip_from_unwind(env, tb, data[0])); + + case IDX_FLAGS_REG: + cc_op =3D data[1]; + if (cc_op =3D=3D CC_OP_DYNAMIC) { + cc_op =3D env->cc_op; + } + return gdb_get_reg32(buf, cpu_compute_eflags_ccop(env, cc_op)); + + default: + g_assert_not_reached(); + } +} + #ifndef CONFIG_USER_ONLY static bool x86_debug_check_breakpoint(CPUState *cs) { @@ -110,6 +148,8 @@ static const TCGCPUOps x86_tcg_ops =3D { .initialize =3D tcg_x86_init, .synchronize_from_tb =3D x86_cpu_synchronize_from_tb, .restore_state_to_opc =3D x86_restore_state_to_opc, + .plugin_need_unwind_for_reg =3D x86_plugin_need_unwind_for_reg, + .plugin_unwind_read_reg =3D x86_plugin_unwind_read_reg, .cpu_exec_enter =3D x86_cpu_exec_enter, .cpu_exec_exit =3D x86_cpu_exec_exit, #ifdef CONFIG_USER_ONLY --=20 2.34.1