Skip to content
Merged
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
9 changes: 5 additions & 4 deletions core/csr_regfile.sv
Original file line number Diff line number Diff line change
Expand Up @@ -1579,10 +1579,11 @@ module csr_regfile
hgatp[1:0] = 2'b0;
// only make VMID_LEN - 1 bit stick, that way software can figure out how many VMID bits are supported
hgatp.vmid = hgatp.vmid & {{(CVA6Cfg.VMIDW - CVA6Cfg.VMID_WIDTH) {1'b0}}, {CVA6Cfg.VMID_WIDTH{1'b1}}};
// only update if we actually support this mode
if (config_pkg::vm_mode_t'(hgatp.mode) == config_pkg::ModeOff ||
config_pkg::vm_mode_t'(hgatp.mode) == CVA6Cfg.MODE_SV)
hgatp_d = hgatp;
// Preserve the current mode if the written mode is unsupported.
if (config_pkg::vm_mode_t'(hgatp.mode) != config_pkg::ModeOff &&
config_pkg::vm_mode_t'(hgatp.mode) != CVA6Cfg.MODE_SV)
hgatp.mode = hgatp_q.mode;
hgatp_d = hgatp;
end
// changing the mode can have side-effects on address translation (e.g.: other instructions), re-fetch
// the next instruction by executing a flush
Expand Down
55 changes: 55 additions & 0 deletions verif/tests/custom/hgatp_warl/hgatp_mode_warl.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include "riscv_test.h"
#include "test_macros.h"

.option arch, +h

#define CSR_HGATP 0x680
#define HGATP_MODE_SV39X4 8
#define HGATP_MODE_UNSUPPORTED 1

RVTEST_RV64M
RVTEST_CODE_BEGIN

li TESTNUM, 1

# Install an initial legal value:
# MODE = Sv39x4
# PPN = 0x100
li t0, HGATP_MODE_SV39X4
slli t0, t0, 60
ori t0, t0, 0x100

csrw CSR_HGATP, t0
csrr t1, CSR_HGATP

bne t1, t0, fail

li TESTNUM, 2

# Write an unsupported MODE with a different PPN.
# MODE must be legalized, but PPN must still update.
li t2, HGATP_MODE_UNSUPPORTED
slli t2, t2, 60
ori t2, t2, 0x200

csrw CSR_HGATP, t2
csrr t3, CSR_HGATP

# Expected:
# MODE remains Sv39x4
# PPN changes to 0x200
li t4, HGATP_MODE_SV39X4
slli t4, t4, 60
ori t4, t4, 0x200

bne t3, t4, fail

j pass

TEST_PASSFAIL

RVTEST_CODE_END

RVTEST_DATA_BEGIN
TEST_DATA
RVTEST_DATA_END
8 changes: 8 additions & 0 deletions verif/tests/testlist_hgatp_warl.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Regression for unsupported hgatp.MODE WARL handling.

testlist:
- test: rv64h-p-hgatp-mode-warl
iterations: 1
path_var: TESTS_PATH
gcc_opts: "-static -mcmodel=medany -fvisibility=hidden -nostdlib -nostartfiles -I<path_var>/riscv-tests/isa/macros/scalar/ -I<path_var>/riscv-tests/env/p/ -I<path_var>/riscv-tests/riscv-target/spike/"
asm_tests: <path_var>/custom/hgatp_warl/hgatp_mode_warl.S
Loading