From nobody Sun Sep 28 15:28:22 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1758698445; cv=none; d=zohomail.com; s=zohoarc; b=fh9lBiifaJul46H/iN4S5uT2SlWZc0eW5rt9ioW1FzL1yNV7I4oH9eHnVFuDKffapLdsl3I22YjxaVYqcjbrjh6dzzPF9wZfHgLaHgRiGB75JDTDEkCWkYENyLX9NTw6887ZchVyWEVMf+fQlOhDrr3f1fijPiaFVv/6imkkewY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758698445; 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:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=TWOUVTWINqlu65xtlyaK/zqiGJHAuw4IkB3zdD7q9Ic=; b=b1lYNek/ZES2qk1fN8Tu6vfHuIoJt/1oVVaPvto8TjFYxIoY7AQqCcX6k6Yyl3MBJu7CeHmy+SKyhpXcjleaLk71+I9id/gaOBT52wBVJKOXpFY8NcPGzyO+NK4LlD3T3Rl0KefiljiDRHw08Z+F9gRIf0Af52Bto6o4ajDPILg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1758698445120685.3238455150598; Wed, 24 Sep 2025 00:20:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1Jmz-0005Ow-SM; Wed, 24 Sep 2025 03:19:46 -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 1v1Jmy-0005O6-4F for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:19:44 -0400 Received: from rev.ng ([94.130.142.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v1Jmo-0003No-GR for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:19:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive:List-Unsubscribe:List-Unsubscribe-Post: List-Help; bh=TWOUVTWINqlu65xtlyaK/zqiGJHAuw4IkB3zdD7q9Ic=; b=k5aUr+zdLg1cyAO GFY70RCSVs2WYGcmXmB5fODiYjgyVn3JyI9PZW5EK/psuZWGXH8RXo/Ijwksjoi2q/ahwTygpBON0 mvFfxooc7wSUgrygrAERcTGycUkm+f/pQO6EXiCcfhQLCsRN5mT07w0vZ64CWGUCQUEHqO3K9KK3b 5I=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com Subject: [RFC PATCH 01/34] target/riscv: Use 32 bits for misa extensions Date: Wed, 24 Sep 2025 09:20:51 +0200 Message-ID: <20250924072124.6493-2-anjo@rev.ng> In-Reply-To: <20250924072124.6493-1-anjo@rev.ng> References: <20250924072124.6493-1-anjo@rev.ng> 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=94.130.142.21; envelope-from=anjo@rev.ng; helo=rev.ng 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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: , Reply-to: Anton Johansson From: Anton Johansson via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758698446533116600 Content-Type: text/plain; charset="utf-8" uint32_t is already in use in most places storing misa extensions such as CPUArchState::misa_exts, RISCVCPUProfile::misa_exts, RISCVImpliedExtsRule::implied_misa_exts, etc. Signed-off-by: Anton Johansson --- target/riscv/cpu.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 4a862da615..a0b2ef1cc1 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -50,7 +50,7 @@ typedef struct CPUArchState CPURISCVState; */ #define RISCV_UW2_ALWAYS_STORE_AMO 1 =20 -#define RV(x) ((target_ulong)1 << (x - 'A')) +#define RV(x) ((uint32_t)1 << (x - 'A')) =20 /* * Update misa_bits[], misa_ext_info_arr[] and misa_ext_cfgs[] @@ -582,7 +582,7 @@ struct RISCVCPUClass { RISCVCPUDef *def; }; =20 -static inline int riscv_has_ext(CPURISCVState *env, target_ulong ext) +static inline int riscv_has_ext(CPURISCVState *env, uint32_t ext) { return (env->misa_ext & ext) !=3D 0; } --=20 2.51.0 From nobody Sun Sep 28 15:28:22 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1758698476; cv=none; d=zohomail.com; s=zohoarc; b=mCVUPKzpOcThKNZADOu7mThPv/+HrJ5x2iOlWwO2MXiRN7NK3iKBq5vFgYoRnMSlrH6eewOnsyHMmEJHPSXQ2EpMfyARDvmUwLw6hMImkrGwNGJNqssg6xSwKGHlToVk2eDkOcBBR2JcbSFa17yo+PPsPiI1FTXIlVB3CFpd0To= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758698476; 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:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=hvwxp5Gp5ncdRD3D2T1SDCR8Zg+RxKaqreS/I19bOrI=; b=DIBcy7sKMQOwBgN/xLaR7GIaILWtkE289uQkVYuHaUybm1jvWbjW+5bZKIT5MM7xde4aS51YcWm3Phlyyk1gbixQpbCxgkrzcBEN0LfgJv0rqr9F5ViYWrIiA2TQAoqbSmF9rpl2p8geXSs5PDUccGTXag2x1VVifxJcLms1FHs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1758698476190214.1500005824878; Wed, 24 Sep 2025 00:21:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1Jn2-0005RU-QW; Wed, 24 Sep 2025 03:19:48 -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 1v1Jn1-0005PS-6X for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:19:47 -0400 Received: from rev.ng ([94.130.142.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v1Jmq-0003Nw-Lt for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:19:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive:List-Unsubscribe:List-Unsubscribe-Post: List-Help; bh=hvwxp5Gp5ncdRD3D2T1SDCR8Zg+RxKaqreS/I19bOrI=; b=GmF7eTRoCSfr+MV NHlQhxNJ40M3U5R+WnpmoyQ+jABMJTdAXnOjtewqgv0t2ETdmmMwEUfqIsJDlltaa21fjJx8L7zNF Qks66j3Yy3zzP8pkNvxKzZ98JiguaJfdUOK+XdhzWaq71SRnI0UHCv15/ranlFwbp5qNako2d8Y+L QY=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com Subject: [RFC PATCH 02/34] target/riscv: Fix size of trivial CPUArchState fields Date: Wed, 24 Sep 2025 09:20:52 +0200 Message-ID: <20250924072124.6493-3-anjo@rev.ng> In-Reply-To: <20250924072124.6493-1-anjo@rev.ng> References: <20250924072124.6493-1-anjo@rev.ng> 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=94.130.142.21; envelope-from=anjo@rev.ng; helo=rev.ng 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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: , Reply-to: Anton Johansson From: Anton Johansson via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758698476909116600 Content-Type: text/plain; charset="utf-8" This commits groups together all CPUArchState fields whose behaviour can be retained by simply changing the size of the field. Note, senvcfg is defined to be SXLEN bits wide, but is widened to 64 bits to match henvcfg and menvcfg. Next, [m|h]edeleg are changed to 64 bits as defined privileged specification, and hvictl is fixed to 32 bits which holds all relevant values, see HVICTL_VALID_MASK. The remaining fields touched in the commit are widened from [H|S|M]XLEN to 64-bit. References to the privileged/unprivileged RISCV specification refer to version 20250508. Signed-off-by: Anton Johansson --- target/riscv/cpu.h | 76 +++++++++++++++++++++--------------------- target/riscv/machine.c | 66 ++++++++++++++++++------------------ 2 files changed, 71 insertions(+), 71 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index a0b2ef1cc1..8c8d34f3ac 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -254,7 +254,7 @@ struct CPUArchState { /* 128-bit helpers upper part return value */ target_ulong retxh; =20 - target_ulong jvt; + uint64_t jvt; =20 /* elp state for zicfilp extension */ bool elp; @@ -271,7 +271,7 @@ struct CPUArchState { target_ulong priv; /* CSRs for execution environment configuration */ uint64_t menvcfg; - target_ulong senvcfg; + uint64_t senvcfg; =20 #ifndef CONFIG_USER_ONLY /* This contains QEMU specific information about the virt state. */ @@ -313,18 +313,18 @@ struct CPUArchState { */ uint64_t vsie; =20 - target_ulong satp; /* since: priv-1.10.0 */ - target_ulong stval; - target_ulong medeleg; + uint64_t satp; /* since: priv-1.10.0 */ + uint64_t stval; + uint64_t medeleg; =20 - target_ulong stvec; - target_ulong sepc; - target_ulong scause; + uint64_t stvec; + uint64_t sepc; + uint64_t scause; =20 - target_ulong mtvec; - target_ulong mepc; + uint64_t mtvec; + uint64_t mepc; target_ulong mcause; - target_ulong mtval; /* since: priv-1.10.0 */ + uint64_t mtval; /* since: priv-1.10.0 */ =20 uint64_t mctrctl; uint32_t sctrdepth; @@ -346,13 +346,13 @@ struct CPUArchState { uint64_t mvip; =20 /* Hypervisor CSRs */ - target_ulong hstatus; - target_ulong hedeleg; + uint64_t hstatus; + uint64_t hedeleg; uint64_t hideleg; uint32_t hcounteren; - target_ulong htval; - target_ulong htinst; - target_ulong hgatp; + uint64_t htval; + uint64_t htinst; + uint64_t hgatp; target_ulong hgeie; target_ulong hgeip; uint64_t htimedelta; @@ -366,7 +366,7 @@ struct CPUArchState { uint64_t hvip; =20 /* Hypervisor controlled virtual interrupt priorities */ - target_ulong hvictl; + uint32_t hvictl; uint8_t hviprio[64]; =20 /* Upper 64-bits of 128-bit CSRs */ @@ -379,26 +379,26 @@ struct CPUArchState { * For RV64 this is a 64-bit vsstatus. */ uint64_t vsstatus; - target_ulong vstvec; - target_ulong vsscratch; - target_ulong vsepc; - target_ulong vscause; - target_ulong vstval; - target_ulong vsatp; + uint64_t vstvec; + uint64_t vsscratch; + uint64_t vsepc; + uint64_t vscause; + uint64_t vstval; + uint64_t vsatp; =20 /* AIA VS-mode CSRs */ target_ulong vsiselect; =20 - target_ulong mtval2; - target_ulong mtinst; + uint64_t mtval2; + uint64_t mtinst; =20 /* HS Backup CSRs */ - target_ulong stvec_hs; - target_ulong sscratch_hs; - target_ulong sepc_hs; - target_ulong scause_hs; - target_ulong stval_hs; - target_ulong satp_hs; + uint64_t stvec_hs; + uint64_t sscratch_hs; + uint64_t sepc_hs; + uint64_t scause_hs; + uint64_t stval_hs; + uint64_t satp_hs; uint64_t mstatus_hs; =20 /* @@ -435,8 +435,8 @@ struct CPUArchState { =20 PMUFixedCtrState pmu_fixed_ctrs[2]; =20 - target_ulong sscratch; - target_ulong mscratch; + uint64_t sscratch; + uint64_t mscratch; =20 /* Sstc CSRs */ uint64_t stimecmp; @@ -506,11 +506,11 @@ struct CPUArchState { #endif /* CONFIG_KVM */ =20 /* RNMI */ - target_ulong mnscratch; - target_ulong mnepc; - target_ulong mncause; /* mncause without bit XLEN-1 set to 1 */ - target_ulong mnstatus; - target_ulong rnmip; + uint64_t mnscratch; + uint64_t mnepc; + uint64_t mncause; /* mncause without bit XLEN-1 set to 1 */ + uint64_t mnstatus; + uint64_t rnmip; uint64_t rnmi_irqvec; uint64_t rnmi_excpvec; }; diff --git a/target/riscv/machine.c b/target/riscv/machine.c index 1600ec44f0..f42be027e3 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -84,13 +84,13 @@ static const VMStateDescription vmstate_hyper =3D { .minimum_version_id =3D 4, .needed =3D hyper_needed, .fields =3D (const VMStateField[]) { - VMSTATE_UINTTL(env.hstatus, RISCVCPU), - VMSTATE_UINTTL(env.hedeleg, RISCVCPU), + VMSTATE_UINT64(env.hstatus, RISCVCPU), + VMSTATE_UINT64(env.hedeleg, RISCVCPU), VMSTATE_UINT64(env.hideleg, RISCVCPU), VMSTATE_UINT32(env.hcounteren, RISCVCPU), - VMSTATE_UINTTL(env.htval, RISCVCPU), - VMSTATE_UINTTL(env.htinst, RISCVCPU), - VMSTATE_UINTTL(env.hgatp, RISCVCPU), + VMSTATE_UINT64(env.htval, RISCVCPU), + VMSTATE_UINT64(env.htinst, RISCVCPU), + VMSTATE_UINT64(env.hgatp, RISCVCPU), VMSTATE_UINTTL(env.hgeie, RISCVCPU), VMSTATE_UINTTL(env.hgeip, RISCVCPU), VMSTATE_UINT64(env.hvien, RISCVCPU), @@ -98,28 +98,28 @@ static const VMStateDescription vmstate_hyper =3D { VMSTATE_UINT64(env.htimedelta, RISCVCPU), VMSTATE_UINT64(env.vstimecmp, RISCVCPU), =20 - VMSTATE_UINTTL(env.hvictl, RISCVCPU), + VMSTATE_UINT32(env.hvictl, RISCVCPU), VMSTATE_UINT8_ARRAY(env.hviprio, RISCVCPU, 64), =20 VMSTATE_UINT64(env.vsstatus, RISCVCPU), - VMSTATE_UINTTL(env.vstvec, RISCVCPU), - VMSTATE_UINTTL(env.vsscratch, RISCVCPU), - VMSTATE_UINTTL(env.vsepc, RISCVCPU), - VMSTATE_UINTTL(env.vscause, RISCVCPU), - VMSTATE_UINTTL(env.vstval, RISCVCPU), - VMSTATE_UINTTL(env.vsatp, RISCVCPU), + VMSTATE_UINT64(env.vstvec, RISCVCPU), + VMSTATE_UINT64(env.vsscratch, RISCVCPU), + VMSTATE_UINT64(env.vsepc, RISCVCPU), + VMSTATE_UINT64(env.vscause, RISCVCPU), + VMSTATE_UINT64(env.vstval, RISCVCPU), + VMSTATE_UINT64(env.vsatp, RISCVCPU), VMSTATE_UINTTL(env.vsiselect, RISCVCPU), VMSTATE_UINT64(env.vsie, RISCVCPU), =20 - VMSTATE_UINTTL(env.mtval2, RISCVCPU), - VMSTATE_UINTTL(env.mtinst, RISCVCPU), + VMSTATE_UINT64(env.mtval2, RISCVCPU), + VMSTATE_UINT64(env.mtinst, RISCVCPU), =20 - VMSTATE_UINTTL(env.stvec_hs, RISCVCPU), - VMSTATE_UINTTL(env.sscratch_hs, RISCVCPU), - VMSTATE_UINTTL(env.sepc_hs, RISCVCPU), - VMSTATE_UINTTL(env.scause_hs, RISCVCPU), - VMSTATE_UINTTL(env.stval_hs, RISCVCPU), - VMSTATE_UINTTL(env.satp_hs, RISCVCPU), + VMSTATE_UINT64(env.stvec_hs, RISCVCPU), + VMSTATE_UINT64(env.sscratch_hs, RISCVCPU), + VMSTATE_UINT64(env.sepc_hs, RISCVCPU), + VMSTATE_UINT64(env.scause_hs, RISCVCPU), + VMSTATE_UINT64(env.stval_hs, RISCVCPU), + VMSTATE_UINT64(env.satp_hs, RISCVCPU), VMSTATE_UINT64(env.mstatus_hs, RISCVCPU), =20 VMSTATE_END_OF_LIST() @@ -295,7 +295,7 @@ static const VMStateDescription vmstate_envcfg =3D { .needed =3D envcfg_needed, .fields =3D (const VMStateField[]) { VMSTATE_UINT64(env.menvcfg, RISCVCPU), - VMSTATE_UINTTL(env.senvcfg, RISCVCPU), + VMSTATE_UINT64(env.senvcfg, RISCVCPU), VMSTATE_UINT64(env.henvcfg, RISCVCPU), VMSTATE_END_OF_LIST() } @@ -359,7 +359,7 @@ static const VMStateDescription vmstate_jvt =3D { .minimum_version_id =3D 1, .needed =3D jvt_needed, .fields =3D (const VMStateField[]) { - VMSTATE_UINTTL(env.jvt, RISCVCPU), + VMSTATE_UINT64(env.jvt, RISCVCPU), VMSTATE_END_OF_LIST() } }; @@ -434,16 +434,16 @@ const VMStateDescription vmstate_riscv_cpu =3D { VMSTATE_UINT64(env.mvip, RISCVCPU), VMSTATE_UINT64(env.sie, RISCVCPU), VMSTATE_UINT64(env.mideleg, RISCVCPU), - VMSTATE_UINTTL(env.satp, RISCVCPU), - VMSTATE_UINTTL(env.stval, RISCVCPU), - VMSTATE_UINTTL(env.medeleg, RISCVCPU), - VMSTATE_UINTTL(env.stvec, RISCVCPU), - VMSTATE_UINTTL(env.sepc, RISCVCPU), - VMSTATE_UINTTL(env.scause, RISCVCPU), - VMSTATE_UINTTL(env.mtvec, RISCVCPU), - VMSTATE_UINTTL(env.mepc, RISCVCPU), + VMSTATE_UINT64(env.satp, RISCVCPU), + VMSTATE_UINT64(env.stval, RISCVCPU), + VMSTATE_UINT64(env.medeleg, RISCVCPU), + VMSTATE_UINT64(env.stvec, RISCVCPU), + VMSTATE_UINT64(env.sepc, RISCVCPU), + VMSTATE_UINT64(env.scause, RISCVCPU), + VMSTATE_UINT64(env.mtvec, RISCVCPU), + VMSTATE_UINT64(env.mepc, RISCVCPU), VMSTATE_UINTTL(env.mcause, RISCVCPU), - VMSTATE_UINTTL(env.mtval, RISCVCPU), + VMSTATE_UINT64(env.mtval, RISCVCPU), VMSTATE_UINTTL(env.miselect, RISCVCPU), VMSTATE_UINTTL(env.siselect, RISCVCPU), VMSTATE_UINT32(env.scounteren, RISCVCPU), @@ -454,8 +454,8 @@ const VMStateDescription vmstate_riscv_cpu =3D { vmstate_pmu_ctr_state, PMUCTRState), VMSTATE_UINTTL_ARRAY(env.mhpmevent_val, RISCVCPU, RV_MAX_MHPMEVENT= S), VMSTATE_UINTTL_ARRAY(env.mhpmeventh_val, RISCVCPU, RV_MAX_MHPMEVEN= TS), - VMSTATE_UINTTL(env.sscratch, RISCVCPU), - VMSTATE_UINTTL(env.mscratch, RISCVCPU), + VMSTATE_UINT64(env.sscratch, RISCVCPU), + VMSTATE_UINT64(env.mscratch, RISCVCPU), VMSTATE_UINT64(env.stimecmp, RISCVCPU), =20 VMSTATE_END_OF_LIST() --=20 2.51.0 From nobody Sun Sep 28 15:28:22 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1758698820; cv=none; d=zohomail.com; s=zohoarc; b=WeLJktJ3jrA23aMwtC7WBIVo6u/kwdi9WBkpyM2sHVMDI8pqqVCU5IbVwSEcg5hwydriYVMp8fJy5ZmFx6PseTPfzxbe38FXTbUY1VPSNMMn4Zk+ycJqDmTrcypr4TSC46oWTblECcSIvqQ9iM9vVmklF+ezFPZR+MYTfgpTW+E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758698820; 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:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=tIUjEoxmD+L3v5TUv5lmknEUjE1dS8nrXtJKYtFhI0M=; b=W/aBVZUyM1svXTve1Jn07OJGhmp0zXD22ExBCJO1QThVYH72P65fupwib7am0O9y0rGYDauaDIy9ASx8VhsJLDuyqFXbo9TRo09z+V4pRgXgM2eJRw5USXOTjI8Ua97qQyUDzMYnRdnqYaBDvvQ6N3cppGwG9Y6azqAPSyHE1nQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1758698820171359.67445100686587; Wed, 24 Sep 2025 00:27:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1Jn6-0005Sa-Vc; Wed, 24 Sep 2025 03:19:53 -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 1v1Jn3-0005RV-2b for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:19:49 -0400 Received: from rev.ng ([94.130.142.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v1Jmq-0003Nz-Lr for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:19:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive:List-Unsubscribe:List-Unsubscribe-Post: List-Help; bh=tIUjEoxmD+L3v5TUv5lmknEUjE1dS8nrXtJKYtFhI0M=; b=G/FRv/dNNOrxu9I WUwmliUrglHH/LdvdYh9ayDDc9rgqUXMaeE7wLEKbiVM6YOVEzg7cDW9laEmfagYBFbBOlrHeCgTL fJHjb1SzX8zXs2gIQwH0tUVosT0SAOGO3KSAB2AJX49IBfYytXydQKnRYHJcptLtSmcoYGZvlPLGe K0=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com Subject: [RFC PATCH 03/34] target/riscv: Fix size of mcause Date: Wed, 24 Sep 2025 09:20:53 +0200 Message-ID: <20250924072124.6493-4-anjo@rev.ng> In-Reply-To: <20250924072124.6493-1-anjo@rev.ng> References: <20250924072124.6493-1-anjo@rev.ng> 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=94.130.142.21; envelope-from=anjo@rev.ng; helo=rev.ng X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no 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: , Reply-to: Anton Johansson From: Anton Johansson via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758698824905116600 Content-Type: text/plain; charset="utf-8" and update formatting in logs. Signed-off-by: Anton Johansson --- target/riscv/cpu.h | 2 +- target/riscv/machine.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 8c8d34f3ac..32e30a36ac 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -323,7 +323,7 @@ struct CPUArchState { =20 uint64_t mtvec; uint64_t mepc; - target_ulong mcause; + uint64_t mcause; uint64_t mtval; /* since: priv-1.10.0 */ =20 uint64_t mctrctl; diff --git a/target/riscv/machine.c b/target/riscv/machine.c index f42be027e3..438c44dbb0 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -442,7 +442,7 @@ const VMStateDescription vmstate_riscv_cpu =3D { VMSTATE_UINT64(env.scause, RISCVCPU), VMSTATE_UINT64(env.mtvec, RISCVCPU), VMSTATE_UINT64(env.mepc, RISCVCPU), - VMSTATE_UINTTL(env.mcause, RISCVCPU), + VMSTATE_UINT64(env.mcause, RISCVCPU), VMSTATE_UINT64(env.mtval, RISCVCPU), VMSTATE_UINTTL(env.miselect, RISCVCPU), VMSTATE_UINTTL(env.siselect, RISCVCPU), --=20 2.51.0 From nobody Sun Sep 28 15:28:22 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1758698483; cv=none; d=zohomail.com; s=zohoarc; b=BFv8GpNsV5rGGpGPqjiEzgH3bJdrUwgb+36F3csf0AxCEwIZ6Lxt8JAyhl7vyFeoU54v+WBQtur6S6uvC+G5hFW8JzjMk0SvHH/7qBr3aDyNvZzB5CyjluXyYnryfnZFG55pIMRuLQDrNMBSR9hk7w/1D8jWut8LcGAKQt4Q8UI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758698483; 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:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=XM/Bwlfn1Sl226Bvx3vx+HDk47D8PqIg+tFiODBQbEA=; b=CB2J1rksnbYnc2Xb0eqUSKXA5uyfFog61vSTMF3wnSY5wTSeJlwT560D3BuVPSCot+s6R3FKmYjfgDBhxvm6pCkj+vX/D4W7SvVaMeIG/dSY644LgOyRQp538j9H2pOeEuk2IfOhrRGh9CIxLfGV937U1hzrUK+6zmvHaiOEeOg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1758698483885283.4887345908776; Wed, 24 Sep 2025 00:21:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1Jn1-0005PH-Cl; Wed, 24 Sep 2025 03:19:47 -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 1v1Jmy-0005O8-6q for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:19:44 -0400 Received: from rev.ng ([94.130.142.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v1Jmq-0003O5-WE for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:19:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive:List-Unsubscribe:List-Unsubscribe-Post: List-Help; bh=XM/Bwlfn1Sl226Bvx3vx+HDk47D8PqIg+tFiODBQbEA=; b=qWfrERk1wZVM4Vp fdW5MZdYgUq1ES230Gqqsa/Q320qEAmALmwa++hRPro/ITm9YsN5IYNi8d5EwjANQwDUR8tkrCzPT dBCqIH5pDkZzzsWm3sKQccoOJURfkbLJJkM9WqvFOpgz38LxTxHl3KwAqyg6h2W120sNZ55W24l8p PU=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com Subject: [RFC PATCH 04/34] target/riscv: Fix size of mhartid Date: Wed, 24 Sep 2025 09:20:54 +0200 Message-ID: <20250924072124.6493-5-anjo@rev.ng> In-Reply-To: <20250924072124.6493-1-anjo@rev.ng> References: <20250924072124.6493-1-anjo@rev.ng> 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=94.130.142.21; envelope-from=anjo@rev.ng; helo=rev.ng 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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: , Reply-to: Anton Johansson From: Anton Johansson via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758698484989116600 Content-Type: text/plain; charset="utf-8" and update formatting in log. Signed-off-by: Anton Johansson --- target/riscv/cpu.h | 2 +- target/riscv/cpu_helper.c | 2 +- target/riscv/machine.c | 2 +- target/riscv/tcg/tcg-cpu.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 32e30a36ac..f94f773a84 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -279,7 +279,7 @@ struct CPUArchState { target_ulong geilen; uint64_t resetvec; =20 - target_ulong mhartid; + uint64_t mhartid; /* * For RV32 this is 32-bit mstatus and 32-bit mstatush. * For RV64 this is a 64-bit mstatus. diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 3479a62cc7..9d0683f200 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -2278,7 +2278,7 @@ void riscv_cpu_do_interrupt(CPUState *cs) riscv_cpu_get_trap_name(cause, async)); =20 qemu_log_mask(CPU_LOG_INT, - "%s: hart:"TARGET_FMT_ld", async:%d, cause:"TARGET_FMT_l= x", " + "%s: hart:%"PRIu64", async:%d, cause:"TARGET_FMT_lx", " "epc:0x"TARGET_FMT_lx", tval:0x"TARGET_FMT_lx", desc=3D%= s\n", __func__, env->mhartid, async, cause, env->pc, tval, riscv_cpu_get_trap_name(cause, async)); diff --git a/target/riscv/machine.c b/target/riscv/machine.c index 438c44dbb0..32cc94858d 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -425,7 +425,7 @@ const VMStateDescription vmstate_riscv_cpu =3D { VMSTATE_UINTTL(env.priv, RISCVCPU), VMSTATE_BOOL(env.virt_enabled, RISCVCPU), VMSTATE_UINT64(env.resetvec, RISCVCPU), - VMSTATE_UINTTL(env.mhartid, RISCVCPU), + VMSTATE_UINT64(env.mhartid, RISCVCPU), VMSTATE_UINT64(env.mstatus, RISCVCPU), VMSTATE_UINT64(env.mip, RISCVCPU), VMSTATE_UINT64(env.miclaim, RISCVCPU), diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c index 78fb279184..f90abbc594 100644 --- a/target/riscv/tcg/tcg-cpu.c +++ b/target/riscv/tcg/tcg-cpu.c @@ -471,7 +471,7 @@ static void riscv_cpu_disable_priv_spec_isa_exts(RISCVC= PU *cpu) continue; } #ifndef CONFIG_USER_ONLY - warn_report("disabling %s extension for hart 0x" TARGET_FMT_lx + warn_report("disabling %s extension for hart 0x%" PRIx64 " because privilege spec version does not match", edata->name, env->mhartid); #else --=20 2.51.0 From nobody Sun Sep 28 15:28:22 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1758698584; cv=none; d=zohomail.com; s=zohoarc; b=Pgmvya6vx9MO1CCVk9pvvDe7z34Tl6Hc0j1hp+Mw3VWN4DRcHG1per01bZU0tMKWtmFDpXGhtn17nxxt6+UnS51zFGQFIrOybQk9fdSDOcqbmXC2WQceuR1fyJopRaGfSgSjxnC5BRvkg5fDjc3uf9Lc5FgEXFtrZN7no6ox/3U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758698584; 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:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=SNZDhnPcG/iwI9uiJToLSsRJihNAUA2OOkjyj/ogJxc=; b=R+NEb47lcL4weXnPkLzmhZFV8O5ZP+igxUvr3hAw1wuUD6JI52apS/lYWctVsKd1u4QOstV6zPR/WANrd0rHYQr5W2S+yhr5saYEy8Q1A/r9XiCBd54Hm/JOnivK4C125/1XAwk+CqQzEZ+WfIoLQAn5Y+zPsuO/bf/ZK0IXU2c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1758698584670674.2641286958045; Wed, 24 Sep 2025 00:23:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1JnC-0005Us-5J; Wed, 24 Sep 2025 03:19:58 -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 1v1Jn9-0005TZ-A8 for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:19:55 -0400 Received: from rev.ng ([94.130.142.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v1Jmu-0003OG-Fe for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:19:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive:List-Unsubscribe:List-Unsubscribe-Post: List-Help; bh=SNZDhnPcG/iwI9uiJToLSsRJihNAUA2OOkjyj/ogJxc=; b=v8zfjtAUGC1Avw4 zXfSGksjuFb28rzBmOxCw9MhrRkkIT6//KwHy6ptzlkmgtm1wCdZqDjxtL49dnTH1Z1PIE3dQEm0h yDoF75Xb7xT3pXG2IyFVwv7dTme82GTFyBqcB+re+7xJwH5Lu9I1xLFrozO4nOnQrWX5tAOhPsm9R os=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com Subject: [RFC PATCH 05/34] target/riscv: Bugfix riscv_pmu_ctr_get_fixed_counters_val() Date: Wed, 24 Sep 2025 09:20:55 +0200 Message-ID: <20250924072124.6493-6-anjo@rev.ng> In-Reply-To: <20250924072124.6493-1-anjo@rev.ng> References: <20250924072124.6493-1-anjo@rev.ng> 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=94.130.142.21; envelope-from=anjo@rev.ng; helo=rev.ng 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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: , Reply-to: Anton Johansson From: Anton Johansson via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758698586172116600 Content-Type: text/plain; charset="utf-8" From my understanding the upper_half argument only indicates whether the upper or lower 32 bits should be returned, and upper_half will only ever be set when MXLEN =3D=3D 32. However, the function also uses upper_half to determine whether the inhibit flags are located in mcyclecfgh or mcyclecfg, but this misses the case where MXLEN =3D=3D 32, upper_half =3D= =3D false for TARGET_RISCV32 where we would also need to read the upper half field. Minor simplifications are also made along with some formatting fixes. Signed-off-by: Anton Johansson --- target/riscv/csr.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 8842e07a73..5997b71b43 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -17,6 +17,7 @@ * this program. If not, see . */ =20 +#include "cpu_bits.h" #include "qemu/osdep.h" #include "qemu/log.h" #include "qemu/timer.h" @@ -1242,18 +1243,21 @@ static target_ulong riscv_pmu_ctr_get_fixed_counter= s_val(CPURISCVState *env, int inst =3D riscv_pmu_ctr_monitor_instructions(env, counter_idx); uint64_t *counter_arr_virt =3D env->pmu_fixed_ctrs[inst].counter_virt; uint64_t *counter_arr =3D env->pmu_fixed_ctrs[inst].counter; - target_ulong result =3D 0; uint64_t curr_val =3D 0; uint64_t cfg_val =3D 0; + bool rv32 =3D riscv_cpu_mxl(env) =3D=3D MXL_RV32; + + /* Ensure upper_half is only set for MXL_RV32 */ + g_assert(rv32 || !upper_half); =20 if (counter_idx =3D=3D 0) { - cfg_val =3D upper_half ? ((uint64_t)env->mcyclecfgh << 32) : + cfg_val =3D rv32 ? ((uint64_t)env->mcyclecfgh << 32) : env->mcyclecfg; } else if (counter_idx =3D=3D 2) { - cfg_val =3D upper_half ? ((uint64_t)env->minstretcfgh << 32) : + cfg_val =3D rv32 ? ((uint64_t)env->minstretcfgh << 32) : env->minstretcfg; } else { - cfg_val =3D upper_half ? + cfg_val =3D rv32 ? ((uint64_t)env->mhpmeventh_val[counter_idx] << 32) : env->mhpmevent_val[counter_idx]; cfg_val &=3D MHPMEVENT_FILTER_MASK; @@ -1261,7 +1265,7 @@ static target_ulong riscv_pmu_ctr_get_fixed_counters_= val(CPURISCVState *env, =20 if (!cfg_val) { if (icount_enabled()) { - curr_val =3D inst ? icount_get_raw() : icount_get(); + curr_val =3D inst ? icount_get_raw() : icount_get(); } else { curr_val =3D cpu_get_host_ticks(); } @@ -1293,13 +1297,7 @@ static target_ulong riscv_pmu_ctr_get_fixed_counters= _val(CPURISCVState *env, } =20 done: - if (riscv_cpu_mxl(env) =3D=3D MXL_RV32) { - result =3D upper_half ? curr_val >> 32 : curr_val; - } else { - result =3D curr_val; - } - - return result; + return upper_half ? curr_val >> 32 : curr_val; } =20 static RISCVException riscv_pmu_write_ctr(CPURISCVState *env, target_ulong= val, --=20 2.51.0 From nobody Sun Sep 28 15:28:22 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1758698543; cv=none; d=zohomail.com; s=zohoarc; b=GeSeYMuU55WTdZLCg1wFPYXQFc7WixFJzxwqK/BClozgvkDj2llt1pj9iQkThfDWw0tqdGQArNH6QIwyHxgE2BZnAR+kNZn6dEluiF7HxzWMGRjpnjl7z+QE2FNQfAXxAzwqldGtjXWhPaD6y9qyJ/iNmz8B1MkDFAZ9pXKbOSw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758698543; 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:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=6/Gip0PjX+Q6V9utA2F2/HpLe4jVvlI12xxQ8AaRq88=; b=l9odITY1Cavl1kIXysZV+qnqZXUUSj+lztzsM2PF4+pnE/nIuBBjidNicrGmten6XxQzXWWnr+RDWbUrqUup351l7xgYvN+g7yMzQ7DTmUm7MEEu4dn/3SAr/U34QpLLHvpaLQKbyRxdm/vzFz9c/pLcWwGoUc0L4kuLkgQqeQk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1758698543094948.5896635743829; Wed, 24 Sep 2025 00:22:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1Jn1-0005Pd-Ho; Wed, 24 Sep 2025 03:19:47 -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 1v1Jmz-0005Og-Gj for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:19:45 -0400 Received: from rev.ng ([94.130.142.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v1Jmp-0003OT-Br for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:19:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive:List-Unsubscribe:List-Unsubscribe-Post: List-Help; bh=6/Gip0PjX+Q6V9utA2F2/HpLe4jVvlI12xxQ8AaRq88=; b=Z5kWt4VlNmjnjIE 35Eh5CLqbSsfawwW4kDEJVV8ORyjBNJwyzAV+5SQG2LXVUFhbX93Rypuaq+IvD+e4VXAZgVyJddqk 2VJezsJQYDPv8WMGJEa8EfQ7Ls1CyUuVFuSxscXmwJ1piZcp5wYpVwT0VYoteLWBdygqgdziIaMxS Fk=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com Subject: [RFC PATCH 06/34] target/riscv: Combine mhpmevent and mhpmeventh Date: Wed, 24 Sep 2025 09:20:56 +0200 Message-ID: <20250924072124.6493-7-anjo@rev.ng> In-Reply-To: <20250924072124.6493-1-anjo@rev.ng> References: <20250924072124.6493-1-anjo@rev.ng> 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=94.130.142.21; envelope-from=anjo@rev.ng; helo=rev.ng 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_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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: , Reply-to: Anton Johansson From: Anton Johansson via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758698543844116600 Content-Type: text/plain; charset="utf-8" According to version 20250508 of the privileged specification, mhpmeventn is 64 bits in size and mhpmeventnh is only ever used when XLEN =3D=3D 32 and accesses the top 32 bits of the 64-bit mhpmeventn registers. Combine the two arrays of target_ulong mhpmeventh[] and mhpmevent[] to a single array of uint64_t. This also allows for some minor code simplification where branches handling either mhpmeventh[] or mhpmevent[] could be combined. Signed-off-by: Anton Johansson --- target/riscv/cpu.h | 10 +++---- target/riscv/csr.c | 67 +++++++++++++++--------------------------- target/riscv/machine.c | 3 +- target/riscv/pmu.c | 53 ++++++++------------------------- 4 files changed, 42 insertions(+), 91 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index f94f773a84..f0f4d71fdf 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -427,11 +427,11 @@ struct CPUArchState { /* PMU counter state */ PMUCTRState pmu_ctrs[RV_MAX_MHPMCOUNTERS]; =20 - /* PMU event selector configured values. First three are unused */ - target_ulong mhpmevent_val[RV_MAX_MHPMEVENTS]; - - /* PMU event selector configured values for RV32 */ - target_ulong mhpmeventh_val[RV_MAX_MHPMEVENTS]; + /* + * PMU event selector configured values. First three are unused. + * For RV32 top 32 bits are accessed via the mhpmeventh CSR. + */ + uint64_t mhpmevent_val[RV_MAX_MHPMEVENTS]; =20 PMUFixedCtrState pmu_fixed_ctrs[2]; =20 diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 5997b71b43..35f296954f 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -1167,8 +1167,9 @@ static RISCVException read_mhpmevent(CPURISCVState *e= nv, int csrno, target_ulong *val) { int evt_index =3D csrno - CSR_MCOUNTINHIBIT; + bool rv32 =3D riscv_cpu_mxl(env) =3D=3D MXL_RV32; =20 - *val =3D env->mhpmevent_val[evt_index]; + *val =3D extract64(env->mhpmevent_val[evt_index], 0, rv32 ? 32 : 64); =20 return RISCV_EXCP_NONE; } @@ -1177,13 +1178,11 @@ static RISCVException write_mhpmevent(CPURISCVState= *env, int csrno, target_ulong val, uintptr_t ra) { int evt_index =3D csrno - CSR_MCOUNTINHIBIT; - uint64_t mhpmevt_val =3D val; + uint64_t mhpmevt_val; uint64_t inh_avail_mask; =20 if (riscv_cpu_mxl(env) =3D=3D MXL_RV32) { - env->mhpmevent_val[evt_index] =3D val; - mhpmevt_val =3D mhpmevt_val | - ((uint64_t)env->mhpmeventh_val[evt_index] << 32); + mhpmevt_val =3D deposit64(env->mhpmevent_val[evt_index], 0, 32, va= l); } else { inh_avail_mask =3D ~MHPMEVENT_FILTER_MASK | MHPMEVENT_BIT_MINH; inh_avail_mask |=3D riscv_has_ext(env, RVU) ? MHPMEVENT_BIT_UINH := 0; @@ -1193,9 +1192,9 @@ static RISCVException write_mhpmevent(CPURISCVState *= env, int csrno, inh_avail_mask |=3D (riscv_has_ext(env, RVH) && riscv_has_ext(env, RVS)) ? MHPMEVENT_BIT_VSINH = : 0; mhpmevt_val =3D val & inh_avail_mask; - env->mhpmevent_val[evt_index] =3D mhpmevt_val; } =20 + env->mhpmevent_val[evt_index] =3D mhpmevt_val; riscv_pmu_update_event_map(env, mhpmevt_val, evt_index); =20 return RISCV_EXCP_NONE; @@ -1206,7 +1205,7 @@ static RISCVException read_mhpmeventh(CPURISCVState *= env, int csrno, { int evt_index =3D csrno - CSR_MHPMEVENT3H + 3; =20 - *val =3D env->mhpmeventh_val[evt_index]; + *val =3D extract64(env->mhpmevent_val[evt_index], 32, 32); =20 return RISCV_EXCP_NONE; } @@ -1215,8 +1214,6 @@ static RISCVException write_mhpmeventh(CPURISCVState = *env, int csrno, target_ulong val, uintptr_t ra) { int evt_index =3D csrno - CSR_MHPMEVENT3H + 3; - uint64_t mhpmevth_val; - uint64_t mhpmevt_val =3D env->mhpmevent_val[evt_index]; target_ulong inh_avail_mask =3D (target_ulong)(~MHPMEVENTH_FILTER_MASK= | MHPMEVENTH_BIT_MINH); =20 @@ -1227,11 +1224,10 @@ static RISCVException write_mhpmeventh(CPURISCVStat= e *env, int csrno, inh_avail_mask |=3D (riscv_has_ext(env, RVH) && riscv_has_ext(env, RVS)) ? MHPMEVENTH_BIT_VSINH : 0; =20 - mhpmevth_val =3D val & inh_avail_mask; - mhpmevt_val =3D mhpmevt_val | (mhpmevth_val << 32); - env->mhpmeventh_val[evt_index] =3D mhpmevth_val; + env->mhpmevent_val[evt_index] =3D deposit64(env->mhpmevent_val[evt_ind= ex], + 32, 32, val & inh_avail_mask= ); =20 - riscv_pmu_update_event_map(env, mhpmevt_val, evt_index); + riscv_pmu_update_event_map(env, env->mhpmevent_val[evt_index], evt_ind= ex); =20 return RISCV_EXCP_NONE; } @@ -1257,9 +1253,7 @@ static target_ulong riscv_pmu_ctr_get_fixed_counters_= val(CPURISCVState *env, cfg_val =3D rv32 ? ((uint64_t)env->minstretcfgh << 32) : env->minstretcfg; } else { - cfg_val =3D rv32 ? - ((uint64_t)env->mhpmeventh_val[counter_idx] << 32) : - env->mhpmevent_val[counter_idx]; + cfg_val =3D env->mhpmevent_val[counter_idx]; cfg_val &=3D MHPMEVENT_FILTER_MASK; } =20 @@ -1472,27 +1466,23 @@ static int rmw_cd_mhpmcounterh(CPURISCVState *env, = int ctr_idx, =20 static int rmw_cd_mhpmevent(CPURISCVState *env, int evt_index, target_ulong *val, target_ulong new_val, - target_ulong wr_mask) + uint64_t wr_mask) { - uint64_t mhpmevt_val =3D new_val; + uint64_t mhpmevt_val =3D env->mhpmevent_val[evt_index]; =20 if (wr_mask !=3D 0 && wr_mask !=3D -1) { return -EINVAL; } =20 if (!wr_mask && val) { - *val =3D env->mhpmevent_val[evt_index]; + *val =3D mhpmevt_val; if (riscv_cpu_cfg(env)->ext_sscofpmf) { *val &=3D ~MHPMEVENT_BIT_MINH; } } else if (wr_mask) { wr_mask &=3D ~MHPMEVENT_BIT_MINH; - mhpmevt_val =3D (new_val & wr_mask) | - (env->mhpmevent_val[evt_index] & ~wr_mask); - if (riscv_cpu_mxl(env) =3D=3D MXL_RV32) { - mhpmevt_val =3D mhpmevt_val | - ((uint64_t)env->mhpmeventh_val[evt_index] << 32); - } + /* wr_mask is 64-bit so upper 32 bits of mhpmevt_val are retained = */ + mhpmevt_val =3D (new_val & wr_mask) | (mhpmevt_val & ~wr_mask); env->mhpmevent_val[evt_index] =3D mhpmevt_val; riscv_pmu_update_event_map(env, mhpmevt_val, evt_index); } else { @@ -1506,24 +1496,23 @@ static int rmw_cd_mhpmeventh(CPURISCVState *env, in= t evt_index, target_ulong *val, target_ulong new_val, target_ulong wr_mask) { - uint64_t mhpmevth_val; uint64_t mhpmevt_val =3D env->mhpmevent_val[evt_index]; + uint32_t mhpmevth_val =3D extract64(mhpmevt_val, 32, 32); =20 if (wr_mask !=3D 0 && wr_mask !=3D -1) { return -EINVAL; } =20 if (!wr_mask && val) { - *val =3D env->mhpmeventh_val[evt_index]; + *val =3D mhpmevth_val; if (riscv_cpu_cfg(env)->ext_sscofpmf) { *val &=3D ~MHPMEVENTH_BIT_MINH; } } else if (wr_mask) { wr_mask &=3D ~MHPMEVENTH_BIT_MINH; - env->mhpmeventh_val[evt_index] =3D - (new_val & wr_mask) | (env->mhpmeventh_val[evt_index] & ~wr_ma= sk); - mhpmevth_val =3D env->mhpmeventh_val[evt_index]; - mhpmevt_val =3D mhpmevt_val | (mhpmevth_val << 32); + mhpmevth_val =3D (new_val & wr_mask) | (mhpmevth_val & ~wr_mask); + mhpmevt_val =3D deposit64(mhpmevt_val, 32, 32, mhpmevth_val); + env->mhpmevent_val[evt_index] =3D mhpmevt_val; riscv_pmu_update_event_map(env, mhpmevt_val, evt_index); } else { return -EINVAL; @@ -1599,8 +1588,6 @@ static RISCVException read_scountovf(CPURISCVState *e= nv, int csrno, int mhpmevt_start =3D CSR_MHPMEVENT3 - CSR_MCOUNTINHIBIT; int i; *val =3D 0; - target_ulong *mhpm_evt_val; - uint64_t of_bit_mask; =20 /* Virtualize scountovf for counter delegation */ if (riscv_cpu_cfg(env)->ext_sscofpmf && @@ -1610,19 +1597,11 @@ static RISCVException read_scountovf(CPURISCVState = *env, int csrno, return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; } =20 - if (riscv_cpu_mxl(env) =3D=3D MXL_RV32) { - mhpm_evt_val =3D env->mhpmeventh_val; - of_bit_mask =3D MHPMEVENTH_BIT_OF; - } else { - mhpm_evt_val =3D env->mhpmevent_val; - of_bit_mask =3D MHPMEVENT_BIT_OF; - } - for (i =3D mhpmevt_start; i < RV_MAX_MHPMEVENTS; i++) { if ((get_field(env->mcounteren, BIT(i))) && - (mhpm_evt_val[i] & of_bit_mask)) { - *val |=3D BIT(i); - } + (env->mhpmevent_val[i] & MHPMEVENT_BIT_OF)) { + *val |=3D BIT(i); + } } =20 return RISCV_EXCP_NONE; diff --git a/target/riscv/machine.c b/target/riscv/machine.c index 32cc94858d..c476bb0089 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -452,8 +452,7 @@ const VMStateDescription vmstate_riscv_cpu =3D { VMSTATE_UINT32(env.mcountinhibit, RISCVCPU), VMSTATE_STRUCT_ARRAY(env.pmu_ctrs, RISCVCPU, RV_MAX_MHPMCOUNTERS, = 0, vmstate_pmu_ctr_state, PMUCTRState), - VMSTATE_UINTTL_ARRAY(env.mhpmevent_val, RISCVCPU, RV_MAX_MHPMEVENT= S), - VMSTATE_UINTTL_ARRAY(env.mhpmeventh_val, RISCVCPU, RV_MAX_MHPMEVEN= TS), + VMSTATE_UINT64_ARRAY(env.mhpmevent_val, RISCVCPU, RV_MAX_MHPMEVENT= S), VMSTATE_UINT64(env.sscratch, RISCVCPU), VMSTATE_UINT64(env.mscratch, RISCVCPU), VMSTATE_UINT64(env.stimecmp, RISCVCPU), diff --git a/target/riscv/pmu.c b/target/riscv/pmu.c index a68809eef3..273822e921 100644 --- a/target/riscv/pmu.c +++ b/target/riscv/pmu.c @@ -110,15 +110,15 @@ static int riscv_pmu_incr_ctr_rv32(RISCVCPU *cpu, uin= t32_t ctr_idx) =20 /* Privilege mode filtering */ if ((env->priv =3D=3D PRV_M && - (env->mhpmeventh_val[ctr_idx] & MHPMEVENTH_BIT_MINH)) || + (env->mhpmevent_val[ctr_idx] & MHPMEVENT_BIT_MINH)) || (env->priv =3D=3D PRV_S && virt_on && - (env->mhpmeventh_val[ctr_idx] & MHPMEVENTH_BIT_VSINH)) || + (env->mhpmevent_val[ctr_idx] & MHPMEVENT_BIT_VSINH)) || (env->priv =3D=3D PRV_U && virt_on && - (env->mhpmeventh_val[ctr_idx] & MHPMEVENTH_BIT_VUINH)) || + (env->mhpmevent_val[ctr_idx] & MHPMEVENT_BIT_VUINH)) || (env->priv =3D=3D PRV_S && !virt_on && - (env->mhpmeventh_val[ctr_idx] & MHPMEVENTH_BIT_SINH)) || + (env->mhpmevent_val[ctr_idx] & MHPMEVENT_BIT_SINH)) || (env->priv =3D=3D PRV_U && !virt_on && - (env->mhpmeventh_val[ctr_idx] & MHPMEVENTH_BIT_UINH))) { + (env->mhpmevent_val[ctr_idx] & MHPMEVENT_BIT_UINH))) { return 0; } =20 @@ -128,8 +128,8 @@ static int riscv_pmu_incr_ctr_rv32(RISCVCPU *cpu, uint3= 2_t ctr_idx) counter->mhpmcounter_val =3D 0; counter->mhpmcounterh_val =3D 0; /* Generate interrupt only if OF bit is clear */ - if (!(env->mhpmeventh_val[ctr_idx] & MHPMEVENTH_BIT_OF)) { - env->mhpmeventh_val[ctr_idx] |=3D MHPMEVENTH_BIT_OF; + if (!(env->mhpmevent_val[ctr_idx] & MHPMEVENT_BIT_OF)) { + env->mhpmevent_val[ctr_idx] |=3D MHPMEVENT_BIT_OF; riscv_cpu_update_mip(env, MIP_LCOFIP, BOOL_TO_MASK(1)); } } else { @@ -420,41 +420,14 @@ int riscv_pmu_update_event_map(CPURISCVState *env, ui= nt64_t value, return 0; } =20 -static bool pmu_hpmevent_is_of_set(CPURISCVState *env, uint32_t ctr_idx) -{ - target_ulong mhpmevent_val; - uint64_t of_bit_mask; - - if (riscv_cpu_mxl(env) =3D=3D MXL_RV32) { - mhpmevent_val =3D env->mhpmeventh_val[ctr_idx]; - of_bit_mask =3D MHPMEVENTH_BIT_OF; - } else { - mhpmevent_val =3D env->mhpmevent_val[ctr_idx]; - of_bit_mask =3D MHPMEVENT_BIT_OF; - } - - return get_field(mhpmevent_val, of_bit_mask); -} - static bool pmu_hpmevent_set_of_if_clear(CPURISCVState *env, uint32_t ctr_= idx) { - target_ulong *mhpmevent_val; - uint64_t of_bit_mask; - - if (riscv_cpu_mxl(env) =3D=3D MXL_RV32) { - mhpmevent_val =3D &env->mhpmeventh_val[ctr_idx]; - of_bit_mask =3D MHPMEVENTH_BIT_OF; - } else { - mhpmevent_val =3D &env->mhpmevent_val[ctr_idx]; - of_bit_mask =3D MHPMEVENT_BIT_OF; - } - - if (!get_field(*mhpmevent_val, of_bit_mask)) { - *mhpmevent_val |=3D of_bit_mask; + if (!get_field(env->mhpmevent_val[ctr_idx], MHPMEVENT_BIT_OF)) { + env->mhpmevent_val[ctr_idx] |=3D MHPMEVENT_BIT_OF; return true; + } else { + return false; } - - return false; } =20 static void pmu_timer_trigger_irq(RISCVCPU *cpu, @@ -479,7 +452,7 @@ static void pmu_timer_trigger_irq(RISCVCPU *cpu, } =20 /* Generate interrupt only if OF bit is clear */ - if (pmu_hpmevent_is_of_set(env, ctr_idx)) { + if (get_field(env->mhpmevent_val[ctr_idx], MHPMEVENT_BIT_OF)) { return; } =20 @@ -538,7 +511,7 @@ int riscv_pmu_setup_timer(CPURISCVState *env, uint64_t = value, uint32_t ctr_idx) =20 /* No need to setup a timer if LCOFI is disabled when OF is set */ if (!riscv_pmu_counter_valid(cpu, ctr_idx) || !cpu->cfg.ext_sscofpmf || - pmu_hpmevent_is_of_set(env, ctr_idx)) { + get_field(env->mhpmevent_val[ctr_idx], MHPMEVENT_BIT_OF)) { return -1; } =20 --=20 2.51.0 From nobody Sun Sep 28 15:28:22 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1758698444; cv=none; d=zohomail.com; s=zohoarc; b=JeUGrsJqdRGYK50qMTrak+Pywv4qUzpyinnF0R+CjApaqp9FAvIJeCe0m9aAtKDLJjCtnNuBKTjj5e0GWsIVCbEzK6ZUQ7YpBTu+WD3MzUeugoTHICCZ673XzbdYRrwgstRT60yirDknMC+EIkxYWo/fFcqbiG8jLLKGKjT7wak= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758698444; 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:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=xQUfxNFEDlvBS35PtAvGNNw8/B9rYjS0FdRgpiMJAHE=; b=YPSxLhwZKWjqh53jgBjQLkiaPKwTLj0y+f7PMMOFoYNWCflmcCw19mw0TatCIYgoyzMKV5EoVlR1dbYaMMTGIzy/a+sgDRbKLBBGz+NFMvrTGaLwiCak2lvUXBac5z5JBD0minAOBJJmqi0jVyaHBMvFPKTxVwFr4+jLZJvP8XA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 17586984439981012.6487204765212; Wed, 24 Sep 2025 00:20:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1Jn2-0005RK-Lb; Wed, 24 Sep 2025 03:19:48 -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 1v1Jmy-0005O9-Pj for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:19:45 -0400 Received: from rev.ng ([94.130.142.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v1Jmq-0003OZ-0V for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:19:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive:List-Unsubscribe:List-Unsubscribe-Post: List-Help; bh=xQUfxNFEDlvBS35PtAvGNNw8/B9rYjS0FdRgpiMJAHE=; b=mGQOOBoLU3beLWt LAXdk9IFXmAyIfFkbh1O7qKHTq+hJSydtr6hkQr3TIJAk/UWC+QdoIGNQKipsmhCEC66sB5NXnhfg CB2CnkibC5ac+BB+LHIW1wLz95HhKBNALkdsoR1NHkyMymp99GW/yY+NZqxRtTLwDyZhL7n/Zhegv Gc=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com Subject: [RFC PATCH 07/34] target/riscv: Combine mcyclecfg and mcyclecfgh Date: Wed, 24 Sep 2025 09:20:57 +0200 Message-ID: <20250924072124.6493-8-anjo@rev.ng> In-Reply-To: <20250924072124.6493-1-anjo@rev.ng> References: <20250924072124.6493-1-anjo@rev.ng> 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=94.130.142.21; envelope-from=anjo@rev.ng; helo=rev.ng 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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: , Reply-to: Anton Johansson From: Anton Johansson via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758698445443116600 Content-Type: text/plain; charset="utf-8" According to version 20250508 of the privileged specification, mcyclecfg is a 64-bit register and mcyclecfgh refers to the top 32 bits of this register when XLEN =3D=3D 32. No real advantage is gained by keeping them separate, and combining them allows for slight simplification. Signed-off-by: Anton Johansson --- target/riscv/cpu.h | 3 +-- target/riscv/csr.c | 28 +++++++++++++++++----------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index f0f4d71fdf..4b80daf117 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -419,8 +419,7 @@ struct CPUArchState { uint32_t mcountinhibit; =20 /* PMU cycle & instret privilege mode filtering */ - target_ulong mcyclecfg; - target_ulong mcyclecfgh; + uint64_t mcyclecfg; target_ulong minstretcfg; target_ulong minstretcfgh; =20 diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 35f296954f..867f8efe83 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -1061,7 +1061,8 @@ static RISCVException read_hpmcounterh(CPURISCVState = *env, int csrno, static RISCVException read_mcyclecfg(CPURISCVState *env, int csrno, target_ulong *val) { - *val =3D env->mcyclecfg; + bool rv32 =3D riscv_cpu_mxl(env) =3D=3D MXL_RV32; + *val =3D extract64(env->mcyclecfg, 0, rv32 ? 32 : 64); return RISCV_EXCP_NONE; } =20 @@ -1071,7 +1072,7 @@ static RISCVException write_mcyclecfg(CPURISCVState *= env, int csrno, uint64_t inh_avail_mask; =20 if (riscv_cpu_mxl(env) =3D=3D MXL_RV32) { - env->mcyclecfg =3D val; + env->mcyclecfg =3D deposit64(env->mcyclecfg, 0, 32, val); } else { /* Set xINH fields if priv mode supported */ inh_avail_mask =3D ~MHPMEVENT_FILTER_MASK | MCYCLECFG_BIT_MINH; @@ -1090,7 +1091,7 @@ static RISCVException write_mcyclecfg(CPURISCVState *= env, int csrno, static RISCVException read_mcyclecfgh(CPURISCVState *env, int csrno, target_ulong *val) { - *val =3D env->mcyclecfgh; + *val =3D extract64(env->mcyclecfg, 32, 32); return RISCV_EXCP_NONE; } =20 @@ -1108,7 +1109,7 @@ static RISCVException write_mcyclecfgh(CPURISCVState = *env, int csrno, inh_avail_mask |=3D (riscv_has_ext(env, RVH) && riscv_has_ext(env, RVS)) ? MCYCLECFGH_BIT_VSINH : 0; =20 - env->mcyclecfgh =3D val & inh_avail_mask; + env->mcyclecfg =3D deposit64(env->mcyclecfg, 32, 32, val & inh_avail_m= ask); return RISCV_EXCP_NONE; } =20 @@ -1247,8 +1248,7 @@ static target_ulong riscv_pmu_ctr_get_fixed_counters_= val(CPURISCVState *env, g_assert(rv32 || !upper_half); =20 if (counter_idx =3D=3D 0) { - cfg_val =3D rv32 ? ((uint64_t)env->mcyclecfgh << 32) : - env->mcyclecfg; + cfg_val =3D env->mcyclecfg; } else if (counter_idx =3D=3D 2) { cfg_val =3D rv32 ? ((uint64_t)env->minstretcfgh << 32) : env->minstretcfg; @@ -1522,8 +1522,12 @@ static int rmw_cd_mhpmeventh(CPURISCVState *env, int= evt_index, } =20 static int rmw_cd_ctr_cfg(CPURISCVState *env, int cfg_index, target_ulong = *val, - target_ulong new_val, target_ulong wr_mask) + target_ulong new_val, uint64_t wr_mask) { + /* + * wr_mask is 64-bit so upper 32 bits of mcyclecfg and minstretcfg + * are retained. + */ switch (cfg_index) { case 0: /* CYCLECFG */ if (wr_mask) { @@ -1549,8 +1553,9 @@ static int rmw_cd_ctr_cfg(CPURISCVState *env, int cfg= _index, target_ulong *val, } =20 static int rmw_cd_ctr_cfgh(CPURISCVState *env, int cfg_index, target_ulong= *val, - target_ulong new_val, target_ulong wr_mask) + target_ulong new_val, target_ulong wr_mask) { + uint64_t cfgh; =20 if (riscv_cpu_mxl(env) !=3D MXL_RV32) { return RISCV_EXCP_ILLEGAL_INST; @@ -1558,12 +1563,13 @@ static int rmw_cd_ctr_cfgh(CPURISCVState *env, int = cfg_index, target_ulong *val, =20 switch (cfg_index) { case 0: /* CYCLECFGH */ + cfgh =3D extract64(env->mcyclecfg, 32, 32); if (wr_mask) { wr_mask &=3D ~MCYCLECFGH_BIT_MINH; - env->mcyclecfgh =3D (new_val & wr_mask) | - (env->mcyclecfgh & ~wr_mask); + cfgh =3D (new_val & wr_mask) | (cfgh & ~wr_mask); + env->mcyclecfg =3D deposit64(env->mcyclecfg, 32, 32, cfgh); } else { - *val =3D env->mcyclecfgh; + *val =3D cfgh; } break; case 2: /* INSTRETCFGH */ --=20 2.51.0 From nobody Sun Sep 28 15:28:22 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1758698913; cv=none; d=zohomail.com; s=zohoarc; b=NqaPir8U5B1PIyCqx7H6mjCPsSILqCG5ZlQUEEp04s/uR4NijKsagFXmJiTlzHNLAR2yCAfEDew31Trg0JT3KnY2WQAGAZ2Ytty9g2mSY8lXTSYrYA0ly2F6o5WKDtZMoD4KU5wLh4LawKjuO6SqnjyKE6/6QYduyp6ACXk3Uwo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758698913; 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:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=Y8Je5iZVgc2ycYZL2Dvu1grRMVwIH4xKSbz9INjaPno=; b=fKdIOt3tqaSbqROP+iwfPWbNNXWMcgAifrvrzaJucRotuXiJkt94Xon/rHhke3+tKyBvuGtDWWt3AxaMMGa9Bo3dcQLAbSEslEorADpjUjR2V+IIBqwTB9dPNrbYgd4kQkVwggLE69SkQxLY/8NZ9fOw+IhS3jq50c/Pd8JPEA4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 17586989136411006.6133168664456; Wed, 24 Sep 2025 00:28:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1Jn6-0005SX-BF; Wed, 24 Sep 2025 03:19:52 -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 1v1Jn1-0005Pa-Dr for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:19:47 -0400 Received: from rev.ng ([94.130.142.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v1Jms-0003Om-8S for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:19:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive:List-Unsubscribe:List-Unsubscribe-Post: List-Help; bh=Y8Je5iZVgc2ycYZL2Dvu1grRMVwIH4xKSbz9INjaPno=; b=AZF4YpIauyDZuXF oqZI2MHtpbE8YA7PpfQ9CJ/FUlk5LkTNdxpoqvk1YTbVzdhc/3mkd48nUAcPU7lQmedXywSTr+6nh s/uaF9kPlzlQOzPcOCA9YUq9hk7DkFCK2AMdZ0V86md0xp8ZfD6VQ5wEcAeJ0szMMNXujbGaw9RCf /Y=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com Subject: [RFC PATCH 08/34] target/riscv: Combine minstretcfg and minstretcfgh Date: Wed, 24 Sep 2025 09:20:58 +0200 Message-ID: <20250924072124.6493-9-anjo@rev.ng> In-Reply-To: <20250924072124.6493-1-anjo@rev.ng> References: <20250924072124.6493-1-anjo@rev.ng> 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=94.130.142.21; envelope-from=anjo@rev.ng; helo=rev.ng 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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: , Reply-to: Anton Johansson From: Anton Johansson via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758698915674116600 Content-Type: text/plain; charset="utf-8" According to version 20250508 of the privileged specification, minstretcfg is a 64-bit register and minstretcfgh refers to the top 32 bits of this register when XLEN =3D=3D 32. No real advantage is gained by keeping them separate, and combining them allows for slight simplification. Signed-off-by: Anton Johansson --- target/riscv/cpu.h | 3 +-- target/riscv/csr.c | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 4b80daf117..81719813cf 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -420,8 +420,7 @@ struct CPUArchState { =20 /* PMU cycle & instret privilege mode filtering */ uint64_t mcyclecfg; - target_ulong minstretcfg; - target_ulong minstretcfgh; + uint64_t minstretcfg; =20 /* PMU counter state */ PMUCTRState pmu_ctrs[RV_MAX_MHPMCOUNTERS]; diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 867f8efe83..4d232b062b 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -1116,7 +1116,8 @@ static RISCVException write_mcyclecfgh(CPURISCVState = *env, int csrno, static RISCVException read_minstretcfg(CPURISCVState *env, int csrno, target_ulong *val) { - *val =3D env->minstretcfg; + bool rv32 =3D riscv_cpu_mxl(env) =3D=3D MXL_RV32; + *val =3D extract64(env->minstretcfg, 0, rv32 ? 32 : 64); return RISCV_EXCP_NONE; } =20 @@ -1143,7 +1144,7 @@ static RISCVException write_minstretcfg(CPURISCVState= *env, int csrno, static RISCVException read_minstretcfgh(CPURISCVState *env, int csrno, target_ulong *val) { - *val =3D env->minstretcfgh; + *val =3D extract64(env->minstretcfg, 32, 32); return RISCV_EXCP_NONE; } =20 @@ -1160,7 +1161,8 @@ static RISCVException write_minstretcfgh(CPURISCVStat= e *env, int csrno, inh_avail_mask |=3D (riscv_has_ext(env, RVH) && riscv_has_ext(env, RVS)) ? MINSTRETCFGH_BIT_VSINH := 0; =20 - env->minstretcfgh =3D val & inh_avail_mask; + env->minstretcfg =3D deposit64(env->minstretcfg, 32, 32, + val & inh_avail_mask); return RISCV_EXCP_NONE; } =20 @@ -1250,8 +1252,7 @@ static target_ulong riscv_pmu_ctr_get_fixed_counters_= val(CPURISCVState *env, if (counter_idx =3D=3D 0) { cfg_val =3D env->mcyclecfg; } else if (counter_idx =3D=3D 2) { - cfg_val =3D rv32 ? ((uint64_t)env->minstretcfgh << 32) : - env->minstretcfg; + cfg_val =3D env->minstretcfg; } else { cfg_val =3D env->mhpmevent_val[counter_idx]; cfg_val &=3D MHPMEVENT_FILTER_MASK; @@ -1573,12 +1574,13 @@ static int rmw_cd_ctr_cfgh(CPURISCVState *env, int = cfg_index, target_ulong *val, } break; case 2: /* INSTRETCFGH */ + cfgh =3D extract64(env->minstretcfg, 32, 32); if (wr_mask) { wr_mask &=3D ~MINSTRETCFGH_BIT_MINH; - env->minstretcfgh =3D (new_val & wr_mask) | - (env->minstretcfgh & ~wr_mask); + cfgh =3D (new_val & wr_mask) | (cfgh & ~wr_mask); + env->minstretcfg =3D deposit64(env->minstretcfg, 32, 32, cfgh); } else { - *val =3D env->minstretcfgh; + *val =3D cfgh; } break; default: --=20 2.51.0 From nobody Sun Sep 28 15:28:22 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1758698444; cv=none; d=zohomail.com; s=zohoarc; b=a0WjY0p7d2CXhQeqUDwy7YlaA2RSjYziCvyI6ZHnXLzqiHVo8UztFomMDAAxlnJSIXNAoBB7m02jZEewO8aHVbxSOTwT6w+ejt7/UHvMeiYDvB198M0dbThKgCHY28hfK+2eorSD5IuVp9HUphSR/qfSLW/HPd2BIPrCG4vwvmo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758698444; 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:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=gv/vATm5ZZPYeNw35feJwyefhLISJPLo9ephGqNgcYs=; b=My0Gdn4dxM6XS+5QyS7Y4q3U04Vk6znWTojklns0QMClwdGlBmJs5j4CyTy9GQWwxLedefW8ZsdeZuqMdz7zvr6vKbZ0p6QT0gxxzm8712Zu/ySu1f+PwUiC2wI6BDc49x87MGTes346OG2xvaug/dxDve/5rS0/VRANSwh5nHg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1758698444348293.6802975427447; Wed, 24 Sep 2025 00:20:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1Jn9-0005Tt-F2; Wed, 24 Sep 2025 03:19:55 -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 1v1Jn6-0005SZ-Ub for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:19:52 -0400 Received: from rev.ng ([94.130.142.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v1Jms-0003Oz-90 for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:19:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive:List-Unsubscribe:List-Unsubscribe-Post: List-Help; bh=gv/vATm5ZZPYeNw35feJwyefhLISJPLo9ephGqNgcYs=; b=wdWuM2Z6BIDnfLY Y4jdamVHHU+gj+eGLggmSsqRQG+7VzaYt9UnCvayLGQ1v6mzbtrFr6byAdHo0VTrw4QOIZjj2it/P /7GZO5FM3jb82iG+6IKVLYmAguovfRA9ue1TQM7QQKIpxdr0Z9ttsIONn2h3EAlCsRjX+sfkPnTTc cI=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com Subject: [RFC PATCH 09/34] target/riscv: Combine mhpmcounter and mhpmcounterh Date: Wed, 24 Sep 2025 09:20:59 +0200 Message-ID: <20250924072124.6493-10-anjo@rev.ng> In-Reply-To: <20250924072124.6493-1-anjo@rev.ng> References: <20250924072124.6493-1-anjo@rev.ng> 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=94.130.142.21; envelope-from=anjo@rev.ng; helo=rev.ng 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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: , Reply-to: Anton Johansson From: Anton Johansson via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758698446567116600 Content-Type: text/plain; charset="utf-8" According to version 20250508 of the privileged specification, mhpmconter is a 64-bit register and mhpmcounterh refers to the top 32 bits of this register when XLEN =3D=3D 32. No real advantage is gained by keeping them separate, and combining allows for slight simplification. Signed-off-by: Anton Johansson --- target/riscv/cpu.h | 8 +-- target/riscv/csr.c | 74 +++++++++++++-------------- target/riscv/machine.c | 6 +-- target/riscv/pmu.c | 111 +++++++++++------------------------------ 4 files changed, 68 insertions(+), 131 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 81719813cf..b0d6e74ea3 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -195,13 +195,9 @@ FIELD(VTYPE, RESERVED, 10, sizeof(target_ulong) * 8 - = 11) =20 typedef struct PMUCTRState { /* Current value of a counter */ - target_ulong mhpmcounter_val; - /* Current value of a counter in RV32 */ - target_ulong mhpmcounterh_val; + uint64_t mhpmcounter_val; /* Snapshot values of counter */ - target_ulong mhpmcounter_prev; - /* Snapshort value of a counter in RV32 */ - target_ulong mhpmcounterh_prev; + uint64_t mhpmcounter_prev; /* Value beyond UINT32_MAX/UINT64_MAX before overflow interrupt trigge= r */ target_ulong irq_overflow_left; } PMUCTRState; diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 4d232b062b..f29a3c9991 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -1299,24 +1299,27 @@ static RISCVException riscv_pmu_write_ctr(CPURISCVS= tate *env, target_ulong val, uint32_t ctr_idx) { PMUCTRState *counter =3D &env->pmu_ctrs[ctr_idx]; - uint64_t mhpmctr_val =3D val; + bool rv32 =3D riscv_cpu_mxl(env) =3D=3D MXL_RV32; + int deposit_size =3D rv32 ? 32 : 64; + uint64_t ctr; + + counter->mhpmcounter_val =3D deposit64(counter->mhpmcounter_val, + 0, deposit_size, val); =20 - counter->mhpmcounter_val =3D val; if (!get_field(env->mcountinhibit, BIT(ctr_idx)) && (riscv_pmu_ctr_monitor_cycles(env, ctr_idx) || riscv_pmu_ctr_monitor_instructions(env, ctr_idx))) { - counter->mhpmcounter_prev =3D riscv_pmu_ctr_get_fixed_counters_val= (env, - ctr_idx, f= alse); + ctr =3D riscv_pmu_ctr_get_fixed_counters_val(env, ctr_idx, false); + counter->mhpmcounter_prev =3D deposit64(counter->mhpmcounter_prev, + 0, deposit_size, ctr); if (ctr_idx > 2) { - if (riscv_cpu_mxl(env) =3D=3D MXL_RV32) { - mhpmctr_val =3D mhpmctr_val | - ((uint64_t)counter->mhpmcounterh_val << 32); - } - riscv_pmu_setup_timer(env, mhpmctr_val, ctr_idx); + riscv_pmu_setup_timer(env, counter->mhpmcounter_val, ctr_idx); } } else { /* Other counters can keep incrementing from the given value */ - counter->mhpmcounter_prev =3D val; + counter->mhpmcounter_prev =3D deposit64(counter->mhpmcounter_prev, + 0, deposit_size, val); + } =20 return RISCV_EXCP_NONE; @@ -1326,21 +1329,22 @@ static RISCVException riscv_pmu_write_ctrh(CPURISCV= State *env, target_ulong val, uint32_t ctr_idx) { PMUCTRState *counter =3D &env->pmu_ctrs[ctr_idx]; - uint64_t mhpmctr_val =3D counter->mhpmcounter_val; - uint64_t mhpmctrh_val =3D val; + uint64_t ctrh; =20 - counter->mhpmcounterh_val =3D val; - mhpmctr_val =3D mhpmctr_val | (mhpmctrh_val << 32); + counter->mhpmcounter_val =3D deposit64(counter->mhpmcounter_val, + 32, 32, val); if (!get_field(env->mcountinhibit, BIT(ctr_idx)) && (riscv_pmu_ctr_monitor_cycles(env, ctr_idx) || riscv_pmu_ctr_monitor_instructions(env, ctr_idx))) { - counter->mhpmcounterh_prev =3D riscv_pmu_ctr_get_fixed_counters_va= l(env, - ctr_idx, = true); + ctrh =3D riscv_pmu_ctr_get_fixed_counters_val(env, ctr_idx, true); + counter->mhpmcounter_prev =3D deposit64(counter->mhpmcounter_prev, + 32, 32, ctrh); if (ctr_idx > 2) { - riscv_pmu_setup_timer(env, mhpmctr_val, ctr_idx); + riscv_pmu_setup_timer(env, counter->mhpmcounter_val, ctr_idx); } } else { - counter->mhpmcounterh_prev =3D val; + counter->mhpmcounter_prev =3D deposit64(counter->mhpmcounter_prev, + 32, 32, val); } =20 return RISCV_EXCP_NONE; @@ -1363,13 +1367,17 @@ static RISCVException write_mhpmcounterh(CPURISCVSt= ate *env, int csrno, } =20 RISCVException riscv_pmu_read_ctr(CPURISCVState *env, target_ulong *val, - bool upper_half, uint32_t ctr_idx) + bool upper_half, uint32_t ctr_idx) { PMUCTRState *counter =3D &env->pmu_ctrs[ctr_idx]; - target_ulong ctr_prev =3D upper_half ? counter->mhpmcounterh_prev : - counter->mhpmcounter_prev; - target_ulong ctr_val =3D upper_half ? counter->mhpmcounterh_val : - counter->mhpmcounter_val; + bool rv32 =3D riscv_cpu_mxl(env) =3D=3D MXL_RV32; + int start =3D upper_half ? 32 : 0; + int length =3D rv32 ? 32 : 64; + uint64_t ctr_prev =3D extract64(counter->mhpmcounter_prev, start, leng= th); + uint64_t ctr_val =3D extract64(counter->mhpmcounter_val, start, lengt= h); + + /* Ensure upper_half is only set for XLEN =3D=3D 32 */ + g_assert(rv32 || !upper_half); =20 if (get_field(env->mcountinhibit, BIT(ctr_idx))) { /* @@ -2994,6 +3002,7 @@ static RISCVException write_mcountinhibit(CPURISCVSta= te *env, int csrno, uint32_t present_ctrs =3D cpu->pmu_avail_ctrs | COUNTEREN_CY | COUNTER= EN_IR; target_ulong updated_ctrs =3D (env->mcountinhibit ^ val) & present_ctr= s; uint64_t mhpmctr_val, prev_count, curr_count; + uint64_t ctrh; =20 /* WARL register - disable unavailable counters; TM bit is always 0 */ env->mcountinhibit =3D val & present_ctrs; @@ -3012,17 +3021,13 @@ static RISCVException write_mcountinhibit(CPURISCVS= tate *env, int csrno, counter->mhpmcounter_prev =3D riscv_pmu_ctr_get_fixed_counters_val(env, cidx, false); if (riscv_cpu_mxl(env) =3D=3D MXL_RV32) { - counter->mhpmcounterh_prev =3D - riscv_pmu_ctr_get_fixed_counters_val(env, cidx, true); + ctrh =3D riscv_pmu_ctr_get_fixed_counters_val(env, cidx, t= rue); + counter->mhpmcounter_prev =3D deposit64(counter->mhpmcount= er_prev, + 32, 32, ctrh); } =20 if (cidx > 2) { - mhpmctr_val =3D counter->mhpmcounter_val; - if (riscv_cpu_mxl(env) =3D=3D MXL_RV32) { - mhpmctr_val =3D mhpmctr_val | - ((uint64_t)counter->mhpmcounterh_val << 32); - } - riscv_pmu_setup_timer(env, mhpmctr_val, cidx); + riscv_pmu_setup_timer(env, counter->mhpmcounter_val, cidx); } } else { curr_count =3D riscv_pmu_ctr_get_fixed_counters_val(env, cidx,= false); @@ -3034,18 +3039,11 @@ static RISCVException write_mcountinhibit(CPURISCVS= tate *env, int csrno, riscv_pmu_ctr_get_fixed_counters_val(env, cidx, true); =20 curr_count =3D curr_count | (tmp << 32); - mhpmctr_val =3D mhpmctr_val | - ((uint64_t)counter->mhpmcounterh_val << 32); - prev_count =3D prev_count | - ((uint64_t)counter->mhpmcounterh_prev << 32); } =20 /* Adjust the counter for later reads. */ mhpmctr_val =3D curr_count - prev_count + mhpmctr_val; counter->mhpmcounter_val =3D mhpmctr_val; - if (riscv_cpu_mxl(env) =3D=3D MXL_RV32) { - counter->mhpmcounterh_val =3D mhpmctr_val >> 32; - } } } =20 diff --git a/target/riscv/machine.c b/target/riscv/machine.c index c476bb0089..7b00cb4804 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -338,10 +338,8 @@ static const VMStateDescription vmstate_pmu_ctr_state = =3D { .minimum_version_id =3D 2, .needed =3D pmu_needed, .fields =3D (const VMStateField[]) { - VMSTATE_UINTTL(mhpmcounter_val, PMUCTRState), - VMSTATE_UINTTL(mhpmcounterh_val, PMUCTRState), - VMSTATE_UINTTL(mhpmcounter_prev, PMUCTRState), - VMSTATE_UINTTL(mhpmcounterh_prev, PMUCTRState), + VMSTATE_UINT64(mhpmcounter_val, PMUCTRState), + VMSTATE_UINT64(mhpmcounter_prev, PMUCTRState), VMSTATE_END_OF_LIST() } }; diff --git a/target/riscv/pmu.c b/target/riscv/pmu.c index 273822e921..708f2ec7aa 100644 --- a/target/riscv/pmu.c +++ b/target/riscv/pmu.c @@ -101,82 +101,6 @@ static bool riscv_pmu_counter_enabled(RISCVCPU *cpu, u= int32_t ctr_idx) } } =20 -static int riscv_pmu_incr_ctr_rv32(RISCVCPU *cpu, uint32_t ctr_idx) -{ - CPURISCVState *env =3D &cpu->env; - target_ulong max_val =3D UINT32_MAX; - PMUCTRState *counter =3D &env->pmu_ctrs[ctr_idx]; - bool virt_on =3D env->virt_enabled; - - /* Privilege mode filtering */ - if ((env->priv =3D=3D PRV_M && - (env->mhpmevent_val[ctr_idx] & MHPMEVENT_BIT_MINH)) || - (env->priv =3D=3D PRV_S && virt_on && - (env->mhpmevent_val[ctr_idx] & MHPMEVENT_BIT_VSINH)) || - (env->priv =3D=3D PRV_U && virt_on && - (env->mhpmevent_val[ctr_idx] & MHPMEVENT_BIT_VUINH)) || - (env->priv =3D=3D PRV_S && !virt_on && - (env->mhpmevent_val[ctr_idx] & MHPMEVENT_BIT_SINH)) || - (env->priv =3D=3D PRV_U && !virt_on && - (env->mhpmevent_val[ctr_idx] & MHPMEVENT_BIT_UINH))) { - return 0; - } - - /* Handle the overflow scenario */ - if (counter->mhpmcounter_val =3D=3D max_val) { - if (counter->mhpmcounterh_val =3D=3D max_val) { - counter->mhpmcounter_val =3D 0; - counter->mhpmcounterh_val =3D 0; - /* Generate interrupt only if OF bit is clear */ - if (!(env->mhpmevent_val[ctr_idx] & MHPMEVENT_BIT_OF)) { - env->mhpmevent_val[ctr_idx] |=3D MHPMEVENT_BIT_OF; - riscv_cpu_update_mip(env, MIP_LCOFIP, BOOL_TO_MASK(1)); - } - } else { - counter->mhpmcounterh_val++; - } - } else { - counter->mhpmcounter_val++; - } - - return 0; -} - -static int riscv_pmu_incr_ctr_rv64(RISCVCPU *cpu, uint32_t ctr_idx) -{ - CPURISCVState *env =3D &cpu->env; - PMUCTRState *counter =3D &env->pmu_ctrs[ctr_idx]; - uint64_t max_val =3D UINT64_MAX; - bool virt_on =3D env->virt_enabled; - - /* Privilege mode filtering */ - if ((env->priv =3D=3D PRV_M && - (env->mhpmevent_val[ctr_idx] & MHPMEVENT_BIT_MINH)) || - (env->priv =3D=3D PRV_S && virt_on && - (env->mhpmevent_val[ctr_idx] & MHPMEVENT_BIT_VSINH)) || - (env->priv =3D=3D PRV_U && virt_on && - (env->mhpmevent_val[ctr_idx] & MHPMEVENT_BIT_VUINH)) || - (env->priv =3D=3D PRV_S && !virt_on && - (env->mhpmevent_val[ctr_idx] & MHPMEVENT_BIT_SINH)) || - (env->priv =3D=3D PRV_U && !virt_on && - (env->mhpmevent_val[ctr_idx] & MHPMEVENT_BIT_UINH))) { - return 0; - } - - /* Handle the overflow scenario */ - if (counter->mhpmcounter_val =3D=3D max_val) { - counter->mhpmcounter_val =3D 0; - /* Generate interrupt only if OF bit is clear */ - if (!(env->mhpmevent_val[ctr_idx] & MHPMEVENT_BIT_OF)) { - env->mhpmevent_val[ctr_idx] |=3D MHPMEVENT_BIT_OF; - riscv_cpu_update_mip(env, MIP_LCOFIP, BOOL_TO_MASK(1)); - } - } else { - counter->mhpmcounter_val++; - } - return 0; -} - /* * Information needed to update counters: * new_priv, new_virt: To correctly save starting snapshot for the newly @@ -275,8 +199,10 @@ void riscv_pmu_update_fixed_ctrs(CPURISCVState *env, t= arget_ulong newpriv, int riscv_pmu_incr_ctr(RISCVCPU *cpu, enum riscv_pmu_event_idx event_idx) { uint32_t ctr_idx; - int ret; CPURISCVState *env =3D &cpu->env; + uint64_t max_val =3D UINT64_MAX; + bool virt_on =3D env->virt_enabled; + PMUCTRState *counter; gpointer value; =20 if (!cpu->cfg.pmu_mask) { @@ -293,13 +219,34 @@ int riscv_pmu_incr_ctr(RISCVCPU *cpu, enum riscv_pmu_= event_idx event_idx) return -1; } =20 - if (riscv_cpu_mxl(env) =3D=3D MXL_RV32) { - ret =3D riscv_pmu_incr_ctr_rv32(cpu, ctr_idx); + /* Privilege mode filtering */ + if ((env->priv =3D=3D PRV_M && + (env->mhpmevent_val[ctr_idx] & MHPMEVENT_BIT_MINH)) || + (env->priv =3D=3D PRV_S && virt_on && + (env->mhpmevent_val[ctr_idx] & MHPMEVENT_BIT_VSINH)) || + (env->priv =3D=3D PRV_U && virt_on && + (env->mhpmevent_val[ctr_idx] & MHPMEVENT_BIT_VUINH)) || + (env->priv =3D=3D PRV_S && !virt_on && + (env->mhpmevent_val[ctr_idx] & MHPMEVENT_BIT_SINH)) || + (env->priv =3D=3D PRV_U && !virt_on && + (env->mhpmevent_val[ctr_idx] & MHPMEVENT_BIT_UINH))) { + return 0; + } + + /* Handle the overflow scenario */ + counter =3D &env->pmu_ctrs[ctr_idx]; + if (counter->mhpmcounter_val =3D=3D max_val) { + counter->mhpmcounter_val =3D 0; + /* Generate interrupt only if OF bit is clear */ + if (!(env->mhpmevent_val[ctr_idx] & MHPMEVENT_BIT_OF)) { + env->mhpmevent_val[ctr_idx] |=3D MHPMEVENT_BIT_OF; + riscv_cpu_update_mip(env, MIP_LCOFIP, BOOL_TO_MASK(1)); + } } else { - ret =3D riscv_pmu_incr_ctr_rv64(cpu, ctr_idx); + counter->mhpmcounter_val++; } =20 - return ret; + return 0; } =20 bool riscv_pmu_ctr_monitor_instructions(CPURISCVState *env, @@ -470,8 +417,6 @@ static void pmu_timer_trigger_irq(RISCVCPU *cpu, if (riscv_cpu_mxl(env) =3D=3D MXL_RV32) { riscv_pmu_read_ctr(env, (target_ulong *)&curr_ctrh_val, true, ctr_= idx); curr_ctr_val =3D curr_ctr_val | (curr_ctrh_val << 32); - ctr_val =3D ctr_val | - ((uint64_t)counter->mhpmcounterh_val << 32); } =20 /* --=20 2.51.0 From nobody Sun Sep 28 15:28:22 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1758698453; cv=none; d=zohomail.com; s=zohoarc; b=XDTGf7ZfKMlkgdiFLUyCr2UYC+oqltO17hYD50oM2h3BdnTf45FaXX/zqeAnchia7BlIlAd0S6i76qGKYJBVjBVjMUl3tOay5CbgvrRkcgWot6Ig1/DT1HhmAZ1Kdm/cTgeKaOlqdNKET2X7M3eQEmUFXNsiZVYrxbPNhGeI2Qw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758698453; 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:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=4MiCprU9r/vpqTGEXJAcvIEUzceAukG6LI+srcuMH+0=; b=eepUjAgBrDa1PjU0sRY5qtDeRaHzaScXkT+flAyzP9WYQlXMgO/7+8nXGauId1ScHWDSr1UO6GWcTMWJAyeFrEiGXy6oG0IgCt/+iPveFCJzWQiIdRWbTryg3qImGkTrovW8qA1TSst9wKR/8xVbKTjxbq9kv1BBKiBR576BQ4w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1758698453135149.77039852918824; Wed, 24 Sep 2025 00:20:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1JnA-0005U4-SW; Wed, 24 Sep 2025 03:19:57 -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 1v1Jn7-0005Sl-1o for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:19:54 -0400 Received: from rev.ng ([94.130.142.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v1Jmv-0003PA-LH for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:19:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive:List-Unsubscribe:List-Unsubscribe-Post: List-Help; bh=4MiCprU9r/vpqTGEXJAcvIEUzceAukG6LI+srcuMH+0=; b=upWmIsNwLWktvuB RJBTmbNDv7Iy4ILA55tfcJL+ftxmjxAtUGa9v4WY1yl7tx9g/4bKN0ugWmH6eaRwltcp4bBOOEZjQ T9NAAvD4+3axi4Pbfup9W0JKTvToCb2EVoGLOZqCqfr8x5dOXuyBHttrexxxdJXxLdRhgS24WhwM6 fk=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com Subject: [RFC PATCH 10/34] target/riscv: Fix size of gpr and gprh Date: Wed, 24 Sep 2025 09:21:00 +0200 Message-ID: <20250924072124.6493-11-anjo@rev.ng> In-Reply-To: <20250924072124.6493-1-anjo@rev.ng> References: <20250924072124.6493-1-anjo@rev.ng> 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=94.130.142.21; envelope-from=anjo@rev.ng; helo=rev.ng 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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: , Reply-to: Anton Johansson From: Anton Johansson via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758698454775116600 Content-Type: text/plain; charset="utf-8" gprh is only needed for TARGET_RISCV64 when modeling 128-bit registers, fixing their size to 64 bits makes sense. gpr is also fixed to 64 bits since all direct uses of env->gpr correctly zero extend/truncate to/from target_ulong, meaning !TARGET_RISCV64 will behave as expected. We do however need to be a bit careful when mapping 64-bit fields to 32-bit TCGv globals on big endian hosts. Signed-off-by: Anton Johansson --- target/riscv/cpu.h | 4 ++-- target/riscv/cpu.c | 2 +- target/riscv/machine.c | 4 ++-- target/riscv/translate.c | 17 +++++++++++++++-- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index b0d6e74ea3..2cd69fa150 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -212,8 +212,8 @@ typedef struct PMUFixedCtrState { } PMUFixedCtrState; =20 struct CPUArchState { - target_ulong gpr[32]; - target_ulong gprh[32]; /* 64 top bits of the 128-bit registers */ + uint64_t gpr[32]; + uint64_t gprh[32]; /* 64 top bits of the 128-bit registers */ =20 /* vector coprocessor state. */ uint64_t vreg[32 * RV_VLEN_MAX / 64] QEMU_ALIGNED(16); diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index d055ddf462..3c910e44cd 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -584,7 +584,7 @@ static void riscv_cpu_dump_state(CPUState *cs, FILE *f,= int flags) =20 for (i =3D 0; i < 32; i++) { qemu_fprintf(f, " %-8s " TARGET_FMT_lx, - riscv_int_regnames[i], env->gpr[i]); + riscv_int_regnames[i], (target_ulong) env->gpr[i]); if ((i & 3) =3D=3D 3) { qemu_fprintf(f, "\n"); } diff --git a/target/riscv/machine.c b/target/riscv/machine.c index 7b00cb4804..9a14a805ef 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -180,7 +180,7 @@ static const VMStateDescription vmstate_rv128 =3D { .minimum_version_id =3D 1, .needed =3D rv128_needed, .fields =3D (const VMStateField[]) { - VMSTATE_UINTTL_ARRAY(env.gprh, RISCVCPU, 32), + VMSTATE_UINT64_ARRAY(env.gprh, RISCVCPU, 32), VMSTATE_UINT64(env.mscratchh, RISCVCPU), VMSTATE_UINT64(env.sscratchh, RISCVCPU), VMSTATE_END_OF_LIST() @@ -404,7 +404,7 @@ const VMStateDescription vmstate_riscv_cpu =3D { .minimum_version_id =3D 10, .post_load =3D riscv_cpu_post_load, .fields =3D (const VMStateField[]) { - VMSTATE_UINTTL_ARRAY(env.gpr, RISCVCPU, 32), + VMSTATE_UINT64_ARRAY(env.gpr, RISCVCPU, 32), VMSTATE_UINT64_ARRAY(env.fpr, RISCVCPU, 32), VMSTATE_UINT8_ARRAY(env.miprio, RISCVCPU, 64), VMSTATE_UINT8_ARRAY(env.siprio, RISCVCPU, 64), diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 9ddef2d6e2..2f8c7a6465 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -26,6 +26,7 @@ #include "exec/translator.h" #include "exec/translation-block.h" #include "exec/log.h" +#include "exec/tswap.h" #include "semihosting/semihost.h" =20 #include "internals.h" @@ -1427,12 +1428,24 @@ void riscv_translate_init(void) */ cpu_gpr[0] =3D NULL; cpu_gprh[0] =3D NULL; + /* + * Be careful with big endian hosts when mapping 64-bit CPUArchState f= ields + * to 32-bit TCGv globals. An offset of 4 bytes is applied so the lea= st + * significant bytes are correctly written to. + */ +#if HOST_BIG_ENDIAN && !defined(TARGET_RISCV64) + size_t field_offset =3D 4; +#else + size_t field_offset =3D 0; +#endif =20 for (i =3D 1; i < 32; i++) { cpu_gpr[i] =3D tcg_global_mem_new(tcg_env, - offsetof(CPURISCVState, gpr[i]), riscv_int_regnames[i]); + offsetof(CPURISCVState, gpr[i]) + field_offset, + riscv_int_regnames[i]); cpu_gprh[i] =3D tcg_global_mem_new(tcg_env, - offsetof(CPURISCVState, gprh[i]), riscv_int_regnamesh[i]); + offsetof(CPURISCVState, gprh[i]) + field_offset, + riscv_int_regnamesh[i]); } =20 for (i =3D 0; i < 32; i++) { --=20 2.51.0 From nobody Sun Sep 28 15:28:22 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1758698447; cv=none; d=zohomail.com; s=zohoarc; b=IxdWPh0MbX6andVUlpH7P6WuZRdf9ppEBENR4d8uZMvX+29URnBuT9CnNwDRMkBT/HyRDDGjlabgy/6jMdBdhFP77gvtjaeQYSL0HOIt2fQm7O6DM0yPRnnHzwkQhb35RKNLZdS7o2qwHuFxczvTcYB2Uk3iAgJIM+rvolrkRgA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758698447; 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:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=2f/lUpVBkdTZv4p6T5HNNfSKogg0M/xXuw7EwsQX/C8=; b=edvwMcWsUrg54ZnjRvygETvH3DIijj6LqHOqYN5Ahg7DuRmPMad8T7fcrkQvLaRbUBh12CmakoOjo9fuPwhg1LVm2KlOQvasYUfsK8x+ydhsjGsQdRVP+nmFAhbqqGIGYg+3k3qVn5Ma3VnMN/FsxbhOOphQORI6fhNj5h75cPU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1758698446973670.409187128985; Wed, 24 Sep 2025 00:20:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1JnF-0005WZ-OP; Wed, 24 Sep 2025 03:20:01 -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 1v1JnE-0005Vi-0m for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:00 -0400 Received: from rev.ng ([94.130.142.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v1Jn8-0003PT-9L for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:19:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive:List-Unsubscribe:List-Unsubscribe-Post: List-Help; bh=2f/lUpVBkdTZv4p6T5HNNfSKogg0M/xXuw7EwsQX/C8=; b=fcSSra2me5NCHi+ 1r8uT5kqx2LQg4iVokwqPeHnT9XBZzj/N4lXR2WZ/a4Y4BEaHayL7Y+8v0dH1OQ3ZkNARs/NZkSYs 1YJY+HwHWimSXLv8gCmpA8RHD8btWKlwClGhj3uQ6BVjDweMkjl1xpqq/OOECsVIJO5ORf4UTB+6v +c=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com Subject: [RFC PATCH 11/34] target/riscv: Fix size of vector CSRs Date: Wed, 24 Sep 2025 09:21:01 +0200 Message-ID: <20250924072124.6493-12-anjo@rev.ng> In-Reply-To: <20250924072124.6493-1-anjo@rev.ng> References: <20250924072124.6493-1-anjo@rev.ng> 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=94.130.142.21; envelope-from=anjo@rev.ng; helo=rev.ng 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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: , Reply-to: Anton Johansson From: Anton Johansson via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758698448904116600 Content-Type: text/plain; charset="utf-8" According to version 20250508 of the unprivileged specification: - vtype: bits 0..7 used, bit XLEN-1 illegal, rest reserved =3D> fix to 64-bits. - vxsat: bit 0 used, vxrm which would occupy bits 1..2 is stored separately, and bits 3..31 are set to 0 =3D> fix to 8-bits. - vxrm: 2 lowest bits are used for rounding mode, rest set to 0 =3D> fix to 8-bits. - vstart: maximum value of VLMAX-1, where VLMAX is at most 2^16 =3D> fix to 32-bits as vstart is mapped to a TCG global. - vl: maximum value of VLEN which is at most 2^16 =3D> fix to 32-bits as vl is mapped to a TCG global. Fields are shuffled for reduced padding. Signed-off-by: Anton Johansson --- target/riscv/cpu.h | 12 ++++++------ target/riscv/machine.c | 10 +++++----- target/riscv/translate.c | 12 ++++++++---- target/riscv/vector_helper.c | 22 ++++++++++++++++++---- target/riscv/insn_trans/trans_rvv.c.inc | 22 +++++++++++----------- 5 files changed, 48 insertions(+), 30 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 2cd69fa150..8f844405bd 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -191,7 +191,7 @@ FIELD(VTYPE, VSEW, 3, 3) FIELD(VTYPE, VTA, 6, 1) FIELD(VTYPE, VMA, 7, 1) FIELD(VTYPE, VEDIV, 8, 2) -FIELD(VTYPE, RESERVED, 10, sizeof(target_ulong) * 8 - 11) +FIELD(VTYPE, RESERVED, 10, sizeof(uint64_t) * 8 - 11) =20 typedef struct PMUCTRState { /* Current value of a counter */ @@ -217,11 +217,11 @@ struct CPUArchState { =20 /* vector coprocessor state. */ uint64_t vreg[32 * RV_VLEN_MAX / 64] QEMU_ALIGNED(16); - target_ulong vxrm; - target_ulong vxsat; - target_ulong vl; - target_ulong vstart; - target_ulong vtype; + uint64_t vtype; + uint32_t vl; + uint32_t vstart; + uint8_t vxrm; + uint8_t vxsat; bool vill; =20 target_ulong pc; diff --git a/target/riscv/machine.c b/target/riscv/machine.c index 9a14a805ef..8e3062aabb 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -141,11 +141,11 @@ static const VMStateDescription vmstate_vector =3D { .needed =3D vector_needed, .fields =3D (const VMStateField[]) { VMSTATE_UINT64_ARRAY(env.vreg, RISCVCPU, 32 * RV_VLEN_MAX / 64), - VMSTATE_UINTTL(env.vxrm, RISCVCPU), - VMSTATE_UINTTL(env.vxsat, RISCVCPU), - VMSTATE_UINTTL(env.vl, RISCVCPU), - VMSTATE_UINTTL(env.vstart, RISCVCPU), - VMSTATE_UINTTL(env.vtype, RISCVCPU), + VMSTATE_UINT8(env.vxrm, RISCVCPU), + VMSTATE_UINT8(env.vxsat, RISCVCPU), + VMSTATE_UINT32(env.vl, RISCVCPU), + VMSTATE_UINT32(env.vstart, RISCVCPU), + VMSTATE_UINT64(env.vtype, RISCVCPU), VMSTATE_BOOL(env.vill, RISCVCPU), VMSTATE_END_OF_LIST() } diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 2f8c7a6465..5e8fc3e543 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -38,8 +38,9 @@ #include "tcg/tcg-cpu.h" =20 /* global register indices */ -static TCGv cpu_gpr[32], cpu_gprh[32], cpu_pc, cpu_vl, cpu_vstart; +static TCGv cpu_gpr[32], cpu_gprh[32], cpu_pc; static TCGv_i64 cpu_fpr[32]; /* assume F and D extensions */ +static TCGv_i32 cpu_vl, cpu_vstart; static TCGv load_res; static TCGv load_val; =20 @@ -1439,6 +1440,10 @@ void riscv_translate_init(void) size_t field_offset =3D 0; #endif =20 + /* 32 bits in size, no offset needed */ + size_t vl_offset =3D offsetof(CPURISCVState, vl); + size_t vstart_offset =3D offsetof(CPURISCVState, vstart); + for (i =3D 1; i < 32; i++) { cpu_gpr[i] =3D tcg_global_mem_new(tcg_env, offsetof(CPURISCVState, gpr[i]) + field_offset, @@ -1454,9 +1459,8 @@ void riscv_translate_init(void) } =20 cpu_pc =3D tcg_global_mem_new(tcg_env, offsetof(CPURISCVState, pc), "p= c"); - cpu_vl =3D tcg_global_mem_new(tcg_env, offsetof(CPURISCVState, vl), "v= l"); - cpu_vstart =3D tcg_global_mem_new(tcg_env, offsetof(CPURISCVState, vst= art), - "vstart"); + cpu_vl =3D tcg_global_mem_new_i32(tcg_env, vl_offset, "vl"); + cpu_vstart =3D tcg_global_mem_new_i32(tcg_env, vstart_offset, "vstart"= ); load_res =3D tcg_global_mem_new(tcg_env, offsetof(CPURISCVState, load_= res), "load_res"); load_val =3D tcg_global_mem_new(tcg_env, offsetof(CPURISCVState, load_= val), diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c index 7c67d67a13..2fc5348044 100644 --- a/target/riscv/vector_helper.c +++ b/target/riscv/vector_helper.c @@ -360,6 +360,12 @@ vext_page_ldst_us(CPURISCVState *env, void *vd, target= _ulong addr, uint32_t evl =3D env->vstart + elems; MMUAccessType access_type =3D is_load ? MMU_DATA_LOAD : MMU_DATA_STORE; =20 + /* + * Maximum vector length is VLMAX =3D=3D 2^16 =3D=3D LMUL * VL / SEW, = and + * occurs for LMUL =3D=3D 8, SEW =3D=3D 8, VL =3D=3D 2^16. + */ + g_assert(env->vstart < UINT16_MAX && UINT16_MAX - env->vstart >=3D ele= ms); + /* Check page permission/pmp/watchpoint/etc. */ probe_pages(env, addr, size, ra, access_type, mmu_index, &host, &flags, true); @@ -2594,19 +2600,27 @@ static inline uint8_t get_round(int vxrm, uint64_t = v, uint8_t shift) =20 d1 =3D extract64(v, shift - 1, 1); D1 =3D extract64(v, 0, shift); - if (vxrm =3D=3D 0) { /* round-to-nearest-up (add +0.5 LSB) */ + switch (vxrm) { + case 0: + /* round-to-nearest-up (add +0.5 LSB) */ return d1; - } else if (vxrm =3D=3D 1) { /* round-to-nearest-even */ + case 1: + /* round-to-nearest-even */ if (shift > 1) { D2 =3D extract64(v, 0, shift - 1); return d1 & ((D2 !=3D 0) | d); } else { return d1 & d; } - } else if (vxrm =3D=3D 3) { /* round-to-odd (OR bits into LSB, aka "ja= m") */ + case 2: + /* round-down (truncate) */ + return 0; + case 3: + /* round-to-odd (OR bits into LSB, aka "jam") */ return !d & (D1 !=3D 0); + default: + g_assert_not_reached(); } - return 0; /* round-down (truncate) */ } =20 static inline int32_t aadd32(CPURISCVState *env, int vxrm, int32_t a, diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_tr= ans/trans_rvv.c.inc index 71f98fb350..f1b624922a 100644 --- a/target/riscv/insn_trans/trans_rvv.c.inc +++ b/target/riscv/insn_trans/trans_rvv.c.inc @@ -194,7 +194,7 @@ static bool do_vsetvl(DisasContext *s, int rd, int rs1,= TCGv s2) =20 if (rd =3D=3D 0 && rs1 =3D=3D 0) { s1 =3D tcg_temp_new(); - tcg_gen_mov_tl(s1, cpu_vl); + tcg_gen_ext_i32_tl(s1, cpu_vl); } else if (rs1 =3D=3D 0) { /* As the mask is at least one bit, RV_VLEN_MAX is >=3D VLMAX */ s1 =3D tcg_constant_tl(RV_VLEN_MAX); @@ -1213,9 +1213,9 @@ static bool ldst_whole_trans(uint32_t vd, uint32_t rs= 1, uint32_t nf, MO_LE | MO_64 | atomicity); } if (i =3D=3D size - 8) { - tcg_gen_movi_tl(cpu_vstart, 0); + tcg_gen_movi_i32(cpu_vstart, 0); } else { - tcg_gen_addi_tl(cpu_vstart, cpu_vstart, 8 >> log2_esz); + tcg_gen_addi_i32(cpu_vstart, cpu_vstart, 8 >> log2_esz= ); } } } else { @@ -1231,9 +1231,9 @@ static bool ldst_whole_trans(uint32_t vd, uint32_t rs= 1, uint32_t nf, MO_LE | MO_32 | atomicity); } if (i =3D=3D size - 4) { - tcg_gen_movi_tl(cpu_vstart, 0); + tcg_gen_movi_i32(cpu_vstart, 0); } else { - tcg_gen_addi_tl(cpu_vstart, cpu_vstart, 4 >> log2_esz); + tcg_gen_addi_i32(cpu_vstart, cpu_vstart, 4 >> log2_esz= ); } } } @@ -3459,7 +3459,7 @@ static bool trans_vmv_x_s(DisasContext *s, arg_vmv_x_= s *a) vec_element_loadi(s, t1, a->rs2, 0, true); tcg_gen_trunc_i64_tl(dest, t1); gen_set_gpr(s, a->rd, dest); - tcg_gen_movi_tl(cpu_vstart, 0); + tcg_gen_movi_i32(cpu_vstart, 0); finalize_rvv_inst(s); return true; } @@ -3476,7 +3476,7 @@ static bool trans_vmv_s_x(DisasContext *s, arg_vmv_s_= x *a) TCGv s1; TCGLabel *over =3D gen_new_label(); =20 - tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); + tcg_gen_brcond_i32(TCG_COND_GEU, cpu_vstart, cpu_vl, over); =20 t1 =3D tcg_temp_new_i64(); =20 @@ -3488,7 +3488,7 @@ static bool trans_vmv_s_x(DisasContext *s, arg_vmv_s_= x *a) tcg_gen_ext_tl_i64(t1, s1); vec_element_storei(s, a->rd, 0, t1); gen_set_label(over); - tcg_gen_movi_tl(cpu_vstart, 0); + tcg_gen_movi_i32(cpu_vstart, 0); finalize_rvv_inst(s); return true; } @@ -3516,7 +3516,7 @@ static bool trans_vfmv_f_s(DisasContext *s, arg_vfmv_= f_s *a) } =20 mark_fs_dirty(s); - tcg_gen_movi_tl(cpu_vstart, 0); + tcg_gen_movi_i32(cpu_vstart, 0); finalize_rvv_inst(s); return true; } @@ -3536,7 +3536,7 @@ static bool trans_vfmv_s_f(DisasContext *s, arg_vfmv_= s_f *a) TCGLabel *over =3D gen_new_label(); =20 /* if vstart >=3D vl, skip vector register write back */ - tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); + tcg_gen_brcond_i32(TCG_COND_GEU, cpu_vstart, cpu_vl, over); =20 /* NaN-box f[rs1] */ t1 =3D tcg_temp_new_i64(); @@ -3545,7 +3545,7 @@ static bool trans_vfmv_s_f(DisasContext *s, arg_vfmv_= s_f *a) vec_element_storei(s, a->rd, 0, t1); =20 gen_set_label(over); - tcg_gen_movi_tl(cpu_vstart, 0); + tcg_gen_movi_i32(cpu_vstart, 0); finalize_rvv_inst(s); return true; } --=20 2.51.0 From nobody Sun Sep 28 15:28:22 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1758698542; cv=none; d=zohomail.com; s=zohoarc; b=XdxwdKzlwiSp67ShF5ZR9TgDQ7/KFXrP8WOQWgJ1ZuaUIcRULWgTdUUpfkSTNRDOf5TWZDNd+01xoX9QRlyqRrvJsQbUoD5TXMpIPUI3deyoiWtXuoqsaTkyASq3M26q1//O93APXWLQ4UIpHYSpYZNeMFfByJ/2+pNYZbHau/4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758698542; 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:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=ycyEoROx2E49zSCIHC7WTPzNPFsO/B3ccL1g0S1JAp4=; b=M2w6hoUrqVVCUqfbWYWaVj5sHx/SuZUesOn8tOrX5nweCkN+OnUNKCqBynM1+YWarg8Yo5oSWHc9JY9HhDUSWILyorQKsW+smWy3LpBhm9Tb43xJ9ZHjiPi7LZo/1cGQVtoMjbTgWfvMCTYqWA9bQj3xEQkPFYqcfiSb9Jkt0HM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 175869854257037.44383865867485; Wed, 24 Sep 2025 00:22:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1JnQ-0005dz-FA; Wed, 24 Sep 2025 03:20:12 -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 1v1JnN-0005bQ-Nm for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:09 -0400 Received: from rev.ng ([94.130.142.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v1JnB-0003Pi-4R for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive:List-Unsubscribe:List-Unsubscribe-Post: List-Help; bh=ycyEoROx2E49zSCIHC7WTPzNPFsO/B3ccL1g0S1JAp4=; b=XgnE8bLptBR9Wcb Sw/YfSXSowfaMrtulREa/hiujrBT/HzY0RfCMxgS72pR9FRyTlCTjs8mFverhVQGHALAXrbM1rz+T a7NLapCMOCThwYFe/olGF0IwKwsr+eAoGXr0079iGLPm1BZ6y9icIQZOsZtewopdo0WTUgh5juAEh uY=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com Subject: [RFC PATCH 12/34] target/riscv: Fix size of pc, load_[val|res] Date: Wed, 24 Sep 2025 09:21:02 +0200 Message-ID: <20250924072124.6493-13-anjo@rev.ng> In-Reply-To: <20250924072124.6493-1-anjo@rev.ng> References: <20250924072124.6493-1-anjo@rev.ng> 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=94.130.142.21; envelope-from=anjo@rev.ng; helo=rev.ng 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, SPF_HELO_PASS=-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: , Reply-to: Anton Johansson From: Anton Johansson via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758698543970116600 Content-Type: text/plain; charset="utf-8" Fix to 64 bits in size and as these are mapped to TCG globals, be careful with host endianness when allocating globals. Casts are added to logging expressions to retain the correct size for TARGET_RISCV32. Signed-off-by: Anton Johansson --- target/riscv/cpu.h | 6 +++--- target/riscv/cpu.c | 3 ++- target/riscv/cpu_helper.c | 4 ++-- target/riscv/machine.c | 6 +++--- target/riscv/translate.c | 12 +++++++----- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 8f844405bd..01ca3e781d 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -224,9 +224,9 @@ struct CPUArchState { uint8_t vxsat; bool vill; =20 - target_ulong pc; - target_ulong load_res; - target_ulong load_val; + uint64_t pc; + uint64_t load_res; + uint64_t load_val; =20 /* Floating-Point state */ uint64_t fpr[32]; /* assume both F and D extensions */ diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 3c910e44cd..4e38487dca 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -528,7 +528,8 @@ static void riscv_cpu_dump_state(CPUState *cs, FILE *f,= int flags) qemu_fprintf(f, " %s %d\n", "V =3D ", env->virt_enabled); } #endif - qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "pc ", env->pc); + qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "pc ", + (target_ulong) env->pc); #ifndef CONFIG_USER_ONLY { static const int dump_csrs[] =3D { diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 9d0683f200..36f7baf690 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -2280,8 +2280,8 @@ void riscv_cpu_do_interrupt(CPUState *cs) qemu_log_mask(CPU_LOG_INT, "%s: hart:%"PRIu64", async:%d, cause:"TARGET_FMT_lx", " "epc:0x"TARGET_FMT_lx", tval:0x"TARGET_FMT_lx", desc=3D%= s\n", - __func__, env->mhartid, async, cause, env->pc, tval, - riscv_cpu_get_trap_name(cause, async)); + __func__, env->mhartid, async, cause, (target_ulong) env= ->pc, + tval, riscv_cpu_get_trap_name(cause, async)); =20 mode =3D env->priv <=3D PRV_S && cause < 64 && (((deleg >> cause) & 1) || s_injected || vs_injected) ? PRV_S : PR= V_M; diff --git a/target/riscv/machine.c b/target/riscv/machine.c index 8e3062aabb..405a960f28 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -408,9 +408,9 @@ const VMStateDescription vmstate_riscv_cpu =3D { VMSTATE_UINT64_ARRAY(env.fpr, RISCVCPU, 32), VMSTATE_UINT8_ARRAY(env.miprio, RISCVCPU, 64), VMSTATE_UINT8_ARRAY(env.siprio, RISCVCPU, 64), - VMSTATE_UINTTL(env.pc, RISCVCPU), - VMSTATE_UINTTL(env.load_res, RISCVCPU), - VMSTATE_UINTTL(env.load_val, RISCVCPU), + VMSTATE_UINT64(env.pc, RISCVCPU), + VMSTATE_UINT64(env.load_res, RISCVCPU), + VMSTATE_UINT64(env.load_val, RISCVCPU), VMSTATE_UINTTL(env.frm, RISCVCPU), VMSTATE_UINTTL(env.badaddr, RISCVCPU), VMSTATE_UINTTL(env.guest_phys_fault_addr, RISCVCPU), diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 5e8fc3e543..b856792d3b 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -1443,6 +1443,10 @@ void riscv_translate_init(void) /* 32 bits in size, no offset needed */ size_t vl_offset =3D offsetof(CPURISCVState, vl); size_t vstart_offset =3D offsetof(CPURISCVState, vstart); + /* 64 bits in size mapped to TCGv, needs offset */ + size_t pc_offset =3D offsetof(CPURISCVState, pc) + field_offset; + size_t res_offset =3D offsetof(CPURISCVState, load_res) + field_off= set; + size_t val_offset =3D offsetof(CPURISCVState, load_val) + field_off= set; =20 for (i =3D 1; i < 32; i++) { cpu_gpr[i] =3D tcg_global_mem_new(tcg_env, @@ -1458,11 +1462,9 @@ void riscv_translate_init(void) offsetof(CPURISCVState, fpr[i]), riscv_fpr_regnames[i]); } =20 - cpu_pc =3D tcg_global_mem_new(tcg_env, offsetof(CPURISCVState, pc), "p= c"); + cpu_pc =3D tcg_global_mem_new(tcg_env, pc_offset, "pc"); cpu_vl =3D tcg_global_mem_new_i32(tcg_env, vl_offset, "vl"); cpu_vstart =3D tcg_global_mem_new_i32(tcg_env, vstart_offset, "vstart"= ); - load_res =3D tcg_global_mem_new(tcg_env, offsetof(CPURISCVState, load_= res), - "load_res"); - load_val =3D tcg_global_mem_new(tcg_env, offsetof(CPURISCVState, load_= val), - "load_val"); + load_res =3D tcg_global_mem_new(tcg_env, res_offset, "load_res"); + load_val =3D tcg_global_mem_new(tcg_env, val_offset, "load_val"); } --=20 2.51.0 From nobody Sun Sep 28 15:28:22 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1758698521; cv=none; d=zohomail.com; s=zohoarc; b=eiiGl2ZXLaJaSTPbhvPfE8GAz4ZMVZE2Vx6VHreSgEOEQDUL1eeUmjsfZQ+mxFY8O25XhN2+7hchMlt8R8a88natt/TjxVEUNc2Bzy1s8gfMa9vbrW5rbITDmr5ZVS5mwBoFDFflyft/F/g5kwX7vseSHCp+yz6YUMKI9ZBNnxY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758698521; 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:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=jS+5jUWqLf8DzdZREyGhxtYoH1mze7wS+V8aFfit5jY=; b=SLNkQXwoVM5GX7VkrRAzQ/1m8YmQNSiWxEF4UNpye2OO8r0XVHiPfTdJBScFgFHzyHf/he7/Om8oOyTuunjaU2YrDYrm4aRcZgahgWGPPz6bucRMVEY2sZH9rrDh0BioFCFa8YetGxEBuTzV7UoX0djSxDV04GGjJqEoduXmGbU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1758698521557534.1601342714647; Wed, 24 Sep 2025 00:22:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1JnN-0005b2-1v; Wed, 24 Sep 2025 03:20:09 -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 1v1JnK-0005Zo-A2 for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:06 -0400 Received: from rev.ng ([94.130.142.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v1JnB-0003Q5-Aw for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive:List-Unsubscribe:List-Unsubscribe-Post: List-Help; bh=jS+5jUWqLf8DzdZREyGhxtYoH1mze7wS+V8aFfit5jY=; b=nYiH3bSWuOzhYQs a/p0bGupwL6BxQAOZyQCJEhxWp8nkMHQ/H7qZJswOjcTE7DZ9Oj6P45gR2ZXqdWrgVBj9hJyanY/Q bglAMc0mD72PqWgk1wxrbEMiaY5SrOCrWWtgXSeapwtJCq7DNtHLUeEM1HRvyu8M1rXDNUkxvV6ZE 3E=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com Subject: [RFC PATCH 13/34] target/riscv: Fix size of frm and fflags Date: Wed, 24 Sep 2025 09:21:03 +0200 Message-ID: <20250924072124.6493-14-anjo@rev.ng> In-Reply-To: <20250924072124.6493-1-anjo@rev.ng> References: <20250924072124.6493-1-anjo@rev.ng> 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=94.130.142.21; envelope-from=anjo@rev.ng; helo=rev.ng 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_VALIDITY_SAFE_BLOCKED=0.001, SPF_PASS=-0.001, T_SPF_HELO_TEMPERROR=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: , Reply-to: Anton Johansson From: Anton Johansson via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758698523698116600 Content-Type: text/plain; charset="utf-8" According to version 20250508 of the unprivileged specification the frm field of fcsr is 3-bits in size, fix it to 8-bits. Similarly fflags is 5 bits, fix to 8. Signed-off-by: Anton Johansson --- target/riscv/cpu.h | 6 +++--- target/riscv/csr.c | 4 ++++ target/riscv/fpu_helper.c | 6 +++--- target/riscv/machine.c | 2 +- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 01ca3e781d..cf10662b3a 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -230,7 +230,7 @@ struct CPUArchState { =20 /* Floating-Point state */ uint64_t fpr[32]; /* assume both F and D extensions */ - target_ulong frm; + uint8_t frm; float_status fp_status; =20 target_ulong badaddr; @@ -663,8 +663,8 @@ G_NORETURN void riscv_raise_exception(CPURISCVState *en= v, RISCVException exception, uintptr_t pc); =20 -target_ulong riscv_cpu_get_fflags(CPURISCVState *env); -void riscv_cpu_set_fflags(CPURISCVState *env, target_ulong); +uint8_t riscv_cpu_get_fflags(CPURISCVState *env); +void riscv_cpu_set_fflags(CPURISCVState *env, uint8_t); =20 FIELD(TB_FLAGS, MEM_IDX, 0, 3) FIELD(TB_FLAGS, FS, 3, 2) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index f29a3c9991..a471e59f2d 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -895,6 +895,10 @@ static RISCVException write_frm(CPURISCVState *env, in= t csrno, static RISCVException read_fcsr(CPURISCVState *env, int csrno, target_ulong *val) { + /* + * This is an 8-bit operation, fflags make up the lower 5 bits and + * frm the upper 3 bits of fcsr. + */ *val =3D (riscv_cpu_get_fflags(env) << FSR_AEXC_SHIFT) | (env->frm << FSR_RD_SHIFT); return RISCV_EXCP_NONE; diff --git a/target/riscv/fpu_helper.c b/target/riscv/fpu_helper.c index af40561b31..db64fca622 100644 --- a/target/riscv/fpu_helper.c +++ b/target/riscv/fpu_helper.c @@ -23,10 +23,10 @@ #include "fpu/softfloat.h" #include "internals.h" =20 -target_ulong riscv_cpu_get_fflags(CPURISCVState *env) +uint8_t riscv_cpu_get_fflags(CPURISCVState *env) { int soft =3D get_float_exception_flags(&env->fp_status); - target_ulong hard =3D 0; + uint8_t hard =3D 0; =20 hard |=3D (soft & float_flag_inexact) ? FPEXC_NX : 0; hard |=3D (soft & float_flag_underflow) ? FPEXC_UF : 0; @@ -37,7 +37,7 @@ target_ulong riscv_cpu_get_fflags(CPURISCVState *env) return hard; } =20 -void riscv_cpu_set_fflags(CPURISCVState *env, target_ulong hard) +void riscv_cpu_set_fflags(CPURISCVState *env, uint8_t hard) { int soft =3D 0; =20 diff --git a/target/riscv/machine.c b/target/riscv/machine.c index 405a960f28..d38243b278 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -411,7 +411,7 @@ const VMStateDescription vmstate_riscv_cpu =3D { VMSTATE_UINT64(env.pc, RISCVCPU), VMSTATE_UINT64(env.load_res, RISCVCPU), VMSTATE_UINT64(env.load_val, RISCVCPU), - VMSTATE_UINTTL(env.frm, RISCVCPU), + VMSTATE_UINT8(env.frm, RISCVCPU), VMSTATE_UINTTL(env.badaddr, RISCVCPU), VMSTATE_UINTTL(env.guest_phys_fault_addr, RISCVCPU), VMSTATE_UINTTL(env.priv_ver, RISCVCPU), --=20 2.51.0 From nobody Sun Sep 28 15:28:22 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1758698635; cv=none; d=zohomail.com; s=zohoarc; b=RRxQ1A4tIJ9DrPX+KtdBGkDngyuvW6V867f73uV65hEtTaCxGmRWXyWsZcQljCrAVlC/zDi6pJs+5hMmapHSqOTDI6XZCS6KGRLPgHdrKen3RcPiJ8JPF5cRlYPl/TQmnjYXUVfJpFakT6NCKcY9w2u7RGhwuao6PAeRf7t6y4I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758698635; 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:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=xnZkf8T3aYXEsrxPDI2eMRXW35Q/mALOg3UnwThFjFw=; b=CneRgwnUCmTFWTbg/8MQYyssb6cvkVjECXIanUvNKk9dAfeN/lwtNQSN71BhgfVZppf/WPEFsQJ2p3bVbScwrI+ZHB3EPvTvAm/P5A+J0SNniRQaRDQZAfgcxT5lKr0paZkrhdWLq4loUTqDNvn2NgWdJVxn1S5b9Olq40hfqFA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1758698635384834.9963825087844; Wed, 24 Sep 2025 00:23:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1JnO-0005be-1g; Wed, 24 Sep 2025 03:20:10 -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 1v1JnL-0005a3-EV for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:07 -0400 Received: from rev.ng ([94.130.142.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v1JnB-0003QK-At for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive:List-Unsubscribe:List-Unsubscribe-Post: List-Help; bh=xnZkf8T3aYXEsrxPDI2eMRXW35Q/mALOg3UnwThFjFw=; b=ZIZTFiOGAcDG3+n Owd3aOU8x6gqj/zmefIz8lTmOFZU8VmNT/DU1a+Uh3H5Ywc3YrFoTnePEueLSK/xWE/6rc8WPTkmX O3wtZUm8ZL8nd76SCbhs7+yWJpPQ3qyPIejKthuNUL1qddg0nCxWtA9vP4g/nSUx+Nv9hu2+qHsPJ B8=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com Subject: [RFC PATCH 14/34] target/riscv: Fix size of badaddr and bins Date: Wed, 24 Sep 2025 09:21:04 +0200 Message-ID: <20250924072124.6493-15-anjo@rev.ng> In-Reply-To: <20250924072124.6493-1-anjo@rev.ng> References: <20250924072124.6493-1-anjo@rev.ng> 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=94.130.142.21; envelope-from=anjo@rev.ng; helo=rev.ng 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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: , Reply-to: Anton Johansson From: Anton Johansson via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758698636600116600 Content-Type: text/plain; charset="utf-8" Fix these fields to 64 bits as they cannot be made smaller. Also make sure stores to these fields from TCG are 64 bits in size to avoid incorrect values on big endian hosts. Signed-off-by: Anton Johansson --- target/riscv/cpu.h | 4 ++-- target/riscv/machine.c | 2 +- target/riscv/translate.c | 6 ++++-- target/riscv/insn_trans/trans_privileged.c.inc | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index cf10662b3a..343cc6bab7 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -233,8 +233,8 @@ struct CPUArchState { uint8_t frm; float_status fp_status; =20 - target_ulong badaddr; - target_ulong bins; + uint64_t badaddr; + uint64_t bins; =20 target_ulong guest_phys_fault_addr; =20 diff --git a/target/riscv/machine.c b/target/riscv/machine.c index d38243b278..a1cd67de99 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -412,7 +412,7 @@ const VMStateDescription vmstate_riscv_cpu =3D { VMSTATE_UINT64(env.load_res, RISCVCPU), VMSTATE_UINT64(env.load_val, RISCVCPU), VMSTATE_UINT8(env.frm, RISCVCPU), - VMSTATE_UINTTL(env.badaddr, RISCVCPU), + VMSTATE_UINT64(env.badaddr, RISCVCPU), VMSTATE_UINTTL(env.guest_phys_fault_addr, RISCVCPU), VMSTATE_UINTTL(env.priv_ver, RISCVCPU), VMSTATE_UINTTL(env.vext_ver, RISCVCPU), diff --git a/target/riscv/translate.c b/target/riscv/translate.c index b856792d3b..339ef91f6b 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -252,7 +252,7 @@ static void generate_exception(DisasContext *ctx, RISCV= Exception excp) =20 static void gen_exception_illegal(DisasContext *ctx) { - tcg_gen_st_i32(tcg_constant_i32(ctx->opcode), tcg_env, + tcg_gen_st_i64(tcg_constant_i64(ctx->opcode), tcg_env, offsetof(CPURISCVState, bins)); if (ctx->virt_inst_excp) { generate_exception(ctx, RISCV_EXCP_VIRT_INSTRUCTION_FAULT); @@ -263,7 +263,9 @@ static void gen_exception_illegal(DisasContext *ctx) =20 static void gen_exception_inst_addr_mis(DisasContext *ctx, TCGv target) { - tcg_gen_st_tl(target, tcg_env, offsetof(CPURISCVState, badaddr)); + TCGv_i64 ext =3D tcg_temp_new_i64(); + tcg_gen_extu_tl_i64(ext, target); + tcg_gen_st_i64(ext, tcg_env, offsetof(CPURISCVState, badaddr)); generate_exception(ctx, RISCV_EXCP_INST_ADDR_MIS); } =20 diff --git a/target/riscv/insn_trans/trans_privileged.c.inc b/target/riscv/= insn_trans/trans_privileged.c.inc index 8a62b4cfcd..a8eaccef67 100644 --- a/target/riscv/insn_trans/trans_privileged.c.inc +++ b/target/riscv/insn_trans/trans_privileged.c.inc @@ -68,7 +68,7 @@ static bool trans_ebreak(DisasContext *ctx, arg_ebreak *a) if (pre =3D=3D 0x01f01013 && ebreak =3D=3D 0x00100073 && post =3D=3D 0= x40705013) { generate_exception(ctx, RISCV_EXCP_SEMIHOST); } else { - tcg_gen_st_tl(tcg_constant_tl(ebreak_addr), tcg_env, + tcg_gen_st_i64(tcg_constant_i64(ebreak_addr), tcg_env, offsetof(CPURISCVState, badaddr)); generate_exception(ctx, RISCV_EXCP_BREAKPOINT); } --=20 2.51.0 From nobody Sun Sep 28 15:28:22 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1758698485; cv=none; d=zohomail.com; s=zohoarc; b=SynPq9CsC6PnzsBx9tZVx23TMb1xOlAo9Qx5HxCO1UV9EatB3G7eVE/vDD2GSwDRzRKN9Nz/D0xGPGVsRSo3Iwl1aGuCzprB1AmZ2HVL7t/W9ub4xwX8dOUlaYp/TqobBYBRE8Czqix4YnQTPN4H6foLec3n9yby/+12/VwEe5g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758698485; 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:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=TfzxWl+or/W5/6gQ6p08jZFPuH70Q3mNAcKQk3lTP6Q=; b=LBmiAKe1VFMze3gM/9Hx11TAYIpSzPpOu+RSaP9JrzuXwU8HZEYjnyWOtp0PSwe7M/5xCQfRpYcpbSYUkD08YuwWylmdeYVyTzi6ov9buV+35094cpkzk9N4yU/hXk5O213fvj0u5o853b1cqNNbmPlSR13DYlPMotn5TSgKpU8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1758698485243711.0397841831826; Wed, 24 Sep 2025 00:21:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1JnJ-0005Z5-FN; Wed, 24 Sep 2025 03:20:05 -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 1v1JnG-0005Xm-TI for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:03 -0400 Received: from rev.ng ([94.130.142.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v1JnC-0003QX-VF for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive:List-Unsubscribe:List-Unsubscribe-Post: List-Help; bh=TfzxWl+or/W5/6gQ6p08jZFPuH70Q3mNAcKQk3lTP6Q=; b=difapeYNemmwQQS nWS2kiygQRXQPlM3ckt3SP3EPUfOLKwc5oU1ruVAckbRhoSWpLDclONtk+pBuc7n0UCK2jujpBZh0 Unq/PMcxAAQwvBXb9ATFWmJdH+NjHOsW89O5aw3fLJPz9CDLx9uiXxqskRTsXRoEDcDBMy+Mw+mak U8=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com Subject: [RFC PATCH 15/34] target/riscv: Fix size of guest_phys_fault_addr Date: Wed, 24 Sep 2025 09:21:05 +0200 Message-ID: <20250924072124.6493-16-anjo@rev.ng> In-Reply-To: <20250924072124.6493-1-anjo@rev.ng> References: <20250924072124.6493-1-anjo@rev.ng> 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=94.130.142.21; envelope-from=anjo@rev.ng; helo=rev.ng 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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: , Reply-to: Anton Johansson From: Anton Johansson via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758698486898116600 Content-Type: text/plain; charset="utf-8" Widen to 64 bits, and use hwaddr as argument to get_physical_address(). Signed-off-by: Anton Johansson --- target/riscv/cpu.h | 2 +- target/riscv/cpu_helper.c | 3 +-- target/riscv/machine.c | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 343cc6bab7..b36d596127 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -236,7 +236,7 @@ struct CPUArchState { uint64_t badaddr; uint64_t bins; =20 - target_ulong guest_phys_fault_addr; + uint64_t guest_phys_fault_addr; =20 target_ulong priv_ver; target_ulong vext_ver; diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 36f7baf690..c9594b8719 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -1186,7 +1186,7 @@ static bool check_svukte_addr(CPURISCVState *env, vad= dr addr) */ static int get_physical_address(CPURISCVState *env, hwaddr *physical, int *ret_prot, vaddr addr, - target_ulong *fault_pte_addr, + hwaddr *fault_pte_addr, int access_type, int mmu_idx, bool first_stage, bool two_stage, bool is_debug, bool is_probe) @@ -1787,7 +1787,6 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, = int size, ret =3D get_physical_address(env, &pa, &prot, address, &env->guest_phys_fault_addr, access_typ= e, mmu_idx, true, true, false, probe); - /* * A G-stage exception may be triggered during two state lookup. * And the env->guest_phys_fault_addr has already been set in diff --git a/target/riscv/machine.c b/target/riscv/machine.c index a1cd67de99..472b2dcd8f 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -413,7 +413,7 @@ const VMStateDescription vmstate_riscv_cpu =3D { VMSTATE_UINT64(env.load_val, RISCVCPU), VMSTATE_UINT8(env.frm, RISCVCPU), VMSTATE_UINT64(env.badaddr, RISCVCPU), - VMSTATE_UINTTL(env.guest_phys_fault_addr, RISCVCPU), + VMSTATE_UINT64(env.guest_phys_fault_addr, RISCVCPU), VMSTATE_UINTTL(env.priv_ver, RISCVCPU), VMSTATE_UINTTL(env.vext_ver, RISCVCPU), VMSTATE_UINT32(env.misa_mxl, RISCVCPU), --=20 2.51.0 From nobody Sun Sep 28 15:28:22 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1758698789; cv=none; d=zohomail.com; s=zohoarc; b=kbWy5DcbpyUtd/w4rRiKCLee7GHcsVz3NQPXh0uNpj7w828qYeZXMMvrIk3Znqzo4yN+Ot/VsBFh+enZB8fHeH1aeLET71IMkMDSW0SfAqHZjhktew8B6gx6kKngKoFvXw5YcYxBJMej2VRMEytcDHQD1USadzVl9RsnAKfiYhA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758698789; 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:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=FuP228aWvrb3rDWGtRNaGaKjMkqO5qyI+ksM3jM6RxE=; b=S1/t+h8hNOy28B89Di5lMsf45NF5ZEMxq4tKxSC1U5dZhdfu+DeNbl47Bojc5UFGtJO3NbRyxojGP9uHSuePIX/q/DLLUv6e+y+k+33YjCRGdaUMQTWVhXulvnTpW9TM6i5Xi+scne9L3S09y8rKzvR8IZGH23tknWZnPH+y78Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1758698789356764.0776919899472; Wed, 24 Sep 2025 00:26:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1JnL-0005a7-PG; Wed, 24 Sep 2025 03:20:07 -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 1v1JnJ-0005Z1-9i for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:05 -0400 Received: from rev.ng ([94.130.142.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v1JnE-0003Qt-OD for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive:List-Unsubscribe:List-Unsubscribe-Post: List-Help; bh=FuP228aWvrb3rDWGtRNaGaKjMkqO5qyI+ksM3jM6RxE=; b=jluqcZPKYgS5Rv2 0ElGQrOM/b1MrmXfdPk8g8w9xwqWIHN+PZxb4lopZXmsSF8+AOgmUC/UprMQF5Le+rDiF5r1CvTXw doOn5YeKHauhnbTysQzDI8a+a/6POUZguciZ4o4eP/A7J0SrsEQmEwL134Pl/4q+jAi10Jup/V/Ki cU=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com Subject: [RFC PATCH 16/34] target/riscv: Fix size of priv_ver and vext_ver Date: Wed, 24 Sep 2025 09:21:06 +0200 Message-ID: <20250924072124.6493-17-anjo@rev.ng> In-Reply-To: <20250924072124.6493-1-anjo@rev.ng> References: <20250924072124.6493-1-anjo@rev.ng> 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=94.130.142.21; envelope-from=anjo@rev.ng; helo=rev.ng 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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: , Reply-to: Anton Johansson From: Anton Johansson via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758698790398116600 Content-Type: text/plain; charset="utf-8" Fix these fields to 32 bits, also update corresponding priv_ver field in DisasContext as well as function arguments. 32 bits was chosen since it's large enough to fit all stored values and int/int32_t is used in RISCVCPUDef and a few functions. Signed-off-by: Anton Johansson --- target/riscv/cpu.h | 6 +++--- target/riscv/machine.c | 4 ++-- target/riscv/translate.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index b36d596127..0f43887c74 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -238,8 +238,8 @@ struct CPUArchState { =20 uint64_t guest_phys_fault_addr; =20 - target_ulong priv_ver; - target_ulong vext_ver; + uint32_t priv_ver; + uint32_t vext_ver; =20 /* RISCVMXL, but uint32_t for vmstate migration */ uint32_t misa_mxl; /* current mxl */ @@ -798,7 +798,7 @@ static inline RISCVMXL riscv_cpu_sxl(CPURISCVState *env) #endif =20 static inline bool riscv_cpu_allow_16bit_insn(const RISCVCPUConfig *cfg, - target_long priv_ver, + uint32_t priv_ver, uint32_t misa_ext) { /* In priv spec version 1.12 or newer, C always implies Zca */ diff --git a/target/riscv/machine.c b/target/riscv/machine.c index 472b2dcd8f..9a2fd3267d 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -414,8 +414,8 @@ const VMStateDescription vmstate_riscv_cpu =3D { VMSTATE_UINT8(env.frm, RISCVCPU), VMSTATE_UINT64(env.badaddr, RISCVCPU), VMSTATE_UINT64(env.guest_phys_fault_addr, RISCVCPU), - VMSTATE_UINTTL(env.priv_ver, RISCVCPU), - VMSTATE_UINTTL(env.vext_ver, RISCVCPU), + VMSTATE_UINT32(env.priv_ver, RISCVCPU), + VMSTATE_UINT32(env.vext_ver, RISCVCPU), VMSTATE_UINT32(env.misa_mxl, RISCVCPU), VMSTATE_UINT32(env.misa_ext, RISCVCPU), VMSTATE_UNUSED(4), diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 339ef91f6b..10d39fd42a 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -59,7 +59,7 @@ typedef struct DisasContext { DisasContextBase base; target_ulong cur_insn_len; target_ulong pc_save; - target_ulong priv_ver; + uint32_t priv_ver; RISCVMXL misa_mxl_max; RISCVMXL xl; RISCVMXL address_xl; --=20 2.51.0 From nobody Sun Sep 28 15:28:22 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1758698826; cv=none; d=zohomail.com; s=zohoarc; b=BcrlgjyEHUN7YgKmS1Ym4mbEDjUZ9jpKiv7h3hspmbjbZQaYM+lxz/h0qODMH5repxtLRzzmxVxlpKNhqf+FvJZtzdHMLibARcqKscdjJUYQBGfLB2V/toNOFKzS0lKLEyW/yq9l0hXPjWiFC9Pguyvth6LtpmwKKNTBeddYMnQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758698826; 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:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=cI2azNyj5+/HhtG+7BoWAyB5BJbSzPZh8toaKt9cr70=; b=XjFBMR2dV1oTCS6k+XinfLtCh80L3A7Apu7lANr4dCNs4CDnbRxyElEe7yAmzrhGPg2nXArnNdZdm2J4VdDKSjzLK0GxPDlr1IobdpQXXaUSwf0eejGKtXp9SfqeNnjkVUpLiy6JEoV7twP/RuyxZ5qeC2Ybam0Qonvyf+2O25g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1758698826677228.6877552892297; Wed, 24 Sep 2025 00:27:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1JnR-0005en-Ux; Wed, 24 Sep 2025 03:20:14 -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 1v1JnQ-0005e6-6R for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:12 -0400 Received: from rev.ng ([94.130.142.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v1JnF-0003R7-9u for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive:List-Unsubscribe:List-Unsubscribe-Post: List-Help; bh=cI2azNyj5+/HhtG+7BoWAyB5BJbSzPZh8toaKt9cr70=; b=s96bPDP3ibYXoF8 8RYN8yq0jaT4fyKrhuaRx/ut1MEumSgyvkgnww6puulreBmwk4QIK6AWFhhFh8gBtmZChKcEyo3pq ptuzyQjZ+EpuXwoCp8K/Zk729uOMsxg9TQZ9M7tlCmO+QDHbh3d4WaycwTLCq1I7vnu3x/z+3Sr3a Sw=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com Subject: [RFC PATCH 17/34] target/riscv: Fix size of retxh Date: Wed, 24 Sep 2025 09:21:07 +0200 Message-ID: <20250924072124.6493-18-anjo@rev.ng> In-Reply-To: <20250924072124.6493-1-anjo@rev.ng> References: <20250924072124.6493-1-anjo@rev.ng> 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=94.130.142.21; envelope-from=anjo@rev.ng; helo=rev.ng 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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: , Reply-to: Anton Johansson From: Anton Johansson via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758698828707116601 Content-Type: text/plain; charset="utf-8" 128-bit helpers only make sense for MXL_RV128, TARGET_RISCV64, and TCGv =3D=3D TCGv_i64, therefore fix retxh to 64 bits. For the sake of being pedandic, update 128-bit instructions to access retxh via 64 bit TCG ops, even if they only make sense when TCGv =3D=3D TCGv_i64. Signed-off-by: Anton Johansson --- target/riscv/cpu.h | 2 +- target/riscv/insn_trans/trans_rvi.c.inc | 8 ++++++-- target/riscv/insn_trans/trans_rvm.c.inc | 16 ++++++++++++---- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 0f43887c74..ffc2c1b424 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -248,7 +248,7 @@ struct CPUArchState { uint32_t xl; /* current xlen */ =20 /* 128-bit helpers upper part return value */ - target_ulong retxh; + uint64_t retxh; =20 uint64_t jvt; =20 diff --git a/target/riscv/insn_trans/trans_rvi.c.inc b/target/riscv/insn_tr= ans/trans_rvi.c.inc index b9c7160468..9c8c04b2dc 100644 --- a/target/riscv/insn_trans/trans_rvi.c.inc +++ b/target/riscv/insn_trans/trans_rvi.c.inc @@ -1012,10 +1012,12 @@ static bool do_csrr_i128(DisasContext *ctx, int rd,= int rc) TCGv destl =3D dest_gpr(ctx, rd); TCGv desth =3D dest_gprh(ctx, rd); TCGv_i32 csr =3D tcg_constant_i32(rc); + TCGv_i64 wide_desth =3D tcg_temp_new_i64(); =20 translator_io_start(&ctx->base); gen_helper_csrr_i128(destl, tcg_env, csr); - tcg_gen_ld_tl(desth, tcg_env, offsetof(CPURISCVState, retxh)); + tcg_gen_ld_i64(wide_desth, tcg_env, offsetof(CPURISCVState, retxh)); + tcg_gen_trunc_i64_tl(desth, wide_desth); gen_set_gpr128(ctx, rd, destl, desth); return do_csr_post(ctx); } @@ -1035,10 +1037,12 @@ static bool do_csrrw_i128(DisasContext *ctx, int rd= , int rc, TCGv destl =3D dest_gpr(ctx, rd); TCGv desth =3D dest_gprh(ctx, rd); TCGv_i32 csr =3D tcg_constant_i32(rc); + TCGv_i64 wide_desth =3D tcg_temp_new_i64(); =20 translator_io_start(&ctx->base); gen_helper_csrrw_i128(destl, tcg_env, csr, srcl, srch, maskl, maskh); - tcg_gen_ld_tl(desth, tcg_env, offsetof(CPURISCVState, retxh)); + tcg_gen_ld_i64(wide_desth, tcg_env, offsetof(CPURISCVState, retxh)); + tcg_gen_trunc_i64_tl(desth, wide_desth); gen_set_gpr128(ctx, rd, destl, desth); return do_csr_post(ctx); } diff --git a/target/riscv/insn_trans/trans_rvm.c.inc b/target/riscv/insn_tr= ans/trans_rvm.c.inc index 795f0ccf14..0e2da5bed2 100644 --- a/target/riscv/insn_trans/trans_rvm.c.inc +++ b/target/riscv/insn_trans/trans_rvm.c.inc @@ -169,8 +169,10 @@ static bool trans_mulhu(DisasContext *ctx, arg_mulhu *= a) static void gen_div_i128(TCGv rdl, TCGv rdh, TCGv rs1l, TCGv rs1h, TCGv rs2l, TCGv rs2h) { + TCGv_i64 wide_rdh =3D tcg_temp_new_i64(); gen_helper_divs_i128(rdl, tcg_env, rs1l, rs1h, rs2l, rs2h); - tcg_gen_ld_tl(rdh, tcg_env, offsetof(CPURISCVState, retxh)); + tcg_gen_ld_i64(wide_rdh, tcg_env, offsetof(CPURISCVState, retxh)); + tcg_gen_trunc_i64_tl(rdh, wide_rdh); } =20 static void gen_div(TCGv ret, TCGv source1, TCGv source2) @@ -212,8 +214,10 @@ static bool trans_div(DisasContext *ctx, arg_div *a) static void gen_divu_i128(TCGv rdl, TCGv rdh, TCGv rs1l, TCGv rs1h, TCGv rs2l, TCGv rs2h) { + TCGv_i64 wide_rdh =3D tcg_temp_new_i64(); gen_helper_divu_i128(rdl, tcg_env, rs1l, rs1h, rs2l, rs2h); - tcg_gen_ld_tl(rdh, tcg_env, offsetof(CPURISCVState, retxh)); + tcg_gen_ld_i64(wide_rdh, tcg_env, offsetof(CPURISCVState, retxh)); + tcg_gen_trunc_i64_tl(rdh, wide_rdh); } =20 static void gen_divu(TCGv ret, TCGv source1, TCGv source2) @@ -244,8 +248,10 @@ static bool trans_divu(DisasContext *ctx, arg_divu *a) static void gen_rem_i128(TCGv rdl, TCGv rdh, TCGv rs1l, TCGv rs1h, TCGv rs2l, TCGv rs2h) { + TCGv_i64 wide_rdh =3D tcg_temp_new_i64(); gen_helper_rems_i128(rdl, tcg_env, rs1l, rs1h, rs2l, rs2h); - tcg_gen_ld_tl(rdh, tcg_env, offsetof(CPURISCVState, retxh)); + tcg_gen_ld_i64(wide_rdh, tcg_env, offsetof(CPURISCVState, retxh)); + tcg_gen_trunc_i64_tl(rdh, wide_rdh); } =20 static void gen_rem(TCGv ret, TCGv source1, TCGv source2) @@ -289,8 +295,10 @@ static bool trans_rem(DisasContext *ctx, arg_rem *a) static void gen_remu_i128(TCGv rdl, TCGv rdh, TCGv rs1l, TCGv rs1h, TCGv rs2l, TCGv rs2h) { + TCGv_i64 wide_rdh =3D tcg_temp_new_i64(); gen_helper_remu_i128(rdl, tcg_env, rs1l, rs1h, rs2l, rs2h); - tcg_gen_ld_tl(rdh, tcg_env, offsetof(CPURISCVState, retxh)); + tcg_gen_ld_i64(wide_rdh, tcg_env, offsetof(CPURISCVState, retxh)); + tcg_gen_trunc_i64_tl(rdh, wide_rdh); } =20 static void gen_remu(TCGv ret, TCGv source1, TCGv source2) --=20 2.51.0 From nobody Sun Sep 28 15:28:22 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1758698541; cv=none; d=zohomail.com; s=zohoarc; b=NVDaqEt+HMsj//D4tUm/ShgrbY/aeKuGC9SS82M51s/3TU5aYthw4zL3SqPbyKHX72OHDkOQtLUb13ZM/LO40LrUmn5BfAT9C3T8YY4QYfooeL+eO+uEp2XwwplwZLltCQ7rnq3YeOKtTY9JRqLbf3hsFUpAxWZzqruDugA96mM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758698541; 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:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=OZO8hLRD1il0/T6biuW8RyclBm1fgAOzTgPsI/lBN/U=; b=WavVpycPE95yh/ZZ2voGBmgld2MclAr8Zh8YCS4nDzyYHHpNQLtK16d1p+d+Csaz2NLiBRJnGMpoxKmLAKKAxow17oa6AtO5o5zB9ZL+yNoTAIC0A9rOSJwA0zzS8pfJTODfAiQgmf4LaWxNQ9gGL23waeC0r0AbrsW2jM+kkvQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 175869854120294.10101705783552; Wed, 24 Sep 2025 00:22:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1JnQ-0005e5-FI; Wed, 24 Sep 2025 03:20:12 -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 1v1JnN-0005bP-NA for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:09 -0400 Received: from rev.ng ([94.130.142.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v1JnJ-0003RG-NO for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive:List-Unsubscribe:List-Unsubscribe-Post: List-Help; bh=OZO8hLRD1il0/T6biuW8RyclBm1fgAOzTgPsI/lBN/U=; b=iytIu81qpqAQpS/ SLRkl//jyRedQlHsNIgLabNM3SJ91IBHZ5/LG+xBHNt0NdNprjN/3cRi/AwjSNIZhoTeFD1RODlko 9eGmsXMnOtQexs+/LLF0+1S36lgYWBRT4diZoQ4QpcaxzcO01aUcrlfMt4taxgHiXj4XCukSLA3Gg Bk=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com Subject: [RFC PATCH 18/34] target/riscv: Fix size of ssp Date: Wed, 24 Sep 2025 09:21:08 +0200 Message-ID: <20250924072124.6493-19-anjo@rev.ng> In-Reply-To: <20250924072124.6493-1-anjo@rev.ng> References: <20250924072124.6493-1-anjo@rev.ng> 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=94.130.142.21; envelope-from=anjo@rev.ng; helo=rev.ng 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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: , Reply-to: Anton Johansson From: Anton Johansson via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758698541810116600 Content-Type: text/plain; charset="utf-8" As ssp holds a pointer, fix to 64 bits in size and make sure stores from TCG use the correct size to avoid problems on big endian hosts. Signed-off-by: Anton Johansson --- target/riscv/cpu.h | 2 +- target/riscv/machine.c | 2 +- target/riscv/insn_trans/trans_rvzicfiss.c.inc | 18 +++++++++++++----- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index ffc2c1b424..1c544bc260 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -255,7 +255,7 @@ struct CPUArchState { /* elp state for zicfilp extension */ bool elp; /* shadow stack register for zicfiss extension */ - target_ulong ssp; + uint64_t ssp; /* env place holder for extra word 2 during unwind */ target_ulong excp_uw2; /* sw check code for sw check exception */ diff --git a/target/riscv/machine.c b/target/riscv/machine.c index 9a2fd3267d..b95d432e0e 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -393,7 +393,7 @@ static const VMStateDescription vmstate_ssp =3D { .minimum_version_id =3D 1, .needed =3D ssp_needed, .fields =3D (const VMStateField[]) { - VMSTATE_UINTTL(env.ssp, RISCVCPU), + VMSTATE_UINT64(env.ssp, RISCVCPU), VMSTATE_END_OF_LIST() } }; diff --git a/target/riscv/insn_trans/trans_rvzicfiss.c.inc b/target/riscv/i= nsn_trans/trans_rvzicfiss.c.inc index b0096adcd0..4333854979 100644 --- a/target/riscv/insn_trans/trans_rvzicfiss.c.inc +++ b/target/riscv/insn_trans/trans_rvzicfiss.c.inc @@ -32,7 +32,9 @@ static bool trans_sspopchk(DisasContext *ctx, arg_sspopch= k *a) TCGLabel *skip =3D gen_new_label(); uint32_t tmp =3D (get_xl(ctx) =3D=3D MXL_RV64) ? 8 : 4; TCGv data =3D tcg_temp_new(); - tcg_gen_ld_tl(addr, tcg_env, offsetof(CPURISCVState, ssp)); + TCGv_i64 wide_addr =3D tcg_temp_new_i64(); + tcg_gen_ld_i64(wide_addr, tcg_env, offsetof(CPURISCVState, ssp)); + tcg_gen_trunc_i64_tl(addr, wide_addr); decode_save_opc(ctx, RISCV_UW2_ALWAYS_STORE_AMO); tcg_gen_qemu_ld_tl(data, addr, SS_MMU_INDEX(ctx), mxl_memop(ctx) | MO_ALIGN); @@ -44,7 +46,8 @@ static bool trans_sspopchk(DisasContext *ctx, arg_sspopch= k *a) tcg_constant_i32(RISCV_EXCP_SW_CHECK)); gen_set_label(skip); tcg_gen_addi_tl(addr, addr, tmp); - tcg_gen_st_tl(addr, tcg_env, offsetof(CPURISCVState, ssp)); + tcg_gen_ext_tl_i64(wide_addr, addr); + tcg_gen_st_i64(wide_addr, tcg_env, offsetof(CPURISCVState, ssp)); =20 return true; } @@ -58,12 +61,15 @@ static bool trans_sspush(DisasContext *ctx, arg_sspush = *a) TCGv addr =3D tcg_temp_new(); int tmp =3D (get_xl(ctx) =3D=3D MXL_RV64) ? -8 : -4; TCGv data =3D get_gpr(ctx, a->rs2, EXT_NONE); + TCGv_i64 wide_addr =3D tcg_temp_new_i64(); decode_save_opc(ctx, RISCV_UW2_ALWAYS_STORE_AMO); - tcg_gen_ld_tl(addr, tcg_env, offsetof(CPURISCVState, ssp)); + tcg_gen_ld_i64(wide_addr, tcg_env, offsetof(CPURISCVState, ssp)); + tcg_gen_trunc_i64_tl(addr, wide_addr); tcg_gen_addi_tl(addr, addr, tmp); tcg_gen_qemu_st_tl(data, addr, SS_MMU_INDEX(ctx), mxl_memop(ctx) | MO_ALIGN); - tcg_gen_st_tl(addr, tcg_env, offsetof(CPURISCVState, ssp)); + tcg_gen_ext_tl_i64(wide_addr, addr); + tcg_gen_st_i64(wide_addr, tcg_env, offsetof(CPURISCVState, ssp)); =20 return true; } @@ -75,7 +81,9 @@ static bool trans_ssrdp(DisasContext *ctx, arg_ssrdp *a) } =20 TCGv dest =3D dest_gpr(ctx, a->rd); - tcg_gen_ld_tl(dest, tcg_env, offsetof(CPURISCVState, ssp)); + TCGv_i64 wide_addr =3D tcg_temp_new_i64(); + tcg_gen_ld_i64(wide_addr, tcg_env, offsetof(CPURISCVState, ssp)); + tcg_gen_trunc_i64_tl(dest, wide_addr); gen_set_gpr(ctx, a->rd, dest); =20 return true; --=20 2.51.0 From nobody Sun Sep 28 15:28:22 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1758698709; cv=none; d=zohomail.com; s=zohoarc; b=ixS+Xbub4G33Sovenflq126LULNWjtmUf1EduEOQpi8c6dV1k2rWnjTyIB/dA+VAPqGC5O7RWSlPN4XpOPDuYuY8gG0517lduLlqLB3vZPjr/P+O4Aj90n9LUcMiCmU1pZOiKXqbMxcpJhhlDY8DWw869BgprvtKzFj8ORohXWk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758698709; 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:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=WJA+f3TtOwcsiPCPlb7yLGWVCIgg5o+ojWR7LclRPYo=; b=mjJXfeiQM0hnk7rhoB8dwAVEeiqZk2/RtDQYnFb0qFprvSU2r76mI/aqXD5so/8Z+/Ob4eVa8Bj0W9XLga48TtHRGbI29TS/3nk3w9cIfIh2rAP63o6+VED5nbFPdaQIJj62tU1HuUsKtPnsJZgMp9VKM/ATzXZYAuNuloxQPHE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1758698709990500.3490662434135; Wed, 24 Sep 2025 00:25:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1Jnn-0005sB-MP; Wed, 24 Sep 2025 03:20:35 -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 1v1JnZ-0005lR-KL for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:23 -0400 Received: from rev.ng ([94.130.142.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v1JnL-0003Ri-A5 for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive:List-Unsubscribe:List-Unsubscribe-Post: List-Help; bh=WJA+f3TtOwcsiPCPlb7yLGWVCIgg5o+ojWR7LclRPYo=; b=UXOgMeUd6vFSsqy IZw9gty21lOr/HO9aj/geeMq/or8YBZVCVs/ckQlZag0nJfy6UKv/mBg3SoOAHBZk0ifFgX/8s8sb 77M5wlqQmbtw3LsQ2FMzaNopHRwMNhzVuwhxThqWxJRyk3+f9QE0YG4ZU+61BSfb8MG5mHXnRG+96 JI=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com Subject: [RFC PATCH 19/34] target/riscv: Fix size of excp_uw2 Date: Wed, 24 Sep 2025 09:21:09 +0200 Message-ID: <20250924072124.6493-20-anjo@rev.ng> In-Reply-To: <20250924072124.6493-1-anjo@rev.ng> References: <20250924072124.6493-1-anjo@rev.ng> 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=94.130.142.21; envelope-from=anjo@rev.ng; helo=rev.ng X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no 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: , Reply-to: Anton Johansson From: Anton Johansson via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758698711377116600 Content-Type: text/plain; charset="utf-8" Fix to 64 bits to match size of instruction start words. Signed-off-by: Anton Johansson --- target/riscv/cpu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 1c544bc260..e714554611 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -257,7 +257,7 @@ struct CPUArchState { /* shadow stack register for zicfiss extension */ uint64_t ssp; /* env place holder for extra word 2 during unwind */ - target_ulong excp_uw2; + uint64_t excp_uw2; /* sw check code for sw check exception */ target_ulong sw_check_code; #ifdef CONFIG_USER_ONLY --=20 2.51.0 From nobody Sun Sep 28 15:28:22 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1758698586; cv=none; d=zohomail.com; s=zohoarc; b=bquIQwKCNi9k1cvZGjad5xkIOGfowEoyyhzf5zc+QWFxzBAugFTD6VVp93nFZT76m5A4anNQWj/8+QLo2DWr+82fvrlDBdrJCH0JG5MTWX0PHQp7XtbWDbD7L6cAQBRUP3Rnc6Cs2RrAWxbp0Cpq8Tq5ZOncN5q2Jm9tOlJ4hXQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758698586; 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:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=KjOR/PJHoV/gG35upckkihIkxsXitjESxQEHa0RGxOk=; b=KRdjdNnkd5zzkCNuTTB9F6POl8NtgshTGHbak/g+LzpAYEnVfxanoR1NOdVw34CHeVhpCCA2WRwBjD2SUTsyXub28k4gmNouo9Ys4ctg6rzTYFbMsRZpR/IsftyCOHSIY7Xew+AK1pvf8TnmfbQ6DT5tMnBUfKz4jSeM7QP18+s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1758698586510883.6875643509311; Wed, 24 Sep 2025 00:23:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1JnV-0005j7-Ut; Wed, 24 Sep 2025 03:20: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 1v1JnT-0005f4-05 for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:15 -0400 Received: from rev.ng ([94.130.142.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v1JnL-0003Rz-8B for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive:List-Unsubscribe:List-Unsubscribe-Post: List-Help; bh=KjOR/PJHoV/gG35upckkihIkxsXitjESxQEHa0RGxOk=; b=GSj/b1AGY6r77MW 5BXmPWDIL2Z/u0rIE7Zc6b5JDiVPkuOUOpYlv1rczxf0Isgna9aTQTpTvUQ7M2P3g5OfTuxX5oW6b 4zLHp3KG+ctle0hZWZuZMu/VkWpCd7xTKuEQnHO1ylK0/vDbR6fv5a2dHBZ+QRPtT949TGJzIjUaG 1Q=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com Subject: [RFC PATCH 20/34] target/riscv: Fix size of sw_check_code Date: Wed, 24 Sep 2025 09:21:10 +0200 Message-ID: <20250924072124.6493-21-anjo@rev.ng> In-Reply-To: <20250924072124.6493-1-anjo@rev.ng> References: <20250924072124.6493-1-anjo@rev.ng> 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=94.130.142.21; envelope-from=anjo@rev.ng; helo=rev.ng 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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: , Reply-to: Anton Johansson From: Anton Johansson via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758698588209116600 Content-Type: text/plain; charset="utf-8" The field only holds values of 2 and 3, fix its size to 8 bits and update stores from TCG. Signed-off-by: Anton Johansson --- target/riscv/cpu.h | 2 +- target/riscv/translate.c | 4 ++-- target/riscv/insn_trans/trans_rvi.c.inc | 8 ++++---- target/riscv/insn_trans/trans_rvzicfiss.c.inc | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index e714554611..6a60e3a6e6 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -259,7 +259,7 @@ struct CPUArchState { /* env place holder for extra word 2 during unwind */ uint64_t excp_uw2; /* sw check code for sw check exception */ - target_ulong sw_check_code; + uint8_t sw_check_code; #ifdef CONFIG_USER_ONLY uint32_t elf_flags; #endif diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 10d39fd42a..5c42271c30 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -1361,8 +1361,8 @@ static void riscv_tr_translate_insn(DisasContextBase = *dcbase, CPUState *cpu) if (ctx->fcfi_lp_expected) { /* Emit after insn_start, i.e. before the op following insn_start.= */ tcg_ctx->emit_before_op =3D QTAILQ_NEXT(ctx->base.insn_start, link= ); - tcg_gen_st_tl(tcg_constant_tl(RISCV_EXCP_SW_CHECK_FCFI_TVAL), - tcg_env, offsetof(CPURISCVState, sw_check_code)); + tcg_gen_st8_i32(tcg_constant_i32(RISCV_EXCP_SW_CHECK_FCFI_TVAL), + tcg_env, offsetof(CPURISCVState, sw_check_code)); gen_helper_raise_exception(tcg_env, tcg_constant_i32(RISCV_EXCP_SW_CHECK)); tcg_ctx->emit_before_op =3D NULL; diff --git a/target/riscv/insn_trans/trans_rvi.c.inc b/target/riscv/insn_tr= ans/trans_rvi.c.inc index 9c8c04b2dc..5efdd95f97 100644 --- a/target/riscv/insn_trans/trans_rvi.c.inc +++ b/target/riscv/insn_trans/trans_rvi.c.inc @@ -53,8 +53,8 @@ static bool trans_lpad(DisasContext *ctx, arg_lpad *a) /* * misaligned, according to spec we should raise sw check exception */ - tcg_gen_st_tl(tcg_constant_tl(RISCV_EXCP_SW_CHECK_FCFI_TVAL), - tcg_env, offsetof(CPURISCVState, sw_check_code)); + tcg_gen_st8_i32(tcg_constant_i32(RISCV_EXCP_SW_CHECK_FCFI_TVAL), + tcg_env, offsetof(CPURISCVState, sw_check_code)); gen_helper_raise_exception(tcg_env, tcg_constant_i32(RISCV_EXCP_SW_CHECK)); return true; @@ -66,8 +66,8 @@ static bool trans_lpad(DisasContext *ctx, arg_lpad *a) TCGv tmp =3D tcg_temp_new(); tcg_gen_extract_tl(tmp, get_gpr(ctx, xT2, EXT_NONE), 12, 20); tcg_gen_brcondi_tl(TCG_COND_EQ, tmp, a->label, skip); - tcg_gen_st_tl(tcg_constant_tl(RISCV_EXCP_SW_CHECK_FCFI_TVAL), - tcg_env, offsetof(CPURISCVState, sw_check_code)); + tcg_gen_st8_i32(tcg_constant_i32(RISCV_EXCP_SW_CHECK_FCFI_TVAL), + tcg_env, offsetof(CPURISCVState, sw_check_code)); gen_helper_raise_exception(tcg_env, tcg_constant_i32(RISCV_EXCP_SW_CHECK)); gen_set_label(skip); diff --git a/target/riscv/insn_trans/trans_rvzicfiss.c.inc b/target/riscv/i= nsn_trans/trans_rvzicfiss.c.inc index 4333854979..0827c97e31 100644 --- a/target/riscv/insn_trans/trans_rvzicfiss.c.inc +++ b/target/riscv/insn_trans/trans_rvzicfiss.c.inc @@ -40,8 +40,8 @@ static bool trans_sspopchk(DisasContext *ctx, arg_sspopch= k *a) mxl_memop(ctx) | MO_ALIGN); TCGv rs1 =3D get_gpr(ctx, a->rs1, EXT_NONE); tcg_gen_brcond_tl(TCG_COND_EQ, data, rs1, skip); - tcg_gen_st_tl(tcg_constant_tl(RISCV_EXCP_SW_CHECK_BCFI_TVAL), - tcg_env, offsetof(CPURISCVState, sw_check_code)); + tcg_gen_st8_i32(tcg_constant_i32(RISCV_EXCP_SW_CHECK_BCFI_TVAL), + tcg_env, offsetof(CPURISCVState, sw_check_code)); gen_helper_raise_exception(tcg_env, tcg_constant_i32(RISCV_EXCP_SW_CHECK)); gen_set_label(skip); --=20 2.51.0 From nobody Sun Sep 28 15:28:22 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1758698913; cv=none; d=zohomail.com; s=zohoarc; b=TlslCgVwTNcytw1nblh9So9MKk9AR3jiVQyTRJxun+P6BLOZn8VrYsO5gFPnz+JaDqFQXI0sd/Y5f3u7jPPtOsgVfUqWpdALFfYw2Turlh/nbRtLLBYkMb1NlZb3pcIu/P6BcG08c/zJL1sp2c+koEDWWvaF6PSgKbIBLU0ztZ8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758698913; 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:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=MBXCoD120HOdlwDPHxjFmfthOrVMD9EoNaDraMOZfI0=; b=eWVOnOC4m6TZ+8LvsyOYGbMTHrRDIVgX+ZOC6Qb0B67mXyVYjhj3PT16VWJ2T7DkayNCn9ySGIlz1skfhT7GhXAoP4L8aW6AeKX7eWpfB33LMJN9ENsZgNMgRW9o7MiYkNXcFdf175IcAOF6IOuTHkLoed8u35oEGwa2IMnL7Ec= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1758698913086912.1049215911231; Wed, 24 Sep 2025 00:28:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1Jno-0005sW-IM; Wed, 24 Sep 2025 03:20:36 -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 1v1JnZ-0005lQ-K6 for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:23 -0400 Received: from rev.ng ([94.130.142.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v1JnN-0003SB-Ta for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive:List-Unsubscribe:List-Unsubscribe-Post: List-Help; bh=MBXCoD120HOdlwDPHxjFmfthOrVMD9EoNaDraMOZfI0=; b=Lw1qUnQALqyfhwy uPFpMpLq5Oytv+/QoBFhfzEEXows6KEwI8vSdVhkskagN7hyRgbHrI2bXSmmq9zml0+YasGkgan7k v3Dao03dfbQQv2BPVYJr5cFJ6eq4j/6WyZhuZbm3IpJstz7eZ7uymutp9wD/bRQBXQ4DpKA0NglsX SE=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com Subject: [RFC PATCH 21/34] target/riscv: Fix size of priv Date: Wed, 24 Sep 2025 09:21:11 +0200 Message-ID: <20250924072124.6493-22-anjo@rev.ng> In-Reply-To: <20250924072124.6493-1-anjo@rev.ng> References: <20250924072124.6493-1-anjo@rev.ng> 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=94.130.142.21; envelope-from=anjo@rev.ng; helo=rev.ng 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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: , Reply-to: Anton Johansson From: Anton Johansson via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758698913624116600 Content-Type: text/plain; charset="utf-8" The priv field of CPUArchState only stores values in the range [0,3], fix to 8 bits in size and update relevant function arguments. Signed-off-by: Anton Johansson --- target/riscv/cpu.h | 8 ++++---- target/riscv/cpu_helper.c | 10 +++++----- target/riscv/machine.c | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 6a60e3a6e6..d484da20b5 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -264,7 +264,7 @@ struct CPUArchState { uint32_t elf_flags; #endif =20 - target_ulong priv; + uint8_t priv; /* CSRs for execution environment configuration */ uint64_t menvcfg; uint64_t senvcfg; @@ -649,10 +649,10 @@ void riscv_cpu_set_aia_ireg_rmw_fn(CPURISCVState *env= , uint32_t priv, RISCVException smstateen_acc_ok(CPURISCVState *env, int index, uint64_t bi= t); #endif /* !CONFIG_USER_ONLY */ =20 -void riscv_cpu_set_mode(CPURISCVState *env, target_ulong newpriv, bool vir= t_en); +void riscv_cpu_set_mode(CPURISCVState *env, uint8_t newpriv, bool virt_en); =20 void riscv_ctr_add_entry(CPURISCVState *env, target_long src, target_long = dst, - enum CTRType type, target_ulong prev_priv, bool prev_virt); + enum CTRType type, uint8_t prev_priv, bool prev_virt); void riscv_ctr_clear(CPURISCVState *env); =20 void riscv_translate_init(void); @@ -723,7 +723,7 @@ static inline int cpu_address_mode(CPURISCVState *env) return mode; } =20 -static inline RISCVMXL cpu_get_xl(CPURISCVState *env, target_ulong mode) +static inline RISCVMXL cpu_get_xl(CPURISCVState *env, uint8_t mode) { RISCVMXL xl =3D env->misa_mxl; /* diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index c9594b8719..a57f33b3cb 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -799,7 +799,7 @@ void riscv_ctr_clear(CPURISCVState *env) memset(env->ctr_data, 0x0, sizeof(env->ctr_data)); } =20 -static uint64_t riscv_ctr_priv_to_mask(target_ulong priv, bool virt) +static uint64_t riscv_ctr_priv_to_mask(uint8_t priv, bool virt) { switch (priv) { case PRV_M: @@ -819,7 +819,7 @@ static uint64_t riscv_ctr_priv_to_mask(target_ulong pri= v, bool virt) g_assert_not_reached(); } =20 -static uint64_t riscv_ctr_get_control(CPURISCVState *env, target_long priv, +static uint64_t riscv_ctr_get_control(CPURISCVState *env, uint8_t priv, bool virt) { switch (priv) { @@ -841,7 +841,7 @@ static uint64_t riscv_ctr_get_control(CPURISCVState *en= v, target_long priv, * and src privilege is less than target privilege. This includes the virt= ual * state as well. */ -static bool riscv_ctr_check_xte(CPURISCVState *env, target_long src_prv, +static bool riscv_ctr_check_xte(CPURISCVState *env, uint8_t src_prv, bool src_virt) { target_long tgt_prv =3D env->priv; @@ -930,7 +930,7 @@ static bool riscv_ctr_check_xte(CPURISCVState *env, tar= get_long src_prv, * idx =3D (sctrstatus.WRPTR - entry - 1) & (depth - 1); */ void riscv_ctr_add_entry(CPURISCVState *env, target_long src, target_long = dst, - enum CTRType type, target_ulong src_priv, bool src_virt) + enum CTRType type, uint8_t src_priv, bool src_virt) { bool tgt_virt =3D env->virt_enabled; uint64_t src_mask =3D riscv_ctr_priv_to_mask(src_priv, src_virt); @@ -1028,7 +1028,7 @@ void riscv_ctr_add_entry(CPURISCVState *env, target_l= ong src, target_long dst, env->sctrstatus =3D set_field(env->sctrstatus, SCTRSTATUS_WRPTR_MASK, = head); } =20 -void riscv_cpu_set_mode(CPURISCVState *env, target_ulong newpriv, bool vir= t_en) +void riscv_cpu_set_mode(CPURISCVState *env, uint8_t newpriv, bool virt_en) { g_assert(newpriv <=3D PRV_M && newpriv !=3D PRV_RESERVED); =20 diff --git a/target/riscv/machine.c b/target/riscv/machine.c index b95d432e0e..a3d5811653 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -420,7 +420,7 @@ const VMStateDescription vmstate_riscv_cpu =3D { VMSTATE_UINT32(env.misa_ext, RISCVCPU), VMSTATE_UNUSED(4), VMSTATE_UINT32(env.misa_ext_mask, RISCVCPU), - VMSTATE_UINTTL(env.priv, RISCVCPU), + VMSTATE_UINT8(env.priv, RISCVCPU), VMSTATE_BOOL(env.virt_enabled, RISCVCPU), VMSTATE_UINT64(env.resetvec, RISCVCPU), VMSTATE_UINT64(env.mhartid, RISCVCPU), --=20 2.51.0 From nobody Sun Sep 28 15:28:22 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1758698754; cv=none; d=zohomail.com; s=zohoarc; b=Br/3DOW/74OqHa5bPcHZxbFk11UcIjr1tCvJoGx94f/Jt9sMbTShQbrAPa9Bur0FwyLGdDKgyGji3vdOt58SEKgiC7lSicLRMaDvDJVTw0DIaGGhXZUpKaLjNlKNcPDXI8eQbw1ujdXAgFW+VfAozoCa8z6TS18lx/+7CddnCxQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758698754; 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:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=Ni3AZda02lJ55lhCKtKuWraJSQXkt9BovJEXXQPIDu8=; b=Lj5O4VUX/7pkv94s5h8M8yYEEL+Z9nXVSMNxSYUJjdPONGG3vJzQh8Zzc9B4Wtwq4EhEq1nvAnHnIn6bFK1KYr4a3mzSyVctY71B7Oe4le5MU8uvIIRYBMBGJ14mrQf5zlDn5XxBH+u9ihpZCfwx3/II7Z0VBIqMkl1mnjEsBxQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1758698754116920.9976242287685; Wed, 24 Sep 2025 00:25:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1Jnn-0005s9-7g; Wed, 24 Sep 2025 03:20:35 -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 1v1JnZ-0005lS-Ko for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:23 -0400 Received: from rev.ng ([94.130.142.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v1JnP-0003SH-EZ for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive:List-Unsubscribe:List-Unsubscribe-Post: List-Help; bh=Ni3AZda02lJ55lhCKtKuWraJSQXkt9BovJEXXQPIDu8=; b=vmA31qMBn46gsF7 V+Z8yK6DGPv3m8RfDsr+bc+cxlT7UnlWG4GGJKPm6sIMXGSL0/EHQeWP5jU3dT1ojK4aT73+VmaAe cKyl232820xYdrUTxeRmAAWoqQwsQnVIzCkfTRwvKnNOXV3MSquatNGjwYUbtLQwTK9pt8GwPSrae Ls=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com Subject: [RFC PATCH 22/34] target/riscv: Fix size of gei fields Date: Wed, 24 Sep 2025 09:21:12 +0200 Message-ID: <20250924072124.6493-23-anjo@rev.ng> In-Reply-To: <20250924072124.6493-1-anjo@rev.ng> References: <20250924072124.6493-1-anjo@rev.ng> 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=94.130.142.21; envelope-from=anjo@rev.ng; helo=rev.ng 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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: , Reply-to: Anton Johansson From: Anton Johansson via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758698755884116600 Content-Type: text/plain; charset="utf-8" geilen takes the values 31 or 63, fix it to 8 bits. hgeie and hgeip are at most 64 bits in size, fix to 64. Update relevant function arguments. Signed-off-by: Anton Johansson --- target/riscv/cpu.h | 10 +++++----- target/riscv/cpu_helper.c | 4 ++-- target/riscv/machine.c | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index d484da20b5..3477e6dd1e 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -272,7 +272,7 @@ struct CPUArchState { #ifndef CONFIG_USER_ONLY /* This contains QEMU specific information about the virt state. */ bool virt_enabled; - target_ulong geilen; + uint8_t geilen; uint64_t resetvec; =20 uint64_t mhartid; @@ -349,8 +349,8 @@ struct CPUArchState { uint64_t htval; uint64_t htinst; uint64_t hgatp; - target_ulong hgeie; - target_ulong hgeip; + uint64_t hgeie; + uint64_t hgeip; uint64_t htimedelta; uint64_t hvien; =20 @@ -601,8 +601,8 @@ int riscv_cpu_mirq_pending(CPURISCVState *env); int riscv_cpu_sirq_pending(CPURISCVState *env); int riscv_cpu_vsirq_pending(CPURISCVState *env); bool riscv_cpu_fp_enabled(CPURISCVState *env); -target_ulong riscv_cpu_get_geilen(CPURISCVState *env); -void riscv_cpu_set_geilen(CPURISCVState *env, target_ulong geilen); +uint8_t riscv_cpu_get_geilen(CPURISCVState *env); +void riscv_cpu_set_geilen(CPURISCVState *env, uint8_t geilen); bool riscv_cpu_vector_enabled(CPURISCVState *env); void riscv_cpu_set_virt_enabled(CPURISCVState *env, bool enable); int riscv_env_mmu_index(CPURISCVState *env, bool ifetch); diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index a57f33b3cb..c5e94359e4 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -662,7 +662,7 @@ void riscv_cpu_swap_hypervisor_regs(CPURISCVState *env) } } =20 -target_ulong riscv_cpu_get_geilen(CPURISCVState *env) +uint8_t riscv_cpu_get_geilen(CPURISCVState *env) { if (!riscv_has_ext(env, RVH)) { return 0; @@ -671,7 +671,7 @@ target_ulong riscv_cpu_get_geilen(CPURISCVState *env) return env->geilen; } =20 -void riscv_cpu_set_geilen(CPURISCVState *env, target_ulong geilen) +void riscv_cpu_set_geilen(CPURISCVState *env, uint8_t geilen) { if (!riscv_has_ext(env, RVH)) { return; diff --git a/target/riscv/machine.c b/target/riscv/machine.c index a3d5811653..52b49c5f45 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -91,8 +91,8 @@ static const VMStateDescription vmstate_hyper =3D { VMSTATE_UINT64(env.htval, RISCVCPU), VMSTATE_UINT64(env.htinst, RISCVCPU), VMSTATE_UINT64(env.hgatp, RISCVCPU), - VMSTATE_UINTTL(env.hgeie, RISCVCPU), - VMSTATE_UINTTL(env.hgeip, RISCVCPU), + VMSTATE_UINT64(env.hgeie, RISCVCPU), + VMSTATE_UINT64(env.hgeip, RISCVCPU), VMSTATE_UINT64(env.hvien, RISCVCPU), VMSTATE_UINT64(env.hvip, RISCVCPU), VMSTATE_UINT64(env.htimedelta, RISCVCPU), --=20 2.51.0 From nobody Sun Sep 28 15:28:22 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1758698957; cv=none; d=zohomail.com; s=zohoarc; b=noGyJ8LSrjdVOZggO8yZjzNOzoUSq/apA8Yqvr2sapev0mt9O88IyhK/a1BJ25V+Gud0hmi2xc5wh6l+2fUUSQrgZ79y4fn0b5v61y5myYml8qKo4RrbPaNt/Ijw5kVlI61fDecbb8NGwDsV0FbYngdXkp6T6tOYWYYt9hbiJIk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758698957; 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:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=iC6P4aYMgMNTdnaZjEtgBllaPFKKCOxhM0zPg+j3TFc=; b=nfhYnPcA5j1LF1lu2/velh6BClzc0dBQzGLDxb4y7kRvVpuW5dIJaqljLFDbKSFZtxqaS71z86oKNAwJjlz7OpDBYf6kO9ypF2HTWoKuXyafVHVNx35fakqpaYKD9r4/GWuDQ5brKmuKmC+9YhGSFjyhZEJ4RR5MyoVP/0/v2mA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1758698957110781.832485380326; Wed, 24 Sep 2025 00:29:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1Jnm-0005rt-Lm; Wed, 24 Sep 2025 03:20:34 -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 1v1JnZ-0005lP-KA for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:23 -0400 Received: from rev.ng ([94.130.142.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v1JnQ-0003SZ-Bb for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive:List-Unsubscribe:List-Unsubscribe-Post: List-Help; bh=iC6P4aYMgMNTdnaZjEtgBllaPFKKCOxhM0zPg+j3TFc=; b=aqlHRHrVqP7S0/p PFdoSAI6VxX9H4PfktHneWgAuZ9zmvAKEFbj7BArBK/3f3VV5yXx/Ue5vOFApKs1EdjmsYoc1gq9B lDCTaFoIk/g6YW+0stdsZnlA4K6d0WxLcHDzbqjE0FnLNz8KKy3QP6WVHSkLOdQNXzdAXt+muqy7V 6E=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com Subject: [RFC PATCH 23/34] target/riscv: Fix size of [m|s|vs]iselect fields Date: Wed, 24 Sep 2025 09:21:13 +0200 Message-ID: <20250924072124.6493-24-anjo@rev.ng> In-Reply-To: <20250924072124.6493-1-anjo@rev.ng> References: <20250924072124.6493-1-anjo@rev.ng> 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=94.130.142.21; envelope-from=anjo@rev.ng; helo=rev.ng 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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: , Reply-to: Anton Johansson From: Anton Johansson via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758698958059116601 Content-Type: text/plain; charset="utf-8" [m|s|vs]iselect are defined in version 20250508 of the privileged specification to be XLEN in size, however QEMU only ever uses at most 16 bits of these fields, so fix them to 16. Update relevant function arguments. Signed-off-by: Anton Johansson --- target/riscv/cpu.h | 6 +++--- target/riscv/csr.c | 32 ++++++++++++++++---------------- target/riscv/machine.c | 6 +++--- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 3477e6dd1e..8ca01764fa 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -336,8 +336,8 @@ struct CPUArchState { uint8_t siprio[64]; =20 /* AIA CSRs */ - target_ulong miselect; - target_ulong siselect; + uint16_t miselect; + uint16_t siselect; uint64_t mvien; uint64_t mvip; =20 @@ -383,7 +383,7 @@ struct CPUArchState { uint64_t vsatp; =20 /* AIA VS-mode CSRs */ - target_ulong vsiselect; + uint16_t vsiselect; =20 uint64_t mtval2; uint64_t mtinst; diff --git a/target/riscv/csr.c b/target/riscv/csr.c index a471e59f2d..5db6780b2d 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -2403,7 +2403,7 @@ static RISCVException rmw_xiselect(CPURISCVState *env= , int csrno, target_ulong *val, target_ulong new_val, target_ulong wr_mask) { - target_ulong *iselect; + uint16_t *iselect; int ret; =20 ret =3D smstateen_acc_ok(env, 0, SMSTATEEN0_SVSLCT); @@ -2446,18 +2446,18 @@ static RISCVException rmw_xiselect(CPURISCVState *e= nv, int csrno, return RISCV_EXCP_NONE; } =20 -static bool xiselect_aia_range(target_ulong isel) +static bool xiselect_aia_range(uint16_t isel) { return (ISELECT_IPRIO0 <=3D isel && isel <=3D ISELECT_IPRIO15) || (ISELECT_IMSIC_FIRST <=3D isel && isel <=3D ISELECT_IMSIC_LAST); } =20 -static bool xiselect_cd_range(target_ulong isel) +static bool xiselect_cd_range(uint16_t isel) { return (ISELECT_CD_FIRST <=3D isel && isel <=3D ISELECT_CD_LAST); } =20 -static bool xiselect_ctr_range(int csrno, target_ulong isel) +static bool xiselect_ctr_range(int csrno, uint16_t isel) { /* MIREG-MIREG6 for the range 0x200-0x2ff are not used by CTR. */ return CTR_ENTRIES_FIRST <=3D isel && isel <=3D CTR_ENTRIES_LAST && @@ -2465,7 +2465,7 @@ static bool xiselect_ctr_range(int csrno, target_ulon= g isel) } =20 static int rmw_iprio(target_ulong xlen, - target_ulong iselect, uint8_t *iprio, + uint16_t iselect, uint8_t *iprio, target_ulong *val, target_ulong new_val, target_ulong wr_mask, int ext_irq_no) { @@ -2509,7 +2509,7 @@ static int rmw_iprio(target_ulong xlen, return 0; } =20 -static int rmw_ctrsource(CPURISCVState *env, int isel, target_ulong *val, +static int rmw_ctrsource(CPURISCVState *env, uint16_t isel, target_ulong *= val, target_ulong new_val, target_ulong wr_mask) { /* @@ -2548,7 +2548,7 @@ static int rmw_ctrsource(CPURISCVState *env, int isel= , target_ulong *val, return 0; } =20 -static int rmw_ctrtarget(CPURISCVState *env, int isel, target_ulong *val, +static int rmw_ctrtarget(CPURISCVState *env, uint16_t isel, target_ulong *= val, target_ulong new_val, target_ulong wr_mask) { /* @@ -2587,7 +2587,7 @@ static int rmw_ctrtarget(CPURISCVState *env, int isel= , target_ulong *val, return 0; } =20 -static int rmw_ctrdata(CPURISCVState *env, int isel, target_ulong *val, +static int rmw_ctrdata(CPURISCVState *env, uint16_t isel, target_ulong *va= l, target_ulong new_val, target_ulong wr_mask) { /* @@ -2628,7 +2628,7 @@ static int rmw_ctrdata(CPURISCVState *env, int isel, = target_ulong *val, } =20 static RISCVException rmw_xireg_aia(CPURISCVState *env, int csrno, - target_ulong isel, target_ulong *val, + uint16_t isel, target_ulong *val, target_ulong new_val, target_ulong wr_mask) { bool virt =3D false, isel_reserved =3D false; @@ -2708,12 +2708,12 @@ done: } =20 static int rmw_xireg_cd(CPURISCVState *env, int csrno, - target_ulong isel, target_ulong *val, + uint16_t isel, target_ulong *val, target_ulong new_val, target_ulong wr_mask) { int ret =3D -EINVAL; - int ctr_index =3D isel - ISELECT_CD_FIRST; - int isel_hpm_start =3D ISELECT_CD_FIRST + 3; + uint16_t ctr_index =3D isel - ISELECT_CD_FIRST; + uint16_t isel_hpm_start =3D ISELECT_CD_FIRST + 3; =20 if (!riscv_cpu_cfg(env)->ext_smcdeleg || !riscv_cpu_cfg(env)->ext_sscc= fg) { ret =3D RISCV_EXCP_ILLEGAL_INST; @@ -2780,7 +2780,7 @@ done: } =20 static int rmw_xireg_ctr(CPURISCVState *env, int csrno, - target_ulong isel, target_ulong *val, + uint16_t isel, target_ulong *val, target_ulong new_val, target_ulong wr_mask) { if (!riscv_cpu_cfg(env)->ext_smctr && !riscv_cpu_cfg(env)->ext_ssctr) { @@ -2808,7 +2808,7 @@ static int rmw_xireg_ctr(CPURISCVState *env, int csrn= o, * extension using csrind should be implemented here. */ static int rmw_xireg_csrind(CPURISCVState *env, int csrno, - target_ulong isel, target_ulong *val, + uint16_t isel, target_ulong *val, target_ulong new_val, target_ulong wr_mask) { bool virt =3D csrno =3D=3D CSR_VSIREG ? true : false; @@ -2838,7 +2838,7 @@ static int rmw_xiregi(CPURISCVState *env, int csrno, = target_ulong *val, target_ulong new_val, target_ulong wr_mask) { int ret =3D -EINVAL; - target_ulong isel; + uint16_t isel; =20 ret =3D smstateen_acc_ok(env, 0, SMSTATEEN0_SVSLCT); if (ret !=3D RISCV_EXCP_NONE) { @@ -2869,7 +2869,7 @@ static RISCVException rmw_xireg(CPURISCVState *env, i= nt csrno, target_ulong wr_mask) { int ret =3D -EINVAL; - target_ulong isel; + uint16_t isel; =20 ret =3D smstateen_acc_ok(env, 0, SMSTATEEN0_SVSLCT); if (ret !=3D RISCV_EXCP_NONE) { diff --git a/target/riscv/machine.c b/target/riscv/machine.c index 52b49c5f45..a18bcdf13e 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -108,7 +108,7 @@ static const VMStateDescription vmstate_hyper =3D { VMSTATE_UINT64(env.vscause, RISCVCPU), VMSTATE_UINT64(env.vstval, RISCVCPU), VMSTATE_UINT64(env.vsatp, RISCVCPU), - VMSTATE_UINTTL(env.vsiselect, RISCVCPU), + VMSTATE_UINT16(env.vsiselect, RISCVCPU), VMSTATE_UINT64(env.vsie, RISCVCPU), =20 VMSTATE_UINT64(env.mtval2, RISCVCPU), @@ -442,8 +442,8 @@ const VMStateDescription vmstate_riscv_cpu =3D { VMSTATE_UINT64(env.mepc, RISCVCPU), VMSTATE_UINT64(env.mcause, RISCVCPU), VMSTATE_UINT64(env.mtval, RISCVCPU), - VMSTATE_UINTTL(env.miselect, RISCVCPU), - VMSTATE_UINTTL(env.siselect, RISCVCPU), + VMSTATE_UINT16(env.miselect, RISCVCPU), + VMSTATE_UINT16(env.siselect, RISCVCPU), VMSTATE_UINT32(env.scounteren, RISCVCPU), VMSTATE_UINT32(env.mcounteren, RISCVCPU), VMSTATE_UINT32(env.scountinhibit, RISCVCPU), --=20 2.51.0 From nobody Sun Sep 28 15:28:22 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1758698941; cv=none; d=zohomail.com; s=zohoarc; b=AZ6ETxDPeEzTgOuO1VV51eA4242g5Vt2ZbB8sNfXx8NQvodl6MJkOU5LN8uxknT7nwZd8A8qTZLVPG57palLBGE4mLGv1LXz/Dm4m0Ei2mJLoTeLs2LdRtF0AV5xWbAAiFrb+iynsC7jw+Zx18ylkKH7F0s97Gd6Kz29a+pW6oA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758698941; 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:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=peqAyKMiYbZr6gvwaAolHm42N25xiC9f2kDM2S0sjp4=; b=OqHI52h141eeeiknoBW4/NtOFC/Iuys+81hi9W6yd/dgIPXz3cPzK+cUK3P/qMGwZK6bLl/LyTf5Ope/KkmMLP8ctky4UHlWKxuRHVUnTzu0BdeW6L5mzZuTU/s2KkFpzoOPyikxZ/gOX1lWkfXe3G7lNDSE7lfBR2MQIoPcyyA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1758698941951908.2206765432959; Wed, 24 Sep 2025 00:29:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1Jnl-0005r1-O6; Wed, 24 Sep 2025 03:20:33 -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 1v1JnZ-0005lT-La for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:23 -0400 Received: from rev.ng ([94.130.142.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v1JnR-0003Sm-5V for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive:List-Unsubscribe:List-Unsubscribe-Post: List-Help; bh=peqAyKMiYbZr6gvwaAolHm42N25xiC9f2kDM2S0sjp4=; b=TkANn3PfKH9PfnJ uD8R0Ql06IuSYoJ5ohLmbfwFxNPQMpJuXWxiXV7GDAESWklKqLy642ttBdvMx5zASuh7agRc/cPdU d385sq//NHWRQBUhZonbRzcZGZWrGyRxCXGYSBPrsFJmAW8sCOwgYMmFLFSUtJ3LnOtFAenC2fhlo KM=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com Subject: [RFC PATCH 24/34] target/riscv: Fix arguments to board IMSIC emulation callbacks Date: Wed, 24 Sep 2025 09:21:14 +0200 Message-ID: <20250924072124.6493-25-anjo@rev.ng> In-Reply-To: <20250924072124.6493-1-anjo@rev.ng> References: <20250924072124.6493-1-anjo@rev.ng> 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=94.130.142.21; envelope-from=anjo@rev.ng; helo=rev.ng 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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: , Reply-to: Anton Johansson From: Anton Johansson via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758698944183116600 Content-Type: text/plain; charset="utf-8" In hw/ the relevant RISCVIMSICState fields eidelivery, eithreshold, eistate are uint32_t. Signed-off-by: Anton Johansson --- target/riscv/cpu.h | 42 ++++++++++++++++++++------------------- hw/intc/riscv_imsic.c | 34 +++++++++++++++---------------- target/riscv/cpu_helper.c | 12 ++++------- target/riscv/csr.c | 24 ++++++++++++---------- 4 files changed, 57 insertions(+), 55 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 8ca01764fa..b8e62a13eb 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -193,6 +193,24 @@ FIELD(VTYPE, VMA, 7, 1) FIELD(VTYPE, VEDIV, 8, 2) FIELD(VTYPE, RESERVED, 10, sizeof(uint64_t) * 8 - 11) =20 +#ifndef CONFIG_USER_ONLY +/* machine specific AIA ireg read-modify-write callback */ +#define AIA_MAKE_IREG(__isel, __priv, __virt, __vgein, __xlen) = \ + ((uint32_t)((((__xlen) & 0xff) << 24) | = \ + (((__vgein) & 0x3f) << 20) | = \ + (((__virt) & 0x1) << 18) | = \ + (((__priv) & 0x3) << 16) | = \ + (__isel & 0xffff))) +#define AIA_IREG_ISEL(__ireg) ((__ireg) & 0xffff) +#define AIA_IREG_PRIV(__ireg) (((__ireg) >> 16) & 0x3) +#define AIA_IREG_VIRT(__ireg) (((__ireg) >> 18) & 0x1) +#define AIA_IREG_VGEIN(__ireg) (((__ireg) >> 20) & 0x3f) +#define AIA_IREG_XLEN(__ireg) (((__ireg) >> 24) & 0xff) + +typedef int aia_ireg_rmw_fn(void *arg, uint32_t reg, uint64_t *val, + uint64_t new_val, uint64_t write_mask); +#endif + typedef struct PMUCTRState { /* Current value of a counter */ uint64_t mhpmcounter_val; @@ -458,20 +476,8 @@ struct CPUArchState { void *rdtime_fn_arg; =20 /* machine specific AIA ireg read-modify-write callback */ -#define AIA_MAKE_IREG(__isel, __priv, __virt, __vgein, __xlen) \ - ((((__xlen) & 0xff) << 24) | \ - (((__vgein) & 0x3f) << 20) | \ - (((__virt) & 0x1) << 18) | \ - (((__priv) & 0x3) << 16) | \ - (__isel & 0xffff)) -#define AIA_IREG_ISEL(__ireg) ((__ireg) & 0xffff) -#define AIA_IREG_PRIV(__ireg) (((__ireg) >> 16) & 0x3) -#define AIA_IREG_VIRT(__ireg) (((__ireg) >> 18) & 0x1) -#define AIA_IREG_VGEIN(__ireg) (((__ireg) >> 20) & 0x3f) -#define AIA_IREG_XLEN(__ireg) (((__ireg) >> 24) & 0xff) - int (*aia_ireg_rmw_fn[4])(void *arg, target_ulong reg, - target_ulong *val, target_ulong new_val, target_ulong write_mask); - void *aia_ireg_rmw_fn_arg[4]; + aia_ireg_rmw_fn *aia_ireg_rmw_cb[4]; + void *aia_ireg_rmw_cb_arg[4]; =20 /* True if in debugger mode. */ bool debugger; @@ -638,12 +644,8 @@ void riscv_cpu_interrupt(CPURISCVState *env); #define BOOL_TO_MASK(x) (-!!(x)) /* helper for riscv_cpu_update_mip value = */ void riscv_cpu_set_rdtime_fn(CPURISCVState *env, uint64_t (*fn)(void *), void *arg); -void riscv_cpu_set_aia_ireg_rmw_fn(CPURISCVState *env, uint32_t priv, - int (*rmw_fn)(void *arg, - target_ulong reg, - target_ulong *val, - target_ulong new_val, - target_ulong write_mask), +void riscv_cpu_set_aia_ireg_rmw_cb(CPURISCVState *env, uint32_t priv, + aia_ireg_rmw_fn *rmw_fn, void *rmw_fn_arg); =20 RISCVException smstateen_acc_ok(CPURISCVState *env, int index, uint64_t bi= t); diff --git a/hw/intc/riscv_imsic.c b/hw/intc/riscv_imsic.c index 6174e1a05d..9274a1e842 100644 --- a/hw/intc/riscv_imsic.c +++ b/hw/intc/riscv_imsic.c @@ -88,11 +88,11 @@ static void riscv_imsic_update(RISCVIMSICState *imsic, = uint32_t page) } =20 static int riscv_imsic_eidelivery_rmw(RISCVIMSICState *imsic, uint32_t pag= e, - target_ulong *val, - target_ulong new_val, - target_ulong wr_mask) + uint64_t *val, + uint64_t new_val, + uint64_t wr_mask) { - target_ulong old_val =3D imsic->eidelivery[page]; + uint32_t old_val =3D imsic->eidelivery[page]; =20 if (val) { *val =3D old_val; @@ -106,11 +106,11 @@ static int riscv_imsic_eidelivery_rmw(RISCVIMSICState= *imsic, uint32_t page, } =20 static int riscv_imsic_eithreshold_rmw(RISCVIMSICState *imsic, uint32_t pa= ge, - target_ulong *val, - target_ulong new_val, - target_ulong wr_mask) + uint64_t *val, + uint64_t new_val, + uint64_t wr_mask) { - target_ulong old_val =3D imsic->eithreshold[page]; + uint32_t old_val =3D imsic->eithreshold[page]; =20 if (val) { *val =3D old_val; @@ -124,8 +124,8 @@ static int riscv_imsic_eithreshold_rmw(RISCVIMSICState = *imsic, uint32_t page, } =20 static int riscv_imsic_topei_rmw(RISCVIMSICState *imsic, uint32_t page, - target_ulong *val, target_ulong new_val, - target_ulong wr_mask) + uint64_t *val, uint64_t new_val, + uint64_t wr_mask) { uint32_t base, topei =3D riscv_imsic_topei(imsic, page); =20 @@ -149,11 +149,11 @@ static int riscv_imsic_topei_rmw(RISCVIMSICState *ims= ic, uint32_t page, =20 static int riscv_imsic_eix_rmw(RISCVIMSICState *imsic, uint32_t xlen, uint32_t page, - uint32_t num, bool pend, target_ulong *val, - target_ulong new_val, target_ulong wr_mask) + uint32_t num, bool pend, uint64_t *val, + uint64_t new_val, uint64_t wr_mask) { uint32_t i, base, prev; - target_ulong mask; + uint64_t mask; uint32_t state =3D (pend) ? IMSIC_EISTATE_PENDING : IMSIC_EISTATE_ENAB= LED; =20 if (xlen !=3D 32) { @@ -178,7 +178,7 @@ static int riscv_imsic_eix_rmw(RISCVIMSICState *imsic, continue; } =20 - mask =3D (target_ulong)1 << i; + mask =3D 1ull << i; if (wr_mask & mask) { if (new_val & mask) { prev =3D qatomic_fetch_or(&imsic->eistate[base + i], state= ); @@ -197,8 +197,8 @@ static int riscv_imsic_eix_rmw(RISCVIMSICState *imsic, return 0; } =20 -static int riscv_imsic_rmw(void *arg, target_ulong reg, target_ulong *val, - target_ulong new_val, target_ulong wr_mask) +static int riscv_imsic_rmw(void *arg, uint32_t reg, uint64_t *val, + uint64_t new_val, uint64_t wr_mask) { RISCVIMSICState *imsic =3D arg; uint32_t isel, priv, virt, vgein, xlen, page; @@ -383,7 +383,7 @@ static void riscv_imsic_realize(DeviceState *dev, Error= **errp) } =20 if (!kvm_irqchip_in_kernel()) { - riscv_cpu_set_aia_ireg_rmw_fn(env, (imsic->mmode) ? PRV_M : PR= V_S, + riscv_cpu_set_aia_ireg_rmw_cb(env, (imsic->mmode) ? PRV_M : PR= V_S, riscv_imsic_rmw, imsic); } } diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index c5e94359e4..2945a89a9c 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -766,17 +766,13 @@ void riscv_cpu_set_rdtime_fn(CPURISCVState *env, uint= 64_t (*fn)(void *), env->rdtime_fn_arg =3D arg; } =20 -void riscv_cpu_set_aia_ireg_rmw_fn(CPURISCVState *env, uint32_t priv, - int (*rmw_fn)(void *arg, - target_ulong reg, - target_ulong *val, - target_ulong new_val, - target_ulong write_mask), +void riscv_cpu_set_aia_ireg_rmw_cb(CPURISCVState *env, uint32_t priv, + aia_ireg_rmw_fn *rmw_fn, void *rmw_fn_arg) { if (priv <=3D PRV_M) { - env->aia_ireg_rmw_fn[priv] =3D rmw_fn; - env->aia_ireg_rmw_fn_arg[priv] =3D rmw_fn_arg; + env->aia_ireg_rmw_cb[priv] =3D rmw_fn; + env->aia_ireg_rmw_cb_arg[priv] =3D rmw_fn_arg; } } =20 diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 5db6780b2d..f73dfbe78b 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -2635,6 +2635,7 @@ static RISCVException rmw_xireg_aia(CPURISCVState *en= v, int csrno, int ret =3D -EINVAL; uint8_t *iprio; target_ulong priv, vgein; + uint64_t wide_val; =20 /* VS-mode CSR number passed in has already been translated */ switch (csrno) { @@ -2679,16 +2680,17 @@ static RISCVException rmw_xireg_aia(CPURISCVState *= env, int csrno, } } else if (ISELECT_IMSIC_FIRST <=3D isel && isel <=3D ISELECT_IMSIC_LA= ST) { /* IMSIC registers only available when machine implements it. */ - if (env->aia_ireg_rmw_fn[priv]) { + if (env->aia_ireg_rmw_cb[priv]) { /* Selected guest interrupt file should not be zero */ if (virt && (!vgein || env->geilen < vgein)) { goto done; } /* Call machine specific IMSIC register emulation */ - ret =3D env->aia_ireg_rmw_fn[priv](env->aia_ireg_rmw_fn_arg[pr= iv], + ret =3D env->aia_ireg_rmw_cb[priv](env->aia_ireg_rmw_cb_arg[pr= iv], AIA_MAKE_IREG(isel, priv, virt, vgein, riscv_cpu_mxl_bits(env)), - val, new_val, wr_mask); + &wide_val, new_val, wr_mask); + *val =3D wide_val; } } else { isel_reserved =3D true; @@ -2920,6 +2922,7 @@ static RISCVException rmw_xtopei(CPURISCVState *env, = int csrno, bool virt; int ret =3D -EINVAL; target_ulong priv, vgein; + uint64_t wide_val; =20 /* Translate CSR number for VS-mode */ csrno =3D aia_xlate_vs_csrno(env, csrno); @@ -2945,7 +2948,7 @@ static RISCVException rmw_xtopei(CPURISCVState *env, = int csrno, }; =20 /* IMSIC CSRs only available when machine implements IMSIC. */ - if (!env->aia_ireg_rmw_fn[priv]) { + if (!env->aia_ireg_rmw_cb[priv]) { goto done; } =20 @@ -2958,10 +2961,11 @@ static RISCVException rmw_xtopei(CPURISCVState *env= , int csrno, } =20 /* Call machine specific IMSIC register emulation for TOPEI */ - ret =3D env->aia_ireg_rmw_fn[priv](env->aia_ireg_rmw_fn_arg[priv], + ret =3D env->aia_ireg_rmw_cb[priv](env->aia_ireg_rmw_cb_arg[priv], AIA_MAKE_IREG(ISELECT_IMSIC_TOPEI, priv, virt, vgein, riscv_cpu_mxl_bits(env)), - val, new_val, wr_mask); + &wide_val, new_val, wr_mask); + *val =3D wide_val; =20 done: if (ret) { @@ -4426,7 +4430,7 @@ static RISCVException read_vstopi(CPURISCVState *env,= int csrno, target_ulong *val) { int irq, ret; - target_ulong topei; + uint64_t topei =3D 0; uint64_t vseip, vsgein; uint32_t iid, iprio, hviid, hviprio, gein; uint32_t s, scount =3D 0, siid[VSTOPI_NUM_SRCS], siprio[VSTOPI_NUM_SRC= S]; @@ -4441,13 +4445,13 @@ static RISCVException read_vstopi(CPURISCVState *en= v, int csrno, if (gein <=3D env->geilen && vseip) { siid[scount] =3D IRQ_S_EXT; siprio[scount] =3D IPRIO_MMAXIPRIO + 1; - if (env->aia_ireg_rmw_fn[PRV_S]) { + if (env->aia_ireg_rmw_cb[PRV_S]) { /* * Call machine specific IMSIC register emulation for * reading TOPEI. */ - ret =3D env->aia_ireg_rmw_fn[PRV_S]( - env->aia_ireg_rmw_fn_arg[PRV_S], + ret =3D env->aia_ireg_rmw_cb[PRV_S]( + env->aia_ireg_rmw_cb_arg[PRV_S], AIA_MAKE_IREG(ISELECT_IMSIC_TOPEI, PRV_S, true, ge= in, riscv_cpu_mxl_bits(env)), &topei, 0, 0); --=20 2.51.0 From nobody Sun Sep 28 15:28:22 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1758698780; cv=none; d=zohomail.com; s=zohoarc; b=K393OLD+sqp3IrCoj9fjPNvwqhqCM/NnMoB77fqMuuVlfmOQWjToev+NHaVJFuhdzWje+ORUuwprHBnAEYVGXc25UCh0l/RbycT/XijK1Bbhd8WBN1YwK/JNXH6eFT+FJVFFJJJe0BjM9aslK2YOJft2Ki7jhUZsKDsKUWDnAbM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758698780; 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:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=AcFO7glU1JYUKVAUaVYHg0PTz3n4bHnE4O0FI7POgPs=; b=LX739wGN+QQzxuUJhbj99Mmbd3LqucoWt+Xfr8du6+EnC2yKZchqNpxC3c1jn3gHpSOgaXFUUkS9zr2sQrcPyQd3GsXwKx6QqhisbIYBLhXV7wTD8JU4FJnOtrMs8aAbn00vvzZU/iaCIrI4jWtswrzo5lVarBooJGw6r0vYDBg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1758698780724612.6125581844883; Wed, 24 Sep 2025 00:26:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1Jno-0005sd-Lt; Wed, 24 Sep 2025 03:20:36 -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 1v1Jnd-0005nb-Bs for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:31 -0400 Received: from rev.ng ([94.130.142.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v1JnT-0003UE-9l for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive:List-Unsubscribe:List-Unsubscribe-Post: List-Help; bh=AcFO7glU1JYUKVAUaVYHg0PTz3n4bHnE4O0FI7POgPs=; b=xQE/FjfOa1UUqm6 5stLgjWqDXCoq2v5SWbTtRCD9iPp6EbhJjENSmyzTtZzpOyo4gggj1iOivExgkllfm2wIr3wtJqIm nRCyb1qJX8bafsWLQL2gFxa4joXcFbPBDI0MqA0ViuLNJGRV3qJTId8DfbpF5A/tDOntwSipd1LHR 00=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com Subject: [RFC PATCH 25/34] target/riscv: Fix size of irq_overflow_left Date: Wed, 24 Sep 2025 09:21:15 +0200 Message-ID: <20250924072124.6493-26-anjo@rev.ng> In-Reply-To: <20250924072124.6493-1-anjo@rev.ng> References: <20250924072124.6493-1-anjo@rev.ng> 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=94.130.142.21; envelope-from=anjo@rev.ng; helo=rev.ng 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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: , Reply-to: Anton Johansson From: Anton Johansson via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758698782300116600 Content-Type: text/plain; charset="utf-8" Fix to 64 bits to hold all relevant values. Signed-off-by: Anton Johansson --- target/riscv/cpu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index b8e62a13eb..853943f23f 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -217,7 +217,7 @@ typedef struct PMUCTRState { /* Snapshot values of counter */ uint64_t mhpmcounter_prev; /* Value beyond UINT32_MAX/UINT64_MAX before overflow interrupt trigge= r */ - target_ulong irq_overflow_left; + uint64_t irq_overflow_left; } PMUCTRState; =20 typedef struct PMUFixedCtrState { --=20 2.51.0 From nobody Sun Sep 28 15:28:22 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1758698532; cv=none; d=zohomail.com; s=zohoarc; b=iV37t0RTTftlNH3qV+SvrRtdo66mv0tXnt6Pp1/cCHG0WefYaeMmWdejiv54wdvcb2ZuMOcDWa45gMBWFW5O4BC72QkldxlHZKZfx+tJICeovOO5fyuy2tzarQ1KHMO/irC8L8RefjtZ0gzb+jKdcN5Csa74VAdpbIFjHb+q14g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758698532; 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:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=bHjTqSNfKt6RvY/kGigQwI0isRTaXI9w2YlyENeawF0=; b=PqPzV4lx3heD8fA29kKt8tnzzsXUC5qTwaxl6PXmpk0lmkPMYJJVC/M7Io95ZyZaNzeSLhLqhWar3ApI2ZAUL14l9WrEyHK7qezgKqOFCprHQellgV89UigcqsW29ldfLMFxv9n/+TWvx7jy3esJQmx+BFDtniK2IwePAchBkgA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1758698532086132.06017344601003; Wed, 24 Sep 2025 00:22:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1Jnr-0005vs-9O; Wed, 24 Sep 2025 03:20:40 -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 1v1Jnd-0005nc-EZ for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:31 -0400 Received: from rev.ng ([94.130.142.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v1JnZ-0003UO-5C for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive:List-Unsubscribe:List-Unsubscribe-Post: List-Help; bh=bHjTqSNfKt6RvY/kGigQwI0isRTaXI9w2YlyENeawF0=; b=e+OgrxO16lq/wMb B1/kWf1MIoj70MAOSIBnDzqEo67WBXodCjJiAMGmnRdlUKtKEWm257nCSIWRO1Or2aBONGYaDHXQ7 UCCIiPVAcu7LEnBlpdxKsC/JN8Q0YXwGmGV1h9WIVbaQn9apdoI8+evmtzExyu73MICX2s8un78vR iw=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com Subject: [RFC PATCH 26/34] target/riscv: Indent PMUFixedCtrState correctly Date: Wed, 24 Sep 2025 09:21:16 +0200 Message-ID: <20250924072124.6493-27-anjo@rev.ng> In-Reply-To: <20250924072124.6493-1-anjo@rev.ng> References: <20250924072124.6493-1-anjo@rev.ng> 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=94.130.142.21; envelope-from=anjo@rev.ng; helo=rev.ng 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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: , Reply-to: Anton Johansson From: Anton Johansson via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758698533816116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: Anton Johansson --- target/riscv/cpu.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 853943f23f..b9ca08d90a 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -221,12 +221,12 @@ typedef struct PMUCTRState { } PMUCTRState; =20 typedef struct PMUFixedCtrState { - /* Track cycle and icount for each privilege mode */ - uint64_t counter[4]; - uint64_t counter_prev[4]; - /* Track cycle and icount for each privilege mode when V =3D 1*/ - uint64_t counter_virt[2]; - uint64_t counter_virt_prev[2]; + /* Track cycle and icount for each privilege mode */ + uint64_t counter[4]; + uint64_t counter_prev[4]; + /* Track cycle and icount for each privilege mode when V =3D 1*/ + uint64_t counter_virt[2]; + uint64_t counter_virt_prev[2]; } PMUFixedCtrState; =20 struct CPUArchState { --=20 2.51.0 From nobody Sun Sep 28 15:28:22 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1758698836; cv=none; d=zohomail.com; s=zohoarc; b=kaca9epEplfYs53oxmQc7FQmJf8ctcLg+KwuvLHe7Or3OJBSyPzJtMV3FSwCnnrN1Wv6xrv6a/LARVNLDSsGoPKgnDB1pje0G/armXOwf+VyuS50PqtsYcXhFfbOOqagexSKfBS7bC6k9LU4C8jxOWSUyO7Pl5Z+4fBwOTnyD8U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758698836; 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:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=u6Q4jRfmF63IPhGXmsVHQd4CtZ0OTZw3MB7be6B0hTg=; b=fQLFUZ3cSjfDQ4TAp9JfLGCLbjliLr/3Ss+UcJNf5Vo9qYBOI/MRm8QZM5msJC6N0OvXVIOOA/F90tjSywMLFrt+fDuLFcuzd66XIbUmFLVb2R6gFNmlV6/FJwfAriu/jIdWuSEC77SsbUUplMU+Cvk0MS3zzIH1C58c+9ykt8k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1758698836114389.0850103508417; Wed, 24 Sep 2025 00:27:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1Jnp-0005tj-3Y; Wed, 24 Sep 2025 03:20:37 -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 1v1Jnd-0005nd-Jn for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:31 -0400 Received: from rev.ng ([94.130.142.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v1JnZ-0003fV-7e for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive:List-Unsubscribe:List-Unsubscribe-Post: List-Help; bh=u6Q4jRfmF63IPhGXmsVHQd4CtZ0OTZw3MB7be6B0hTg=; b=cdVZNQfQRGCRpsw pujANHOcG3TIdzB8IIlVy1eqL2rH9tLInMqauQkKoR2safHyUIw2C5iHi5uMXLd75YA5aj47/E6Nz eAnN1mHOQ6++h5F9ad4DEaREjowqLkdNql4arRT3pNMo/fuPsz58UPo26ecL5bug1cEqkshnebCFS e8=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com Subject: [RFC PATCH 27/34] target/riscv: Replace target_ulong in riscv_cpu_get_trap_name() Date: Wed, 24 Sep 2025 09:21:17 +0200 Message-ID: <20250924072124.6493-28-anjo@rev.ng> In-Reply-To: <20250924072124.6493-1-anjo@rev.ng> References: <20250924072124.6493-1-anjo@rev.ng> 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=94.130.142.21; envelope-from=anjo@rev.ng; helo=rev.ng 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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: , Reply-to: Anton Johansson From: Anton Johansson via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758698836914116600 Content-Type: text/plain; charset="utf-8" Fix cause argument to 64 bit to match env->mcause. Signed-off-by: Anton Johansson --- target/riscv/cpu.h | 2 +- target/riscv/cpu.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index b9ca08d90a..1498ae063e 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -593,7 +593,7 @@ extern const char * const riscv_int_regnames[]; extern const char * const riscv_int_regnamesh[]; extern const char * const riscv_fpr_regnames[]; =20 -const char *riscv_cpu_get_trap_name(target_ulong cause, bool async); +const char *riscv_cpu_get_trap_name(uint64_t cause, bool async); int riscv_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cs, int cpuid, DumpState *s); int riscv_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cs, diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 4e38487dca..5206abe640 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -348,7 +348,7 @@ static const char * const riscv_intr_names[] =3D { "reserved" }; =20 -const char *riscv_cpu_get_trap_name(target_ulong cause, bool async) +const char *riscv_cpu_get_trap_name(uint64_t cause, bool async) { if (async) { return (cause < ARRAY_SIZE(riscv_intr_names)) ? --=20 2.51.0 From nobody Sun Sep 28 15:28:22 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1758698818; cv=none; d=zohomail.com; s=zohoarc; b=JR1vte7u732fKdwt4BW5xqAJyl07kuInogReMqUNjBQdaIwoglMZlfgZOi62ZMUvAfSycLT1rMIU9A1ZYqCDVm0l3rB5tdwZNvBjabwpUn2mZHMy7/9/oUV5PAAg3Uy88lZfBKUB2tJNjslz1ERxlxmZdg2N5tI+HwQM7Kw+DxU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758698818; 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:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=ui9d7qGLrNXHd9ideOeuKiUKn3f8NG9mb5zPIxxyYtQ=; b=HM9jLu2skvvOgR5TCbeWn1N8YwtPLTYkkhsvmfODkc32HxIyWLSlNdN2tqw1NWg7yWIUBuI8Zcmrf8/D1DZVJT28uapJUL9/yYPNDpQ2974ic5k72y9Ll4gcbfJPSu/3sudKEI+KhLbK6eoquUrw8grwPk76OpCb39egj4KVXFg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1758698818078825.2433986879901; Wed, 24 Sep 2025 00:26:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1Jno-0005sR-0l; Wed, 24 Sep 2025 03:20:36 -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 1v1Jnh-0005pD-TG for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:32 -0400 Received: from rev.ng ([94.130.142.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v1JnZ-0003fm-7d for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive:List-Unsubscribe:List-Unsubscribe-Post: List-Help; bh=ui9d7qGLrNXHd9ideOeuKiUKn3f8NG9mb5zPIxxyYtQ=; b=aN9wrBeUSbxiwkO tV/Qu02uCt0Xb9H6Jkm/k6fDJmeWLx1DHohd8L9j1C2MJY8bJmCysJGjPL4kkjoZvfQYVDPQJ0xb+ VHtUZx1XBBXbL+rp6YLZO3G8oblyNT36BkNICK95VamJ9hm5KeLZbJaBRzovxAJBHpWrNSDUOH2cy 2k=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com Subject: [RFC PATCH 28/34] target/riscv: Replace target_ulong in riscv_ctr_add_entry() Date: Wed, 24 Sep 2025 09:21:18 +0200 Message-ID: <20250924072124.6493-29-anjo@rev.ng> In-Reply-To: <20250924072124.6493-1-anjo@rev.ng> References: <20250924072124.6493-1-anjo@rev.ng> 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=94.130.142.21; envelope-from=anjo@rev.ng; helo=rev.ng 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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: , Reply-to: Anton Johansson From: Anton Johansson via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758698818521116600 Content-Type: text/plain; charset="utf-8" Widen to 64 bits in size to hold all relevant values. Signed-off-by: Anton Johansson --- target/riscv/cpu.h | 2 +- target/riscv/cpu_helper.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 1498ae063e..592c741947 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -653,7 +653,7 @@ RISCVException smstateen_acc_ok(CPURISCVState *env, int= index, uint64_t bit); =20 void riscv_cpu_set_mode(CPURISCVState *env, uint8_t newpriv, bool virt_en); =20 -void riscv_ctr_add_entry(CPURISCVState *env, target_long src, target_long = dst, +void riscv_ctr_add_entry(CPURISCVState *env, uint64_t src, uint64_t dst, enum CTRType type, uint8_t prev_priv, bool prev_virt); void riscv_ctr_clear(CPURISCVState *env); =20 diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 2945a89a9c..4acfccc9d8 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -925,8 +925,8 @@ static bool riscv_ctr_check_xte(CPURISCVState *env, uin= t8_t src_prv, * entry =3D isel - CTR_ENTRIES_FIRST; * idx =3D (sctrstatus.WRPTR - entry - 1) & (depth - 1); */ -void riscv_ctr_add_entry(CPURISCVState *env, target_long src, target_long = dst, - enum CTRType type, uint8_t src_priv, bool src_virt) +void riscv_ctr_add_entry(CPURISCVState *env, uint64_t src, uint64_t dst, + enum CTRType type, uint8_t src_priv, bool src_vir= t) { bool tgt_virt =3D env->virt_enabled; uint64_t src_mask =3D riscv_ctr_priv_to_mask(src_priv, src_virt); --=20 2.51.0 From nobody Sun Sep 28 15:28:22 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1758698935; cv=none; d=zohomail.com; s=zohoarc; b=P6LvQQ+4Y4WwbbaZEH5UK1wSIHucyU4gWZL5DWyZQMNBr8M4O/jOcDhbK5CQNg159ni2rPqIdKMy+5gveAn6qD1VA+PntdGSLUdfRri/Xc33VUJ7qONRL5URwDBQY1GdBQ7WVFOUivlV76ejEHbXroNOQQlAfQoxIc17mZLsmiI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758698935; 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:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=sDybAYeeUsTQsbUo0pXvCjbSZzRWA1DwGfuoWsq/Zjo=; b=jB3W2evWAb4jiwxnJfnVFxjUUoD/77ZOm1s/kc0yNV1xxPDHTKQdPhilFY58Gaist7w22O4cp0QuqJGHLCmqBBtmqEreiT5i4g8AnBDDasXuD4razyV082cCWLAUExRShYzEtOaSXI89r0lXa58HkL2wI0L2+1ko3ECXLCuCee8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1758698935134316.8897398166861; Wed, 24 Sep 2025 00:28:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1Jnp-0005tk-75; Wed, 24 Sep 2025 03:20:37 -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 1v1Jnj-0005pi-PV for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:32 -0400 Received: from rev.ng ([94.130.142.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v1Jnc-0003gG-5D for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive:List-Unsubscribe:List-Unsubscribe-Post: List-Help; bh=sDybAYeeUsTQsbUo0pXvCjbSZzRWA1DwGfuoWsq/Zjo=; b=G95CjJhdKUXEFTx sI7f7a+Lgyi8F9UjwfwrFqTr8RK9ziU2U9ieVfDUqp2DHwua0sMdoK9llnLuLQSpi32PpQGzbbFj8 7VZCI5jg2UkpGJUMzjeapspHsXjYnZoNnNnpiD/8Bks5S6L+OPBSL8q7rsXVBPvn+PKWvcKiTUce2 XE=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com Subject: [RFC PATCH 29/34] target/riscv: Fix size of trigger data Date: Wed, 24 Sep 2025 09:21:19 +0200 Message-ID: <20250924072124.6493-30-anjo@rev.ng> In-Reply-To: <20250924072124.6493-1-anjo@rev.ng> References: <20250924072124.6493-1-anjo@rev.ng> 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=94.130.142.21; envelope-from=anjo@rev.ng; helo=rev.ng 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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: , Reply-to: Anton Johansson From: Anton Johansson via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758698935802116600 Content-Type: text/plain; charset="utf-8" mcontext is at most 14 bits in size with the H extension, fix to 16 bits. trigger_cur indexes into tdata*[RV_MAX_TRIGGERS] which holds 2 elements, fix to 8 bits. Signed-off-by: Anton Johansson --- target/riscv/cpu.h | 10 +++++----- target/riscv/machine.c | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 592c741947..f8ab66adb3 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -460,11 +460,11 @@ struct CPUArchState { target_ulong mseccfg; =20 /* trigger module */ - target_ulong trigger_cur; - target_ulong tdata1[RV_MAX_TRIGGERS]; - target_ulong tdata2[RV_MAX_TRIGGERS]; - target_ulong tdata3[RV_MAX_TRIGGERS]; - target_ulong mcontext; + uint16_t mcontext; + uint8_t trigger_cur; + uint64_t tdata1[RV_MAX_TRIGGERS]; + uint64_t tdata2[RV_MAX_TRIGGERS]; + uint64_t tdata3[RV_MAX_TRIGGERS]; struct CPUBreakpoint *cpu_breakpoint[RV_MAX_TRIGGERS]; struct CPUWatchpoint *cpu_watchpoint[RV_MAX_TRIGGERS]; QEMUTimer *itrigger_timer[RV_MAX_TRIGGERS]; diff --git a/target/riscv/machine.c b/target/riscv/machine.c index a18bcdf13e..72bc0b04b5 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -243,10 +243,10 @@ static const VMStateDescription vmstate_debug =3D { .needed =3D debug_needed, .post_load =3D debug_post_load, .fields =3D (const VMStateField[]) { - VMSTATE_UINTTL(env.trigger_cur, RISCVCPU), - VMSTATE_UINTTL_ARRAY(env.tdata1, RISCVCPU, RV_MAX_TRIGGERS), - VMSTATE_UINTTL_ARRAY(env.tdata2, RISCVCPU, RV_MAX_TRIGGERS), - VMSTATE_UINTTL_ARRAY(env.tdata3, RISCVCPU, RV_MAX_TRIGGERS), + VMSTATE_UINT8(env.trigger_cur, RISCVCPU), + VMSTATE_UINT64_ARRAY(env.tdata1, RISCVCPU, RV_MAX_TRIGGERS), + VMSTATE_UINT64_ARRAY(env.tdata2, RISCVCPU, RV_MAX_TRIGGERS), + VMSTATE_UINT64_ARRAY(env.tdata3, RISCVCPU, RV_MAX_TRIGGERS), VMSTATE_END_OF_LIST() } }; --=20 2.51.0 From nobody Sun Sep 28 15:28:22 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1758698651; cv=none; d=zohomail.com; s=zohoarc; b=IkBUheXW6MrC7g+KHZgIS5a9bfi2eFDCbXW/8NQm1gdxnovOesTgMSW9yyH6PDeeE3KuE5bTsI90WliHoOLb4LA8MfGoSQxcJSl3hZbDuGHb8Z7TXI3wTZmBmtQtRvxZOfIXyJ4ElflthByjHQtagw45sfO2SEsDLnGJv4KYbKE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758698651; 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:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=Sqz+ivCspogTyB/gCdvWNpQo0T3U3V/5KehjqwKx1ss=; b=dnvot6c4sbWU/WPOpgJaL+uQ6f1hNzciIjaoGB58V3Il8F3K83lrRlizH2Z4wCCqQ2a4FFVOMXV+3iV+aILwdNKUEGL44WL2aHZ9h/n2yjGjvoFc3JhTcYwTQR9OJfwVC4oQFjkIl3ORez5hqmOLUT8seHrXsKw7lfj1PDHJhlk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1758698651854913.4553678571162; Wed, 24 Sep 2025 00:24:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1Jnn-0005sA-Fk; Wed, 24 Sep 2025 03:20:35 -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 1v1Jnh-0005pE-Ti for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:32 -0400 Received: from rev.ng ([94.130.142.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v1Jnb-0003ge-LD for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive:List-Unsubscribe:List-Unsubscribe-Post: List-Help; bh=Sqz+ivCspogTyB/gCdvWNpQo0T3U3V/5KehjqwKx1ss=; b=DN1ZfxHJJy3+oWA pi1cFsUn6Ub84+SRqHUhq420LxzpIhOku66DdvzHXbGj+Uyhp+Ik6IJvfJCeYQX28DvPZDOBPzfLX zy67lQK2Ql7pIdZzhpnJGebsMe8Oqj3adD0Q4WG5laVbNBOXARqh6tubAwJ0sHukE75QlsrH1TBLV tY=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com Subject: [RFC PATCH 30/34] target/riscv: Fix size of mseccfg Date: Wed, 24 Sep 2025 09:21:20 +0200 Message-ID: <20250924072124.6493-31-anjo@rev.ng> In-Reply-To: <20250924072124.6493-1-anjo@rev.ng> References: <20250924072124.6493-1-anjo@rev.ng> 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=94.130.142.21; envelope-from=anjo@rev.ng; helo=rev.ng 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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: , Reply-to: Anton Johansson From: Anton Johansson via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758698652755116600 Content-Type: text/plain; charset="utf-8" mseccfg is defined in version 20250508 of the privileged specification to be 64 bits in size. Update relevant function arguments. Signed-off-by: Anton Johansson --- target/riscv/cpu.h | 2 +- target/riscv/pmp.h | 4 ++-- target/riscv/pmp.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index f8ab66adb3..4c90b8b035 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -457,7 +457,7 @@ struct CPUArchState { =20 /* physical memory protection */ pmp_table_t pmp_state; - target_ulong mseccfg; + uint64_t mseccfg; =20 /* trigger module */ uint16_t mcontext; diff --git a/target/riscv/pmp.h b/target/riscv/pmp.h index 271cf24169..e322904637 100644 --- a/target/riscv/pmp.h +++ b/target/riscv/pmp.h @@ -69,8 +69,8 @@ void pmpcfg_csr_write(CPURISCVState *env, uint32_t reg_in= dex, target_ulong val); target_ulong pmpcfg_csr_read(CPURISCVState *env, uint32_t reg_index); =20 -void mseccfg_csr_write(CPURISCVState *env, target_ulong val); -target_ulong mseccfg_csr_read(CPURISCVState *env); +void mseccfg_csr_write(CPURISCVState *env, uint64_t val); +uint64_t mseccfg_csr_read(CPURISCVState *env); =20 void pmpaddr_csr_write(CPURISCVState *env, uint32_t addr_index, target_ulong val); diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c index 72f1372a49..85199c7387 100644 --- a/target/riscv/pmp.c +++ b/target/riscv/pmp.c @@ -597,7 +597,7 @@ target_ulong pmpaddr_csr_read(CPURISCVState *env, uint3= 2_t addr_index) /* * Handle a write to a mseccfg CSR */ -void mseccfg_csr_write(CPURISCVState *env, target_ulong val) +void mseccfg_csr_write(CPURISCVState *env, uint64_t val) { int i; uint64_t mask =3D MSECCFG_MMWP | MSECCFG_MML; @@ -643,7 +643,7 @@ void mseccfg_csr_write(CPURISCVState *env, target_ulong= val) /* * Handle a read from a mseccfg CSR */ -target_ulong mseccfg_csr_read(CPURISCVState *env) +uint64_t mseccfg_csr_read(CPURISCVState *env) { trace_mseccfg_csr_read(env->mhartid, env->mseccfg); return env->mseccfg; --=20 2.51.0 From nobody Sun Sep 28 15:28:22 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1758698480; cv=none; d=zohomail.com; s=zohoarc; b=T2vKM/EMF44eSL1i0FNrU5Tv+eVZmCRzqpu7yofaeR1d6YA476nVsJ6KbBGHd5o4wsEyfZMr5r/KHqfl+qB/X4DbhmHof0l0WvdGk/HJ8RmobYitX8ijeL19pWCnN1KfnGYoR0crvb/IGh/w/GPBantCxDaC8r0xJbjOi1H2VKg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758698480; 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:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=I1gMG2L8YpYilfMkG81ggclFtIPYKdFhhQ3xAqN8STs=; b=kyQvsqFu8Sfuqdu9LpMz8E7QHqDxLtqhU5Z2O1QLsZmNxs7iEJpBfZyJO8sC68X61RotbAjEo1mf6sXC+JCkDF++Z+ZclIC87Q3g/3xArdvUHR1h+BcN9xajEoiDNASUNU3gJbQ1Nm5k20Jvw9F2fJ03b/O6OVjRoxSmUTaWo6Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1758698480702338.10653416346224; Wed, 24 Sep 2025 00:21:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1Jnq-0005tl-Dq; Wed, 24 Sep 2025 03:20:38 -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 1v1Jnm-0005rj-EA for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:34 -0400 Received: from rev.ng ([94.130.142.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v1Jnf-0003gx-EN for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive:List-Unsubscribe:List-Unsubscribe-Post: List-Help; bh=I1gMG2L8YpYilfMkG81ggclFtIPYKdFhhQ3xAqN8STs=; b=IOUmdr9QyRikf8H FZgPpE3KDNvh+WCWEqNkgPUem40lB/LD1NZTHWTtfRPX4gE8VxDkEwTL9NdfZ8ZKvhgjSoAbM86D/ nlAPZuN39NmHsahMxMJ3wSj9FBwkAU48nhxOojRml+vaqm5/4Iehc4TX4qStRsKAwRNMqxdG2q1AW 4w=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com Subject: [RFC PATCH 31/34] target/riscv: Move debug.h include away from cpu.h Date: Wed, 24 Sep 2025 09:21:21 +0200 Message-ID: <20250924072124.6493-32-anjo@rev.ng> In-Reply-To: <20250924072124.6493-1-anjo@rev.ng> References: <20250924072124.6493-1-anjo@rev.ng> 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=94.130.142.21; envelope-from=anjo@rev.ng; helo=rev.ng 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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: , Reply-to: Anton Johansson From: Anton Johansson via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758698481169116600 Content-Type: text/plain; charset="utf-8" All debug.h definitions except for RV_MAX_TRIGGERS are internal to target/riscv. Move RV_MAX_TRIGGERS to cpu.h and include debug.h from all translation units which relied on the cpu.h include. Signed-off-by: Anton Johansson --- target/riscv/cpu.h | 4 ++-- target/riscv/debug.h | 2 -- target/riscv/cpu.c | 3 +++ target/riscv/csr.c | 3 +++ target/riscv/debug.c | 1 + target/riscv/tcg/tcg-cpu.c | 1 + 6 files changed, 10 insertions(+), 4 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 4c90b8b035..2fe5cb211a 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -177,14 +177,14 @@ extern RISCVCPUImpliedExtsRule *riscv_multi_ext_impli= ed_rules[]; #define MAX_RISCV_PMPS (64) #define OLD_MAX_RISCV_PMPS (16) =20 -#if !defined(CONFIG_USER_ONLY) +#if !defined(CONFIG_LINUX_USER) #include "pmp.h" -#include "debug.h" #endif =20 #define RV_VLEN_MAX 1024 #define RV_MAX_MHPMEVENTS 32 #define RV_MAX_MHPMCOUNTERS 32 +#define RV_MAX_TRIGGERS 2 =20 FIELD(VTYPE, VLMUL, 0, 3) FIELD(VTYPE, VSEW, 3, 3) diff --git a/target/riscv/debug.h b/target/riscv/debug.h index f76b8f944a..d3aae619db 100644 --- a/target/riscv/debug.h +++ b/target/riscv/debug.h @@ -24,8 +24,6 @@ =20 #include "exec/breakpoint.h" =20 -#define RV_MAX_TRIGGERS 2 - /* register index of tdata CSRs */ enum { TDATA1 =3D 0, diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 5206abe640..246ec81beb 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -37,6 +37,9 @@ #include "kvm/kvm_riscv.h" #include "tcg/tcg-cpu.h" #include "tcg/tcg.h" +#if !defined(CONFIG_USER_ONLY) +#include "debug.h" +#endif =20 /* RISC-V CPU definitions */ static const char riscv_single_letter_exts[] =3D "IEMAFDQCBPVH"; diff --git a/target/riscv/csr.c b/target/riscv/csr.c index f73dfbe78b..b3c5b75aac 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -33,6 +33,9 @@ #include "qapi/error.h" #include "tcg/insn-start-words.h" #include "internals.h" +#if !defined(CONFIG_USER_ONLY) +#include "debug.h" +#endif #include =20 /* CSR function table public API */ diff --git a/target/riscv/debug.c b/target/riscv/debug.c index 5664466749..f5b2043405 100644 --- a/target/riscv/debug.c +++ b/target/riscv/debug.c @@ -27,6 +27,7 @@ #include "qemu/log.h" #include "qapi/error.h" #include "cpu.h" +#include "debug.h" #include "trace.h" #include "exec/helper-proto.h" #include "exec/watchpoint.h" diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c index f90abbc594..8e0e929aaa 100644 --- a/target/riscv/tcg/tcg-cpu.c +++ b/target/riscv/tcg/tcg-cpu.c @@ -37,6 +37,7 @@ #include "hw/boards.h" #include "system/tcg.h" #include "exec/icount.h" +#include "debug.h" #endif =20 /* Hash that stores user set extensions */ --=20 2.51.0 From nobody Sun Sep 28 15:28:22 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1758698939; cv=none; d=zohomail.com; s=zohoarc; b=d7q9GQQrhBDry3CkS2ieZSlCQWgnFh+qs7YtnodUQgJaFLPT5Nz+7WWTdH22iJdUYUazrAZz0tc98v19IyIY21g6HnxpWUlVeYZjpGaB8fVbpbGzMc6Tkbqb5Vm3S9FOamIiUX61jkjbIBaiHgOJMOMeZapopUB5C1GRPh4tDZU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758698939; 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:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=MNpjYgMF/EbsYxSaIdxv6ElSJE2S9U0Z43guSKBIDhI=; b=lH7PZxACkWWwlVRDBwMjAUPJ73TtyNPYn5tgGRwezKeq4mc4XrrRBNbn6LoJJo5JbsLNYtUf0755rraA8uH68+JoSx826orAMcgX2M966eQE2K4quNWeOv4A3XO5swham8apigdYfu8V/aWzCQ81plUiuYJZabZTN6r5vfmv5rY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1758698939863160.28255913500914; Wed, 24 Sep 2025 00:28:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1Jnp-0005ti-1C; Wed, 24 Sep 2025 03:20:37 -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 1v1Jnm-0005rk-Dr for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:34 -0400 Received: from rev.ng ([94.130.142.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v1Jnj-0003h9-0U for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive:List-Unsubscribe:List-Unsubscribe-Post: List-Help; bh=MNpjYgMF/EbsYxSaIdxv6ElSJE2S9U0Z43guSKBIDhI=; b=FJbvpxX4nynDXiB JNu3kUc6FDEANF/xRk2JqnaAIF59YX/GcCcf7vNV66Vs1zy4oaxsi6+va8RyMj41HkQCY4aV16mqH ZK9o7EeYyYgP8NgPwvPa35MvHWFMhsJPaAr05MEyqtQysQPjQpASYZ7IJo2Wc4xHrQW6BgtvPjSgD Bw=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com Subject: [RFC PATCH 32/34] target/riscv: Move CSR declarations to separate csr.h header Date: Wed, 24 Sep 2025 09:21:22 +0200 Message-ID: <20250924072124.6493-33-anjo@rev.ng> In-Reply-To: <20250924072124.6493-1-anjo@rev.ng> References: <20250924072124.6493-1-anjo@rev.ng> 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=94.130.142.21; envelope-from=anjo@rev.ng; helo=rev.ng 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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: , Reply-to: Anton Johansson From: Anton Johansson via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758698942272116600 Content-Type: text/plain; charset="utf-8" Most of these definitions save riscv_csrr, riscv_csrrw, riscv_csr_read, riscv_csr_write are only used in target/. Move declarations to a separate headers which will soon be made internal to target/. csr.h is temporarily included from cpu.h to not break includes from outside target/, this include will be removed in the following commit. Signed-off-by: Anton Johansson --- target/riscv/cpu.h | 82 +-------------------------------- target/riscv/csr.h | 94 ++++++++++++++++++++++++++++++++++++++ target/riscv/cpu.c | 1 + target/riscv/csr.c | 1 + target/riscv/gdbstub.c | 1 + target/riscv/kvm/kvm-cpu.c | 1 + target/riscv/op_helper.c | 1 + target/riscv/th_csr.c | 1 + 8 files changed, 101 insertions(+), 81 deletions(-) create mode 100644 target/riscv/csr.h diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 2fe5cb211a..a954605e83 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -849,75 +849,7 @@ RISCVPmPmm riscv_pm_get_pmm(CPURISCVState *env); RISCVPmPmm riscv_pm_get_virt_pmm(CPURISCVState *env); uint32_t riscv_pm_get_pmlen(RISCVPmPmm pmm); =20 -RISCVException riscv_csrr(CPURISCVState *env, int csrno, - target_ulong *ret_value); - -RISCVException riscv_csrrw(CPURISCVState *env, int csrno, - target_ulong *ret_value, target_ulong new_value, - target_ulong write_mask, uintptr_t ra); -RISCVException riscv_csrrw_debug(CPURISCVState *env, int csrno, - target_ulong *ret_value, - target_ulong new_value, - target_ulong write_mask); - -static inline void riscv_csr_write(CPURISCVState *env, int csrno, - target_ulong val) -{ - riscv_csrrw(env, csrno, NULL, val, MAKE_64BIT_MASK(0, TARGET_LONG_BITS= ), 0); -} - -static inline target_ulong riscv_csr_read(CPURISCVState *env, int csrno) -{ - target_ulong val =3D 0; - riscv_csrrw(env, csrno, &val, 0, 0, 0); - return val; -} - -typedef RISCVException (*riscv_csr_predicate_fn)(CPURISCVState *env, - int csrno); -typedef RISCVException (*riscv_csr_read_fn)(CPURISCVState *env, int csrno, - target_ulong *ret_value); -typedef RISCVException (*riscv_csr_write_fn)(CPURISCVState *env, int csrno, - target_ulong new_value, - uintptr_t ra); -typedef RISCVException (*riscv_csr_op_fn)(CPURISCVState *env, int csrno, - target_ulong *ret_value, - target_ulong new_value, - target_ulong write_mask); - -RISCVException riscv_csrr_i128(CPURISCVState *env, int csrno, - Int128 *ret_value); -RISCVException riscv_csrrw_i128(CPURISCVState *env, int csrno, - Int128 *ret_value, Int128 new_value, - Int128 write_mask, uintptr_t ra); - -typedef RISCVException (*riscv_csr_read128_fn)(CPURISCVState *env, int csr= no, - Int128 *ret_value); -typedef RISCVException (*riscv_csr_write128_fn)(CPURISCVState *env, int cs= rno, - Int128 new_value); - -typedef struct { - const char *name; - riscv_csr_predicate_fn predicate; - riscv_csr_read_fn read; - riscv_csr_write_fn write; - riscv_csr_op_fn op; - riscv_csr_read128_fn read128; - riscv_csr_write128_fn write128; - /* The default priv spec version should be PRIV_VERSION_1_10_0 (i.e 0)= */ - uint32_t min_priv_ver; -} riscv_csr_operations; - -struct RISCVCSR { - int csrno; - bool (*insertion_test)(RISCVCPU *cpu); - riscv_csr_operations csr_ops; -}; - -/* CSR function table constants */ -enum { - CSR_TABLE_SIZE =3D 0x1000 -}; +#include "csr.h" =20 /* * The event id are encoded based on the encoding specified in the @@ -961,23 +893,11 @@ void riscv_cpu_finalize_features(RISCVCPU *cpu, Error= **errp); void riscv_add_satp_mode_properties(Object *obj); bool riscv_cpu_accelerator_compatible(RISCVCPU *cpu); =20 -/* CSR function table */ -extern riscv_csr_operations csr_ops[CSR_TABLE_SIZE]; - extern const bool valid_vm_1_10_32[], valid_vm_1_10_64[]; =20 -void riscv_get_csr_ops(int csrno, riscv_csr_operations *ops); -void riscv_set_csr_ops(int csrno, const riscv_csr_operations *ops); - void riscv_cpu_register_gdb_regs_for_features(CPUState *cs); =20 -target_ulong riscv_new_csr_seed(target_ulong new_value, - target_ulong write_mask); - const char *satp_mode_str(uint8_t satp_mode, bool is_32_bit); =20 -/* In th_csr.c */ -extern const RISCVCSR th_csr_list[]; - const char *priv_spec_to_str(int priv_version); #endif /* RISCV_CPU_H */ diff --git a/target/riscv/csr.h b/target/riscv/csr.h new file mode 100644 index 0000000000..fab53992bb --- /dev/null +++ b/target/riscv/csr.h @@ -0,0 +1,94 @@ +/* + * QEMU RISC-V CSRs + * + * Copyright (c) 2016-2017 Sagar Karandikar, sagark@eecs.berkeley.edu + * Copyright (c) 2017-2018 SiFive, Inc. + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef RISCV_CSR_H +#define RISCV_CSR_H + +target_ulong riscv_new_csr_seed(target_ulong new_value, + target_ulong write_mask); + +RISCVException riscv_csrr(CPURISCVState *env, int csrno, + target_ulong *ret_value); + +RISCVException riscv_csrrw(CPURISCVState *env, int csrno, + target_ulong *ret_value, target_ulong new_value, + target_ulong write_mask, uintptr_t ra); +RISCVException riscv_csrrw_debug(CPURISCVState *env, int csrno, + target_ulong *ret_value, + target_ulong new_value, + target_ulong write_mask); + +static inline void riscv_csr_write(CPURISCVState *env, int csrno, + target_ulong val) +{ + riscv_csrrw(env, csrno, NULL, val, MAKE_64BIT_MASK(0, TARGET_LONG_BITS= ), 0); +} + +static inline target_ulong riscv_csr_read(CPURISCVState *env, int csrno) +{ + target_ulong val =3D 0; + riscv_csrrw(env, csrno, &val, 0, 0, 0); + return val; +} + +typedef RISCVException (*riscv_csr_predicate_fn)(CPURISCVState *env, + int csrno); +typedef RISCVException (*riscv_csr_read_fn)(CPURISCVState *env, int csrno, + target_ulong *ret_value); +typedef RISCVException (*riscv_csr_write_fn)(CPURISCVState *env, int csrno, + target_ulong new_value, + uintptr_t ra); +typedef RISCVException (*riscv_csr_op_fn)(CPURISCVState *env, int csrno, + target_ulong *ret_value, + target_ulong new_value, + target_ulong write_mask); + +RISCVException riscv_csrr_i128(CPURISCVState *env, int csrno, + Int128 *ret_value); +RISCVException riscv_csrrw_i128(CPURISCVState *env, int csrno, + Int128 *ret_value, Int128 new_value, + Int128 write_mask, uintptr_t ra); + +typedef RISCVException (*riscv_csr_read128_fn)(CPURISCVState *env, int csr= no, + Int128 *ret_value); +typedef RISCVException (*riscv_csr_write128_fn)(CPURISCVState *env, int cs= rno, + Int128 new_value); + +typedef struct { + const char *name; + riscv_csr_predicate_fn predicate; + riscv_csr_read_fn read; + riscv_csr_write_fn write; + riscv_csr_op_fn op; + riscv_csr_read128_fn read128; + riscv_csr_write128_fn write128; + /* The default priv spec version should be PRIV_VERSION_1_10_0 (i.e 0)= */ + uint32_t min_priv_ver; +} riscv_csr_operations; + +struct RISCVCSR { + int csrno; + bool (*insertion_test)(RISCVCPU *cpu); + riscv_csr_operations csr_ops; +}; + +/* CSR function table constants */ +enum { + CSR_TABLE_SIZE =3D 0x1000 +}; + +/* CSR function table */ +extern riscv_csr_operations csr_ops[CSR_TABLE_SIZE]; + +void riscv_get_csr_ops(int csrno, riscv_csr_operations *ops); +void riscv_set_csr_ops(int csrno, const riscv_csr_operations *ops); + +/* In th_csr.c */ +extern const RISCVCSR th_csr_list[]; + +#endif /* RISCV_CSR_H */ diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 246ec81beb..d8d06f92bc 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -23,6 +23,7 @@ #include "qemu/log.h" #include "cpu.h" #include "cpu_vendorid.h" +#include "csr.h" #include "internals.h" #include "qapi/error.h" #include "qapi/visitor.h" diff --git a/target/riscv/csr.c b/target/riscv/csr.c index b3c5b75aac..f079a89793 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -22,6 +22,7 @@ #include "qemu/log.h" #include "qemu/timer.h" #include "cpu.h" +#include "csr.h" #include "tcg/tcg-cpu.h" #include "pmu.h" #include "time_helper.h" diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c index 1934f919c0..f8d3bc0df1 100644 --- a/target/riscv/gdbstub.c +++ b/target/riscv/gdbstub.c @@ -20,6 +20,7 @@ #include "exec/gdbstub.h" #include "gdbstub/helpers.h" #include "cpu.h" +#include "csr.h" =20 struct TypeSize { const char *gdb_type; diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c index 5c19062c19..ad58e84158 100644 --- a/target/riscv/kvm/kvm-cpu.c +++ b/target/riscv/kvm/kvm-cpu.c @@ -31,6 +31,7 @@ #include "system/kvm.h" #include "system/kvm_int.h" #include "cpu.h" +#include "csr.h" #include "trace.h" #include "accel/accel-cpu-target.h" #include "hw/pci/pci.h" diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c index 110292e84d..d2d9f2a47a 100644 --- a/target/riscv/op_helper.c +++ b/target/riscv/op_helper.c @@ -20,6 +20,7 @@ =20 #include "qemu/osdep.h" #include "cpu.h" +#include "csr.h" #include "internals.h" #include "exec/cputlb.h" #include "accel/tcg/cpu-ldst.h" diff --git a/target/riscv/th_csr.c b/target/riscv/th_csr.c index 49eb7bbab5..bf6f8d62a3 100644 --- a/target/riscv/th_csr.c +++ b/target/riscv/th_csr.c @@ -19,6 +19,7 @@ #include "qemu/osdep.h" #include "cpu.h" #include "cpu_vendorid.h" +#include "csr.h" =20 #define CSR_TH_SXSTATUS 0x5c0 =20 --=20 2.51.0 From nobody Sun Sep 28 15:28:22 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1758698932; cv=none; d=zohomail.com; s=zohoarc; b=krC+WxvNaEpibOJHr623bNDoYynJfXJdwnsOBI6TpoIRAJyMzwiCi8BnDWjzteMBKrJXmN/cPtioIZgNXlP0b4ItHoiTFNNb/ao7cmcAGcJzj+4Yo1lBdFHejOi9IwheWaD9dTBGvLBII91GSNda/08OgMpGX0TcqxrAAsZXlmI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758698932; 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:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=7oHRxPq9Z6cPf1b6yiYBrI164arRf+hxCj2kw7nzqZY=; b=CL2aVMtAABGDSEkM2xxEdKMDrBjvozVZXTQBsdAV0l53GJM5HHRM+gDj0NX9d/CDSdEsM85ARkCDsWivYBA+y3wmBTOVFNRoyhRi1an7hA0vWnYI78FZUPNMYOWcq1/iyNIMfpsA/D44q7jVmQAMlfkcBvQAqwQP5X9Dgab1rSY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1758698932284139.61631799425004; Wed, 24 Sep 2025 00:28:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1Jnt-0005xM-5J; Wed, 24 Sep 2025 03:20:41 -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 1v1Jnq-0005vc-UA for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:40 -0400 Received: from rev.ng ([94.130.142.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v1Jnj-0003hD-6l for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive:List-Unsubscribe:List-Unsubscribe-Post: List-Help; bh=7oHRxPq9Z6cPf1b6yiYBrI164arRf+hxCj2kw7nzqZY=; b=ekzMp14fPfxnsh7 RzSo+jQk1wnvXRVug/JPSgUgpedaYszq3D/oZ2V5DnymveDA/uxbAKbb0CxT/MHcKRshAeWKUwzhw Fx3PxDvVSgCTeWiuof/Zr0TMMuiMyuJXzGGx+rmRRlaijbXFXFDABMX5NY/41o7dsLwb3G8t1lC70 AY=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com Subject: [RFC PATCH 33/34] target/riscv: Introduce externally facing CSR access functions Date: Wed, 24 Sep 2025 09:21:23 +0200 Message-ID: <20250924072124.6493-34-anjo@rev.ng> In-Reply-To: <20250924072124.6493-1-anjo@rev.ng> References: <20250924072124.6493-1-anjo@rev.ng> 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=94.130.142.21; envelope-from=anjo@rev.ng; helo=rev.ng 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, T_SPF_TEMPERROR=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: , Reply-to: Anton Johansson From: Anton Johansson via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758698934268116600 Content-Type: text/plain; charset="utf-8" Convert riscv_csr_[read|write]() into target_ulong angnostic CSR access functions that can be safely used from outside of target/ without knowledge of the target register size. Replace the 4 existing CSR accesses in hw/ and linux-user/. Signed-off-by: Anton Johansson --- target/riscv/cpu.h | 7 ++++++- target/riscv/csr.h | 13 ------------- hw/riscv/riscv_hart.c | 7 +++---- linux-user/riscv/signal.c | 5 +++-- target/riscv/csr.c | 17 +++++++++++++++++ 5 files changed, 29 insertions(+), 20 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index a954605e83..12b6cafbf0 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -849,7 +849,12 @@ RISCVPmPmm riscv_pm_get_pmm(CPURISCVState *env); RISCVPmPmm riscv_pm_get_virt_pmm(CPURISCVState *env); uint32_t riscv_pm_get_pmlen(RISCVPmPmm pmm); =20 -#include "csr.h" +/* + * Externally facing CSR access functions, asserts if access fails. + */ + +int riscv_csr_write_i64(CPURISCVState *env, int csrno, uint64_t val); +int riscv_csr_read_i64(CPURISCVState *env, int csrn, uint64_t *res); =20 /* * The event id are encoded based on the encoding specified in the diff --git a/target/riscv/csr.h b/target/riscv/csr.h index fab53992bb..552e6c5de5 100644 --- a/target/riscv/csr.h +++ b/target/riscv/csr.h @@ -23,19 +23,6 @@ RISCVException riscv_csrrw_debug(CPURISCVState *env, int= csrno, target_ulong new_value, target_ulong write_mask); =20 -static inline void riscv_csr_write(CPURISCVState *env, int csrno, - target_ulong val) -{ - riscv_csrrw(env, csrno, NULL, val, MAKE_64BIT_MASK(0, TARGET_LONG_BITS= ), 0); -} - -static inline target_ulong riscv_csr_read(CPURISCVState *env, int csrno) -{ - target_ulong val =3D 0; - riscv_csrrw(env, csrno, &val, 0, 0, 0); - return val; -} - typedef RISCVException (*riscv_csr_predicate_fn)(CPURISCVState *env, int csrno); typedef RISCVException (*riscv_csr_read_fn)(CPURISCVState *env, int csrno, diff --git a/hw/riscv/riscv_hart.c b/hw/riscv/riscv_hart.c index 7f2676008c..c7e98a4308 100644 --- a/hw/riscv/riscv_hart.c +++ b/hw/riscv/riscv_hart.c @@ -67,12 +67,11 @@ static void csr_call(char *cmd, uint64_t cpu_num, int c= srno, uint64_t *val) RISCVCPU *cpu =3D RISCV_CPU(cpu_by_arch_id(cpu_num)); CPURISCVState *env =3D &cpu->env; =20 - int ret =3D RISCV_EXCP_NONE; + RISCVException ret =3D RISCV_EXCP_NONE; if (strcmp(cmd, "get_csr") =3D=3D 0) { - ret =3D riscv_csrr(env, csrno, (target_ulong *)val); + ret =3D riscv_csr_read_i64(env, csrno, val); } else if (strcmp(cmd, "set_csr") =3D=3D 0) { - ret =3D riscv_csrrw(env, csrno, NULL, *(target_ulong *)val, - MAKE_64BIT_MASK(0, TARGET_LONG_BITS), 0); + ret =3D riscv_csr_write_i64(env, csrno, *val); } =20 g_assert(ret =3D=3D RISCV_EXCP_NONE); diff --git a/linux-user/riscv/signal.c b/linux-user/riscv/signal.c index 358fa1d82d..9d5ba300e4 100644 --- a/linux-user/riscv/signal.c +++ b/linux-user/riscv/signal.c @@ -90,7 +90,8 @@ static void setup_sigcontext(struct target_sigcontext *sc= , CPURISCVState *env) __put_user(env->fpr[i], &sc->fpr[i]); } =20 - uint32_t fcsr =3D riscv_csr_read(env, CSR_FCSR); + uint64_t fcsr; + riscv_csr_read_i64(env, CSR_FCSR, &fcsr); __put_user(fcsr, &sc->fcsr); } =20 @@ -159,7 +160,7 @@ static void restore_sigcontext(CPURISCVState *env, stru= ct target_sigcontext *sc) =20 uint32_t fcsr; __get_user(fcsr, &sc->fcsr); - riscv_csr_write(env, CSR_FCSR, fcsr); + riscv_csr_write_i64(env, CSR_FCSR, fcsr); } =20 static void restore_ucontext(CPURISCVState *env, struct target_ucontext *u= c) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index f079a89793..846052a6ed 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -5656,6 +5656,23 @@ RISCVException riscv_csrrw(CPURISCVState *env, int c= srno, return riscv_csrrw_do64(env, csrno, ret_value, new_value, write_mask, = ra); } =20 +int riscv_csr_write_i64(CPURISCVState *env, int csrno, uint64_t val) +{ + RISCVException ret; + ret =3D riscv_csrrw(env, csrno, NULL, val, + MAKE_64BIT_MASK(0, TARGET_LONG_BITS), 0); + return ret; +} + +int riscv_csr_read_i64(CPURISCVState *env, int csrno, uint64_t *res) +{ + RISCVException ret; + target_ulong val =3D 0; + ret =3D riscv_csrr(env, csrno, &val); + *res =3D val; + return ret; +} + static RISCVException riscv_csrrw_do128(CPURISCVState *env, int csrno, Int128 *ret_value, Int128 new_value, --=20 2.51.0 From nobody Sun Sep 28 15:28:22 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1758698708; cv=none; d=zohomail.com; s=zohoarc; b=XKg1bp8coMVWaoSHlrLIT+1MLwo4JnUiyluknzShm+vhVvH8MkBJFhcfkJPSyeMan7JFBYVk2HL535oFUvbhNSlM0t25BfxJXLmpl/c6/8UHTnTtsK3cb3zUgbH6FUuo1hviwCs9E8Q5jP5JV7YksQ9QLDB82LrLZcpj+y9Inf0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758698708; 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:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=p7zOOqCv9NfopwAwQRfWfxNnq+p4UwtqD5QxNAbVGJM=; b=khuvOvu9V5JFxNr94RiAnvLJxPcsFDzZuwQ+Z4ORvHmMuBevLsngBjHaAmRpB5lGb55I2hE+5EEneLL0n5StXPhlKHVaXOnvAip733A3o71EzfWqpabdqakKMBRH0X5Rd8QeCvM23WASpKobUpQ6KpblPs2E4u4UBZ8I27xrWXg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1758698708966336.4100905521557; Wed, 24 Sep 2025 00:25:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v1Jns-0005x9-KV; Wed, 24 Sep 2025 03:20:40 -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 1v1Jnn-0005sQ-Si for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:35 -0400 Received: from rev.ng ([94.130.142.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v1Jnk-0003hM-6g for qemu-devel@nongnu.org; Wed, 24 Sep 2025 03:20:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive:List-Unsubscribe:List-Unsubscribe-Post: List-Help; bh=p7zOOqCv9NfopwAwQRfWfxNnq+p4UwtqD5QxNAbVGJM=; b=HaBmLGzrsZVdrF2 6AQHKwjFsZSOxXq7NfEAx3ONYzn894UJShvutrCeirvY9pSNvQ02NopecxSi8EnjgSjw0+cU5CF6U uEhIZh0cdX6zFpTsiefjempxbY8mzNrVySTj73ij0hlmRJ/SMoV8cFcPtceP/7ji/HZlgzgkqs5Xi yA=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com Subject: [RFC PATCH 34/34] target/riscv: Make pmp.h target_ulong agnostic Date: Wed, 24 Sep 2025 09:21:24 +0200 Message-ID: <20250924072124.6493-35-anjo@rev.ng> In-Reply-To: <20250924072124.6493-1-anjo@rev.ng> References: <20250924072124.6493-1-anjo@rev.ng> 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=94.130.142.21; envelope-from=anjo@rev.ng; helo=rev.ng 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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: , Reply-to: Anton Johansson From: Anton Johansson via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758698709555116600 Content-Type: text/plain; charset="utf-8" The pmp.h header is exposed through cpu.h. pmp_table_t is also used in CPUArchState. CSR declaraions are only used in target/ and are moved to csr.h. In pmp.h, addr_reg is widened to 64 bits and the privilege mode parameter is fixed to 8 bits, similar to previous commits. Signed-off-by: Anton Johansson --- target/riscv/csr.h | 12 ++++++++++++ target/riscv/pmp.h | 20 +++++--------------- target/riscv/machine.c | 2 +- target/riscv/pmp.c | 9 +++++---- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/target/riscv/csr.h b/target/riscv/csr.h index 552e6c5de5..3752a0ef43 100644 --- a/target/riscv/csr.h +++ b/target/riscv/csr.h @@ -78,4 +78,16 @@ void riscv_set_csr_ops(int csrno, const riscv_csr_operat= ions *ops); /* In th_csr.c */ extern const RISCVCSR th_csr_list[]; =20 +/* PMP CSRs, defined in pmp.c */ +void pmpcfg_csr_write(CPURISCVState *env, uint32_t reg_index, + target_ulong val); +target_ulong pmpcfg_csr_read(CPURISCVState *env, uint32_t reg_index); + +void mseccfg_csr_write(CPURISCVState *env, uint64_t val); +uint64_t mseccfg_csr_read(CPURISCVState *env); + +void pmpaddr_csr_write(CPURISCVState *env, uint32_t addr_index, + target_ulong val); +target_ulong pmpaddr_csr_read(CPURISCVState *env, uint32_t addr_index); + #endif /* RISCV_CSR_H */ diff --git a/target/riscv/pmp.h b/target/riscv/pmp.h index e322904637..c9b0ee6c58 100644 --- a/target/riscv/pmp.h +++ b/target/riscv/pmp.h @@ -22,8 +22,6 @@ #ifndef RISCV_PMP_H #define RISCV_PMP_H =20 -#include "cpu.h" - typedef enum { PMP_READ =3D 1 << 0, PMP_WRITE =3D 1 << 1, @@ -50,7 +48,7 @@ typedef enum { } mseccfg_field_t; =20 typedef struct { - target_ulong addr_reg; + uint64_t addr_reg; uint8_t cfg_reg; } pmp_entry_t; =20 @@ -65,21 +63,13 @@ typedef struct { uint32_t num_rules; } pmp_table_t; =20 -void pmpcfg_csr_write(CPURISCVState *env, uint32_t reg_index, - target_ulong val); -target_ulong pmpcfg_csr_read(CPURISCVState *env, uint32_t reg_index); - -void mseccfg_csr_write(CPURISCVState *env, uint64_t val); -uint64_t mseccfg_csr_read(CPURISCVState *env); +typedef struct CPUArchState CPURISCVState; =20 -void pmpaddr_csr_write(CPURISCVState *env, uint32_t addr_index, - target_ulong val); -target_ulong pmpaddr_csr_read(CPURISCVState *env, uint32_t addr_index); bool pmp_hart_has_privs(CPURISCVState *env, hwaddr addr, - target_ulong size, pmp_priv_t privs, + int size, pmp_priv_t privs, pmp_priv_t *allowed_privs, - target_ulong mode); -target_ulong pmp_get_tlb_size(CPURISCVState *env, hwaddr addr); + uint8_t mode); +uint64_t pmp_get_tlb_size(CPURISCVState *env, hwaddr addr); void pmp_update_rule_addr(CPURISCVState *env, uint32_t pmp_index); void pmp_update_rule_nums(CPURISCVState *env); uint32_t pmp_get_num_rules(CPURISCVState *env); diff --git a/target/riscv/machine.c b/target/riscv/machine.c index 72bc0b04b5..8545bb121c 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -51,7 +51,7 @@ static const VMStateDescription vmstate_pmp_entry =3D { .version_id =3D 1, .minimum_version_id =3D 1, .fields =3D (const VMStateField[]) { - VMSTATE_UINTTL(addr_reg, pmp_entry_t), + VMSTATE_UINT64(addr_reg, pmp_entry_t), VMSTATE_UINT8(cfg_reg, pmp_entry_t), VMSTATE_END_OF_LIST() } diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c index 85199c7387..6089e2730e 100644 --- a/target/riscv/pmp.c +++ b/target/riscv/pmp.c @@ -23,6 +23,7 @@ #include "qemu/log.h" #include "qapi/error.h" #include "cpu.h" +#include "csr.h" #include "trace.h" #include "exec/cputlb.h" #include "exec/page-protection.h" @@ -272,7 +273,7 @@ static int pmp_is_in_range(CPURISCVState *env, int pmp_= index, hwaddr addr) */ static bool pmp_hart_has_privs_default(CPURISCVState *env, pmp_priv_t priv= s, pmp_priv_t *allowed_privs, - target_ulong mode) + uint8_t mode) { bool ret; =20 @@ -331,8 +332,8 @@ static bool pmp_hart_has_privs_default(CPURISCVState *e= nv, pmp_priv_t privs, * Return false if no match */ bool pmp_hart_has_privs(CPURISCVState *env, hwaddr addr, - target_ulong size, pmp_priv_t privs, - pmp_priv_t *allowed_privs, target_ulong mode) + int size, pmp_priv_t privs, + pmp_priv_t *allowed_privs, uint8_t mode) { int i =3D 0; int pmp_size =3D 0; @@ -662,7 +663,7 @@ uint64_t mseccfg_csr_read(CPURISCVState *env) * To avoid this we return a size of 1 (which means no caching) if the PMP * region only covers partial of the TLB page. */ -target_ulong pmp_get_tlb_size(CPURISCVState *env, hwaddr addr) +uint64_t pmp_get_tlb_size(CPURISCVState *env, hwaddr addr) { hwaddr pmp_sa; hwaddr pmp_ea; --=20 2.51.0