Skip to content

Commit

Permalink
Check that User mode is enable to set MPP to U-mode (fix #1756) (#1781)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gchauvon authored Jan 25, 2024
1 parent e0ca601 commit 13a4a09
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions core/csr_regfile.sv
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,9 @@ module csr_regfile

mstatus_d.sxl = riscv::XLEN_64;
mstatus_d.uxl = riscv::XLEN_64;

if (!CVA6Cfg.RVU) begin
mstatus_d.mpp = riscv::PRIV_LVL_M;
end
// mark the floating point extension register as dirty
if (CVA6Cfg.FpPresent && (dirty_fp_state_csr || dirty_fp_state_i)) begin
mstatus_d.fs = riscv::Dirty;
Expand Down Expand Up @@ -1248,14 +1250,17 @@ module csr_regfile
// mode is changed to y; xPIE is set to 1; and xPP is set to U
if (mret) begin
// return from exception, IF doesn't care from where we are returning
eret_o = 1'b1;
eret_o = 1'b1;
// return to the previous privilege level and restore all enable flags
// get the previous machine interrupt enable flag
mstatus_d.mie = mstatus_q.mpie;
mstatus_d.mie = mstatus_q.mpie;
// restore the previous privilege level
priv_lvl_d = mstatus_q.mpp;
// set mpp to user mode
mstatus_d.mpp = riscv::PRIV_LVL_U;
priv_lvl_d = mstatus_q.mpp;
mstatus_d.mpp = riscv::PRIV_LVL_M;
if (CVA6Cfg.RVU) begin
// set mpp to user mode
mstatus_d.mpp = riscv::PRIV_LVL_U;
end
// set mpie to 1
mstatus_d.mpie = 1'b1;
end
Expand Down

0 comments on commit 13a4a09

Please sign in to comment.