From nobody Fri Nov 14 19:42:16 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=1762189860; cv=none; d=zohomail.com; s=zohoarc; b=VRf1s/8576gRkAzCcYkH3Eop59UNG3ueJsB6JNfWNYBUIclrcNW8Lnmc/yYM4sVvoklzH+mB2jeCdXE/tBdIBIH6RolB9D716GjUFb3sw01Tlex2xGkgo1Vo3ZkFGVf2y+9clUueawtn9V8cI1gnPDAoNb9y+li04Q+3yAYKOTw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762189860; 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=WUuPdEn0qgdXUUZKD+H/GZrOe8IYCwWf2jpSidT2Pmw=; b=jG5+p98pfOPWfNyDjkPLnrIGjjIY4ABNRVb8rj2OhaDzOlDYWdjgTfxBqgtZRF16PGXQbBiQj2+vzwMaU7ZLvAXADEic1yERZ/07POwXGaC3QDSIrBoX9d6JScfS1Vp9P69pCowNA3hBvnGo2pEOflMkZbFVNlhqUWimOTQuJoM= 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 1762189860003742.6979159532312; Mon, 3 Nov 2025 09:11:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vFy3c-0000S0-Sd; Mon, 03 Nov 2025 12:09:30 -0500 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 1vFy3a-0000RG-Qc for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:26 -0500 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 1vFy3T-0000qu-Cg for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:26 -0500 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=WUuPdEn0qgdXUUZKD+H/GZrOe8IYCwWf2jpSidT2Pmw=; b=Np1ocfErCE5gfmd OtLfcCqhKrypFPEH3BJUjOGQfe/yQuPsvYAX79n6kkm7EjHtOxdDITJIj9d/CwuMWqvCQCRiPx8W1 7A94XEPFpP7zdHQQYmYT3eqo9yIcUF//XrCITxkchu2wr+VH57+B9ZoTHOOOQYNRLPCXH929crA34 s8=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com, Anton Johansson Subject: [PATCH v5 01/25] target/riscv: Fix size of gpr and gprh Date: Mon, 3 Nov 2025 18:11:44 +0100 Message-ID: <20251103171208.24355-2-anjo@rev.ng> In-Reply-To: <20251103171208.24355-1-anjo@rev.ng> References: <20251103171208.24355-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_CERTIFIED_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: 1762189862734154100 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. Note, the cpu/rv128 VMSTATE version is bumped, breaking migration from older versions. Signed-off-by: Anton Johansson Acked-by: Alistair Francis Reviewed-by: Pierrick Bouvier --- target/riscv/cpu.h | 4 ++-- target/riscv/cpu.c | 2 +- target/riscv/machine.c | 8 ++++---- target/riscv/riscv-qmp-cmds.c | 2 +- target/riscv/translate.c | 17 +++++++++++++++-- 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 2e0b86e68d..6b4edbfe9e 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -213,8 +213,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 73d4280d7c..dc97d35458 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -583,7 +583,7 @@ static void riscv_cpu_dump_state(CPUState *cs, FILE *f,= int flags) #endif =20 for (i =3D 0; i < 32; i++) { - qemu_fprintf(f, " %-8s " TARGET_FMT_lx, + qemu_fprintf(f, " %-8s %" PRIx64, riscv_int_regnames[i], 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 09c032a879..7349383eab 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -177,11 +177,11 @@ static bool rv128_needed(void *opaque) =20 static const VMStateDescription vmstate_rv128 =3D { .name =3D "cpu/rv128", - .version_id =3D 1, - .minimum_version_id =3D 1, + .version_id =3D 2, + .minimum_version_id =3D 2, .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() @@ -429,7 +429,7 @@ const VMStateDescription vmstate_riscv_cpu =3D { .minimum_version_id =3D 11, .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/riscv-qmp-cmds.c b/target/riscv/riscv-qmp-cmds.c index d5e9bec0f8..93488450bd 100644 --- a/target/riscv/riscv-qmp-cmds.c +++ b/target/riscv/riscv-qmp-cmds.c @@ -262,7 +262,7 @@ static bool reg_is_ulong_integer(CPURISCVState *env, co= nst char *name, target_ulong *val, bool is_gprh) { const char * const *reg_names; - target_ulong *vals; + uint64_t *vals; =20 if (is_gprh) { reg_names =3D riscv_int_regnamesh; diff --git a/target/riscv/translate.c b/target/riscv/translate.c index e1f4dc5ffd..8df1a2ed3c 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -27,6 +27,7 @@ #include "accel/tcg/cpu-ldst.h" #include "exec/translation-block.h" #include "exec/log.h" +#include "exec/tswap.h" #include "semihosting/semihost.h" =20 #include "internals.h" @@ -1443,12 +1444,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 Fri Nov 14 19:42:16 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=1762190046; cv=none; d=zohomail.com; s=zohoarc; b=V0jBSkxTmzSeZ518VJG7KVcgAxwDgCXvHwJLNaw67e9UPJ8PbaNHs6BGL94+gUKMoyAmzGzUgvY6VMwydtycXyhL8iyNjeyTyg4SP+s2wfK1tD01XW1DuhOCqjOrFw0u54rZgbT4B23QBdxh4PjQEg2C0OQxXEruK7FsSso2X/g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762190046; 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=yeQbonbjBSkFyDPSjjviKlOlNX70Akb/D4JXGYtklGc=; b=EwIcm8rnagRtL9KNyJe0vzkvPfS+YIEmfO2y9YR0pqoWgBrlI34RJquzIF3CPeRowd/GEkLLEdraqLKZehPfzrxYd26Gfx3CU5ZmR6cvZ8toSHgY96X5ZJr1hSk8QV9pzxI38fB1MDn/BHp1+ILweDuI9FJ5ya3Js6p8KkOoG7w= 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 176219004660337.365525114001; Mon, 3 Nov 2025 09:14:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vFy3g-0000Sc-4i; Mon, 03 Nov 2025 12:09:32 -0500 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 1vFy3b-0000RO-CZ for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:27 -0500 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 1vFy3T-0000rP-4O for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:27 -0500 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=yeQbonbjBSkFyDPSjjviKlOlNX70Akb/D4JXGYtklGc=; b=ZGLejCLs/SAYRPr IWBmgUQHbokhqD38BUB4SN2Jee0xxdW++BRLkgvPoHLN0Es+jPSDZfhj7k17Te5UnhG9GnLnF2HFr kJb48jtQi8b58zklKM0RGF3RIo0TPhMhe5i0QKCp+gqeqvu9M4tMjp2Qp+FymFkK5IU26QS1Vv9vn fw=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com, Anton Johansson Subject: [PATCH v5 02/25] target/riscv: Fix size of vector CSRs Date: Mon, 3 Nov 2025 18:11:45 +0100 Message-ID: <20251103171208.24355-3-anjo@rev.ng> In-Reply-To: <20251103171208.24355-1-anjo@rev.ng> References: <20251103171208.24355-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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1762190048313158500 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. Note, the cpu/vector VMSTATE version is bumped, breaking migration from older versions. Signed-off-by: Anton Johansson Acked-by: Alistair Francis Reviewed-by: Pierrick Bouvier --- target/riscv/cpu.h | 12 ++++++------ target/riscv/machine.c | 14 +++++++------- target/riscv/translate.c | 12 ++++++++---- target/riscv/vector_helper.c | 22 ++++++++++++++++++---- target/riscv/insn_trans/trans_rvv.c.inc | 24 ++++++++++++------------ 5 files changed, 51 insertions(+), 33 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 6b4edbfe9e..bd200ccad4 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -192,7 +192,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 */ @@ -218,11 +218,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 7349383eab..440b09fc32 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -137,16 +137,16 @@ static bool vector_needed(void *opaque) =20 static const VMStateDescription vmstate_vector =3D { .name =3D "cpu/vector", - .version_id =3D 2, - .minimum_version_id =3D 2, + .version_id =3D 3, + .minimum_version_id =3D 3, .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_UINT64(env.vtype, RISCVCPU), + VMSTATE_UINT32(env.vl, RISCVCPU), + VMSTATE_UINT32(env.vstart, RISCVCPU), + VMSTATE_UINT8(env.vxrm, RISCVCPU), + VMSTATE_UINT8(env.vxsat, RISCVCPU), VMSTATE_BOOL(env.vill, RISCVCPU), VMSTATE_END_OF_LIST() } diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 8df1a2ed3c..15eee7f6ee 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -39,8 +39,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 @@ -1455,6 +1456,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, @@ -1470,9 +1475,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 2de3358ee8..cf9a199566 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 2a487179f6..32474a21dc 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; } @@ -3610,7 +3610,7 @@ static bool trans_##NAME(DisasContext *s, arg_rmrr *a= ) \ \ fns[s->sew](dest, mask, src1, src2, tcg_env, desc); \ \ - 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 Fri Nov 14 19:42:16 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=1762190030; cv=none; d=zohomail.com; s=zohoarc; b=DFXAJrlacGwsiqf+rv44aKQ+Ayej/mweIjJ8JJcQTeRSCfr/1Jv91t0ee3IwE2ly8I+tDwI+7LVC0biA9gGS6xmW3OgPlHNpNAaYOnCbafCd5Eh1lxO9E2nHolwYfdUGsBdrjgTPWcg62tU3FiW0aEhjA4pgKJyXkxlHeBuGooI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762190030; 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=xzmt7cLSz4yJS8IzF79BoJ0z6M/UFl7qXf5BHQA55gk=; b=jKZD7ws+U6ztueKlQHaZneJ07Gc5EZP6O00+VjNIIRv1p38sbzCSol8bblK+rpBIQ+sDZ9J3nEA8h68PHoX3UI8pyxhvNzuXn/PRb5aDXtksHEIn0XY2MUqalStovMvNnPLQ3BzeKUnFEEaLKu7Xk78yT65UDLeiq61EVrd76E8= 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 1762190030025405.6211199335452; Mon, 3 Nov 2025 09:13:50 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vFy3g-0000SY-17; Mon, 03 Nov 2025 12:09:32 -0500 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 1vFy3e-0000SI-EF for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:30 -0500 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 1vFy3T-0000r8-2G for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:30 -0500 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=xzmt7cLSz4yJS8IzF79BoJ0z6M/UFl7qXf5BHQA55gk=; b=OpICEMA5rgSB8Te JABJ2IYWl3O84+3zcn+n3eupi1tEZR5nbgyIymcSdQkypr6cr/kRG07c2vQEoXqWCAypOJgkiJLTI 85k00KKT+yXpGLGWyW2J1w0+5vpwWxvJCEEkQffRXzRdK/3Zeo3lfmXNN3/Hf6oJoYF+fMGU1k+/8 Ks=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com, Anton Johansson Subject: [PATCH v5 03/25] target/riscv: Fix size of pc, load_[val|res] Date: Mon, 3 Nov 2025 18:11:46 +0100 Message-ID: <20251103171208.24355-4-anjo@rev.ng> In-Reply-To: <20251103171208.24355-1-anjo@rev.ng> References: <20251103171208.24355-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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1762190036348158500 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 Reviewed-by: Pierrick Bouvier Acked-by: Alistair Francis --- target/riscv/cpu.h | 6 +++--- target/riscv/cpu.c | 2 +- target/riscv/cpu_helper.c | 6 +++--- target/riscv/machine.c | 6 +++--- target/riscv/translate.c | 12 +++++++----- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index bd200ccad4..f00ae69e8a 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -225,9 +225,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 dc97d35458..353b927dd5 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -528,7 +528,7 @@ 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 %" PRIx64 "\n", "pc ", 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 1f791e4de3..e105dec426 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -2278,9 +2278,9 @@ void riscv_cpu_do_interrupt(CPUState *cs) =20 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)); + "epc:0x%"PRIx64", tval:0x"TARGET_FMT_lx", desc=3D%s\n", + __func__, env->mhartid, async, cause, 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 440b09fc32..66ed3f6504 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -433,9 +433,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 15eee7f6ee..e82805e178 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -1459,6 +1459,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, @@ -1474,11 +1478,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 Fri Nov 14 19:42:16 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=1762190051; cv=none; d=zohomail.com; s=zohoarc; b=H1V3fgfet+bmPgvgh901EiEQdv/E7PwNM5fXGApe//tJQGow3K7sN21YjwxoP8kX0XVdvvxPLKev389kK8fDUWGnsLPIIJcFzIFtjxRG2ufTpTQU9M8MTIEyZ5DFvrwxnMdXQoEbv5ALQpeZhKwPF9Hq5Du1a6u5qnucgR10ijE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762190051; 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=SjfF/Dlfl0nJgW6S1cKGeSe4Vy0F3QMqVm17FHT1Gl0=; b=QyKk/JYxw0mWOCfJ5/6dbvBT1GFHxHmMBpvV8Y1MCN78dev4M/F4Av0SMzabA9EnjsRWwm2tAfls6F0uh4qAwicWtNRR+N+YtBWVEtloTSd7ktGP0VhCr0WNRw4CAfgBbEx5eXf9aXbdUVZtEMIlb1EE2GBSsYysUFzcOah+pJI= 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 1762190051883378.49792961046955; Mon, 3 Nov 2025 09:14:11 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vFy3g-0000Sg-8o; Mon, 03 Nov 2025 12:09:33 -0500 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 1vFy3e-0000S8-AZ for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:30 -0500 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 1vFy3U-0000rN-87 for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:29 -0500 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=SjfF/Dlfl0nJgW6S1cKGeSe4Vy0F3QMqVm17FHT1Gl0=; b=kCIRBvCKos86qIy Jaexf0ipDZigSp8J4/wHQCdfpuZ1UF2qu+e4E4bVf8AEm/MX92TNOgGJAm0M7mAYJ1F9AmAIEsm/1 xabSHeQnBWKJyCFkg04Y24b3fZ3XsDmQUQNzbe0Af+vmhV4pZLovsm1KVeKooY68QhR+i5o29KrjG dw=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com, Anton Johansson Subject: [PATCH v5 04/25] target/riscv: Fix size of frm and fflags Date: Mon, 3 Nov 2025 18:11:47 +0100 Message-ID: <20251103171208.24355-5-anjo@rev.ng> In-Reply-To: <20251103171208.24355-1-anjo@rev.ng> References: <20251103171208.24355-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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1762190053748154100 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 Reviewed-by: Pierrick Bouvier Acked-by: Alistair Francis --- 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 f00ae69e8a..a55d4ac690 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -231,7 +231,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; @@ -665,8 +665,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 6e7b6d7019..1c6797ca8d 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 66ed3f6504..07995fb303 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -436,7 +436,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 Fri Nov 14 19:42:16 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=1762189925; cv=none; d=zohomail.com; s=zohoarc; b=ZpCPV3ZEO2ZxWiuidSod5iPxOtewthUNCoeWZWxe3/FJv/u+QTOd4IRGwf1hmGgI79Awdk6ZkTCcSxrz0LHo2KrBIU0dZulOPkNxaBzlxpbYvPB13alaEajXrfRRqYcf52TdQXdA0umN2rNaqMztHPofUVyhsPkdLhiHJoqmd2w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762189925; 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=oPYMt1nwOncuKeTCFe+bid+ugpIOeU5iaMXrQYZRJDo=; b=TRiupj1NX9UtvhzDgwD3gm5VLCbMuGl11p9YMnkPvCnRxu7ABgGUj9fi9MADKuJhvKuGdZXbuxfY5+Pi0iJftt9P43VXQx5ytWV3RWFUqiLJw+pDyqKmkgncbh7u+7XLzxL3Tjpr2SdpulT9EnX2p2YFEtUj7GLUgGxBJswbxfE= 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 1762189924722578.0158420015111; Mon, 3 Nov 2025 09:12:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vFy3i-0000TJ-Fp; Mon, 03 Nov 2025 12:09:34 -0500 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 1vFy3g-0000SH-Cv for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:32 -0500 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 1vFy3U-0000rS-CP for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:29 -0500 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=oPYMt1nwOncuKeTCFe+bid+ugpIOeU5iaMXrQYZRJDo=; b=M6UTJWdRWgvdiEb NBvNfGwlja8WWb3RIfsQN3H4feda+P70hVMOdJAWboDFORgbrDGfjuc0sNxHWYdKA9wl5ksPQq+Ol Efw0G2hWQcp6kikY/R6KmaH69NWIZNPXHB2QLtVCWP81jKy/jQE4TAk5NjLRV87dlbzOfAL4pVKqX kM=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com, Anton Johansson Subject: [PATCH v5 05/25] target/riscv: Fix size of badaddr and bins Date: Mon, 3 Nov 2025 18:11:48 +0100 Message-ID: <20251103171208.24355-6-anjo@rev.ng> In-Reply-To: <20251103171208.24355-1-anjo@rev.ng> References: <20251103171208.24355-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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1762189927410158500 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 Reviewed-by: Pierrick Bouvier Acked-by: Alistair Francis --- 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 a55d4ac690..77dd0ad6e4 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -234,8 +234,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 07995fb303..b047321073 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -437,7 +437,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 e82805e178..5eabc7b9dc 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -265,7 +265,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); @@ -276,7 +276,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 Fri Nov 14 19:42:16 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=1762190101; cv=none; d=zohomail.com; s=zohoarc; b=h96qTsJm0RuKrzxYlxRNXv4xxa5QXMdC3RLEQixuRb9tfOXTknRC/Rh1tRPJDGHD5hmzVRg9pkBTXZmjavH35spQK+Bi5QXPI0DQAL6QUu5W+tqQ3KBwtoPFwspvwT5PW2ihrdv4x5WPDypR/d/pQzJSIwKlwCSC/LlcdLBuGFA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762190101; 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=OLFNERCRTHBzWJFDjAl53bj22G8oN3ivJxQ4R76Lj3A=; b=EU88GtNglRJJBD8qVRMf5ng6bJY9b2VuIcPoxzRHeo11XhqpJz5U1Fu+zYRXMYKKDfHMUapfTjiFFFk1LZItA/YARs0zz5KSMGr7TGBZYNcKg4IMY4XHz5U4SpS1B8zxl/j5MftxSXVpQaohwOYNNutFSX9bv1uJnHdMZH14qfY= 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 1762190101489628.4271526325318; Mon, 3 Nov 2025 09:15:01 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vFy3l-0000UQ-VF; Mon, 03 Nov 2025 12:09:38 -0500 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 1vFy3i-0000TH-6U for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:34 -0500 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 1vFy3U-0000rZ-Cj for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:33 -0500 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=OLFNERCRTHBzWJFDjAl53bj22G8oN3ivJxQ4R76Lj3A=; b=Zgz5hAYj0xobc0M XzNPb3i+m+FNgwZzqRT7XwQIoaEfpmNPjuio5vDq4sQFgT1/2axHSEHQb0s0k4v+BtenJH+RdBPrw rj7AEj/cwTNH9VbQrQy+N+IUVN0AIunteakLw6UTTfNUq3ofO5OMc9dmaxIygH8w+vL4zKVV57OLR 2A=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com, Anton Johansson Subject: [PATCH v5 06/25] target/riscv: Fix size of guest_phys_fault_addr Date: Mon, 3 Nov 2025 18:11:49 +0100 Message-ID: <20251103171208.24355-7-anjo@rev.ng> In-Reply-To: <20251103171208.24355-1-anjo@rev.ng> References: <20251103171208.24355-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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1762190102101154100 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 Reviewed-by: Pierrick Bouvier Acked-by: Alistair Francis --- 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 77dd0ad6e4..28fbcc1030 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -237,7 +237,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 e105dec426..210e7bae6d 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -1185,7 +1185,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) @@ -1786,7 +1786,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 b047321073..27034180c4 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -438,7 +438,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 Fri Nov 14 19:42:16 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=1762190107; cv=none; d=zohomail.com; s=zohoarc; b=ciYSUyO8K8/7nOou24rZmweOlQl3g0XjtbMMnjziHjgx3Rg7wkGUuMAS/bS1wVO3zwSokuI8k5ato9OlybqghiJbnzmyQT4qRqH4s6jrZmSvxz5lbrorY0A8qHMndy+b0CKouOHaP8SvM3ouHZVkP3rdOq465IRxCo7qZCbwxaE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762190107; 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=mqyLrCHGBd9VgFCLfxbbtYgG4JkofLIXqcYFoB9kySs=; b=oE9n228xcxAGgmgU3CNCoIjK1GCOT43oerDUe00oZy0AIWqXeYU0viBchjBbOac9K2xJAK866DmIXiA2LOjzBnwqXLoMr4p6vjHEVJ9kAn8c+aDQBCH90MPqehbN8n2Is3/Ul/fzRqVSrsK0FBHigbSe2+PuAAhsB+PB+vzC6xo= 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 1762190107352522.9327197880347; Mon, 3 Nov 2025 09:15:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vFy3m-0000Ui-1Q; Mon, 03 Nov 2025 12:09:38 -0500 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 1vFy3k-0000UF-Bz for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:36 -0500 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 1vFy3W-0000rf-FG for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:36 -0500 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=mqyLrCHGBd9VgFCLfxbbtYgG4JkofLIXqcYFoB9kySs=; b=HLJocd0kjp7mRz3 AEdYPez1PvSuVus1Tty9SKBQQjzlgPsbp9Ajjyc8Wkt7ajEQ6ID9UYf0epOjP7edTpdUF3xiKHr8M K+qyDtv4zheVfKpUAl3nFWozQEv00KXtpE4Oni8tnoazF5sVM8kXJ5XvN4B9MMzNK8/Lwpy1XA8oB 6A=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com, Anton Johansson Subject: [PATCH v5 07/25] target/riscv: Fix size of priv_ver and vext_ver Date: Mon, 3 Nov 2025 18:11:50 +0100 Message-ID: <20251103171208.24355-8-anjo@rev.ng> In-Reply-To: <20251103171208.24355-1-anjo@rev.ng> References: <20251103171208.24355-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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1762190108759158500 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 Reviewed-by: Pierrick Bouvier Acked-by: Alistair Francis --- 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 28fbcc1030..ce66ce3bb3 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -239,8 +239,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 */ @@ -800,7 +800,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 27034180c4..1cf744c5f0 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -439,8 +439,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 5eabc7b9dc..5a6913057c 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -60,7 +60,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 Fri Nov 14 19:42:16 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=1762189859; cv=none; d=zohomail.com; s=zohoarc; b=dOtc9OwV4d2CkafUYy+poMt7swe9QiuYQDl0Cunbi0fUNw3nSBPf+ce9iUZP38OmJIhOn+qqlsepNf3y/MJNwqY/GQjIG7n0Six8P1sIqTuk0Jbg+RHjcFtQFxaj3qb566klfbVSg78wlzbZP4gEIEro3WswbgRSktrSPd1T94o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762189859; 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=JB4tUyL4dqHZl2rdK0QL12f5f7Xs5+oTYjNclq1baoY=; b=AkBYVJ98lm6MR6Uw9GqbT4Arr70CdX4h1qATMgOrRvCxYqRJs8BT+OLX+B+sfa7FWpu3HvWVs4mdVjinvrlnl4+mxKv6obtAvxI70A2/26yvf1OzyfydkN7U4gbuXuhdB6A1Ehes3dV+Nj3qNNUGI/2qyXDnJ08zYXVcBFrY4uA= 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 1762189859359525.9592039326657; Mon, 3 Nov 2025 09:10:59 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vFy3k-0000U9-8a; Mon, 03 Nov 2025 12:09:36 -0500 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 1vFy3i-0000TG-4Y for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:34 -0500 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 1vFy3U-0000rn-53 for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:33 -0500 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=JB4tUyL4dqHZl2rdK0QL12f5f7Xs5+oTYjNclq1baoY=; b=SpcSUSbjBssFFiE 4yshhvOItEViwGFC5NA0Yvdw5Y5hZQxjqiZ/HO0oHcrlsEjIf6ZpDcoxTGpV24K5OXiizraXFtFa/ zZO/oVZbkCazy6ECAVAvMI8xV5k49qGxo/uytCS+txBUqBxdN/4O51/rDj6pS8jZgXzM15b5uL2aL xQ=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com, Anton Johansson Subject: [PATCH v5 08/25] target/riscv: Fix size of retxh Date: Mon, 3 Nov 2025 18:11:51 +0100 Message-ID: <20251103171208.24355-9-anjo@rev.ng> In-Reply-To: <20251103171208.24355-1-anjo@rev.ng> References: <20251103171208.24355-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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1762189862780154100 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 Reviewed-by: Pierrick Bouvier Acked-by: Alistair Francis --- 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 ce66ce3bb3..7c54a08eb4 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -249,7 +249,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 54b9b4f241..104a8ebe20 100644 --- a/target/riscv/insn_trans/trans_rvi.c.inc +++ b/target/riscv/insn_trans/trans_rvi.c.inc @@ -1014,10 +1014,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); } @@ -1037,10 +1039,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 Fri Nov 14 19:42:16 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=1762190162; cv=none; d=zohomail.com; s=zohoarc; b=UsbHmd0hqhBjW12oD9HRxfiRFd8t1ekM03vxhJZDgvgNyek4PBPWey/ocPwG7biUsDwZhZBxCYk2uq1DsJMtxi6QMAD3QwI/TVKkULDLUXxMl47mhla9RpkZmMcLgMbnkNbQFVbIoOetI1DAsAuZAZtvIGIH6dPZAmo2TNmW4AM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762190162; 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=JTclVRBMtgGwr1WRYJzVLDg5Lk0+x88TQC1Cio9tuf4=; b=ksjeR4J6WgP3YEaibxCwprtfGDp1G1F/KBYpp4787usNZSLKPyqmmbrFDHOTQO/e5Nkerp0KWakihAZzRYdEKu39bIpdHUVa/Ip9BLlJFYV/m/V6+0boxw0AbEO6t8KacQD88mRZY3RdsaAGnAXvAVzpy/qqZezMgCq6C5L+9iU= 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 1762190162946306.18201874388023; Mon, 3 Nov 2025 09:16:02 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vFy3u-0000XM-EL; Mon, 03 Nov 2025 12:09:46 -0500 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 1vFy3r-0000WE-Ai for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:43 -0500 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 1vFy3i-0000ru-As for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:42 -0500 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=JTclVRBMtgGwr1WRYJzVLDg5Lk0+x88TQC1Cio9tuf4=; b=cgj0mIUfyMptMsI rfl/oi4RJrw0hsQoAiRoVxi2TbpvylVWGUHzHa9NuHfn9DfVwWJWoYaNf5fGPIhj6pT5geJ1VvNhM +KEtTzGfiDhK0xtO4na5Qn/eH9zyKlMFthIFXYDUaMdQ3tmi58yP1HMTuIVC31zBGKSSbk7hALW1E 1g=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com, Anton Johansson Subject: [PATCH v5 09/25] target/riscv: Fix size of ssp Date: Mon, 3 Nov 2025 18:11:52 +0100 Message-ID: <20251103171208.24355-10-anjo@rev.ng> In-Reply-To: <20251103171208.24355-1-anjo@rev.ng> References: <20251103171208.24355-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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1762190164583154100 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. Note, the cpu/ssp VMSTATE version is bumped, breaking migration from older versions. Signed-off-by: Anton Johansson Reviewed-by: Pierrick Bouvier Acked-by: Alistair Francis --- target/riscv/cpu.h | 2 +- target/riscv/machine.c | 6 +++--- target/riscv/insn_trans/trans_rvzicfiss.c.inc | 18 +++++++++++++----- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 7c54a08eb4..1e4128128b 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -256,7 +256,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 1cf744c5f0..c55794c554 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -390,11 +390,11 @@ static bool ssp_needed(void *opaque) =20 static const VMStateDescription vmstate_ssp =3D { .name =3D "cpu/ssp", - .version_id =3D 1, - .minimum_version_id =3D 1, + .version_id =3D 2, + .minimum_version_id =3D 2, .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 0b6ad57965..40e5a1b7df 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); @@ -45,7 +47,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; } @@ -59,12 +62,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; } @@ -76,7 +82,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 Fri Nov 14 19:42:16 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=1762190040; cv=none; d=zohomail.com; s=zohoarc; b=fC4m0cIXWH5KJcpPbvp9/BM8RCBErURDyCw286+yRUwmYsMGGayHgvU4O39qJUrYAjJTqESZ72dtZRsNAdrY8Fu0hzV+DQGlzERRuKCYdYJn/GD5XkXC/+B/l8D2n6/U5/svdNveJktOo132QLqOJrlRqji0aALPaooG2n+77Y4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762190040; h=Content-Type: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=aXQr0gN36alGHxr+qGmiqW6v4Iaeqk6Qo8uj64HlnEg=; b=DBF2ECYsQpoUjdK0+yR6W5DQJboPUO0hKegd1KBjVZPs+FkAT8wnbYyI1K+zK1AT/0zqy4kjFdJx9T6OTINw+JgfVBiCgziwWn1BcQ0GdPCLKJ6qHtrqp/EOFiF9odi4pxcfWopoyfJI0lGPH2631a8rrgZHNE0qBIJcD0t0wcE= 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 1762190040554958.6280359450818; Mon, 3 Nov 2025 09:14:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vFy3l-0000UT-GW; Mon, 03 Nov 2025 12:09:37 -0500 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 1vFy3k-0000U3-2y for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:36 -0500 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 1vFy3V-0000sD-98 for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: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=aXQr0gN36alGHxr+qGmiqW6v4Iaeqk6Qo8uj64HlnEg=; b=Y1rwZ13DaPapL9h CuYQaI+vQ0ChWHANWrZayNYr6VEkHuRFRtjOvBTTdCKx+SYHQqVYib57HJ2inmGUCzBbnI6N3b0ME uT9fXvJbZ4WAERm4rAce80ZRPcU5HzWHYQFWZbG1EYtGA1to4DOfGeKbYz2GqrVsIYwdgZlxT/VFo Fc=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com, Anton Johansson Subject: [PATCH v5 10/25] target/riscv: Fix size of excp_uw2 Date: Mon, 3 Nov 2025 18:11:53 +0100 Message-ID: <20251103171208.24355-11-anjo@rev.ng> In-Reply-To: <20251103171208.24355-1-anjo@rev.ng> References: <20251103171208.24355-1-anjo@rev.ng> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1762190041579154100 Fix to 64 bits to match size of instruction start words. Signed-off-by: Anton Johansson Reviewed-by: Pierrick Bouvier Reviewed-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Alistair Francis --- 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 1e4128128b..f901608d0e 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -258,7 +258,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 Fri Nov 14 19:42:16 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=1762190108; cv=none; d=zohomail.com; s=zohoarc; b=DpkcmycLWMpmUEsZ6A9d7W8+kB+JtLTfEiCObRJNJXYikTb5cvc1//AdLGHbP+J1+u90GBQ9mc/9R45rXOr4zR3uSNFrPt9gON75Dj+XHHpYPxOd8RLhqhub7xAGVQPvG1uv5FubzloruLgzERtDE/gw1O1XJR2z/5UDt4d0DEw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762190108; h=Content-Type: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=/JWX58fLEOumjtEggtpYYPCTc75FSdSeBBwvHfyqbbY=; b=T1fWYwLkE2Yf+g/EvfRry8qb8tDaHGmpi65cCA1Xk+qbWKdz4Ltt8bQ3lFbPrMuZyKX7W6svwn2bq5k6DCwWy1bYd13hSdke3cF3P0XJg+1qSou9mURgkEkGOm22EHp5/2ZCNLi8X9EsVJ8uJ7LTyPrFvVCP4s4l5USdbXxeBjg= 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 1762190108812231.7711567048343; Mon, 3 Nov 2025 09:15:08 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vFy3s-0000X3-Jr; Mon, 03 Nov 2025 12:09:44 -0500 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 1vFy3p-0000Vo-Ho for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:42 -0500 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 1vFy3h-0000sW-EE for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:41 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: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=/JWX58fLEOumjtEggtpYYPCTc75FSdSeBBwvHfyqbbY=; b=TLtXghv5y0KShFq GTYJU3NfyW86FZHVcXYiC2mocIVR2JPUUOMGT9qn1RYnw9/2k0ocU2g5dlRtD24BlZ1A8ohbQ/fu0 h0qTP8hKSM3VqlQ2rdaxfHqVVPd+U0zZIUXjFa8guMddi7mnumEqEzbG4OedP/zpIzq4aKzXAshwC oA=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com, Anton Johansson Subject: [PATCH v5 11/25] target/riscv: Fix size of sw_check_code Date: Mon, 3 Nov 2025 18:11:54 +0100 Message-ID: <20251103171208.24355-12-anjo@rev.ng> In-Reply-To: <20251103171208.24355-1-anjo@rev.ng> References: <20251103171208.24355-1-anjo@rev.ng> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1762190110214154100 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 Reviewed-by: Pierrick Bouvier Reviewed-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Alistair Francis --- 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 f901608d0e..191a3fb3d9 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -260,7 +260,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 5a6913057c..f4f0b96d0a 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -1377,8 +1377,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 104a8ebe20..37d2f4d957 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 40e5a1b7df..cb9c5419fa 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_update_pc(ctx, 0); gen_helper_raise_exception(tcg_env, tcg_constant_i32(RISCV_EXCP_SW_CHECK)); --=20 2.51.0 From nobody Fri Nov 14 19:42:16 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=1762190025; cv=none; d=zohomail.com; s=zohoarc; b=mgrzvV6hF8NH1qiDxcP0BD+2tbks0zecIkW13ItDvz7lBOKJCgnXgkWxrzpSQvDtUGLjlUAmgXBtjEg/azLn3PrS+3qnBUQghrO/QBBIZJE5JWVzuhbwG38UJS1SXEMsnGYtnZqthqzI164QBVkWwXsQHW4x/Or4t5VnjYErKBU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762190025; 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=fhHIF14aZaL5bswiWWZk8ZrOvTFnjdR1muzxmPNyYn8=; b=XWUWQeFiWgwqnAEZUOaUxf67gSOv3rvex2b+zj8sVaGE7hQthvKmO8lPJFoTzWTzGUfMmzAznh107rymDLSm/t5mrFdwdCREmpwuLCpHtYb4iI03zPeC6PNfO0gL2zJAG03mM/ztMVrDrw4CTQpPyU1ZeHoo3fLjqvNBXfn3lA8= 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 1762190025797414.62581083870907; Mon, 3 Nov 2025 09:13:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vFy42-0000Ze-S0; Mon, 03 Nov 2025 12:09:54 -0500 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 1vFy3x-0000YV-VW for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:51 -0500 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 1vFy3f-0000sR-ON for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:48 -0500 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=fhHIF14aZaL5bswiWWZk8ZrOvTFnjdR1muzxmPNyYn8=; b=eQefXwk9rOikajR UmqzIOgscbj6pTM9xQgLd1Xio1znvmXCcDFxIkuXF6V2Z9blBZAM+k5XyBEHw2q3Vwy5hkWRTk8I6 4rpz5RNwPdpvyT985Mhpzo+vlzLSszegxlGmhuDcIZHWpCxZmFOQlIaEkRHUr8DJhssdlD/VojH96 TE=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com, Anton Johansson Subject: [PATCH v5 12/25] target/riscv: Fix size of priv Date: Mon, 3 Nov 2025 18:11:55 +0100 Message-ID: <20251103171208.24355-13-anjo@rev.ng> In-Reply-To: <20251103171208.24355-1-anjo@rev.ng> References: <20251103171208.24355-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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1762190026265158500 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. Introduce a new privilege_mode_t typedef for passing around the privilege mode. Signed-off-by: Anton Johansson Reviewed-by: Pierrick Bouvier Acked-by: Alistair Francis --- target/riscv/cpu.h | 15 +++++++++++---- target/riscv/cpu_helper.c | 13 ++++++++----- target/riscv/machine.c | 2 +- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 191a3fb3d9..4c42971809 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -109,6 +109,12 @@ typedef struct riscv_cpu_profile { =20 extern RISCVCPUProfile *riscv_profiles[]; =20 +/* + * Type large enough to hold all PRV_* fields, update CPUArchState::priv + * migration field if changing this type. + */ +typedef uint8_t privilege_mode_t; + /* Privileged specification version */ #define PRIV_VER_1_10_0_STR "v1.10.0" #define PRIV_VER_1_11_0_STR "v1.11.0" @@ -265,7 +271,7 @@ struct CPUArchState { uint32_t elf_flags; #endif =20 - target_ulong priv; + privilege_mode_t priv; /* CSRs for execution environment configuration */ uint64_t menvcfg; uint64_t senvcfg; @@ -651,10 +657,11 @@ 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, privilege_mode_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, privilege_mode_t prev_priv, bool prev_virt); void riscv_ctr_clear(CPURISCVState *env); =20 void riscv_translate_init(void); @@ -725,7 +732,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, privilege_mode_t mod= e) { RISCVMXL xl =3D env->misa_mxl; /* diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 210e7bae6d..38b57bc622 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -798,7 +798,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(privilege_mode_t priv, bool virt) { switch (priv) { case PRV_M: @@ -818,7 +818,8 @@ 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, + privilege_mode_t priv, bool virt) { switch (priv) { @@ -840,7 +841,8 @@ 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, + privilege_mode_t src_prv, bool src_virt) { target_long tgt_prv =3D env->priv; @@ -929,7 +931,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, privilege_mode_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); @@ -1027,7 +1029,8 @@ 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, privilege_mode_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 c55794c554..ce5e44325d 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -445,7 +445,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 Fri Nov 14 19:42:16 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=1762190054; cv=none; d=zohomail.com; s=zohoarc; b=XMWttL9s0L30Rl5wQjg2/6p4rbGilg8yVOF0evkTZgMpUC8sYnolfBsKyuifoBiitYwgPuUr02jUFf5cWjgYf0xHIQlBFfZnfbZwCfYxS1CB0LqbpPp/I2+d2mBEKYcbo/hkUe2UEdatlKuK2b87gvVQF83Ii7CQoE94jNHWFbM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762190054; 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=okOiofNy7st7WsZ2e3AUHi2e/nfBmPBAYNfiTpuL2hk=; b=eoO3dFj/LGal57w25xibPsE5PltoNrouzdTg87G3JMw7Mp2VWAcZB32WM0pPvKyX3Naf7uzT9eTJ8RXGdnPrciC+k5L6G2KOwbEtMgRTuS2KzKOcgttG2YSSfYTbBW/3RFAHdFREG/Gxz36mUyET3fvbk0SzrRSMygsQPySfER8= 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 1762190054682922.8719995699568; Mon, 3 Nov 2025 09:14:14 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vFy3q-0000Vp-Kc; Mon, 03 Nov 2025 12:09:42 -0500 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 1vFy3n-0000Vc-JR for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:40 -0500 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 1vFy3h-0000sa-7D for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:38 -0500 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=okOiofNy7st7WsZ2e3AUHi2e/nfBmPBAYNfiTpuL2hk=; b=mxHDqSNwCDvZT9N v67rhIcGLMJkRlWoRVoqoClRf8pqsgcdrZfOgCFfgMbahab6Ff87YOMX/8UQHUlM6TVCi50Y0U9CQ CFUlD8Zd4um2m0lO3HTGC40WtX9Gd1CkV1HpB7ftFMa50CvKoRqH1TYvZzcj4ZesypFkhA+RGZO6+ sI=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com, Anton Johansson Subject: [PATCH v5 13/25] target/riscv: Fix size of gei fields Date: Mon, 3 Nov 2025 18:11:56 +0100 Message-ID: <20251103171208.24355-14-anjo@rev.ng> In-Reply-To: <20251103171208.24355-1-anjo@rev.ng> References: <20251103171208.24355-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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1762190058377158500 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 Reviewed-by: Pierrick Bouvier Acked-by: Alistair Francis --- 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 4c42971809..5f051796f4 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -279,7 +279,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; @@ -356,8 +356,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 @@ -609,8 +609,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 38b57bc622..e0a324b401 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -661,7 +661,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; @@ -670,7 +670,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 ce5e44325d..8a8f5be8d6 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 Fri Nov 14 19:42:16 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=1762190102; cv=none; d=zohomail.com; s=zohoarc; b=JtZ+ty8Qpzp/0vHAgwnbD3FsqQIZ1AjoI2M0j3T3bn+EY3hDnM5ZVjl/7VB4lvGXtrEB/IsiaJGaCefOU6HFl3zlfkTTPr8KENpo2J28L7cTigGzAl3zZCuZWgFC3CqPtYyTnt/oHUuXlNyu+eAnjLr1UtGv+E1KYg5vCT+OJPA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762190102; 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=Ty7V6mUm7E7xW82v49FaJ5HOHnoOvuLwGtXFsf+RLyA=; b=OLuIgSka8mZoWyS54rkmMJAla/Z8kXXCYc5mWU+Ycxwhaz1ziuTNgE+255HQJHDFl52FZ6ttOHRuy0wtzj1P4irTCC19NavpDO3z/5HBDyCCyJZgis9fJ8lGy1FlkNoUU38c3ii7NRAIqYnLBF4um4truKc/nyhtfv3MEMmu2cc= 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 1762190102497444.2898132322364; Mon, 3 Nov 2025 09:15:02 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vFy3s-0000Wq-Gu; Mon, 03 Nov 2025 12:09:44 -0500 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 1vFy3r-0000WA-5k for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:43 -0500 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 1vFy3i-0000si-Jo for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:41 -0500 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=Ty7V6mUm7E7xW82v49FaJ5HOHnoOvuLwGtXFsf+RLyA=; b=gyn0j9JPXyqaomj DnUcufYH21DTx5F14tF3Jjw5RT5X7oEUXpEf+P+rfatbg6UlEuG6dlqBYOV5AI5ONMMT5ESaDpa8z VWxBFUsVHPAaDu8yMmBjstK+LW+m/3254rbNc4E+bDtLBRBhFThN00RIaJRcvl/JjJ4rdG5YwYU0j Ns=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com, Anton Johansson Subject: [PATCH v5 14/25] target/riscv: Fix size of [m|s|vs]iselect fields Date: Mon, 3 Nov 2025 18:11:57 +0100 Message-ID: <20251103171208.24355-15-anjo@rev.ng> In-Reply-To: <20251103171208.24355-1-anjo@rev.ng> References: <20251103171208.24355-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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1762190102758158501 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 Reviewed-by: Pierrick Bouvier Acked-by: Alistair Francis --- 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 5f051796f4..b35851cf4f 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -343,8 +343,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 @@ -390,7 +390,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 1c6797ca8d..a29edbb369 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -2398,7 +2398,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); @@ -2441,18 +2441,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 && @@ -2460,7 +2460,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) { @@ -2504,7 +2504,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) { /* @@ -2543,7 +2543,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) { /* @@ -2582,7 +2582,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) { /* @@ -2623,7 +2623,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; @@ -2703,12 +2703,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; @@ -2775,7 +2775,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) { @@ -2803,7 +2803,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; @@ -2833,7 +2833,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) { @@ -2864,7 +2864,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 8a8f5be8d6..376075b2bd 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), @@ -467,8 +467,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 Fri Nov 14 19:42:16 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=1762190036; cv=none; d=zohomail.com; s=zohoarc; b=aTLw/Z1Swy3Ig/Lp8wddRfzd2bPNV22lsdbBrqPNZ6RoGaUhm9T91IK1YoN2ZOK0Ixysat9FHx9LOQlVBp3QoGwz2NGf69lsOQHRQ33g0805idZDvYfOXLV4Omg/XIXAU2RnUWUbhA/37+tOLOc4Y4N2uVd0FOz+uQTIVhNMKcc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762190036; 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=dGnm7pdQmqNFKtnziFqNJ7W7qTBfOWwiSusg4UD7Pt0=; b=Rwe1KZ2uHDepu6O+t4qOxvfVCnJCCeJpmNtyEo0VvD+Ma9bVxfjYnof7aewqQt+DRIdKb5jR5+/phERkCWY7UUO6yPVADpJVWz2tTJli8lK8bfLdY1NnFpP6yomi5zjjy0itjGB+ntvGRtuayBJbY4vOAOkoO8zXiOr2587JK28= 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 1762190036295783.8888706337129; Mon, 3 Nov 2025 09:13:56 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vFy3u-0000XW-6s; Mon, 03 Nov 2025 12:09:46 -0500 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 1vFy3s-0000XJ-UF for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:44 -0500 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 1vFy3i-0000st-Fz for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:44 -0500 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=dGnm7pdQmqNFKtnziFqNJ7W7qTBfOWwiSusg4UD7Pt0=; b=S2b3Lq+U0z0BA7T WiEJSdyZPiYSK20B+5X1QdlPJFszO2KW2SQHXEvdWiCQG2/A5FOheUyrfTux4yqOG8DQL4/N2S5OR JjPs0Yti9XTpQQpDV1KA7isWFhWtErqrby6LQTJeLjvkG0JbkAkeTbDWgHTaSNnZycHKu4+rAbqbP Bk=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com, Anton Johansson Subject: [PATCH v5 15/25] target/riscv: Fix arguments to board IMSIC emulation callbacks Date: Mon, 3 Nov 2025 18:11:58 +0100 Message-ID: <20251103171208.24355-16-anjo@rev.ng> In-Reply-To: <20251103171208.24355-1-anjo@rev.ng> References: <20251103171208.24355-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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1762190037683154100 Content-Type: text/plain; charset="utf-8" In hw/ the relevant RISCVIMSICState fields eidelivery, eithreshold, eistate are uint32_t. Signed-off-by: Anton Johansson Reviewed-by: Pierrick Bouvier Acked-by: Alistair Francis --- 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 b35851cf4f..d6ad0e1896 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -200,6 +200,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; @@ -465,20 +483,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; @@ -646,12 +652,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 e0a324b401..b102f15ac6 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -765,17 +765,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 a29edbb369..debb236262 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -2630,6 +2630,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) { @@ -2674,16 +2675,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; @@ -2915,6 +2917,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); @@ -2940,7 +2943,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 @@ -2953,10 +2956,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) { @@ -4408,7 +4412,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]; @@ -4423,13 +4427,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 Fri Nov 14 19:42:16 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=1762189933; cv=none; d=zohomail.com; s=zohoarc; b=irM49YbVT7NfgKb+nwWru37Qz3O1f5LD+NfNd6Q5aANbt4+gbjQmgUkuCx7rwXbHFAxzlAvOQWJjXU6H49flQZzI8UmyyhMSFyxBX4FzxvOeT+MgBa5iiCSKkwwaiDZjasKEEhbEsP14BycABz0ivPmopCqR8dR671b5qJsqB/Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762189933; h=Content-Type: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=+LPD70edNKpPGCjvnRpTqMb65+ebJRGrKQjyEBZ6vUA=; b=dyIcObFiaN89MWu2QkGRakloLynfMz7f7Pn1D+7Ym7xmRJ9ZRvaaTeP8zwyFCs1nZa0gVxnhJ++S17SSw0qDW3bGyXagEUizJg4Bh7ZIBZG2HS05tGBvnZ/xnFJcVOVd3xfRZGmRKbo4LGXbVdsXTpSzc7UV+HkNqyJER1KNxVI= 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 1762189933528895.1357169113816; Mon, 3 Nov 2025 09:12:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vFy3v-0000Y8-SV; Mon, 03 Nov 2025 12:09:47 -0500 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 1vFy3t-0000XU-UO for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:45 -0500 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 1vFy3i-0000t0-PN for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: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=+LPD70edNKpPGCjvnRpTqMb65+ebJRGrKQjyEBZ6vUA=; b=fdzqakkY7pLuxKR dh3koX9DDfpziMlvneOdRBJsRicnMkEUwatkWm0owuPzMWQC0UbIg2Q4Pi/7mT4pdOOUle3R3zjeR xUyeVN+ftyo7CutAOSXXXW4MN8ocGg2ZuaF7O6/FB1QITd/eRMFTFe74ub5dMRFRpJYFXBBNhGzqm 48=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com, Anton Johansson Subject: [PATCH v5 16/25] target/riscv: Fix size of irq_overflow_left Date: Mon, 3 Nov 2025 18:11:59 +0100 Message-ID: <20251103171208.24355-17-anjo@rev.ng> In-Reply-To: <20251103171208.24355-1-anjo@rev.ng> References: <20251103171208.24355-1-anjo@rev.ng> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1762189937522158500 Fix to 64 bits to hold all relevant values. Signed-off-by: Anton Johansson Reviewed-by: Pierrick Bouvier Reviewed-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Alistair Francis --- 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 d6ad0e1896..604a356292 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -224,7 +224,7 @@ typedef struct PMUCTRState { /* Snapshot value of a 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 Fri Nov 14 19:42:16 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=1762190108; cv=none; d=zohomail.com; s=zohoarc; b=JWUxF1LFDfnDT2MZVua1LxYw/4SyuI5hK1m0BLrzER5FY9+BidwvsTPq+uWLBWTC7KltR3MUUI1ZUnxqOaNPvimOX9CHGyGfFqHJNVo5YnujJoQfsJNCbpMY1/bpzLKc6vpq8+hRB8HOQp9Gwghvq3uuN9nIeITM3wd4Onuw4Xs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762190108; h=Content-Type: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=RLifIEJrI9KVH1NJRXBNvfzXM1nf3RF23aE8Dmp5dOM=; b=Vgda9HzJpWL3+Wih/D8YiC7ee/HnZUEXoz+vbGqnpL6fUV0NZGYmLFl31BMEUb68VM3an/Dxx249+uwbeRqvsiIG6HBMZ+9i+yWXSkOcITuvEcLeh+rn2XSsm/6BYLG1dk3dj22V+k5AY16WaTkxFfnjshF/WEFNp5CBqvzTx78= 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 1762190108361665.916444412961; Mon, 3 Nov 2025 09:15:08 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vFy3x-0000YN-6f; Mon, 03 Nov 2025 12:09:49 -0500 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 1vFy3u-0000XV-2W for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:46 -0500 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 1vFy3i-0000t7-So for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: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=RLifIEJrI9KVH1NJRXBNvfzXM1nf3RF23aE8Dmp5dOM=; b=tPFUy7fcv+ZYSZf U7RCIRPBMm9Bj3PdxvywJES1iq3ekjoMdYvoxTnp0pVHc42sZj04FFFEhwR8bJvCr8IIaicnlPSYZ nrzA7i8iVQpwGKkfuOTaV8oH4/JgGqKXZNe/STklTKjlKJNXN/fxLTcIOo9S/w01d2/Ww2wRcXSD4 ck=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com, Anton Johansson Subject: [PATCH v5 17/25] target/riscv: Indent PMUFixedCtrState correctly Date: Mon, 3 Nov 2025 18:12:00 +0100 Message-ID: <20251103171208.24355-18-anjo@rev.ng> In-Reply-To: <20251103171208.24355-1-anjo@rev.ng> References: <20251103171208.24355-1-anjo@rev.ng> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1762190114825158500 Signed-off-by: Anton Johansson Reviewed-by: Pierrick Bouvier Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis --- 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 604a356292..4c6b977ce2 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -228,12 +228,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 Fri Nov 14 19:42:16 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=1762190100; cv=none; d=zohomail.com; s=zohoarc; b=bWRcuhC5SSwWiU8B+De1g8U+Lvl60K25plEeljBy4EtT4IbZC8gOlazZQ4GLiI3QSGsRJFJb/42dDkrI+Qyjvlrnw3YTU60YYUUdv6crX+c30EVgqjWWGwLCb6To6cxM/AVzsc+jlQf/OXJeJFCZxsiTKPHCnKrrT/6OUji3MEw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762190100; h=Content-Type: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=eU8cSHXOEb1LdYL9OhW7+NAKhCZgSb4TWkZB/nxXFjA=; b=ALVeu4F4e4Dt5iidLNIQIVJU0XKW+GYD2Vrlf4wH7D2uj/udouE25eMeGlecS+hL16CElrLvmnE5KOaRA3I6VAZ6zqZDGG9YyetpI8ean9HwvDFZW7bLcSSQhwhpUn0UdrV7JwN4H+llhaL4XI0gexmzpnZdZesJ/PJxMYrRE3A= 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 1762190100125111.75861863684361; Mon, 3 Nov 2025 09:15:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vFy3x-0000Yl-Is; Mon, 03 Nov 2025 12:09:49 -0500 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 1vFy3u-0000XP-DR for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:46 -0500 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 1vFy3j-0000tH-Gd for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: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=eU8cSHXOEb1LdYL9OhW7+NAKhCZgSb4TWkZB/nxXFjA=; b=OOeG/VkaAKFJc6F tBfwxqgVaXGMytk6oRsHxd1Jz/nwxc4rKd5Jg7+fEy8PyRbYhJDE0EvgeX7t9eIHif0yLfazZSlfO W/hQQe/hQ/N9zTYrtzviV5P9UcdoCE4o/iJ5mMFBQRzRjQGRqtEc+8RZz4bFYSVl1nE+NWO+wBV0G 5w=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com, Anton Johansson Subject: [PATCH v5 18/25] target/riscv: Replace target_ulong in riscv_cpu_get_trap_name() Date: Mon, 3 Nov 2025 18:12:01 +0100 Message-ID: <20251103171208.24355-19-anjo@rev.ng> In-Reply-To: <20251103171208.24355-1-anjo@rev.ng> References: <20251103171208.24355-1-anjo@rev.ng> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1762190102073154100 Fix cause argument to 64 bit to match env->mcause. Signed-off-by: Anton Johansson Reviewed-by: Pierrick Bouvier Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis --- 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 4c6b977ce2..c2be30795a 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -601,7 +601,7 @@ extern const char * const riscv_int_regnamesh[]; extern const char * const riscv_fpr_regnames[]; extern const char * const riscv_rvv_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 353b927dd5..3378c40dbf 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 Fri Nov 14 19:42:16 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=1762190160; cv=none; d=zohomail.com; s=zohoarc; b=cKvYy6i27fOelS5iFmwvuEO4pYVnZO+nqmFColYLPc31p7UjMRgpO6un18sAjxg9C51TMDVkC7cTh+qOsqe6PKjfRASREjFKK/zHZ9nw23u2wZCnUUGamcPIQM9MpBQ92HQJ+aPNOMJZqclpTquicWFKJ6lAyn7LiMRv5xrgYi4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762190160; h=Content-Type: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=yV+bqWtAZS5pr5GZ5j9aWShDLTAV5Q6XBoKnG1ob4lY=; b=bRF2CWEZr6rMLICkmLaMazlLCSO3Vg8nOcXrVeM+p4cmEdCDVv2BmG7H0Xdm/IzUUJ8ajm7FiFZBCuETu9ykb+rHUyZy1of/iBVOp0YhOz7mpYfu4vpWPpMY0ct9wiqSaG8uRBXxeAgns91giJ9WrkKyFHK9ujev0uKLvQT6/p8= 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 1762190160724263.2017165939028; Mon, 3 Nov 2025 09:16:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vFy41-0000a9-L1; Mon, 03 Nov 2025 12:09:53 -0500 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 1vFy40-0000Zc-Le for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:52 -0500 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 1vFy3l-0000tO-9R for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: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=yV+bqWtAZS5pr5GZ5j9aWShDLTAV5Q6XBoKnG1ob4lY=; b=rsR0m+TN1WkEnaY tF4jdMWmQOxTSN1PTW+or91KDFBQMSsyG55nXj4ucqd5LKZJlPTfFACoNUSN725mha0/xxahRx5xa XnuSVqBeQnSKEEspaeyiaMJ41DE4IbHZa/IV3uT0qZsjUGEF0oO+37C+3Cr0mYmCPnCdSKD/Z3YNj tA=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com, Anton Johansson Subject: [PATCH v5 19/25] target/riscv: Replace target_ulong in riscv_ctr_add_entry() Date: Mon, 3 Nov 2025 18:12:02 +0100 Message-ID: <20251103171208.24355-20-anjo@rev.ng> In-Reply-To: <20251103171208.24355-1-anjo@rev.ng> References: <20251103171208.24355-1-anjo@rev.ng> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1762190162557154100 Widen to 64 bits in size to hold all relevant values. Note: src and dst arguments change from signed to unsigned but no functional change is incurred. Signed-off-by: Anton Johansson Reviewed-by: Pierrick Bouvier Reviewed-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Alistair Francis --- target/riscv/cpu.h | 5 +++-- target/riscv/cpu_helper.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index c2be30795a..ee4444f22d 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -662,8 +662,9 @@ RISCVException smstateen_acc_ok(CPURISCVState *env, int= index, uint64_t bit); void riscv_cpu_set_mode(CPURISCVState *env, privilege_mode_t newpriv, bool virt_en); =20 -void riscv_ctr_add_entry(CPURISCVState *env, target_long src, target_long = dst, - enum CTRType type, privilege_mode_t prev_priv, bool prev_virt); +void riscv_ctr_add_entry(CPURISCVState *env, uint64_t src, uint64_t dst, + enum CTRType type, privilege_mode_t prev_priv, + bool prev_virt); void riscv_ctr_clear(CPURISCVState *env); =20 void riscv_translate_init(void); diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index b102f15ac6..20ff05a4b2 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -926,8 +926,9 @@ static bool riscv_ctr_check_xte(CPURISCVState *env, * 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, privilege_mode_t src_priv, bool src_virt) +void riscv_ctr_add_entry(CPURISCVState *env, uint64_t src, uint64_t dst, + enum CTRType type, privilege_mode_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); --=20 2.51.0 From nobody Fri Nov 14 19:42:16 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=1762190058; cv=none; d=zohomail.com; s=zohoarc; b=k671fXMIeXcXENEmwXQCcxMs2fxaU+k1+PK14HSnvECQKNB5OyNYt/BU+7zd1A6CoRu0rKZJsFAwfAJ3QgEkAac24HcWvJ1pvlcL6LV8sE4mRcT/2v9rgAK9UM37ATA5HP2lDBuOqqLwXVlyDuTXYfvm8IGHkzKcAl9mFhIQ2HQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762190058; h=Content-Type: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=25qOpz0IPQn7WWT7YwM8Q4jnwJo27QOlw8+jdalefsw=; b=KoivaCY1Hy8XxbjWHcLYtfgQ7KYN09qMx5LPfisl1hDk9PJxReSklZYPwSAPOPk4fwcBHFu5/iKxuVtH9DST+bojtVEYhGWEIJ6ulYneOa3lMJoZvz73O4QQPiP+i2cXfgTn5U7bqEtmkGyfjMSs7JZJUv6ZU16egxYa+DKGOUg= 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 1762190058824875.7804353421097; Mon, 3 Nov 2025 09:14:18 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vFy4A-0000bV-J0; Mon, 03 Nov 2025 12:10:02 -0500 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 1vFy45-0000aw-7b for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:57 -0500 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 1vFy3m-0000tw-Qs for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: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=25qOpz0IPQn7WWT7YwM8Q4jnwJo27QOlw8+jdalefsw=; b=WjSWUmialRO96dO Q5krrqmTUqX0KXlHzoq+YG5rAG/ojOVYPDm95lCf1bSC1jK5NDrUmcIUp0YLsRtRp4Bx20WQymENc bZwLl2WagLp+qgjaws4jtNzI63vgD/ib4wetW+4E/2W/p3nk0McRC9iTy5ltMKg62CYH84CEfz6EJ Mc=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com, Anton Johansson Subject: [PATCH v5 20/25] target/riscv: Fix size of trigger data Date: Mon, 3 Nov 2025 18:12:03 +0100 Message-ID: <20251103171208.24355-21-anjo@rev.ng> In-Reply-To: <20251103171208.24355-1-anjo@rev.ng> References: <20251103171208.24355-1-anjo@rev.ng> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1762190060434158500 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. This patch also adds a migration entry for mcontext which is used in tandem with other debug data that is already migrated. Note, the cpu/debug VMSTATE version is bumped, breaking migration from older versions. Signed-off-by: Anton Johansson Reviewed-by: Pierrick Bouvier Reviewed-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Alistair Francis --- target/riscv/cpu.h | 10 +++++----- target/riscv/machine.c | 13 +++++++------ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index ee4444f22d..153480846a 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -467,11 +467,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 376075b2bd..c6ebb58882 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -239,15 +239,16 @@ static int debug_post_load(void *opaque, int version_= id) =20 static const VMStateDescription vmstate_debug =3D { .name =3D "cpu/debug", - .version_id =3D 2, - .minimum_version_id =3D 2, + .version_id =3D 3, + .minimum_version_id =3D 3, .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_UINT16(env.mcontext, RISCVCPU), + 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 Fri Nov 14 19:42:16 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=1762190116; cv=none; d=zohomail.com; s=zohoarc; b=nNfdKI/RSl7SG9WVZRja6vpVWBKVlol9rlAkyPOgoClVFF5I6oYJvrWcETDUNOGf7ETlG4QcHRylS32lalbd11jeCanyqFJbEelWc1i0N0GRHpE5iK7pCH6YDKP4a0BWHhMO3j/AxZ8fFpIcHzvCGnFOXNVIfT0nwqC5qf5i87s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762190116; h=Content-Type: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=q6Opor7lQGZigqevcgCM7+jdNW3PiYzYgsH0ftxO0eA=; b=hihzpdVADTgntrI+O4oWoItwviVu06iSo9CkZqbZyH2GD4UQS3GX2Qw9GsQ4Z3Cm85GB6HSadNtcv7R2hT5TOFWlGDP2eQ2y8u0N4xAkJBSZUXVr/eP86xTLTtbZoL5t4SpgU0TRLHUR6kZamSbBUjg8Frjv/feNgsa44cV2DNo= 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 1762190116624920.1561101535282; Mon, 3 Nov 2025 09:15:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vFy41-0000aA-M7; Mon, 03 Nov 2025 12:09:54 -0500 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 1vFy3y-0000ZA-RY for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:50 -0500 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 1vFy3k-0000td-QP for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: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=q6Opor7lQGZigqevcgCM7+jdNW3PiYzYgsH0ftxO0eA=; b=XPJ/G+YPstFDieE aKsPSJ85WUMoOZAKmb/EC2nBnQzALUmJjqjWVNm/R353nXcOIbnYxrhcys+MW2x+Uwz6JQCVWqq/7 Hovo9r2DghZay9Xuzpat1RijB7dXJQ1IbHtuxQETqQl9EzWcVRBbdk1hvkWa9U8wW9Cu55Xi9u1Px HI=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com, Anton Johansson Subject: [PATCH v5 21/25] target/riscv: Fix size of mseccfg Date: Mon, 3 Nov 2025 18:12:04 +0100 Message-ID: <20251103171208.24355-22-anjo@rev.ng> In-Reply-To: <20251103171208.24355-1-anjo@rev.ng> References: <20251103171208.24355-1-anjo@rev.ng> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1762190118228154100 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 Reviewed-by: Pierrick Bouvier Reviewed-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Alistair Francis --- 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 153480846a..cc40d6c86c 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -464,7 +464,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 3ef62d26ad..0b23b4b8ed 100644 --- a/target/riscv/pmp.c +++ b/target/riscv/pmp.c @@ -643,7 +643,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; @@ -689,7 +689,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 Fri Nov 14 19:42:16 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=1762189880; cv=none; d=zohomail.com; s=zohoarc; b=Gu+RezLN1996LLd5sMweB075U2rAmRr28ILdqS3Bx6K4hic5LGjhMhI+BuQoT46RhHzX3Mohd3DhOFUdA31kbL45o76CskB1pzH/Hj16uMv/+ZeLza2ktox/y25/qQH3sN9RQZD2FMSPSYymxiecGSSb9dgLCkdy2Imvqjo6Nn0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762189880; h=Content-Type: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=lzmZ31+4RMrnAe1lCBOO49+JZ+ZqCuvVlq3vEdgNDF0=; b=BQrbbtesX9E4KyfUYQw2YWKXknuC1etVpRQ+sjhtlo/AcZfnyWEaCoif/VoPi946G2JG9e5K4vjneBVlhb4R2e06CQgbJWVXamLQu1saTYAywn1NawDjimYeWH0EosrGLnBiqu1tjoNAJ2YPCDBvlDlYpjcUpTXjIb6o69uc34s= 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 1762189875501478.29260680451955; Mon, 3 Nov 2025 09:11:15 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vFy4J-0000hL-Ty; Mon, 03 Nov 2025 12:10:12 -0500 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 1vFy46-0000b2-2y for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:58 -0500 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 1vFy3o-0000tk-7S for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: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=lzmZ31+4RMrnAe1lCBOO49+JZ+ZqCuvVlq3vEdgNDF0=; b=jzF2TQThdYVZs6L VTwf3ekV2uAqTvigaYR+n8VdEbjadjbHND0F4N1s0JPd7hdoIdVkeQ8RcGzCiurp1u5lepEnbUeUe 32ZJTOBucyi+sENEnUmEkh/0sRUKFEHlfVgCgF2106TilX7psYeoGus/jPzQXgQiZTcTkVo8VJl3k EU=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com, Anton Johansson Subject: [PATCH v5 22/25] target/riscv: Move debug.h include away from cpu.h Date: Mon, 3 Nov 2025 18:12:05 +0100 Message-ID: <20251103171208.24355-23-anjo@rev.ng> In-Reply-To: <20251103171208.24355-1-anjo@rev.ng> References: <20251103171208.24355-1-anjo@rev.ng> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1762189881604158500 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 Reviewed-by: Pierrick Bouvier Reviewed-by: Alistair Francis Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- target/riscv/cpu.h | 2 +- target/riscv/debug.h | 2 -- target/riscv/cpu.c | 3 +++ target/riscv/cpu_helper.c | 2 +- target/riscv/csr.c | 3 +++ target/riscv/debug.c | 1 + target/riscv/machine.c | 2 +- target/riscv/tcg/tcg-cpu.c | 1 + 8 files changed, 11 insertions(+), 5 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index cc40d6c86c..d1a8384646 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -186,12 +186,12 @@ extern RISCVCPUImpliedExtsRule *riscv_multi_ext_impli= ed_rules[]; =20 #if !defined(CONFIG_USER_ONLY) #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 3378c40dbf..2084b0d0bf 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 "target/riscv/debug.h" +#endif =20 /* RISC-V CPU definitions */ static const char riscv_single_letter_exts[] =3D "IEMAFDQCBPVH"; diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 20ff05a4b2..ce3d1e86a2 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -34,7 +34,7 @@ #include "semihosting/common-semi.h" #include "exec/icount.h" #include "cpu_bits.h" -#include "debug.h" +#include "target/riscv/debug.h" #include "pmp.h" =20 int riscv_env_mmu_index(CPURISCVState *env, bool ifetch) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index debb236262..e60741def2 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -31,6 +31,9 @@ #include "qapi/error.h" #include "tcg/insn-start-words.h" #include "internals.h" +#if !defined(CONFIG_USER_ONLY) +#include "target/riscv/debug.h" +#endif #include =20 /* CSR function table public API */ diff --git a/target/riscv/debug.c b/target/riscv/debug.c index 5664466749..30d39ee5cd 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 "target/riscv/debug.h" #include "trace.h" #include "exec/helper-proto.h" #include "exec/watchpoint.h" diff --git a/target/riscv/machine.c b/target/riscv/machine.c index c6ebb58882..36f4c3251d 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -22,7 +22,7 @@ #include "system/kvm.h" #include "migration/cpu.h" #include "exec/icount.h" -#include "debug.h" +#include "target/riscv/debug.h" =20 static bool pmp_needed(void *opaque) { diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c index 850a383702..59ed7e796c 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 "target/riscv/debug.h" #endif =20 /* Hash that stores user set extensions */ --=20 2.51.0 From nobody Fri Nov 14 19:42:16 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=1762189932; cv=none; d=zohomail.com; s=zohoarc; b=FrMG6+6cY7ll1dETKgw24hc0Q7SI4/AvRbGKDDyqogI/xgSPGCme4Iq0ArqhbChSKBIU4bHh694RgLKf3x2CKtYPRz/+De7ElFfpXjpIkSirw3IaqvHDzp3tsiii9ZA7r0Zk/7chmNVnXvEzWjDZ/2acriYTi+hBw07qQjWH7+Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762189932; h=Content-Type: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=ceCGNi73dSxmTd0X5VbD2VSE4aTpxz1746XxjDQRM3g=; b=WgvCzdXX7xz/NuwindBQAjaosGZOXrVIuR3EiGo5S+30JUEHMrM3eWb9byboYckTv6FADjG05kejOlVT5uFnLuftq/P2bUmbdTUsTZR19EH2PMpQQlB3Yh971OGtqr6fHPCRPXnAep1sAAwZHdwxFfCJzF+uqrFKC/1+ZLnluOM= 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 1762189932706458.12587772273775; Mon, 3 Nov 2025 09:12:12 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vFy4F-0000bs-TL; Mon, 03 Nov 2025 12:10:07 -0500 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 1vFy45-0000b1-W6 for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:58 -0500 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 1vFy3n-0000tn-RL for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: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=ceCGNi73dSxmTd0X5VbD2VSE4aTpxz1746XxjDQRM3g=; b=rCzjcR9hSkdA4GH V4Y8Y7x3mlNGefh8QyPRmyDpEwSGsN+p7UCM4b3Y9lbFVO3y1m8R9lFmWHJWOW50l2mXWgkjAOZqN dU0Prb778KhrBZsbknaYXIAiaIwDqPfty+TJO8Jbi/Ok5T89GfXIXmViirNA45tRnp1zq2tI6AO/y Oo=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com, Anton Johansson Subject: [PATCH v5 23/25] target/riscv: Move CSR declarations to separate csr.h header Date: Mon, 3 Nov 2025 18:12:06 +0100 Message-ID: <20251103171208.24355-24-anjo@rev.ng> In-Reply-To: <20251103171208.24355-1-anjo@rev.ng> References: <20251103171208.24355-1-anjo@rev.ng> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1762189934873154100 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 Reviewed-by: Pierrick Bouvier Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- 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/riscv-qmp-cmds.c | 1 + target/riscv/th_csr.c | 1 + 9 files changed, 102 insertions(+), 81 deletions(-) create mode 100644 target/riscv/csr.h diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index d1a8384646..e751ceb24a 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -859,75 +859,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_csrr(env, csrno, &val); - 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 "target/riscv/csr.h" =20 /* * The event id are encoded based on the encoding specified in the @@ -971,23 +903,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..5b92f6fecc --- /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_csrr(env, csrno, &val); + 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 2084b0d0bf..7a8b8d736e 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 "target/riscv/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 e60741def2..0f2ed881d5 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -21,6 +21,7 @@ #include "qemu/log.h" #include "qemu/timer.h" #include "cpu.h" +#include "target/riscv/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..d54ba179e6 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 "target/riscv/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 000e44b2b7..b985c08b17 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 "target/riscv/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 6ccc127c30..9767febb5a 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 "target/riscv/csr.h" #include "internals.h" #include "exec/cputlb.h" #include "accel/tcg/cpu-ldst.h" diff --git a/target/riscv/riscv-qmp-cmds.c b/target/riscv/riscv-qmp-cmds.c index 93488450bd..fdc6ba8c83 100644 --- a/target/riscv/riscv-qmp-cmds.c +++ b/target/riscv/riscv-qmp-cmds.c @@ -39,6 +39,7 @@ #include "system/tcg.h" #include "cpu-qom.h" #include "cpu.h" +#include "target/riscv/csr.h" =20 static void riscv_cpu_add_definition(gpointer data, gpointer user_data) { diff --git a/target/riscv/th_csr.c b/target/riscv/th_csr.c index 49eb7bbab5..a4ea4ce391 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 "target/riscv/csr.h" =20 #define CSR_TH_SXSTATUS 0x5c0 =20 --=20 2.51.0 From nobody Fri Nov 14 19:42:16 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=1762189890; cv=none; d=zohomail.com; s=zohoarc; b=n003BFpOe1k0s6tUvcdegSM2+mI1B4yLMErI2ul3VpMJyUxfiKJKxaht1zrKtHk+ve7BQkkUJj5lyLJw9R9bRApsOVJjUPX8pfZkI1Ewk34JNFLhS4ogCTsSUsMBcRA2V966EsPjgKuPWejiZ6mBgfKlyngkmE7gyaqocgrcwOY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762189890; 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=d7JyKwBkIkaig0Rkbv5IkbhgBXe/lGt5tv3SeTLR+7M=; b=CcRbuv3XRqniYryrpivruPj2AoE57QLyl+QeNEOpLvv5suypn9LpEJNv0kclGhBWT7fKepBJzsrOQ07TnPmO0mGn1jNNhQ5oasICuGOr4ITyRHMq9nHWpBfP3uANmT863dgPpP+qeWTQLK/Ex1ufZ+6jVzAUtTL0IwFcjc+k6Jc= 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 1762189889936276.26647514586784; Mon, 3 Nov 2025 09:11:29 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vFy4I-0000h8-G9; Mon, 03 Nov 2025 12:10:11 -0500 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 1vFy4B-0000bq-Ex for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:10:07 -0500 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 1vFy3r-0000tu-8t for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:10:02 -0500 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=d7JyKwBkIkaig0Rkbv5IkbhgBXe/lGt5tv3SeTLR+7M=; b=dp/0EXYl/RTimmB wy5RTgHiKJZ9eqWHhMlPn087u2cJBTAzKk3qGV97V7kFN8Mocekiwn1vBUXrmqVjfp7tCUvQEpjBo XuSS1gwWYuxLKdLVbOiaIcL7i6HG9dmtqVfJ+/F7HSwgoNSErKFOnJJ1SNV44XOOIcboHZeJnQGMy ug=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com, Anton Johansson Subject: [PATCH v5 24/25] target/riscv: Introduce externally facing CSR access functions Date: Mon, 3 Nov 2025 18:12:07 +0100 Message-ID: <20251103171208.24355-25-anjo@rev.ng> In-Reply-To: <20251103171208.24355-1-anjo@rev.ng> References: <20251103171208.24355-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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1762189892340154100 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 Reviewed-by: Pierrick Bouvier --- 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 e751ceb24a..616406f07f 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -859,7 +859,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 "target/riscv/csr.h" +/* + * Externally facing CSR access functions, wrappers around riscv_csr*(). + */ + +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 5b92f6fecc..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_csrr(env, csrno, &val); - 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 0f2ed881d5..c3cf8e6312 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -5638,6 +5638,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 Fri Nov 14 19:42:16 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=1762190010; cv=none; d=zohomail.com; s=zohoarc; b=bQ/oo0MJr2K779GCwviG96UKAhTRHiUxw2Jrj+WxuRzLKi0VDiJTAImAhDTZEvjxmayAFmtZSonrVCnM9SBTOhQlpQRwtxNXDZU5ueCXvFhJWElFH15Rd3iy518ewsm+GZI7SEjmaMMlcZMGPaERGNc5iJjChqIumUrdRiwVOJw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762190010; h=Content-Type: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=eev5Lo5++MldWSwigyJl/p1GZnnsmAjufLhfJFBnfBE=; b=K1/qnpWfoptbSdwhFl40auV0tJ8PzHLM9Ikchi3D9FdBKKpWrgtC9r7cJ+Yniprj+ox+QLklUdZ0aCd3t/pIAYMM3/lI5+Z4+edCfpQWHe5Ep049r9ZrE8ZfkWcblpg5AJtqCPY82/fs7j7/NdT63UksN9lZAEJsB+PGXGkrD70= 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 1762190010583262.00947568045217; Mon, 3 Nov 2025 09:13:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vFy45-0000b0-7X; Mon, 03 Nov 2025 12:09:57 -0500 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 1vFy3z-0000ZS-Qx for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:51 -0500 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 1vFy3n-0000uC-Bh for qemu-devel@nongnu.org; Mon, 03 Nov 2025 12:09:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: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=eev5Lo5++MldWSwigyJl/p1GZnnsmAjufLhfJFBnfBE=; b=C3esiOMK9AiW8Eg 0zwefiFvR5MK0VZVYr03nJUdQ/og1yM3M706x/nCoTPhIM54qTbuuOKVnwPzYPYBzWNhokgV8O1UT co0046X6CAlSDmTYR9ffPcJ4u+EONJrjRTZydBPt0jdFcdWO3+L/A+0sOMI3vEYU4SeMkn/vSZe9a 2I=; To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, philmd@linaro.org, alistair.francis@wdc.com, palmer@dabbelt.com, Anton Johansson Subject: [PATCH v5 25/25] target/riscv: Make pmp.h target_ulong agnostic Date: Mon, 3 Nov 2025 18:12:08 +0100 Message-ID: <20251103171208.24355-26-anjo@rev.ng> In-Reply-To: <20251103171208.24355-1-anjo@rev.ng> References: <20251103171208.24355-1-anjo@rev.ng> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1762190014256158501 The pmp.h header is exposed through cpu.h. pmp_table_t is also used in CPUArchState. CSR declarations 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. Note, the cpu/pmp/entry and cpu/pmp VMSTATE versions are bumped, breaking migration from older versions. Signed-off-by: Anton Johansson Reviewed-by: Pierrick Bouvier Reviewed-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Alistair Francis --- target/riscv/csr.h | 12 ++++++++++++ target/riscv/pmp.h | 20 +++++--------------- target/riscv/machine.c | 10 +++++----- target/riscv/pmp.c | 10 ++++++---- 4 files changed, 28 insertions(+), 24 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..f5d6ec2bbf 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); + privilege_mode_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 36f4c3251d..13eb292c4a 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -48,10 +48,10 @@ static int pmp_post_load(void *opaque, int version_id) =20 static const VMStateDescription vmstate_pmp_entry =3D { .name =3D "cpu/pmp/entry", - .version_id =3D 1, - .minimum_version_id =3D 1, + .version_id =3D 2, + .minimum_version_id =3D 2, .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() } @@ -59,8 +59,8 @@ static const VMStateDescription vmstate_pmp_entry =3D { =20 static const VMStateDescription vmstate_pmp =3D { .name =3D "cpu/pmp", - .version_id =3D 1, - .minimum_version_id =3D 1, + .version_id =3D 2, + .minimum_version_id =3D 2, .needed =3D pmp_needed, .post_load =3D pmp_post_load, .fields =3D (const VMStateField[]) { diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c index 0b23b4b8ed..c68c787cf2 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" @@ -298,7 +299,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) + privilege_mode_t mode) { bool ret; =20 @@ -357,8 +358,9 @@ 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, + privilege_mode_t mode) { int i =3D 0; int pmp_size =3D 0; @@ -708,7 +710,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