Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions arch/riscv/cpu_bits.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@
#define MSTATUS_MXR 0x00080000
#define MSTATUS_VM 0x1F000000 /* until: priv-1.9.1 */
#define MSTATUS_TVM 0x00100000 /* since: priv-1.10 */
#define MSTATUS_TW 0x20000000 /* since: priv-1.10 */
#define MSTATUS_TSR 0x40000000 /* since: priv-1.10 */
#define MSTATUS_TW 0x00200000 /* since: priv-1.10 */
#define MSTATUS_TSR 0x00400000 /* since: priv-1.10 */

#define MSTATUS_VS_INITIAL 0x00000600
#define MSTATUS_FS_INITIAL 0x00002000
Expand Down
4 changes: 4 additions & 0 deletions arch/riscv/op_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,10 @@ inline void csr_write_helper(CPUState *env, target_ulong val_to_write, target_ul
target_ulong mask = MSTATUS_MIE | MSTATUS_MPIE | MSTATUS_FS | MSTATUS_MPRV | MSTATUS_MPP | MSTATUS_MXR | MSTATUS_VS;
if(riscv_has_ext(env, RISCV_FEATURE_RVS)) {
mask |= MSTATUS_SIE | MSTATUS_SPIE | MSTATUS_SUM | MSTATUS_SPP;

if(env->privilege_architecture >= RISCV_PRIV1_10) {
mask |= MSTATUS_TVM | MSTATUS_TW | MSTATUS_TSR;
}
}

if(env->privilege_architecture < RISCV_PRIV1_10) {
Expand Down
14 changes: 14 additions & 0 deletions arch/riscv/translate.c
Original file line number Diff line number Diff line change
Expand Up @@ -3546,6 +3546,20 @@ static void gen_system(DisasContext *dc, uint32_t opc, int rd, int rs1, int rs2,
}
break;
case 0x9: /* SFENCE.VMA */
/* SFENCE.VMA is privileged: U-mode must always trap */
if(env->priv < PRV_S) {
generate_exception(dc, RISCV_EXCP_ILLEGAL_INST);
break;
}

/* In S-mode, TVM=1 also traps (priv spec >= 1.10) */
if(env->privilege_architecture >= RISCV_PRIV1_10 &&
env->priv == PRV_S &&
get_field(env->mstatus, MSTATUS_TVM)) {
generate_exception(dc, RISCV_EXCP_ILLEGAL_INST);
break;
}

/* TODO: handle ASID specific fences */
gen_helper_tlb_flush(cpu_env);
break;
Expand Down