>
> pmp_unlock_entries(env);
> +
> + /* Is SPMP enabled? */
> + if (riscv_cpu_cfg(env)->spmp) {
> + env->mpmpdeleg = MPMP_DELEG_DEFAULT;
> + env->spmp_state.num_deleg_rules = 64 - MPMP_DELEG_DEFAULT;
>
Can we replace the const number with a macro?
+ spmp_unlock_entries(env);
> + }
> #else
> env->priv = PRV_U;
> env->senvcfg = 0;
> diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
> index c265098324..e19c1216ea 100644
> --- a/target/riscv/cpu.h
> +++ b/target/riscv/cpu.h
> @@ -179,6 +179,7 @@ extern RISCVCPUImpliedExtsRule
> *riscv_multi_ext_implied_rules[];
> #define MIN_RISCV_PMP_GRANULARITY 4
>
> #define MAX_RISCV_SPMPS (64)
> +#define MPMP_DELEG_DEFAULT (64)
>
Why do we need MPMP_DELEG_DEFAULT?
Since SPMP and PMP share the same PMP entries, maybe we can directly use
MAX_RISCV_PMPS instead?
+/* S-mode Physical Memory Protection */
> +static RISCVException rmw_mpmpdeleg(CPURISCVState *env, int csrno,
> + target_ulong *ret_val,
> + target_ulong new_val, target_ulong
> wr_mask)
> +{
> + uint16_t new_mpmpdeleg = (env->mpmpdeleg & ~wr_mask) | (new_val &
> wr_mask);
> +
> + if (ret_val) {
> + *ret_val = env->mpmpdeleg;
> + }
> +
> + /*
> + * pmpnum is locked if MSECCFG_MML is set
> + * and if new_mpmpdeleg is higher than last locked rule
> + */
> + if (!(env->mseccfg & MSECCFG_MML) &&
> + (new_mpmpdeleg & 0x7F) > env->pmp_state.last_locked_rule) {
> + env->mpmpdeleg = new_mpmpdeleg & 0x7F;
> + }
> +
> + env->spmp_state.num_deleg_rules = MPMP_DELEG_DEFAULT - env->mpmpdeleg;
> + return RISCV_EXCP_NONE;
> +}
> +
>
Do we need to flush tlb here ?