Skip to content

Commit 7d9d018

Browse files
committed
Fix broken CSR privilege check, enable all ASID bits
1 parent 5e1f556 commit 7d9d018

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/cpu/worker.mlog.jinja

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2283,13 +2283,9 @@ modify_csr:
22832283
#% do declare_locals(modify_csr_locals)
22842284

22852285
# csr is stored in imm
2286-
# csr[11:10] indicates whether the register is read/write (00, 01, 10) or read-only (11)
2287-
op and $$readonly imm 0b110000000000
2288-
op equal $$readonly $$readonly 0b110000000000
2289-
22902286
# csr[9:8] encodes the lowest privilege level that can access the CSR
22912287
op shr $$csr_11_8 imm 8
2292-
op and $required_privilege $$csr_11_8 0b1100000000
2288+
op and $required_privilege $$csr_11_8 0b11
22932289
jump ILLEGAL_OP lessThan privilege_mode $required_privilege
22942290

22952291
# disable all hypervisor CSRs
@@ -2303,7 +2299,7 @@ modify_csr:
23032299

23042300
# IMPORTANT: the values of modify_csr_op and modify_csr_write need to be updated if anything after this line is changed
23052301
# -----------------
2306-
op add $$modify_csr_write @counter 11
2302+
op add $$modify_csr_write @counter 12
23072303
op add $$modify_csr_op @counter $$modify_csr_op
23082304
jump modify_csr__read always
23092305

@@ -2328,7 +2324,9 @@ modify_csr__conditional_write:
23282324
jump end_instruction_with_rd equal rs1_id 0
23292325

23302326
modify_csr__always_write:
2331-
jump ILLEGAL_OP equal $$readonly true
2327+
# csr[11:10] indicates whether the register is read/write (00, 01, 10) or read-only (11)
2328+
op and $$readonly imm 0b110000000000
2329+
jump ILLEGAL_OP equal $$readonly 0b110000000000
23322330

23332331
set @counter $$modify_csr_write
23342332
# -----------------
@@ -2591,8 +2589,9 @@ modify_csr__satp__ok:
25912589
op add $$modify_csr_write @counter 1
25922590
set @counter $$modify_csr_op
25932591

2594-
# ASIDLEN=0 ---------
2595-
op and csr_satp $$new_value 0b10000000001111111111111111111111
2592+
# we don't use ASID for anything, but riscv-sail doesn't allow us to configure ASIDLEN, so the tests will fail if we zero ASID
2593+
# https://github.com/riscv/sail-riscv/blob/d8c3006f0ff4dbd33be876d9d62abb085c7f5298/model/riscv_xlen.sail#L25
2594+
set csr_satp $$new_value
25962595

25972596
# invalidate icache_var when writing satp because next_pc may now point to a different page
25982597
# TODO: we might be able to move this into SFENCE.VMA

0 commit comments

Comments
 (0)