From: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
To: "Fea.Wang" <fea.wang@sifive.com>,
qemu-devel@nongnu.org, qemu-riscv@nongnu.org
Cc: Frank Chang <frank.chang@sifive.com>,
Palmer Dabbelt <palmer@dabbelt.com>,
Alistair Francis <alistair.francis@wdc.com>,
Bin Meng <bin.meng@windriver.com>,
Weiwei Li <liwei1518@gmail.com>,
Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Subject: Re: [PATCH 4/5] target/riscv: Add MEDELEGH, HEDELEGH csrs for RV32
Date: Mon, 13 May 2024 10:48:44 +0800 [thread overview]
Message-ID: <c9969b2a-db87-4694-9fe9-bad7aa6bf749@linux.alibaba.com> (raw)
In-Reply-To: <20240510065856.2436870-5-fea.wang@sifive.com>
On 2024/5/10 14:58, Fea.Wang wrote:
> Based on privileged spec 1.13, the RV32 needs to implement MEDELEGH
> and HEDELEGH for exception codes 32-47 for reserving and exception codes
> 48-63 for custom use. Add the CSR number though the implementation is
> just reading zero and writing ignore. Besides, for accessing HEDELEGH, it
> should be controlled by mstateen0 'P1P13' bit.
>
> Signed-off-by: Fea.Wang <fea.wang@sifive.com>
> Reviewed-by: Frank Chang <frank.chang@sifive.com>
> ---
> target/riscv/cpu_bits.h | 2 ++
> target/riscv/csr.c | 31 +++++++++++++++++++++++++++++++
> 2 files changed, 33 insertions(+)
>
> diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
> index 28bd3fb0b4..f888025c59 100644
> --- a/target/riscv/cpu_bits.h
> +++ b/target/riscv/cpu_bits.h
> @@ -156,6 +156,8 @@
>
> /* 32-bit only */
> #define CSR_MSTATUSH 0x310
> +#define CSR_MEDELEGH 0x312
> +#define CSR_HEDELEGH 0x612
>
> /* Machine Trap Handling */
> #define CSR_MSCRATCH 0x340
> diff --git a/target/riscv/csr.c b/target/riscv/csr.c
> index d844ce770e..4d7313f456 100644
> --- a/target/riscv/csr.c
> +++ b/target/riscv/csr.c
> @@ -3227,6 +3227,33 @@ static RISCVException write_hedeleg(CPURISCVState *env, int csrno,
> return RISCV_EXCP_NONE;
> }
>
> +static RISCVException read_hedelegh(CPURISCVState *env, int csrno,
> + target_ulong *val)
> +{
> + RISCVException ret;
> + ret = smstateen_acc_ok(env, 0, SMSTATEEN0_P1P13);
> + if (ret != RISCV_EXCP_NONE) {
> + return ret;
> + }
> +
> + /* Reserved, now read zero */
> + *val = 0;
> + return RISCV_EXCP_NONE;
> +}
> +
> +static RISCVException write_hedelegh(CPURISCVState *env, int csrno,
> + target_ulong val)
> +{
> + RISCVException ret;
> + ret = smstateen_acc_ok(env, 0, SMSTATEEN0_P1P13);
> + if (ret != RISCV_EXCP_NONE) {
> + return ret;
> + }
> +
> + /* Reserved, now write ignore */
> + return RISCV_EXCP_NONE;
> +}
> +
> static RISCVException rmw_hvien64(CPURISCVState *env, int csrno,
> uint64_t *ret_val,
> uint64_t new_val, uint64_t wr_mask)
> @@ -4674,6 +4701,10 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = {
>
> [CSR_MSTATUSH] = { "mstatush", any32, read_mstatush,
> write_mstatush },
> + [CSR_MEDELEGH] = { "medelegh", any32, read_zero, write_ignore,
> + .min_priv_ver = PRIV_VERSION_1_13_0 },
> + [CSR_HEDELEGH] = { "hedelegh", any32, read_hedelegh, write_hedelegh,
Using hmode32 instead of any32.
Otherwise,
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
> + .min_priv_ver = PRIV_VERSION_1_13_0 },
>
> /* Machine Trap Handling */
> [CSR_MSCRATCH] = { "mscratch", any, read_mscratch, write_mscratch,
next prev parent reply other threads:[~2024-05-13 2:50 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-10 6:58 [PATCH 0/5] target/riscv: Support RISC-V privilege 1.13 spec Fea.Wang
2024-05-10 6:58 ` [PATCH 1/5] target/riscv: Reuse the conversion function of priv_spec and string Fea.Wang
2024-05-11 14:41 ` liwei
2024-05-13 2:54 ` LIU Zhiwei
2024-05-15 7:46 ` Fea Wang
2024-05-10 6:58 ` [PATCH 2/5] target/riscv: Support the version for ss1p13 Fea.Wang
2024-05-11 14:42 ` liwei
2024-05-13 2:52 ` LIU Zhiwei
2024-05-10 6:58 ` [PATCH 3/5] target/riscv: Add 'P1P13' bit in SMSTATEEN0 Fea.Wang
2024-05-11 14:46 ` liwei
2024-05-13 2:51 ` LIU Zhiwei
2024-05-15 7:46 ` Fea Wang
2024-05-10 6:58 ` [PATCH 4/5] target/riscv: Add MEDELEGH, HEDELEGH csrs for RV32 Fea.Wang
2024-05-13 2:48 ` LIU Zhiwei [this message]
2024-05-15 7:47 ` Fea Wang
2024-05-10 6:58 ` [PATCH 5/5] target/riscv: Reserve exception codes for sw-check and hw-err Fea.Wang
2024-05-13 2:43 ` LIU Zhiwei
-- strict thread matches above, loose matches on Subject: below --
2024-05-15 7:53 [PATCH v2 0/5] target/riscv: Support RISC-V privilege 1.13 spec Fea.Wang
2024-05-15 7:53 ` [PATCH 4/5] target/riscv: Add MEDELEGH, HEDELEGH csrs for RV32 Fea.Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c9969b2a-db87-4694-9fe9-bad7aa6bf749@linux.alibaba.com \
--to=zhiwei_liu@linux.alibaba.com \
--cc=alistair.francis@wdc.com \
--cc=bin.meng@windriver.com \
--cc=dbarboza@ventanamicro.com \
--cc=fea.wang@sifive.com \
--cc=frank.chang@sifive.com \
--cc=liwei1518@gmail.com \
--cc=palmer@dabbelt.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).