target/riscv: Disallow WFI instruction from U-mode
PATCH 1/1 target/riscv: Disallow WFI instruction from U-mode
From the RISC-V Priviliged Specification:
"When S-mode is implemented, then executing WFI in U-mode causes an illegal instruction exception, unless it completes within an implementation-specific, bounded time limit. A future revision of this specification might add a feature that allows S-mode to selectively permit WFI in U-mode."
--- target/riscv/op_helper.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
target/riscv/op_helper.c +4 -4
@@ -129,10 +129,10 @@ target_ulong helper_mret(CPURISCVState *env, target_ulong cpu_pc_deb)void helper_wfi (CPURISCVState *env) {CPUState *cs =env_cpu (env); - -if (env->priv ==PRV_S && - env->priv_ver >=PRIV_VERSION_1_10_0 && -get_field (env->mstatus,MSTATUS_TW )) { +if (!(env->priv >=PRV_S ) || + (env->priv ==PRV_S && + env->priv_ver >=PRIV_VERSION_1_10_0 && +get_field (env->mstatus,MSTATUS_TW ))) {riscv_raise_exception (env,RISCV_EXCP_ILLEGAL_INST ,GETPC ()); }else { cs->halted =1 ;
Signature · 1 line
2.25.0
Quoted 1 line · Jonathan Behrens
+ if (!(env->priv >=
PRV_S) ||
For integers, !(x >= y) is a poor way to write x < y.
r~
Haha, fair enough. I just copied that line from one of the other functions in that file, which all use the same style. The check is actually a bit worse than it looks because PRV_S is defined to be 1. Hence, the whole thing is equivalent to just writing env->priv == PRV_U. I can send out a new version with that changed.
Jonathan
Quoted 9 lines · Richard Henderson
Quoted 1 line · Jonathan Behrens
+ if (!(env->priv >=
PRV_S) ||For integers, !(x >= y) is a poor way to write x < y.
r~