target/riscv: Add User CSRs read-only check
For U-mode CSRs, read-only check is also needed. Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Message-id: 20210810014552.4884-1-zhiwei_liu@c-sky.com Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
This commit is contained in:
parent
a8b37120d4
commit
42109837b5
|
@ -1422,11 +1422,11 @@ RISCVException riscv_csrrw(CPURISCVState *env, int csrno,
|
||||||
RISCVException ret;
|
RISCVException ret;
|
||||||
target_ulong old_value;
|
target_ulong old_value;
|
||||||
RISCVCPU *cpu = env_archcpu(env);
|
RISCVCPU *cpu = env_archcpu(env);
|
||||||
|
int read_only = get_field(csrno, 0xC00) == 3;
|
||||||
|
|
||||||
/* check privileges and return RISCV_EXCP_ILLEGAL_INST if check fails */
|
/* check privileges and return RISCV_EXCP_ILLEGAL_INST if check fails */
|
||||||
#if !defined(CONFIG_USER_ONLY)
|
#if !defined(CONFIG_USER_ONLY)
|
||||||
int effective_priv = env->priv;
|
int effective_priv = env->priv;
|
||||||
int read_only = get_field(csrno, 0xC00) == 3;
|
|
||||||
|
|
||||||
if (riscv_has_ext(env, RVH) &&
|
if (riscv_has_ext(env, RVH) &&
|
||||||
env->priv == PRV_S &&
|
env->priv == PRV_S &&
|
||||||
|
@ -1439,11 +1439,13 @@ RISCVException riscv_csrrw(CPURISCVState *env, int csrno,
|
||||||
effective_priv++;
|
effective_priv++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((write_mask && read_only) ||
|
if (!env->debugger && (effective_priv < get_field(csrno, 0x300))) {
|
||||||
(!env->debugger && (effective_priv < get_field(csrno, 0x300)))) {
|
|
||||||
return RISCV_EXCP_ILLEGAL_INST;
|
return RISCV_EXCP_ILLEGAL_INST;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
if (write_mask && read_only) {
|
||||||
|
return RISCV_EXCP_ILLEGAL_INST;
|
||||||
|
}
|
||||||
|
|
||||||
/* ensure the CSR extension is enabled. */
|
/* ensure the CSR extension is enabled. */
|
||||||
if (!cpu->cfg.ext_icsr) {
|
if (!cpu->cfg.ext_icsr) {
|
||||||
|
|
Loading…
Reference in a new issue