From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
To: frank.chang@sifive.com, qemu-devel@nongnu.org, qemu-riscv@nongnu.org
Cc: Palmer Dabbelt <palmer@dabbelt.com>,
Alistair Francis <alistair.francis@wdc.com>,
Bin Meng <bmeng.cn@gmail.com>, Weiwei Li <liwei1518@gmail.com>,
Liu Zhiwei <zhiwei_liu@linux.alibaba.com>
Subject: Re: [PATCH v10 6/7] target/riscv: Add Zicfilp support for Smrnmi
Date: Thu, 26 Dec 2024 09:53:25 -0300 [thread overview]
Message-ID: <e99fa25f-5c92-4261-828f-2351820e1806@ventanamicro.com> (raw)
In-Reply-To: <20241217062440.884261-7-frank.chang@sifive.com>
On 12/17/24 3:24 AM, frank.chang@sifive.com wrote:
> From: Frank Chang <frank.chang@sifive.com>
>
> Zicfilp extension introduces the MNPELP (bit 9) in mnstatus.
> The MNPELP field holds the previous ELP.
>
> When a RNMI trap is delivered, the MNPELP is set to ELP and ELP set
> to NO_LP_EXPECTED. Upon a mnret, if the mnstatus.MNPP holds the
> value y, then ELP is set to the value of MNPELP if yLPE is 1;
> otherwise, it is set to NO_LP_EXPECTED.
>
> Signed-off-by: Frank Chang <frank.chang@sifive.com>
> ---
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
> target/riscv/cpu_bits.h | 1 +
> target/riscv/cpu_helper.c | 11 ++++++++++-
> target/riscv/op_helper.c | 9 +++++++++
> 3 files changed, 20 insertions(+), 1 deletion(-)
>
> diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
> index 17787fd693..be9d0f5c05 100644
> --- a/target/riscv/cpu_bits.h
> +++ b/target/riscv/cpu_bits.h
> @@ -643,6 +643,7 @@ typedef enum {
> /* RNMI mnstatus CSR mask */
> #define MNSTATUS_NMIE 0x00000008
> #define MNSTATUS_MNPV 0x00000080
> +#define MNSTATUS_MNPELP 0x00000200
> #define MNSTATUS_MNPP 0x00001800
>
> /* VM modes (satp.mode) privileged ISA 1.10 */
> diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
> index e5ffbbbd83..1fb1e31031 100644
> --- a/target/riscv/cpu_helper.c
> +++ b/target/riscv/cpu_helper.c
> @@ -1918,6 +1918,10 @@ void riscv_cpu_do_interrupt(CPUState *cs)
> env->mnepc = env->pc;
> env->pc = env->rnmi_irqvec;
>
> + if (cpu_get_fcfien(env)) {
> + env->mnstatus = set_field(env->mnstatus, MNSTATUS_MNPELP, env->elp);
> + }
> +
> /* Trapping to M mode, virt is disabled */
> riscv_cpu_set_mode(env, PRV_M, false);
>
> @@ -2085,7 +2089,12 @@ void riscv_cpu_do_interrupt(CPUState *cs)
> /* handle the trap in M-mode */
> /* save elp status */
> if (cpu_get_fcfien(env)) {
> - env->mstatus = set_field(env->mstatus, MSTATUS_MPELP, env->elp);
> + if (nnmi_excep) {
> + env->mnstatus = set_field(env->mnstatus, MNSTATUS_MNPELP,
> + env->elp);
> + } else {
> + env->mstatus = set_field(env->mstatus, MSTATUS_MPELP, env->elp);
> + }
> }
>
> if (riscv_has_ext(env, RVH)) {
> diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c
> index 63ec53e992..a4b625fcd9 100644
> --- a/target/riscv/op_helper.c
> +++ b/target/riscv/op_helper.c
> @@ -402,6 +402,15 @@ target_ulong helper_mnret(CPURISCVState *env)
>
> riscv_cpu_set_mode(env, prev_priv, prev_virt);
>
> + /*
> + * If forward cfi enabled for new priv, restore elp status
> + * and clear mnpelp in mnstatus
> + */
> + if (cpu_get_fcfien(env)) {
> + env->elp = get_field(env->mnstatus, MNSTATUS_MNPELP);
> + }
> + env->mnstatus = set_field(env->mnstatus, MNSTATUS_MNPELP, 0);
> +
> return retpc;
> }
>
next prev parent reply other threads:[~2024-12-26 12:54 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-17 6:24 [PATCH v10 0/7] Add Smrnmi support frank.chang
2024-12-17 6:24 ` [PATCH v10 1/7] target/riscv: Add 'ext_smrnmi' in the RISCVCPUConfig frank.chang
2024-12-17 6:24 ` [PATCH v10 2/7] target/riscv: Add Smrnmi CSRs frank.chang
2024-12-17 6:24 ` [PATCH v10 3/7] target/riscv: Handle Smrnmi interrupt and exception frank.chang
2024-12-26 12:42 ` Daniel Henrique Barboza
2024-12-31 3:11 ` Frank Chang
2024-12-31 9:19 ` Daniel Henrique Barboza
2024-12-17 6:24 ` [PATCH v10 4/7] target/riscv: Add Smrnmi mnret instruction frank.chang
2024-12-26 12:47 ` Daniel Henrique Barboza
2024-12-17 6:24 ` [PATCH v10 5/7] target/riscv: Add Smrnmi cpu extension frank.chang
2024-12-26 12:51 ` Daniel Henrique Barboza
2024-12-17 6:24 ` [PATCH v10 6/7] target/riscv: Add Zicfilp support for Smrnmi frank.chang
2024-12-26 12:53 ` Daniel Henrique Barboza [this message]
2024-12-17 6:24 ` [PATCH v10 7/7] target/riscv: Disable Smrnmi for the 'max' type CPU frank.chang
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=e99fa25f-5c92-4261-828f-2351820e1806@ventanamicro.com \
--to=dbarboza@ventanamicro.com \
--cc=alistair.francis@wdc.com \
--cc=bmeng.cn@gmail.com \
--cc=frank.chang@sifive.com \
--cc=liwei1518@gmail.com \
--cc=palmer@dabbelt.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=zhiwei_liu@linux.alibaba.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.