From nobody Mon Feb 9 19:54:10 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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 1657608899283158.27599220568902; Mon, 11 Jul 2022 23:54:59 -0700 (PDT) Received: from localhost ([::1]:50918 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oB9nN-00086G-Vw for importer@patchew.org; Tue, 12 Jul 2022 02:54:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53600) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oB9SM-0003Wq-Dl; Tue, 12 Jul 2022 02:33:14 -0400 Received: from smtp21.cstnet.cn ([159.226.251.21]:53778 helo=cstnet.cn) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oB9SJ-0001bz-Cd; Tue, 12 Jul 2022 02:33:13 -0400 Received: from localhost.localdomain (unknown [180.156.173.38]) by APP-01 (Coremail) with SMTP id qwCowADns1idFc1ijYPeDg--.64613S6; Tue, 12 Jul 2022 14:33:05 +0800 (CST) From: Weiwei Li To: palmer@dabbelt.com, alistair.francis@wdc.com, bin.meng@windriver.com, qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: wangjunqiang@iscas.ac.cn, lazyparser@gmail.com, Weiwei Li Subject: [PATCH v2 4/6] target/riscv: add check for csrs existed with U extension Date: Tue, 12 Jul 2022 14:32:34 +0800 Message-Id: <20220712063236.23834-5-liweiwei@iscas.ac.cn> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220712063236.23834-1-liweiwei@iscas.ac.cn> References: <20220712063236.23834-1-liweiwei@iscas.ac.cn> X-CM-TRANSID: qwCowADns1idFc1ijYPeDg--.64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TnIWIevJa73UjIFyTuYvjfUOBTYUUUUU X-Originating-IP: [180.156.173.38] X-CM-SenderInfo: 5olzvxxzhlqxpvfd2hldfou0/ 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=159.226.251.21; envelope-from=liweiwei@iscas.ac.cn; helo=cstnet.cn X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1657608901617100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" - add umode/umode32 predicate for mcounteren,menvcfg/menvcfgh Signed-off-by: Weiwei Li Signed-off-by: Junqiang Wang Reviewed-by: Alistair Francis Reviewed-by: Andrew Jones --- target/riscv/csr.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 7d4b6ceced..1edeb69366 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -339,6 +339,25 @@ static RISCVException hmode32(CPURISCVState *env, int = csrno) =20 } =20 +static RISCVException umode(CPURISCVState *env, int csrno) +{ + if (riscv_has_ext(env, RVU)) { + /* User extension is supported */ + return RISCV_EXCP_NONE; + } + + return RISCV_EXCP_ILLEGAL_INST; +} + +static RISCVException umode32(CPURISCVState *env, int csrno) +{ + if (riscv_cpu_mxl(env) !=3D MXL_RV32) { + return RISCV_EXCP_ILLEGAL_INST; + } + + return umode(env, csrno); +} + /* Checks if PointerMasking registers could be accessed */ static RISCVException pointer_masking(CPURISCVState *env, int csrno) { @@ -3519,7 +3538,7 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { [CSR_MEDELEG] =3D { "medeleg", any, read_medeleg, write_medel= eg }, [CSR_MIE] =3D { "mie", any, NULL, NULL, rmw_mie = }, [CSR_MTVEC] =3D { "mtvec", any, read_mtvec, write_mtvec= }, - [CSR_MCOUNTEREN] =3D { "mcounteren", any, read_mcounteren, + [CSR_MCOUNTEREN] =3D { "mcounteren", umode, read_mcounteren, write_mcounteren = }, =20 [CSR_MSTATUSH] =3D { "mstatush", any32, read_mstatush, @@ -3553,9 +3572,9 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { [CSR_MIPH] =3D { "miph", aia_any32, NULL, NULL, rmw_miph }, =20 /* Execution environment configuration */ - [CSR_MENVCFG] =3D { "menvcfg", any, read_menvcfg, write_menvcfg, + [CSR_MENVCFG] =3D { "menvcfg", umode, read_menvcfg, write_menvcfg, .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, - [CSR_MENVCFGH] =3D { "menvcfgh", any32, read_menvcfgh, write_menvcfgh, + [CSR_MENVCFGH] =3D { "menvcfgh", umode32, read_menvcfgh, write_menvcfg= h, .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, [CSR_SENVCFG] =3D { "senvcfg", smode, read_senvcfg, write_senvcfg, .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, --=20 2.17.1