Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(priv): prevent mstatus.MPP changing to 2 #581

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion include/cpu/difftest.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static inline bool difftest_check_vreg(const char *name, vaddr_t pc, rtlreg_t *r
static inline bool difftest_check_store(vaddr_t pc) {
#ifdef CONFIG_RVV
size_t step = store_queue_size();
for (int i = 0; i < step ;i ++) {
for (size_t i = 0; i < step ;i ++) {
#endif
if (store_queue_empty()) return true;
store_commit_t dut = store_queue_fornt();
Expand Down
2 changes: 1 addition & 1 deletion src/isa/riscv64/include/isa-def.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ typedef struct {
} instr;
} riscv64_ISADecodeInfo;

enum { MODE_U = 0, MODE_S, MODE_HS, MODE_M };
enum { MODE_U = 0, MODE_S, MODE_RESERVED, MODE_M };

int get_data_mmu_state();
#ifdef CONFIG_RVH
Expand Down
10 changes: 9 additions & 1 deletion src/isa/riscv64/system/priv.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ static inline word_t* csr_decode(uint32_t addr) {
// base mstatus wmask
#define MSTATUS_WMASK_BASE (0x7e19aaUL)

// mstatus.mpp mask
#define MSTATUS_OFFSET_MPP 11
#define MSTATUS_MASK_MPP (0x3UL << MSTATUS_OFFSET_MPP)

// FS
#if !defined(CONFIG_FPU_NONE) || defined(CONFIG_RV_MSTATUS_FS_WRITABLE)
#define MSTATUS_WMASK_FS (0x3UL << 13)
Expand Down Expand Up @@ -1326,6 +1330,10 @@ static inline void csr_write(word_t *dest, word_t src) {
}
}
#endif //CONFIG_RV_SSDBLTRP
// mstatus.MPP cannot hold 2
if (((mstatus_t *) &src)->mpp == MODE_RESERVED) {
mstatus_wmask &= ~MSTATUS_MASK_MPP;
}
mstatus->val = mask_bitset(mstatus->val, mstatus_wmask, src);
update_mmu_state(); // maybe this write update mprv, mpp or mpv
#ifdef CONFIG_RV_SMDBLTRP
Expand Down Expand Up @@ -1355,7 +1363,7 @@ static inline void csr_write(word_t *dest, word_t src) {
// by writing that mode to MPP then reading it back. If the machine
// provides only U and M modes, then only a single hardware storage bit
// is required to represent either 00 or 11 in MPP.
if (mstatus->mpp == MODE_HS) {
if (mstatus->mpp == MODE_RESERVED) {
// MODE_H is not implemented. The write will not take effect.
mstatus->mpp = prev_mpp;
}
Expand Down