From nobody Sat Nov 23 21:58:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1728905020; cv=none; d=zohomail.com; s=zohoarc; b=NNvByDQYu/qr0e1d0Avc9S44doCzBTAZfUqCQ1z0pCCn55wsb7fXDEunA2TdeTFGWAxW0Z28iDueMPMOetv4TNXM5xSAWTEqxy2Ufd40bGSXY3c+z0z1loYZkdExIXCFBgGkCBnU+zIj+UNKftkwmyCCoBUkoAGlA8S7t2unF/I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728905020; 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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=qjN8wKf5K4ezvTvEHU+TdCvJYSkiifzqI48ozvO9hPc=; b=awskNl3HCZqjjimKZafrPlSRQzEeYbiOTY2NdLzWFHXLd/AUcaLeVqe5ye7Z+a2UzwJBSy2zBC2I6zaXWZ9SAHDDfmFCxVU+tEzoGbcBtbp56Shq5AFxkAdf2n3d/rdUGNLKpZKRqhZL2TR/oisiIC/EuJphnHoS3LxhrczT1l0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1728905020809542.506115343172; Mon, 14 Oct 2024 04:23:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t0J9r-0006VL-MV; Mon, 14 Oct 2024 07:22:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t0J9p-0006UY-Ur for qemu-devel@nongnu.org; Mon, 14 Oct 2024 07:22:37 -0400 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t0J9n-0002bt-5G for qemu-devel@nongnu.org; Mon, 14 Oct 2024 07:22:37 -0400 Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-37d538fe5f2so2254686f8f.2 for ; Mon, 14 Oct 2024 04:22:34 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:e17:9700:16d2:7456:6634:9626]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37d4b6bd382sm11117303f8f.43.2024.10.14.04.22.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 04:22:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1728904953; x=1729509753; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qjN8wKf5K4ezvTvEHU+TdCvJYSkiifzqI48ozvO9hPc=; b=OF3h6zDa2Qu2X35AyMNZjVJPNoK0d0CqCiV2aCnfC7AXt1o8/kmfFd2LkK9ASX0Ryq ROZzFbIPJ3lpxxEEI0mESO47UoWR8HN2KfEjkq3xHKHJAWKyxL1fU9DGl+zc0BjDzd8M G7rcWp9/tly2xN/5HUbUMoG9LEZCLSLmgj/ry5Kj5gn2B1Yc985NANTgEdj/HZQqpH7S HfQ5NO1oOIGGzBmqd4r30yk73NK0BQrsCir/MRX9/e+FvhI34RdxQGBhIj8XCXgH0X8B EB1T4kK6w/Kpd7UUQ1kla+DdZEWrTwSWG5+oqu53idNEFq7QyWhty0SDq2ex4dkitamy 7GXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728904953; x=1729509753; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qjN8wKf5K4ezvTvEHU+TdCvJYSkiifzqI48ozvO9hPc=; b=HnDwrf2wgpppyqYwf9fX6w9ImSmav3jSyC1I4Rz1ll5xzOrjekkipk/pPYM3W7qS62 evIJOD7yTrgv77d4p9PsC8LEQdo+Xcw4Twa+mUytlLuKj9brMJRbwaMLF7zfHAl0/P7a gEw8FEZTShWk6OeOHS350SLGEQpDPrx4GHLoL812vnYf+1nlTbwSQC5Rco4y/bp68Ch2 vfVhwAYGUJWRyaJNadd5yCERr9kIWiOlo1w3h/zNUhBl/MQvTjFwtzRgQFI6n1poWKlh jDKwi+/+w5ty/o2PVRKx2ng7NQI/YocJwPJgHtAnCRAWDz2JG5otgMQHsRaM9/0n5s2R R1ng== X-Forwarded-Encrypted: i=1; AJvYcCXfcRZyZOT2HhXK6f9yeTDsBLxojyorFtTx/ciAYhjK8+oecx9sKtg6s/GimVsEYojNq4APaidP5Wxa@nongnu.org X-Gm-Message-State: AOJu0Yz/YahTWIr5mL6NAzxdEYvloPA+Akp9YGvgVU3JeUDgTsVCv7DQ qpgZb2VnUvWmN2eEVaaMO6TeFa9L2STEkhwReRj586Z5u1UX9iWc3IYMfuzXXXA= X-Google-Smtp-Source: AGHT+IGbPzMcm/Zfjl0n05/ZyduCCSZBi+fLF4QFyNAiF3cWdTPk7r1AQRqagmIxtqV9k8E1fM5AAQ== X-Received: by 2002:a5d:6703:0:b0:37d:4dd5:220f with SMTP id ffacd0b85a97d-37d551fba84mr7417012f8f.26.1728904953126; Mon, 14 Oct 2024 04:22:33 -0700 (PDT) From: =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= To: qemu-riscv@nongnu.org, Palmer Dabbelt , Alistair Francis , Bin Meng Cc: =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , Ved Shanbhogue , Atish Patra , qemu-devel@nongnu.org Subject: [PATCH v3 1/8] target/riscv: Add Ssdbltrp CSRs handling Date: Mon, 14 Oct 2024 13:22:11 +0200 Message-ID: <20241014112225.90297-2-cleger@rivosinc.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241014112225.90297-1-cleger@rivosinc.com> References: <20241014112225.90297-1-cleger@rivosinc.com> 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=2a00:1450:4864:20::42e; envelope-from=cleger@rivosinc.com; helo=mail-wr1-x42e.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1728905022571116600 Add ext_ssdbltrp in RISCVCPUConfig and implement MSTATUS.SDT, {H|M}ENVCFG.DTE and modify the availability of MTVAL2 based on the presence of the Ssdbltrp ISA extension. Signed-off-by: Cl=C3=A9ment L=C3=A9ger Reviewed-by: Alistair Francis --- target/riscv/cpu.h | 1 + target/riscv/cpu_bits.h | 6 ++++++ target/riscv/cpu_cfg.h | 1 + target/riscv/cpu_helper.c | 20 +++++++++++++++++ target/riscv/csr.c | 45 ++++++++++++++++++++++++++++++--------- 5 files changed, 63 insertions(+), 10 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index a84e719d3f..ee984bf270 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -553,6 +553,7 @@ void riscv_cpu_set_geilen(CPURISCVState *env, target_ul= ong 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); +bool riscv_env_smode_dbltrp_enabled(CPURISCVState *env, bool virt); G_NORETURN void riscv_cpu_do_unaligned_access(CPUState *cs, vaddr addr, MMUAccessType access_type, int mmu_idx, uintptr_t reta= ddr); diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h index da1723496c..3a5588d4df 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -558,6 +558,7 @@ #define MSTATUS_TVM 0x00100000 /* since: priv-1.10 */ #define MSTATUS_TW 0x00200000 /* since: priv-1.10 */ #define MSTATUS_TSR 0x00400000 /* since: priv-1.10 */ +#define MSTATUS_SDT 0x01000000 #define MSTATUS_GVA 0x4000000000ULL #define MSTATUS_MPV 0x8000000000ULL =20 @@ -588,6 +589,7 @@ typedef enum { #define SSTATUS_XS 0x00018000 #define SSTATUS_SUM 0x00040000 /* since: priv-1.10 */ #define SSTATUS_MXR 0x00080000 +#define SSTATUS_SDT 0x01000000 =20 #define SSTATUS64_UXL 0x0000000300000000ULL =20 @@ -777,11 +779,13 @@ typedef enum RISCVException { #define MENVCFG_CBIE (3UL << 4) #define MENVCFG_CBCFE BIT(6) #define MENVCFG_CBZE BIT(7) +#define MENVCFG_DTE (1ULL << 59) #define MENVCFG_ADUE (1ULL << 61) #define MENVCFG_PBMTE (1ULL << 62) #define MENVCFG_STCE (1ULL << 63) =20 /* For RV32 */ +#define MENVCFGH_DTE BIT(27) #define MENVCFGH_ADUE BIT(29) #define MENVCFGH_PBMTE BIT(30) #define MENVCFGH_STCE BIT(31) @@ -795,11 +799,13 @@ typedef enum RISCVException { #define HENVCFG_CBIE MENVCFG_CBIE #define HENVCFG_CBCFE MENVCFG_CBCFE #define HENVCFG_CBZE MENVCFG_CBZE +#define HENVCFG_DTE MENVCFG_DTE #define HENVCFG_ADUE MENVCFG_ADUE #define HENVCFG_PBMTE MENVCFG_PBMTE #define HENVCFG_STCE MENVCFG_STCE =20 /* For RV32 */ +#define HENVCFGH_DTE MENVCFGH_DTE #define HENVCFGH_ADUE MENVCFGH_ADUE #define HENVCFGH_PBMTE MENVCFGH_PBMTE #define HENVCFGH_STCE MENVCFGH_STCE diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h index ae2a945b5f..dd804f95d4 100644 --- a/target/riscv/cpu_cfg.h +++ b/target/riscv/cpu_cfg.h @@ -77,6 +77,7 @@ struct RISCVCPUConfig { bool ext_smstateen; bool ext_sstc; bool ext_smcntrpmf; + bool ext_ssdbltrp; bool ext_svadu; bool ext_svinval; bool ext_svnapot; diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 9d0400035f..77e7736d8a 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -63,6 +63,22 @@ int riscv_env_mmu_index(CPURISCVState *env, bool ifetch) #endif } =20 +bool riscv_env_smode_dbltrp_enabled(CPURISCVState *env, bool virt) +{ +#ifdef CONFIG_USER_ONLY + return false; +#else + if (!riscv_cpu_cfg(env)->ext_ssdbltrp) { + return false; + } + if (virt) { + return (env->henvcfg & HENVCFG_DTE) !=3D 0; + } else { + return (env->menvcfg & MENVCFG_DTE) !=3D 0; + } +#endif +} + void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc, uint64_t *cs_base, uint32_t *pflags) { @@ -562,6 +578,10 @@ void riscv_cpu_swap_hypervisor_regs(CPURISCVState *env) =20 g_assert(riscv_has_ext(env, RVH)); =20 + if (riscv_env_smode_dbltrp_enabled(env, current_virt)) { + mstatus_mask |=3D MSTATUS_SDT; + } + if (current_virt) { /* Current V=3D1 and we are about to change to V=3D0 */ env->vsstatus =3D env->mstatus & mstatus_mask; diff --git a/target/riscv/csr.c b/target/riscv/csr.c index e5de72453c..d8280ec956 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -540,6 +540,15 @@ static RISCVException aia_hmode32(CPURISCVState *env, = int csrno) return hmode32(env, csrno); } =20 +static RISCVException dbltrp_hmode(CPURISCVState *env, int csrno) +{ + if (riscv_cpu_cfg(env)->ext_ssdbltrp) { + return RISCV_EXCP_NONE; + } + + return hmode(env, csrno); +} + static RISCVException pmp(CPURISCVState *env, int csrno) { if (riscv_cpu_cfg(env)->pmp) { @@ -1402,7 +1411,7 @@ static const target_ulong vs_delegable_excps =3D DELE= GABLE_EXCPS & (1ULL << (RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT))); static const target_ulong sstatus_v1_10_mask =3D SSTATUS_SIE | SSTATUS_SPI= E | SSTATUS_UIE | SSTATUS_UPIE | SSTATUS_SPP | SSTATUS_FS | SSTATUS_XS | - SSTATUS_SUM | SSTATUS_MXR | SSTATUS_VS; + SSTATUS_SUM | SSTATUS_MXR | SSTATUS_VS | SSTATUS_SDT; =20 /* * Spec allows for bits 13:63 to be either read-only or writable. @@ -1600,6 +1609,14 @@ static RISCVException write_mstatus(CPURISCVState *e= nv, int csrno, mask |=3D MSTATUS_VS; } =20 + if (riscv_env_smode_dbltrp_enabled(env, env->virt_enabled)) { + mask |=3D MSTATUS_SDT; + if ((val & MSTATUS_SDT) !=3D 0) { + mstatus &=3D ~MSTATUS_SIE; + val &=3D ~MSTATUS_SIE; + } + } + if (xl !=3D MXL_RV32 || env->debugger) { if (riscv_has_ext(env, RVH)) { mask |=3D MSTATUS_MPV | MSTATUS_GVA; @@ -2354,7 +2371,8 @@ static RISCVException write_menvcfg(CPURISCVState *en= v, int csrno, if (riscv_cpu_mxl(env) =3D=3D MXL_RV64) { mask |=3D (cfg->ext_svpbmt ? MENVCFG_PBMTE : 0) | (cfg->ext_sstc ? MENVCFG_STCE : 0) | - (cfg->ext_svadu ? MENVCFG_ADUE : 0); + (cfg->ext_svadu ? MENVCFG_ADUE : 0) | + (cfg->ext_ssdbltrp ? MENVCFG_DTE : 0); } env->menvcfg =3D (env->menvcfg & ~mask) | (val & mask); =20 @@ -2374,7 +2392,8 @@ static RISCVException write_menvcfgh(CPURISCVState *e= nv, int csrno, const RISCVCPUConfig *cfg =3D riscv_cpu_cfg(env); uint64_t mask =3D (cfg->ext_svpbmt ? MENVCFG_PBMTE : 0) | (cfg->ext_sstc ? MENVCFG_STCE : 0) | - (cfg->ext_svadu ? MENVCFG_ADUE : 0); + (cfg->ext_svadu ? MENVCFG_ADUE : 0) | + (cfg->ext_ssdbltrp ? MENVCFG_DTE : 0); uint64_t valh =3D (uint64_t)val << 32; =20 env->menvcfg =3D (env->menvcfg & ~mask) | (valh & mask); @@ -2425,9 +2444,10 @@ static RISCVException read_henvcfg(CPURISCVState *en= v, int csrno, * henvcfg.pbmte is read_only 0 when menvcfg.pbmte =3D 0 * henvcfg.stce is read_only 0 when menvcfg.stce =3D 0 * henvcfg.adue is read_only 0 when menvcfg.adue =3D 0 + * henvcfg.dte is read_only 0 when menvcfg.dte =3D 0 */ - *val =3D env->henvcfg & (~(HENVCFG_PBMTE | HENVCFG_STCE | HENVCFG_ADUE= ) | - env->menvcfg); + *val =3D env->henvcfg & (~(HENVCFG_PBMTE | HENVCFG_STCE | HENVCFG_ADUE= | + HENVCFG_DTE) | env->menvcfg); return RISCV_EXCP_NONE; } =20 @@ -2435,6 +2455,7 @@ static RISCVException write_henvcfg(CPURISCVState *en= v, int csrno, target_ulong val) { uint64_t mask =3D HENVCFG_FIOM | HENVCFG_CBIE | HENVCFG_CBCFE | HENVCF= G_CBZE; + uint64_t menvcfg_mask; RISCVException ret; =20 ret =3D smstateen_acc_ok(env, 0, SMSTATEEN0_HSENVCFG); @@ -2443,7 +2464,11 @@ static RISCVException write_henvcfg(CPURISCVState *e= nv, int csrno, } =20 if (riscv_cpu_mxl(env) =3D=3D MXL_RV64) { - mask |=3D env->menvcfg & (HENVCFG_PBMTE | HENVCFG_STCE | HENVCFG_A= DUE); + menvcfg_mask =3D HENVCFG_PBMTE | HENVCFG_STCE | HENVCFG_ADUE; + if (riscv_cpu_cfg(env)->ext_ssdbltrp) { + menvcfg_mask |=3D HENVCFG_DTE; + } + mask |=3D env->menvcfg & menvcfg_mask; } =20 env->henvcfg =3D (env->henvcfg & ~mask) | (val & mask); @@ -2461,8 +2486,8 @@ static RISCVException read_henvcfgh(CPURISCVState *en= v, int csrno, return ret; } =20 - *val =3D (env->henvcfg & (~(HENVCFG_PBMTE | HENVCFG_STCE | HENVCFG_ADU= E) | - env->menvcfg)) >> 32; + *val =3D (env->henvcfg & (~(HENVCFG_PBMTE | HENVCFG_STCE | HENVCFG_ADU= E | + HENVCFG_DTE) | env->menvcfg)) >> 32; return RISCV_EXCP_NONE; } =20 @@ -2470,7 +2495,7 @@ static RISCVException write_henvcfgh(CPURISCVState *e= nv, int csrno, target_ulong val) { uint64_t mask =3D env->menvcfg & (HENVCFG_PBMTE | HENVCFG_STCE | - HENVCFG_ADUE); + HENVCFG_ADUE | HENVCFG_DTE); uint64_t valh =3D (uint64_t)val << 32; RISCVException ret; =20 @@ -5246,7 +5271,7 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { [CSR_VSATP] =3D { "vsatp", hmode, read_vsatp, write_v= satp, .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, =20 - [CSR_MTVAL2] =3D { "mtval2", hmode, read_mtval2, write_m= tval2, + [CSR_MTVAL2] =3D { "mtval2", dbltrp_hmode, read_mtval2, write_mtv= al2, .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, [CSR_MTINST] =3D { "mtinst", hmode, read_mtinst, write_m= tinst, .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, --=20 2.45.2 From nobody Sat Nov 23 21:58:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1728905055; cv=none; d=zohomail.com; s=zohoarc; b=Y2oLv8eZfnSOqhi5/pAAMVFwYrL818irba4Jy8Q8GVoixBVsWgsC4eTuIG0lGGtSqCs5RWE4ooTuVksWmPxdANs05Qr8KcwVYt69alknaZXAvEM3tIpaB0VEElJ2kgiLht7sf/ic0fZgHW0jeMzV3l15d6PngeTchXkNS0IjIl8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728905055; 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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=990Tx1Qy7IC4XWEHL20LmKjYVwPDG37slOaxsBSKYtM=; b=fx2o7yMuHeqRoqn3pdP1wW6kOjx23DoB4ShENKlZixAdG+y0BTXLO/Ac3VxDcTmwWUBhQN2Dy1Ei6pqTjb2s5McbgbSTy++pyesr3rdzJjlyPoFdTkua1CXEXd5A/7Sd/Jznv5ecItRl7yzpVK9LaHuEY+ZX+fmM1MsWsAXAoQw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1728905055365230.37959178425194; Mon, 14 Oct 2024 04:24:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t0J9u-0006XC-9h; Mon, 14 Oct 2024 07:22:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t0J9s-0006Vu-EZ for qemu-devel@nongnu.org; Mon, 14 Oct 2024 07:22:40 -0400 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t0J9o-0002cC-C0 for qemu-devel@nongnu.org; Mon, 14 Oct 2024 07:22:40 -0400 Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-37d4ba20075so2707589f8f.0 for ; Mon, 14 Oct 2024 04:22:35 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:e17:9700:16d2:7456:6634:9626]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37d4b6bd382sm11117303f8f.43.2024.10.14.04.22.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 04:22:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1728904955; x=1729509755; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=990Tx1Qy7IC4XWEHL20LmKjYVwPDG37slOaxsBSKYtM=; b=y0rX1wlFmycsk12CTESDyq0NIDrs3pumWVWJFdZ68Ud53SETw/4OX3gUpNLTANtqaX OZGavihpQfhYxuaVc0/R0cBWDLcBUNK6yyl+sQ5+NRTE0Z5HgpNLvTZyhD2sVZvxU6lt uS0Pl6ljmpWvDCa4/7LIyqQ13UM8zlSjx+XahVFTX1aBNfPujsK4L7Xe6N5o8NdqTC/h I3OUc7RTNrN5n0/NpTpWUJIV8kfMaHk4lOAQOBNdBxhIL496i8313wGsnhTzO+g5uSDW yKEokPb6htVqmIIibWpH+PtNUlQCDw9eRDQUS4a4tZkKgrNzqUAfqLexPCeELbOZkSFx +Ncg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728904955; x=1729509755; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=990Tx1Qy7IC4XWEHL20LmKjYVwPDG37slOaxsBSKYtM=; b=jck9+ZzaqSlLWDXo9n3bIspez2s0P6WyWbUSJLLSU2vjCzM3p7DR+AuNv/FA3AADim O2u6NjuCpT1iNtIgrxRG80LvEsrdoB13nIugVTetKS19deRuMcdTGOXJlOed2XYoqn9R 0vYRUioq6eps1RF8HgIoIpHm6RJeZ12R528flBlA9No4EfB+beEJJsMQY03hDDaLwvx6 xzssBrU5Rl3G5cQphXZND7IgUTU7TOEwl8oCGbGM5ZCSsaZcewGg1KlpD9iH9a0i5T2T B2Ot/jfQ3OnS0t37UNFMAfQnj8oDiyCqGTJzbqg2bxsGb/W9DsFZrFbv5t+qNcThWB+1 rsoA== X-Forwarded-Encrypted: i=1; AJvYcCWbRDr1SExweEksyZBRlJjzLcw0wxeuwVbt3gmvodjN6ZBKOEv2zPw3FnSA9SghaB6y0Ow5rESvwVAD@nongnu.org X-Gm-Message-State: AOJu0YyxmiikYLJOj9FhQrOSv+6UxXxnaHRpMFIQ7Fxqet5O+mGJg2bn ZSA1uaVGsMJslK0OKMaBWOKlxDWzkrVTaMPMLhL1Pf4SnS5aIi9mnqhsFhx6ay8= X-Google-Smtp-Source: AGHT+IGBwg6+az91sKfdJJ7OleyK1sJ5Nc58uitn0czINmWh1s+13lyAc3K3Bz0ESbOBgNwZw1loZQ== X-Received: by 2002:adf:fa89:0:b0:37c:c9ae:23fb with SMTP id ffacd0b85a97d-37d5529ad6amr7693169f8f.40.1728904954656; Mon, 14 Oct 2024 04:22:34 -0700 (PDT) From: =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= To: qemu-riscv@nongnu.org, Palmer Dabbelt , Alistair Francis , Bin Meng Cc: =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , Ved Shanbhogue , Atish Patra , qemu-devel@nongnu.org Subject: [PATCH v3 2/8] target/riscv: Implement Ssdbltrp sret, mret and mnret behavior Date: Mon, 14 Oct 2024 13:22:12 +0200 Message-ID: <20241014112225.90297-3-cleger@rivosinc.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241014112225.90297-1-cleger@rivosinc.com> References: <20241014112225.90297-1-cleger@rivosinc.com> 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=2a00:1450:4864:20::42e; envelope-from=cleger@rivosinc.com; helo=mail-wr1-x42e.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1728905056092116600 When the Ssdbltrp extension is enabled, SSTATUS.SDT field is cleared when executing sret. When executing mret/mnret, SSTATUS.SDT is cleared when returning to U, VS or VU and VSSTATUS.SDT is cleared when returning to VU from HS. Signed-off-by: Cl=C3=A9ment L=C3=A9ger --- target/riscv/op_helper.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c index 6895c7596b..00b6f75102 100644 --- a/target/riscv/op_helper.c +++ b/target/riscv/op_helper.c @@ -287,6 +287,18 @@ target_ulong helper_sret(CPURISCVState *env) get_field(mstatus, MSTATUS_SPIE)); mstatus =3D set_field(mstatus, MSTATUS_SPIE, 1); mstatus =3D set_field(mstatus, MSTATUS_SPP, PRV_U); + + if (riscv_cpu_cfg(env)->ext_ssdbltrp) { + if (riscv_has_ext(env, RVH)) { + target_ulong prev_vu =3D get_field(env->hstatus, HSTATUS_SPV) = && + prev_priv =3D=3D PRV_U; + /* Returning to VU from HS, vsstatus.sdt =3D 0 */ + if (!env->virt_enabled && prev_vu) { + env->vsstatus =3D set_field(env->vsstatus, MSTATUS_SDT, 0); + } + } + mstatus =3D set_field(mstatus, MSTATUS_SDT, 0); + } if (env->priv_ver >=3D PRIV_VERSION_1_12_0) { mstatus =3D set_field(mstatus, MSTATUS_MPRV, 0); } @@ -297,7 +309,6 @@ target_ulong helper_sret(CPURISCVState *env) target_ulong hstatus =3D env->hstatus; =20 prev_virt =3D get_field(hstatus, HSTATUS_SPV); - hstatus =3D set_field(hstatus, HSTATUS_SPV, 0); =20 env->hstatus =3D hstatus; @@ -328,6 +339,22 @@ static void check_ret_from_m_mode(CPURISCVState *env, = target_ulong retpc, riscv_raise_exception(env, RISCV_EXCP_INST_ACCESS_FAULT, GETPC()); } } +static target_ulong ssdbltrp_mxret(CPURISCVState *env, target_ulong mstatu= s, + target_ulong prev_priv, + target_ulong prev_virt) +{ + /* If returning to U, VS or VU, sstatus.sdt =3D 0 */ + if (prev_priv =3D=3D PRV_U || (prev_virt && + (prev_priv =3D=3D PRV_S || prev_priv =3D=3D PRV_U))) { + mstatus =3D set_field(mstatus, MSTATUS_SDT, 0); + /* If returning to VU, vsstatus.sdt =3D 0 */ + if (prev_virt && prev_priv =3D=3D PRV_U) { + env->vsstatus =3D set_field(env->vsstatus, MSTATUS_SDT, 0); + } + } + + return mstatus; +} =20 target_ulong helper_mret(CPURISCVState *env) { @@ -345,6 +372,9 @@ target_ulong helper_mret(CPURISCVState *env) mstatus =3D set_field(mstatus, MSTATUS_MPP, riscv_has_ext(env, RVU) ? PRV_U : PRV_M); mstatus =3D set_field(mstatus, MSTATUS_MPV, 0); + if (riscv_cpu_cfg(env)->ext_ssdbltrp) { + mstatus =3D ssdbltrp_mxret(env, mstatus, prev_priv, prev_virt); + } if ((env->priv_ver >=3D PRIV_VERSION_1_12_0) && (prev_priv !=3D PRV_M)= ) { mstatus =3D set_field(mstatus, MSTATUS_MPRV, 0); } @@ -382,6 +412,9 @@ target_ulong helper_mnret(CPURISCVState *env) if (prev_priv < PRV_M) { env->mstatus =3D set_field(env->mstatus, MSTATUS_MPRV, false); } + if (riscv_cpu_cfg(env)->ext_ssdbltrp) { + env->mstatus =3D ssdbltrp_mxret(env, env->mstatus, prev_priv, prev= _virt); + } =20 if (riscv_has_ext(env, RVH) && prev_virt) { riscv_cpu_swap_hypervisor_regs(env); --=20 2.45.2 From nobody Sat Nov 23 21:58:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1728905023; cv=none; d=zohomail.com; s=zohoarc; b=g7z4aP9SCi12oYchsxoovNv4kTL/a+fQhSRhkZnt3+kkpAl3dNSxns0JEnJ/l+8XGDqK8vENK6SB3cTnCMyfby8s/gNjstseI0DvGqaT0mvunOuAI4ySkDuV4l8XeGcL+CjcjYOwrb/i2VVqKiOTIQzb/LGS7zxZfdNCRbM67+I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728905023; 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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=/Xvl0BCdfuSbxLN2r2iyzpL1Dr4H5UKtM3MitHEn5Ro=; b=MId5AxmicLSY6x1iZjsgMxvGzyHB/KFMuUkHVm/DeIu5AmWkUxK8cmQB7pHFwpYWLM1UXbC37mer23gRDkEXvcGgNvLNvr0j6hK8qteOCV4aVo4exQCsTtwnpBpLl8vImTRB8tmyZSmxVgk9YjR5ACf9PP/vEbROuFh2R9TCWxI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1728905023231659.7830364844822; Mon, 14 Oct 2024 04:23:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t0J9v-0006Xs-0C; Mon, 14 Oct 2024 07:22:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t0J9r-0006VT-MV for qemu-devel@nongnu.org; Mon, 14 Oct 2024 07:22:39 -0400 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t0J9p-0002cV-PA for qemu-devel@nongnu.org; Mon, 14 Oct 2024 07:22:39 -0400 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-37d4a5ecc44so2953341f8f.2 for ; Mon, 14 Oct 2024 04:22:37 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:e17:9700:16d2:7456:6634:9626]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37d4b6bd382sm11117303f8f.43.2024.10.14.04.22.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 04:22:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1728904956; x=1729509756; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/Xvl0BCdfuSbxLN2r2iyzpL1Dr4H5UKtM3MitHEn5Ro=; b=vN+gZ/Ze+Jpr9YUr7RTD0bsowZTVgPb/7PDg4nsxvuGv0knpFZgOd8ZQuiX6g6Guzr HUnYjGh3D4a+wbhmRGEppNwrwGjup2Vj4Ie1izB3SMb/LhmVJhiteasZfO9lURXYjj2I EEzp7Vg0fVu/aeDieGJAmTN/lkyuMt6C5u975ZWEz/gSWqS3ciUAME0jp2xx4pAtf4i6 5dN+jRMFZfM08pKjD5+4yzclrEx8RBKFxFhxBoNKYIuC7jMMKi+uhX1sr4iB/aPZvidW aCwoanPfcxs6EMk7xufVG1ZBpeV5nWtkrwlv0OLvmnDdUQum+HoxkRhGE0IMSlTt//Zv cnCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728904956; x=1729509756; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/Xvl0BCdfuSbxLN2r2iyzpL1Dr4H5UKtM3MitHEn5Ro=; b=S65zlL1AMkLKd88kYWRZQHq10KIdfFitL5R3W93Bx/kD/X89bUZUorCzPudKBL0xV4 iaP9DjWIJXbuvcQU3hoZsXMpCx2Ql1MSeoShV5DjciHIYLuMoXzhVh2gPPEm1MS1PT2o acC/9ELe0+IiXgj5CFi+76o6vM4k5SLkEJ7aJhR0rxTAZHOHCwUpuOXSo19XjHJxr7WE Y4tWScWedYKdHJVQ94uI6sSSiSwSwn0v0DoDMgOwtcFWXWB+5VP8TlrCHQXASVVmkICw eC7k+F2pnIRG1s+OgqWVMRH/nVfXLsLUf3AQAwnm+0bAxzvf7x+Vk1x4ImSDZzKDMso1 inUg== X-Forwarded-Encrypted: i=1; AJvYcCVC6yw/EnGGH+Hpor+/Wf4rGu16UiUTtu9zleC/kBwkCgjoJPgL+/Aug0Ib9Ob4qGcD7s89fd7Ajcxm@nongnu.org X-Gm-Message-State: AOJu0YyP6gjXyPgT+bH0Sm3wMQoI88Omx+9OQR1uP0YPwELb53Rzf0QP KuNzsKpxBlHFLZutxWk05F25zoYJJi3eQPaA4bk+niE1Py8wf+x5+sF0ODoAChM= X-Google-Smtp-Source: AGHT+IFTB/L7tF0axs2brZvg17fG9mIyc4+5Q2dmhE3fpbB1PWz/09HLp4+yLKbAmiQis3S/zP/xSA== X-Received: by 2002:a05:6000:1d0:b0:374:cd3e:7d98 with SMTP id ffacd0b85a97d-37d551e3caamr8208016f8f.19.1728904955744; Mon, 14 Oct 2024 04:22:35 -0700 (PDT) From: =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= To: qemu-riscv@nongnu.org, Palmer Dabbelt , Alistair Francis , Bin Meng Cc: =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , Ved Shanbhogue , Atish Patra , qemu-devel@nongnu.org Subject: [PATCH v3 3/8] target/riscv: Implement Ssdbltrp exception handling Date: Mon, 14 Oct 2024 13:22:13 +0200 Message-ID: <20241014112225.90297-4-cleger@rivosinc.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241014112225.90297-1-cleger@rivosinc.com> References: <20241014112225.90297-1-cleger@rivosinc.com> 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=2a00:1450:4864:20::42a; envelope-from=cleger@rivosinc.com; helo=mail-wr1-x42a.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1728905023852116600 When the Ssdbltrp ISA extension is enabled, if a trap happens in S-mode while SSTATUS.SDT isn't cleared, generate a double trap exception to M-mode. Signed-off-by: Cl=C3=A9ment L=C3=A9ger --- target/riscv/cpu.c | 2 +- target/riscv/cpu_bits.h | 1 + target/riscv/cpu_helper.c | 42 ++++++++++++++++++++++++++++++++++----- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index cf06cd741a..65347ccd5a 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -284,7 +284,7 @@ static const char * const riscv_excp_names[] =3D { "load_page_fault", "reserved", "store_page_fault", - "reserved", + "double_trap", "reserved", "reserved", "reserved", diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h index 3a5588d4df..5557a86348 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -699,6 +699,7 @@ typedef enum RISCVException { RISCV_EXCP_INST_PAGE_FAULT =3D 0xc, /* since: priv-1.10.0 */ RISCV_EXCP_LOAD_PAGE_FAULT =3D 0xd, /* since: priv-1.10.0 */ RISCV_EXCP_STORE_PAGE_FAULT =3D 0xf, /* since: priv-1.10.0 */ + RISCV_EXCP_DOUBLE_TRAP =3D 0x10, RISCV_EXCP_SW_CHECK =3D 0x12, /* since: priv-1.13.0 */ RISCV_EXCP_HW_ERR =3D 0x13, /* since: priv-1.13.0 */ RISCV_EXCP_INST_GUEST_PAGE_FAULT =3D 0x14, diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 77e7736d8a..5173155070 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -1711,6 +1711,7 @@ void riscv_cpu_do_interrupt(CPUState *cs) CPURISCVState *env =3D &cpu->env; bool virt =3D env->virt_enabled; bool write_gva =3D false; + bool vsmode_exc; uint64_t s; int mode; =20 @@ -1725,6 +1726,8 @@ void riscv_cpu_do_interrupt(CPUState *cs) !(env->mip & (1 << cause)); bool vs_injected =3D env->hvip & (1 << cause) & env->hvien && !(env->mip & (1 << cause)); + bool smode_double_trap =3D false; + uint64_t hdeleg =3D async ? env->hideleg : env->hedeleg; target_ulong tval =3D 0; target_ulong tinst =3D 0; target_ulong htval =3D 0; @@ -1841,13 +1844,34 @@ void riscv_cpu_do_interrupt(CPUState *cs) !async && mode =3D=3D PRV_M; =20 + vsmode_exc =3D env->virt_enabled && (((hdeleg >> cause) & 1) || vs_inj= ected); + /* + * Check double trap condition only if already in S-mode and targeting + * S-mode + */ + if (cpu->cfg.ext_ssdbltrp && env->priv =3D=3D PRV_S && mode =3D=3D PRV= _S) { + bool dte =3D (env->menvcfg & MENVCFG_DTE) !=3D 0; + bool sdt =3D (env->mstatus & MSTATUS_SDT) !=3D 0; + /* In VS or HS */ + if (riscv_has_ext(env, RVH)) { + if (vsmode_exc) { + /* VS -> VS, use henvcfg instead of menvcfg*/ + dte =3D (env->henvcfg & HENVCFG_DTE) !=3D 0; + } else if (env->virt_enabled) { + /* VS -> HS, mret/sret always reset dte to false */ + dte =3D false; + } + } + smode_double_trap =3D dte && sdt; + if (smode_double_trap) { + mode =3D PRV_M; + } + } + if (mode =3D=3D PRV_S) { /* handle the trap in S-mode */ if (riscv_has_ext(env, RVH)) { - uint64_t hdeleg =3D async ? env->hideleg : env->hedeleg; - - if (env->virt_enabled && - (((hdeleg >> cause) & 1) || vs_injected)) { + if (vsmode_exc) { /* Trap to VS mode */ /* * See if we need to adjust cause. Yes if its VS mode inte= rrupt @@ -1880,6 +1904,9 @@ void riscv_cpu_do_interrupt(CPUState *cs) s =3D set_field(s, MSTATUS_SPIE, get_field(s, MSTATUS_SIE)); s =3D set_field(s, MSTATUS_SPP, env->priv); s =3D set_field(s, MSTATUS_SIE, 0); + if (riscv_env_smode_dbltrp_enabled(env, virt)) { + s =3D set_field(s, MSTATUS_SDT, 1); + } env->mstatus =3D s; env->scause =3D cause | ((target_ulong)async << (TARGET_LONG_BITS = - 1)); env->sepc =3D env->pc; @@ -1913,9 +1940,14 @@ void riscv_cpu_do_interrupt(CPUState *cs) s =3D set_field(s, MSTATUS_MIE, 0); env->mstatus =3D s; env->mcause =3D cause | ~(((target_ulong)-1) >> async); + if (smode_double_trap) { + env->mtval2 =3D env->mcause; + env->mcause =3D RISCV_EXCP_DOUBLE_TRAP; + } else { + env->mtval2 =3D mtval2; + } env->mepc =3D env->pc; env->mtval =3D tval; - env->mtval2 =3D mtval2; env->mtinst =3D tinst; =20 if (cpu->cfg.ext_smrnmi && nmi_execp) { --=20 2.45.2 From nobody Sat Nov 23 21:58:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1728905130; cv=none; d=zohomail.com; s=zohoarc; b=dZIvd9i2DrtefyZ5pWRvG1YIzdjs3f9fy7DRqdKwTiqb758X5I5pV7B01n2e1lARzfnVLx9OXaQpckNQ/tU4stYQGUAn+7cHelgQsKI8vx23AvJh6y1dglH6qY2UzobyWgW3MAnEy+2a2Ni3B1jjkrV+dCFvJDks6NgsNCENt24= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728905130; 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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=hfu45ZedV2oYYdcJlwtmsTcYcSwVZM5Rhrrvekmn4k8=; b=aU5c+9X66N4HqC3+hUqITmBn3t2WnfM1uC7MjYF0SoBBEbulMDgxbZJ7RNagja8SxGHY4dD0PxN8kpAkLAa9+B5lIEbN0bGjJ/nmWmzZFTy743cSWyNxRVM3WpUsP+His44Yy6WTf3Ci1LJlF1Msus1GFBWAxJ/V0Ka1FcR2FY0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1728905130447437.1466762063219; Mon, 14 Oct 2024 04:25:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t0J9x-0006Z9-Mi; Mon, 14 Oct 2024 07:22:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t0J9s-0006Vt-D9 for qemu-devel@nongnu.org; Mon, 14 Oct 2024 07:22:41 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t0J9q-0002cg-KJ for qemu-devel@nongnu.org; Mon, 14 Oct 2024 07:22:40 -0400 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-37d533b5412so1864712f8f.2 for ; Mon, 14 Oct 2024 04:22:38 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:e17:9700:16d2:7456:6634:9626]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37d4b6bd382sm11117303f8f.43.2024.10.14.04.22.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 04:22:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1728904957; x=1729509757; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hfu45ZedV2oYYdcJlwtmsTcYcSwVZM5Rhrrvekmn4k8=; b=UH6JDFFrND2LAVhA0VJ9uuwc/mpP4GrxkZ3eK/YZGrFuYJGare87/cNrdwYi2PnmEZ 8nlYbiqFwCopv8yic0/soHN088bAJ1K1whbsw6iJGpBCaO9cf7ZkofLOeAWObx0daGwf HxlL+PivNgzVpcUBlzGeYyV0IqJfBXIq1jzak+XXlfGGhCXCp4u4Z4LINywvHK6E37Z9 x0rDmD2NKXyKnz4VXqs3t0oraLoEUzFIZ4M/rig1IPPKXeNDQ4GxiEm6vOS6rXoEOR/3 CzAcFERR7zVGX4vFQ7O/SfcJiZ+Okqcl2UzPYZb/H+XE01R23mk/IrRWI10xT5ThPd3u Gkyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728904957; x=1729509757; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hfu45ZedV2oYYdcJlwtmsTcYcSwVZM5Rhrrvekmn4k8=; b=jMCWyerQZnGI0EkNwJKjSTtdeN6gyCgSrLIbVTbfV5ToTSpC/XUQjAjQLKbsirhJAI Mc23FVXUyFGNlRwcLYw7OvQ8z/QxcIxKemVeusk4XWaZ2rBdc+drhGrCnFXhi4RYR+cF 63PypjVfvfja+MYHXtv+/V8n677MKruVY0HEv4xEGSvO0bz71pLZO/PFn0MI1/zv0cbv YfcAPGiwGzC5qH58MhrhQJDhqETy4Dbz7fTrjJgow3ZL0Tr2AawZiH5HY1HKS8Npuf/T p16pKDhOYadH0hqirhNm7I7M2p6Dw8KfQhNmftgFieAoi1FkkmJOFe3JJuCcqRVZnAbS DypQ== X-Forwarded-Encrypted: i=1; AJvYcCUxDuvhyMk2UKAedKQtwPAcXI4jT3BV81ozl26yVVqZKfrMVJO3Bzt8d4k1jLctuuBLhoi9Wx2WzTR6@nongnu.org X-Gm-Message-State: AOJu0YzEANVt8LNebWPRCz7b9eXGhZMZzhYBrd7HVFdn+TU6Y0WYAeIj SqVC/1WWwR3VTvDMDsQLxgmvPh8R/yFkbok2CrPfXzgfBbs+0mjaW7Lpl6W+WTE= X-Google-Smtp-Source: AGHT+IGEz87dAj2XpG48PJ4i3nQmZtvyODMgISsVz2OeZad48TXvTMv1MX19c7lw0kyBmqky4QXirA== X-Received: by 2002:a5d:68c5:0:b0:37d:46a8:ad4e with SMTP id ffacd0b85a97d-37d551b9740mr7558620f8f.15.1728904956802; Mon, 14 Oct 2024 04:22:36 -0700 (PDT) From: =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= To: qemu-riscv@nongnu.org, Palmer Dabbelt , Alistair Francis , Bin Meng Cc: =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , Ved Shanbhogue , Atish Patra , qemu-devel@nongnu.org Subject: [PATCH v3 4/8] target/riscv: Add Ssdbltrp ISA extension enable switch Date: Mon, 14 Oct 2024 13:22:14 +0200 Message-ID: <20241014112225.90297-5-cleger@rivosinc.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241014112225.90297-1-cleger@rivosinc.com> References: <20241014112225.90297-1-cleger@rivosinc.com> 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=2a00:1450:4864:20::432; envelope-from=cleger@rivosinc.com; helo=mail-wr1-x432.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1728905132460116600 Add the switch to enable the Ssdbltrp ISA extension. Signed-off-by: Cl=C3=A9ment L=C3=A9ger --- target/riscv/cpu.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 65347ccd5a..4a146bb637 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -190,6 +190,7 @@ const RISCVIsaExtData isa_edata_arr[] =3D { ISA_EXT_DATA_ENTRY(ssccptr, PRIV_VERSION_1_11_0, has_priv_1_11), ISA_EXT_DATA_ENTRY(sscofpmf, PRIV_VERSION_1_12_0, ext_sscofpmf), ISA_EXT_DATA_ENTRY(sscounterenw, PRIV_VERSION_1_12_0, has_priv_1_12), + ISA_EXT_DATA_ENTRY(ssdbltrp, PRIV_VERSION_1_13_0, ext_ssdbltrp), ISA_EXT_DATA_ENTRY(sstc, PRIV_VERSION_1_12_0, ext_sstc), ISA_EXT_DATA_ENTRY(sstvala, PRIV_VERSION_1_12_0, has_priv_1_12), ISA_EXT_DATA_ENTRY(sstvecd, PRIV_VERSION_1_12_0, has_priv_1_12), @@ -1492,6 +1493,7 @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = =3D { MULTI_EXT_CFG_BOOL("smrnmi", ext_smrnmi, false), MULTI_EXT_CFG_BOOL("smstateen", ext_smstateen, false), MULTI_EXT_CFG_BOOL("ssaia", ext_ssaia, false), + MULTI_EXT_CFG_BOOL("ssdbltrp", ext_ssdbltrp, false), MULTI_EXT_CFG_BOOL("svade", ext_svade, false), MULTI_EXT_CFG_BOOL("svadu", ext_svadu, true), MULTI_EXT_CFG_BOOL("svinval", ext_svinval, false), --=20 2.45.2 From nobody Sat Nov 23 21:58:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1728905061; cv=none; d=zohomail.com; s=zohoarc; b=eAnpKbBmE7Ik9SkdLEB/Riv/bPN3YbGlfBnva6DsXYBvpaI6FUcXZGy4MND2w2eEiAfay1HTwjQfHoX0/EQBJLpzAr4qp2I4/X46hAIJWFh24H+BADkT74/4uCfhfunmQzLS8ARkPy31tSucDaVZ/YBKNzz5H4ZR1RJPwBW+jg8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728905061; 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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=fQQO2T5uiR+FYgD4cQeDW1X+EPKbvqM649D/aATLO28=; b=FfbHmhCSio5QO/JGyJvL7fOF3lVLSr9+5JQ4oDaAJb9yjUIZa58hBA3RjBwgi9d1m9e3+L6d33sbTN/zd3v3HvwQ7ohHH7zRmW1l/Dc9gultWY6shfGBMsrmi97DwhZfvAbT4yD1SHTSb4rZZOKLLiQeXQ0Igu1KPTmEyaP6KTI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1728905061746591.0338866760892; Mon, 14 Oct 2024 04:24:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t0J9w-0006YI-6V; Mon, 14 Oct 2024 07:22:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t0J9t-0006WX-CM for qemu-devel@nongnu.org; Mon, 14 Oct 2024 07:22:41 -0400 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t0J9r-0002d9-Kv for qemu-devel@nongnu.org; Mon, 14 Oct 2024 07:22:41 -0400 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-43117ed8adbso45611915e9.2 for ; Mon, 14 Oct 2024 04:22:39 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:e17:9700:16d2:7456:6634:9626]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37d4b6bd382sm11117303f8f.43.2024.10.14.04.22.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 04:22:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1728904958; x=1729509758; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fQQO2T5uiR+FYgD4cQeDW1X+EPKbvqM649D/aATLO28=; b=Rsdz0dKLUyq4qvZLGDmpXelSsVwgsoCPmyjgxL7fVFSGycmF8jIh+M/iuFbLD/gpc+ 05y4bZZiuUIzhFvIXg0z0TwESvvbmvlpDyOEvAyBkKAmzmvdCOQV4lLsHYiBi6O/xhil Z7mIxHVcNkwbXzEalMqWcOIgwRVujZ2SgqUf/hfe5Y+1NRKpqQyzh9cK6DAPJOznnCdl 9sKZXgUeoFOtCfYIX84MniyHVMuU1O3YEmIfwRXFBEQ+Ps07guxa3ulN6tFJCZDsQ/vF aWR6uqbDGfEjdbnkWno1B87lyNgyb2JCfn+pKDspDZpvu1RJ6bm3OsqYd7wa0zm8siAo /32A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728904958; x=1729509758; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fQQO2T5uiR+FYgD4cQeDW1X+EPKbvqM649D/aATLO28=; b=iOQRbVdxy66VvlOpGRrDXYwvczA7br1FFk054Dp6n5IRC0j50p6zpBdYNgUe1iBmJa F7bqRBWaaNYqJkknrl5z433bDlkQOai6stPEX5XUPMvr42MeyEChJkPqCDMaA/mJvJRU 6Hx27mVzp7EwMM7oR8FuEZBNtOVwOSKgWSty8/Oab2u1fTE6mcsiHbOs6w9/2Q2RepM/ mCIYcP74xwnJg+iOzpSHmMn+EAytiaAR0+3QwtFPCyS7zOHFebYMgtfK4YLDJAnneaRV j2n8916X34pLQIRWEv1oW4xXgqxBwyhJDwsI9oY+i7YifhrrgdmwWXVAFskNaAmF2xVC yfVg== X-Forwarded-Encrypted: i=1; AJvYcCWQaPRWFt94LYxrqZsJnWrw/i9gNrkeXs+OVDzmt/hhs0N9DKwzYhRgLeOh5PgYHOO5Fd8N4JjUhcDy@nongnu.org X-Gm-Message-State: AOJu0Yz3Cazfd2EKoqlFv9tDDoTc9jdEczY4CmY0C9wKhg0KTFvMmnHT WrHEx4uzb1PPyVeXZjYTwhUsWFwqB1h1MM6gF/nC/n/pV7K6KUSp9x2n8CjFBdA= X-Google-Smtp-Source: AGHT+IEjYxqgLJ2n8zlhNXgKVsYmlQ03KfR0qpjFGlsWbLm/7uQv5GlqIwVpRXnShmdSKGUsKvnKTw== X-Received: by 2002:adf:ffc5:0:b0:374:c1c5:43ca with SMTP id ffacd0b85a97d-37d5ffa3561mr6197519f8f.32.1728904957840; Mon, 14 Oct 2024 04:22:37 -0700 (PDT) From: =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= To: qemu-riscv@nongnu.org, Palmer Dabbelt , Alistair Francis , Bin Meng Cc: =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , Ved Shanbhogue , Atish Patra , qemu-devel@nongnu.org Subject: [PATCH v3 5/8] target/riscv: Add Smdbltrp CSRs handling Date: Mon, 14 Oct 2024 13:22:15 +0200 Message-ID: <20241014112225.90297-6-cleger@rivosinc.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241014112225.90297-1-cleger@rivosinc.com> References: <20241014112225.90297-1-cleger@rivosinc.com> 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=2a00:1450:4864:20::333; envelope-from=cleger@rivosinc.com; helo=mail-wm1-x333.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1728905062436116600 Add `ext_smdbltrp`in RISCVCPUConfig and implement MSTATUS.MDT behavior. Also set MDT to 1 at reset according to the specification. Signed-off-by: Cl=C3=A9ment L=C3=A9ger --- target/riscv/cpu.c | 3 +++ target/riscv/cpu_bits.h | 1 + target/riscv/cpu_cfg.h | 1 + target/riscv/csr.c | 15 +++++++++++++++ 4 files changed, 20 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 4a146bb637..53e3bb6b37 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -946,6 +946,9 @@ static void riscv_cpu_reset_hold(Object *obj, ResetType= type) env->mstatus_hs =3D set_field(env->mstatus_hs, MSTATUS64_UXL, env->misa_mxl); } + if (riscv_cpu_cfg(env)->ext_smdbltrp) { + env->mstatus =3D set_field(env->mstatus, MSTATUS_MDT, 1); + } } env->mcause =3D 0; env->miclaim =3D MIP_SGEIP; diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h index 5557a86348..62bab1bf55 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -561,6 +561,7 @@ #define MSTATUS_SDT 0x01000000 #define MSTATUS_GVA 0x4000000000ULL #define MSTATUS_MPV 0x8000000000ULL +#define MSTATUS_MDT 0x40000000000ULL /* Smdbltrp extension */ =20 #define MSTATUS64_UXL 0x0000000300000000ULL #define MSTATUS64_SXL 0x0000000C00000000ULL diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h index dd804f95d4..4c4caa2b39 100644 --- a/target/riscv/cpu_cfg.h +++ b/target/riscv/cpu_cfg.h @@ -78,6 +78,7 @@ struct RISCVCPUConfig { bool ext_sstc; bool ext_smcntrpmf; bool ext_ssdbltrp; + bool ext_smdbltrp; bool ext_svadu; bool ext_svinval; bool ext_svnapot; diff --git a/target/riscv/csr.c b/target/riscv/csr.c index d8280ec956..cc1940447a 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -1617,6 +1617,14 @@ static RISCVException write_mstatus(CPURISCVState *e= nv, int csrno, } } =20 + if (riscv_cpu_cfg(env)->ext_smdbltrp) { + mask |=3D MSTATUS_MDT; + if ((val & MSTATUS_MDT) !=3D 0) { + mstatus &=3D ~MSTATUS_MIE; + val &=3D ~MSTATUS_MIE; + } + } + if (xl !=3D MXL_RV32 || env->debugger) { if (riscv_has_ext(env, RVH)) { mask |=3D MSTATUS_MPV | MSTATUS_GVA; @@ -1655,6 +1663,13 @@ static RISCVException write_mstatush(CPURISCVState *= env, int csrno, uint64_t valh =3D (uint64_t)val << 32; uint64_t mask =3D riscv_has_ext(env, RVH) ? MSTATUS_MPV | MSTATUS_GVA = : 0; =20 + if (riscv_cpu_cfg(env)->ext_smdbltrp) { + mask |=3D MSTATUS_MDT; + if ((val & MSTATUS_MDT) !=3D 0) { + env->mstatus &=3D ~MSTATUS_MIE; + val &=3D ~MSTATUS_MIE; + } + } env->mstatus =3D (env->mstatus & ~mask) | (valh & mask); =20 return RISCV_EXCP_NONE; --=20 2.45.2 From nobody Sat Nov 23 21:58:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1728905093; cv=none; d=zohomail.com; s=zohoarc; b=C5Ola2wb+FZRZqodfMIT51L8hWBb2TjX62/1Qr6hQNQBPli4sbO7m25U0uTBy1Uww+snOvpxGsX8B7ARg6zGs6eW6qFPvnY5DfYz1OMDJPkcU1SS5x9ITSAnu3Ey+uR0X/oV8cazWujZ6fWpcujrbzq4JVOJYcIPD6sPz2Pbnp4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728905093; 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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=iLp4r6f6llKlFkIQR3exhrK8GnjMUvUuiR9NnPTHniw=; b=D9XNMEOL7anSCwvwjYCscufylrlRzXhsADsD0ovpLyQgh7xjui8JyOT0Gq2cgo43xWrOc5ZRPfn4sCb/MLwvXOvD4AvpaUBJ8hQzhd5A+Uf4+HpsswI1RxGQCJlVgSpge2IqH7FX9UlJ64A0SPm8M2b76/kq0ZYqS2BMXYc9hmE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1728905093481979.6313113979546; Mon, 14 Oct 2024 04:24:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t0JA3-0006bw-8K; Mon, 14 Oct 2024 07:22:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t0J9x-0006ZD-Qr for qemu-devel@nongnu.org; Mon, 14 Oct 2024 07:22:45 -0400 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t0J9v-0002dp-1H for qemu-devel@nongnu.org; Mon, 14 Oct 2024 07:22:45 -0400 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-37d4c482844so2351814f8f.0 for ; Mon, 14 Oct 2024 04:22:40 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:e17:9700:16d2:7456:6634:9626]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37d4b6bd382sm11117303f8f.43.2024.10.14.04.22.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 04:22:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1728904959; x=1729509759; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iLp4r6f6llKlFkIQR3exhrK8GnjMUvUuiR9NnPTHniw=; b=WLVCQyOzLmCtAkGRxPuHpOhZujOWR4PvHm0zK3Gd0etwBtnxllwLWn61IRpl1//GVj TIQyMGUXOINzHJJ6SFvB9RzO4eP44qmJYiQjIAuSGb+Lx5w7IC0Evcv3hnqiKdVPoDRg N7gPM69hLl/SNzz+tiNYozFUBhmqROGglhPIe6Sagp4FaJOdR0n3QuDDe5U4/ATo8ejM XKXv0zDNH0T2zufpxzYztia0CugOySGJPoMJ5NGn3fvOuycCQlkFAU5+TBnlB0duS2tD aFyl5Z9RKzakDeD4Pv7vNwz5JsecQrQE79jGqU8OBlWWXjTpAtSUj6/K6qfK2P+W+IJ6 HekA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728904959; x=1729509759; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iLp4r6f6llKlFkIQR3exhrK8GnjMUvUuiR9NnPTHniw=; b=EFwfwpeUXnXJOz3tyOTa2HX5TmFaeKrq6PRuJZwruFPR1/2aH70oLxQcMA9EWtSV4U +CD5VhWm+E9m6gONOWvakK+GfzjAXIXEIb/CF0rJ5TflWE0opU0TnrSSifoXHG6y0ULH 2fEXiLpzQ9D+luuyBV8HlDFrqutE6S2sVrmI58H4NYJAbZL1S8elk/YVtKPrALYofqmL QcdOXJHEGJ2TpBr2wbob6yHllmICAkuRTdZVfuJZEykWqWIP5+/f8IA/c/jb30rqKnkt ImIzW+bUjP/4F5fph9j62rGDz9qQ6DR8F7aqLlmzjfJZNO32rRTilztsHxOQuJl4+4Q4 MURg== X-Forwarded-Encrypted: i=1; AJvYcCXDYeobWD9rzebLLHERw/oGcPj4UFs9asPa9ob3L+A0LV1Vpvhogv2BugdS5+kjCOrrEaydnLTGQdt5@nongnu.org X-Gm-Message-State: AOJu0YxgqkTC5QLU5FTZgJ3G1IWdip6vEpelK1r01arFBVRqhbCe/o90 m+Hu3vQxFgGX0Ll9TvzX9b/le/CD7uHI1jLAp4dhlGCIH2KMiPj18CjdRavMlsM= X-Google-Smtp-Source: AGHT+IGcm4wAoeiVRTAh/v/bSmxcwTVDPXMFZEHIdbI9BOBLCSP4QpJehj9WHmu22Ars0836ai+vkw== X-Received: by 2002:a5d:4f91:0:b0:37d:45f0:dd08 with SMTP id ffacd0b85a97d-37d551aac31mr7285938f8f.11.1728904959344; Mon, 14 Oct 2024 04:22:39 -0700 (PDT) From: =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= To: qemu-riscv@nongnu.org, Palmer Dabbelt , Alistair Francis , Bin Meng Cc: =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , Ved Shanbhogue , Atish Patra , qemu-devel@nongnu.org Subject: [PATCH v3 6/8] target/riscv: Implement Smdbltrp sret, mret and mnret behavior Date: Mon, 14 Oct 2024 13:22:16 +0200 Message-ID: <20241014112225.90297-7-cleger@rivosinc.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241014112225.90297-1-cleger@rivosinc.com> References: <20241014112225.90297-1-cleger@rivosinc.com> 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=2a00:1450:4864:20::42a; envelope-from=cleger@rivosinc.com; helo=mail-wr1-x42a.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1728905094187116600 When the Ssdbltrp extension is enabled, SSTATUS.MDT field is cleared when executing sret if executed in M-mode. When executing mret/mnret, SSTATUS.MDT is cleared. Signed-off-by: Cl=C3=A9ment L=C3=A9ger --- target/riscv/op_helper.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c index 00b6f75102..9d0911f697 100644 --- a/target/riscv/op_helper.c +++ b/target/riscv/op_helper.c @@ -299,6 +299,9 @@ target_ulong helper_sret(CPURISCVState *env) } mstatus =3D set_field(mstatus, MSTATUS_SDT, 0); } + if (riscv_cpu_cfg(env)->ext_smdbltrp && env->priv >=3D PRV_M) { + mstatus =3D set_field(mstatus, MSTATUS_MDT, 0); + } if (env->priv_ver >=3D PRIV_VERSION_1_12_0) { mstatus =3D set_field(mstatus, MSTATUS_MPRV, 0); } @@ -375,6 +378,9 @@ target_ulong helper_mret(CPURISCVState *env) if (riscv_cpu_cfg(env)->ext_ssdbltrp) { mstatus =3D ssdbltrp_mxret(env, mstatus, prev_priv, prev_virt); } + if (riscv_cpu_cfg(env)->ext_smdbltrp) { + mstatus =3D set_field(mstatus, MSTATUS_MDT, 0); + } if ((env->priv_ver >=3D PRIV_VERSION_1_12_0) && (prev_priv !=3D PRV_M)= ) { mstatus =3D set_field(mstatus, MSTATUS_MPRV, 0); } @@ -416,6 +422,12 @@ target_ulong helper_mnret(CPURISCVState *env) env->mstatus =3D ssdbltrp_mxret(env, env->mstatus, prev_priv, prev= _virt); } =20 + if (riscv_cpu_cfg(env)->ext_smdbltrp) { + if (prev_priv < PRV_M) { + env->mstatus =3D set_field(env->mstatus, MSTATUS_MDT, false); + } + } + if (riscv_has_ext(env, RVH) && prev_virt) { riscv_cpu_swap_hypervisor_regs(env); } --=20 2.45.2 From nobody Sat Nov 23 21:58:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1728905090; cv=none; d=zohomail.com; s=zohoarc; b=I0V/HmTQaSUI9GOAvu5tj9O9FzjMbw3S8dikCXc3d9Y+4hi4XoEwaPBFcnebS+4hmoUoTMqhjV7gotfYT3iNqbmIyColyFed3UU/zvPlTue+boQxIyPJ2hC/yWnMu2HZGDbmMmy05psQy8zLke6d7Nis+satSSiRESpZIwVVZ9M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728905090; 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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=0jjVOqHYyme7TuTf7cP0qU+WrovStk5IdwfY0O87Bfg=; b=eZcfVSm1l/97T7pDz2jeKzm2zBRrIZlX8B61PGxSomvg4E1uVgek+Bn973yLVyewDdomD8qybyg7G9gxitiP999rG7EkXuqyMUesSBjKA4bvpxHvLiEYIj6GuVM8LJ0qkOw5OiY+r/bpisp2ln8hJiioJwhZxe9x6+pctJ44+28= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1728905090299669.4628647335741; Mon, 14 Oct 2024 04:24:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t0J9z-0006aq-4e; Mon, 14 Oct 2024 07:22:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t0J9w-0006YK-AE for qemu-devel@nongnu.org; Mon, 14 Oct 2024 07:22:44 -0400 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t0J9u-0002eK-HO for qemu-devel@nongnu.org; Mon, 14 Oct 2024 07:22:44 -0400 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-37d47eff9acso2449464f8f.3 for ; Mon, 14 Oct 2024 04:22:42 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:e17:9700:16d2:7456:6634:9626]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37d4b6bd382sm11117303f8f.43.2024.10.14.04.22.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 04:22:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1728904961; x=1729509761; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0jjVOqHYyme7TuTf7cP0qU+WrovStk5IdwfY0O87Bfg=; b=TpleimeFxDfFZpYBGoksyP8y9xG5HRya70/ivnohPtoelFLVlquESknbytmZWWuX6p tucSea1NIx/gzXGk+x6dspa3vrRPv2AgHCBYxFRnBJU3A+Qj1UDo3nMOYSxJunbKmDgq uhqvPlYZF10rrZcCfOq4OTxvAG5hEuSxmGaSTsSu1s6lqlC9fQbiHGdANnAZWpMwQDSM SWKsZUFp9LEhBJO9r/1dk8LaG4v5rzeTP3CqeG9AO1gySIOB8/2dxFn4+XBrCoXCpWxF TgIQIRQ++ZTsWMT/vvsFMaY6wl+tzWxCL51aqT+JIenHwjL4bywftYVGJt8BiMIYu5yU UMqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728904961; x=1729509761; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0jjVOqHYyme7TuTf7cP0qU+WrovStk5IdwfY0O87Bfg=; b=sE71x6MaOVOEN2vx8jIHXyPb/DtdHLgrCUCuEbD/BQQn89Fj5Bo4PuYD7K5I1pRUgy CRqaMfbz2ql37zTAwDm8ftsaMWIEVga3yBlKKRnsAeIzsUEceaI+mwQQp4AILVZ+eZYm nswFIPtlaIb9snx8afLLpm5RVBPFQUAeg9bBzoDWb73TTB8M5p7ZLmNeAUiQhmWYC6YC 2VxpH1MvIiV8SFAHE9DqU0F3CD2ueTH8yWpvWSSIGigsFqMoucn7F7tDuDHDhiR5AnII MlVfh6JNYIbpAqsKbqytoSmnpnnP2ItPfvfP1OqNMH9IrwLhQgTSN2fS6BobgRqoUG1g Nw1g== X-Forwarded-Encrypted: i=1; AJvYcCVrGMYvqPKXQ3pOiL7JYHKgStSjVZICssoSPvbZ8NlatPdn+QwTdur5Mm4sNkEVQorUs9ed7fBeIZcq@nongnu.org X-Gm-Message-State: AOJu0YzICOopz8j9WSRI4q2jrLhxlv5PBLipo0G8nPWOswZJMP3bImxq nio0B+51hQWKioiphXIIdfo4s3NrSZRsDrQa+2XBk2x9zh6DxLfhul7EuSbrJRA= X-Google-Smtp-Source: AGHT+IEhB0fsnX6b9YVK+DJ0kLB/v+DmYLq6ZjkIFYA6wjx0kLtx1QnYd3CVEK855WuOjkwTLeUPkA== X-Received: by 2002:a05:6000:b91:b0:37d:47e2:5e30 with SMTP id ffacd0b85a97d-37d5ff6ce3fmr5078588f8f.42.1728904960778; Mon, 14 Oct 2024 04:22:40 -0700 (PDT) From: =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= To: qemu-riscv@nongnu.org, Palmer Dabbelt , Alistair Francis , Bin Meng Cc: =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , Ved Shanbhogue , Atish Patra , qemu-devel@nongnu.org Subject: [PATCH v3 7/8] target/riscv: Implement Smdbltrp behavior Date: Mon, 14 Oct 2024 13:22:17 +0200 Message-ID: <20241014112225.90297-8-cleger@rivosinc.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241014112225.90297-1-cleger@rivosinc.com> References: <20241014112225.90297-1-cleger@rivosinc.com> 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=2a00:1450:4864:20::430; envelope-from=cleger@rivosinc.com; helo=mail-wr1-x430.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1728905092587116600 When the Smsdbltrp ISA extension is enabled, if a trap happens while MSTATUS.MDT is already set, it will trigger an abort or an NMI is the Smrnmi extension is available. Signed-off-by: Cl=C3=A9ment L=C3=A9ger --- target/riscv/cpu_helper.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 5173155070..8b44986cd6 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -1699,6 +1699,17 @@ static target_ulong riscv_transformed_insn(CPURISCVS= tate *env, return xinsn; } =20 +static void riscv_do_nmi(CPURISCVState *env, target_ulong cause, bool virt) +{ + env->mnstatus =3D set_field(env->mnstatus, MNSTATUS_NMIE, false); + env->mnstatus =3D set_field(env->mnstatus, MNSTATUS_MNPV, virt); + env->mnstatus =3D set_field(env->mnstatus, MNSTATUS_MNPP, env->priv); + env->mncause =3D cause; + env->mnepc =3D env->pc; + env->pc =3D env->rnmi_irqvec; + riscv_cpu_set_mode(env, PRV_M, virt); +} + /* * Handle Traps * @@ -1735,15 +1746,8 @@ void riscv_cpu_do_interrupt(CPUState *cs) bool nmi_execp =3D false; =20 if (cpu->cfg.ext_smrnmi && env->rnmip && async) { - env->mnstatus =3D set_field(env->mnstatus, MNSTATUS_NMIE, false); - env->mnstatus =3D set_field(env->mnstatus, MNSTATUS_MNPV, - env->virt_enabled); - env->mnstatus =3D set_field(env->mnstatus, MNSTATUS_MNPP, - env->priv); - env->mncause =3D cause | ((target_ulong)1U << (TARGET_LONG_BITS - = 1)); - env->mnepc =3D env->pc; - env->pc =3D env->rnmi_irqvec; - riscv_cpu_set_mode(env, PRV_M, virt); + riscv_do_nmi(env, cause | ((target_ulong)1U << (TARGET_LONG_BITS -= 1)), + virt); return; } =20 @@ -1938,6 +1942,19 @@ void riscv_cpu_do_interrupt(CPUState *cs) s =3D set_field(s, MSTATUS_MPIE, get_field(s, MSTATUS_MIE)); s =3D set_field(s, MSTATUS_MPP, env->priv); s =3D set_field(s, MSTATUS_MIE, 0); + if (cpu->cfg.ext_smdbltrp) { + if (env->mstatus & MSTATUS_MDT) { + assert(env->priv =3D=3D PRV_M); + if (!cpu->cfg.ext_smrnmi || nmi_execp) { + cpu_abort(CPU(cpu), "M-mode double trap\n"); + } else { + riscv_do_nmi(env, cause, false); + return; + } + } + + s =3D set_field(s, MSTATUS_MDT, 1); + } env->mstatus =3D s; env->mcause =3D cause | ~(((target_ulong)-1) >> async); if (smode_double_trap) { --=20 2.45.2 From nobody Sat Nov 23 21:58:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1728905037; cv=none; d=zohomail.com; s=zohoarc; b=KPcGwJ5NbodaWnXxaIJntfDxtkWN1QQfXe/KzLhiCpYXZg5hjdU41N01GodqfsrrwOxmO213D98ZebMfHvDLxEo95NMrZ4WFG8ios4+0+Q7QR4SWlLwqj3jjmiCqfyeP4971bV7PXBO+oKBy5X9cy+3S0r3i/jnbpeFENvJ/rEY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728905037; 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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Bs7mZGN57rwci/6WEq54tvzRiLyMQyqdFuQO/8gdTa8=; b=V9MEyNdeD8roNzCSRrJhWbtwPaM46hyC8GSavReAW4PNMEetM5rlf8qgtgf6mt68KqmLAKrD8wxQbfHYZt99RtGMASYvo7cjt2+uGlcGqNqDZLbyQlY5fesBJWLzfaYxJtERMc5/w3dVKhpoeT/nIYKj8YL0W1bRZ3Mo3ZVZ5vg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17289050370851017.7129227244426; Mon, 14 Oct 2024 04:23:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t0JA4-0006cb-Nc; Mon, 14 Oct 2024 07:22:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t0JA0-0006bY-HJ for qemu-devel@nongnu.org; Mon, 14 Oct 2024 07:22:48 -0400 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t0J9v-0002eT-Lm for qemu-devel@nongnu.org; Mon, 14 Oct 2024 07:22:48 -0400 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-37d533b5412so1864752f8f.2 for ; Mon, 14 Oct 2024 04:22:43 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:e17:9700:16d2:7456:6634:9626]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37d4b6bd382sm11117303f8f.43.2024.10.14.04.22.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 04:22:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1728904962; x=1729509762; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Bs7mZGN57rwci/6WEq54tvzRiLyMQyqdFuQO/8gdTa8=; b=RWhftqtB9oAvT9jZRb7xvY/GV7SHXgfef4vqz0djLZDcWJhfBO7fjsJT4XSVFM//kf 832teysxPLmoLDlmXwfuf+1JtBvo0YHICDhqJyLCTPlg/V3fbSZfF9oMGXhrg/1cdaOE YGWE0Kigp3X25LX/SxLBezKidBDW1dxQOZ+iNcjyTtVBZrGi2tNoAVuPuIuhArnO8oaS KIVqBuHBZT6DPMrcz4JImV8Vy9+zufWX2dNGCbOdG6cvTrTkQDMKFqJsOjpQmyufu/nq na2+DxZuuwK+nwtBxBAl5lhDayJS7FKItRjK8u9WmJ2P2hteV3UXGYP8AmL3jcB2OQrZ A08A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728904962; x=1729509762; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Bs7mZGN57rwci/6WEq54tvzRiLyMQyqdFuQO/8gdTa8=; b=v5eXDyOgPGa/6lobkE5BqQ/XsJId5l8o30qyaCYiWRmDQLCN2re1J3K6g4VKKsl9oa 2ADDK7+61P0Nq0qJI1FZrGGDuE5YN5axOrOGsemh4qN/yCcoZkqoLfLa/0oZeJjlPP4S igHRb6FRLXqLIV3qy9/wfA36XZcoL8MGinBiTYyEUaXs2IE+pSJTDsKwxtbxapvet0dj 3bh+DvjFyMBa8W5dKfLOeVAUmmTrjtZICVu0wyJsBZbPbHfPNgT/HK/T8S4AT0ZisRhI rGDy/5LVYC88PYw+UZYcVKgDd8NqxWtqbKfrN0F83ULjsymKSMYfxzs95HoDswlcabxv R6xw== X-Forwarded-Encrypted: i=1; AJvYcCWT+31SBxhKX4THabSaFdQhjjJw8TcCIfI9BKNMOBspCGyn4GHr4aYeGO2PLyiotBExo58B0t+d7mQ2@nongnu.org X-Gm-Message-State: AOJu0YxY9rG/7YWTBjw62SwBCOI7ws5QUHHoMzLhR+n/awPLMH8RQwjz KAyCqX/vNSg99MGaYmKtrQRHcJKwafJcQZUEM4aC8NP6lFjHu7rtM2wX6M4JrAA= X-Google-Smtp-Source: AGHT+IHVoszcHRSpck+Vri3JaU0HLDDM5ZRCPiA1+qUluW2CjBagWVV2HSZXY+QuixQzSBygvKPfIQ== X-Received: by 2002:adf:e681:0:b0:37d:4aa5:eae5 with SMTP id ffacd0b85a97d-37d5531bc58mr7200031f8f.55.1728904961909; Mon, 14 Oct 2024 04:22:41 -0700 (PDT) From: =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= To: qemu-riscv@nongnu.org, Palmer Dabbelt , Alistair Francis , Bin Meng Cc: =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , Ved Shanbhogue , Atish Patra , qemu-devel@nongnu.org Subject: [PATCH v3 8/8] target/riscv: Add Smdbltrp ISA extension enable switch Date: Mon, 14 Oct 2024 13:22:18 +0200 Message-ID: <20241014112225.90297-9-cleger@rivosinc.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241014112225.90297-1-cleger@rivosinc.com> References: <20241014112225.90297-1-cleger@rivosinc.com> 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=2a00:1450:4864:20::436; envelope-from=cleger@rivosinc.com; helo=mail-wr1-x436.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1728905038007116600 Add the switch to enable the Smdbltrp ISA extension. Signed-off-by: Cl=C3=A9ment L=C3=A9ger --- target/riscv/cpu.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 53e3bb6b37..6e22bfe37d 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -183,6 +183,7 @@ const RISCVIsaExtData isa_edata_arr[] =3D { ISA_EXT_DATA_ENTRY(zhinxmin, PRIV_VERSION_1_12_0, ext_zhinxmin), ISA_EXT_DATA_ENTRY(smaia, PRIV_VERSION_1_12_0, ext_smaia), ISA_EXT_DATA_ENTRY(smcntrpmf, PRIV_VERSION_1_12_0, ext_smcntrpmf), + ISA_EXT_DATA_ENTRY(smdbltrp, PRIV_VERSION_1_13_0, ext_smdbltrp), ISA_EXT_DATA_ENTRY(smepmp, PRIV_VERSION_1_12_0, ext_smepmp), ISA_EXT_DATA_ENTRY(smrnmi, PRIV_VERSION_1_12_0, ext_smrnmi), ISA_EXT_DATA_ENTRY(smstateen, PRIV_VERSION_1_12_0, ext_smstateen), @@ -1492,6 +1493,7 @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = =3D { MULTI_EXT_CFG_BOOL("sstc", ext_sstc, true), =20 MULTI_EXT_CFG_BOOL("smaia", ext_smaia, false), + MULTI_EXT_CFG_BOOL("smdbltrp", ext_smdbltrp, false), MULTI_EXT_CFG_BOOL("smepmp", ext_smepmp, false), MULTI_EXT_CFG_BOOL("smrnmi", ext_smrnmi, false), MULTI_EXT_CFG_BOOL("smstateen", ext_smstateen, false), --=20 2.45.2