Skip to content

Commit

Permalink
RISC-V: No traps on writes to misa,minstret,mcycle
Browse files Browse the repository at this point in the history
These fields are marked WARL (Write Any Values, Reads
Legal Values) in the RISC-V Privileged Architecture
Specification so instead of raising exceptions,
illegal writes are silently dropped.

Cc: Sagar Karandikar <sagark@eecs.berkeley.edu>
Cc: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
Cc: Palmer Dabbelt <palmer@sifive.com>
Cc: Alistair Francis <Alistair.Francis@wdc.com>
Signed-off-by: Michael Clark <mjc@sifive.com>
  • Loading branch information
Michael Clark committed May 5, 2018
1 parent 1d1ee55 commit b8643bd
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions target/riscv/op_helper.c
Expand Up @@ -213,17 +213,19 @@ void csr_write_helper(CPURISCVState *env, target_ulong val_to_write,
break;
}
case CSR_MINSTRET:
qemu_log_mask(LOG_UNIMP, "CSR_MINSTRET: write not implemented");
goto do_illegal;
/* minstret is WARL so unsupported writes are ignored */
break;
case CSR_MCYCLE:
qemu_log_mask(LOG_UNIMP, "CSR_MCYCLE: write not implemented");
goto do_illegal;
/* mcycle is WARL so unsupported writes are ignored */
break;
#if defined(TARGET_RISCV32)
case CSR_MINSTRETH:
qemu_log_mask(LOG_UNIMP, "CSR_MINSTRETH: write not implemented");
goto do_illegal;
/* minstreth is WARL so unsupported writes are ignored */
break;
case CSR_MCYCLEH:
qemu_log_mask(LOG_UNIMP, "CSR_MCYCLEH: write not implemented");
goto do_illegal;
/* mcycleh is WARL so unsupported writes are ignored */
break;
#endif
case CSR_MUCOUNTEREN:
if (env->priv_ver <= PRIV_VERSION_1_09_1) {
env->scounteren = val_to_write;
Expand Down Expand Up @@ -337,10 +339,9 @@ void csr_write_helper(CPURISCVState *env, target_ulong val_to_write,
case CSR_MBADADDR:
env->mbadaddr = val_to_write;
break;
case CSR_MISA: {
qemu_log_mask(LOG_UNIMP, "CSR_MISA: misa writes not supported");
goto do_illegal;
}
case CSR_MISA:
/* misa is WARL so unsupported writes are ignored */
break;
case CSR_PMPCFG0:
case CSR_PMPCFG1:
case CSR_PMPCFG2:
Expand Down

0 comments on commit b8643bd

Please sign in to comment.