Skip to content

Commit aef009c

Browse files
fix: mstatus.SXL/UXL should be 0 when S/U modes are not implemented (#3231)
This PR fixes #3182 by ensuring the SXL and UXL fields in mstatus are tied to 0 when S-mode or U-mode is not implemented, as required by the RISC-V Privileged Spec. Co-authored-by: JeanRochCoulon <jean-roch.coulon@thalesgroup.com>
1 parent 587312e commit aef009c

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

core/csr_regfile.sv

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,8 +1938,10 @@ module csr_regfile
19381938
endcase
19391939
end
19401940
if (CVA6Cfg.IS_XLEN64) begin
1941-
mstatus_d.sxl = riscv::XLEN_64;
1942-
mstatus_d.uxl = riscv::XLEN_64;
1941+
if (CVA6Cfg.RVS) mstatus_d.sxl = riscv::XLEN_64;
1942+
else mstatus_d.sxl = riscv::XLEN_NA;
1943+
if (CVA6Cfg.RVU) mstatus_d.uxl = riscv::XLEN_64;
1944+
else mstatus_d.uxl = riscv::XLEN_NA;
19431945
end
19441946
if (!CVA6Cfg.RVU) begin
19451947
mstatus_d.mpp = riscv::PRIV_LVL_M;

core/include/riscv_pkg.sv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ package riscv;
3737

3838
// type which holds xlen
3939
typedef enum logic [1:0] {
40+
XLEN_NA = 2'b00, // Used for mstatus.{S/U}XL when {S/U} not implemented
4041
XLEN_32 = 2'b01,
4142
XLEN_64 = 2'b10,
4243
XLEN_128 = 2'b11

0 commit comments

Comments
 (0)