Skip to content

Commit a7c23c5

Browse files
committed
dirty.S: Add test for ADUE bit
1 parent 0a43dc3 commit a7c23c5

File tree

2 files changed

+68
-8
lines changed

2 files changed

+68
-8
lines changed

isa/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ vpath %.S $(src_dir)
5050
$(RISCV_OBJDUMP) $< > $@
5151

5252
%.out: %
53-
$(RISCV_SIM) --isa=rv64gc_zfh_zicboz_svnapot_zicntr --misaligned $< 2> $@
53+
$(RISCV_SIM) --isa=rv64gc_zfh_zicboz_svnapot_zicntr_svadu --misaligned $< 2> $@
5454

5555
%.out32: %
56-
$(RISCV_SIM) --isa=rv32gc_zfh_zicboz_svnapot_zicntr --misaligned $< 2> $@
56+
$(RISCV_SIM) --isa=rv32gc_zfh_zicboz_svnapot_zicntr_svadu --misaligned $< 2> $@
5757

5858
define compile_template
5959

isa/rv64si/dirty.S

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,45 @@ RVTEST_CODE_BEGIN
3434
li t2, 1
3535
sw t2, dummy - DRAM_BASE, a0
3636

37-
# Set SUM=1 so user memory access is permitted
3837
li TESTNUM, 3
38+
# set ADUE to 0
39+
#if __riscv_xlen == 64
40+
li a1, MENVCFG_ADUE
41+
csrc menvcfg, a1
42+
#else
43+
li a1, MENVCFGH_ADUE
44+
csrc menvcfgh, a1
45+
#endif
46+
47+
# We do this test twice (as 3 and again as 4). For the second run,
48+
# we'll have toggled ADUE and branch to here:
49+
1:
50+
# Set SUM=1 so user memory access is permitted
3951
li a1, ((MSTATUS_MPP & ~(MSTATUS_MPP<<1)) * PRV_S) | MSTATUS_SUM
4052
csrs mstatus, a1
4153

4254
# Make sure SUM=1 works
4355
lw t0, dummy - DRAM_BASE
4456
bnez t0, die
4557

46-
# Try a non-faulting store to make sure dirty bit is set
58+
# Clear D bit, then do a non-faulting store and ensure D bit is set
59+
# Leave MPRV
60+
li t0, MSTATUS_MPRV
61+
csrc mstatus, t0
62+
63+
# Clear D bit
64+
lw t0, page_table_1
65+
li a0, ~(PTE_D)
66+
and t0, t0, a0
67+
sw t0, page_table_1, a0
68+
sfence.vma
69+
70+
# Enter MPRV again
71+
li t0, MSTATUS_MPRV
72+
csrs mstatus, t0
73+
74+
# Now, the non-faulting store
75+
addi t2, t2, 1
4776
sw t2, dummy - DRAM_BASE, a0
4877

4978
# Make sure it succeeded
@@ -55,6 +84,7 @@ RVTEST_CODE_BEGIN
5584
csrc mstatus, t0
5685

5786
# Make sure D bit is set
87+
sfence.vma
5888
lw t0, page_table_1
5989
li a0, PTE_A | PTE_D
6090
and t0, t0, a0
@@ -64,8 +94,26 @@ RVTEST_CODE_BEGIN
6494
li t0, MSTATUS_MPRV
6595
csrs mstatus, t0
6696

97+
addi TESTNUM, TESTNUM, 1
98+
li t0, 5
99+
beq TESTNUM, t0, 1f
100+
101+
# reset this value:
102+
sw zero, dummy - DRAM_BASE, a0
103+
104+
# set ADUE to 1
105+
#if __riscv_xlen == 64
106+
li a1, MENVCFG_ADUE
107+
csrs menvcfg, a1
108+
#else
109+
li a1, MENVCFGH_ADUE
110+
csrs menvcfgh, a1
111+
#endif
112+
113+
j 1b
114+
1:
67115
# Make sure that superpage entries trap when PPN LSBs are set.
68-
li TESTNUM, 4
116+
li TESTNUM, 5
69117
lw a0, page_table_1 - DRAM_BASE
70118
or a0, a0, 1 << PTE_PPN_SHIFT
71119
sw a0, page_table_1 - DRAM_BASE, t0
@@ -97,9 +145,21 @@ skip:
97145
mret
98146

99147
1:
100-
li t1, 3
101-
bne TESTNUM, t1, 1f
148+
li t1, 4
149+
bgt TESTNUM, t1, 1f
102150
# The implementation doesn't appear to set D bits in HW.
151+
# Verify that ADUE is 0.
152+
#if __riscv_xlen == 64
153+
csrr a1, menvcfg
154+
li t0, MENVCFG_ADUE
155+
and a1, a1, t0
156+
bnez a1, die
157+
#else
158+
csrr a1, menvcfgh
159+
li t0, MENVCFGH_ADUE
160+
and a1, a1, t0
161+
bnez a1, die
162+
#endif
103163
# Make sure the D bit really is clear.
104164
lw t0, page_table_1
105165
and t1, t0, PTE_D
@@ -111,7 +171,7 @@ skip:
111171
mret
112172

113173
1:
114-
li t1, 4
174+
li t1, 5
115175
bne TESTNUM, t1, 1f
116176
j pass
117177

0 commit comments

Comments
 (0)