Skip to content

Commit 23fea69

Browse files
committed
olddirty: add this for side-by-side compare. DO NOT SUBMIT
1 parent dbe9444 commit 23fea69

File tree

2 files changed

+134
-0
lines changed

2 files changed

+134
-0
lines changed

isa/rv64si/Makefrag

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
rv64si_sc_tests = \
66
csr \
7+
olddirty \
78
dirty \
89
icache-alias \
910
ma_fetch \

isa/rv64si/olddirty.S

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# See LICENSE for license details.
2+
3+
#*****************************************************************************
4+
# dirty.S
5+
#-----------------------------------------------------------------------------
6+
#
7+
# Test VM referenced and dirty bits.
8+
#
9+
10+
#include "riscv_test.h"
11+
#include "test_macros.h"
12+
13+
#if (DRAM_BASE >> 30 << 30) != DRAM_BASE
14+
# error This test requires DRAM_BASE be SV39 superpage-aligned
15+
#endif
16+
17+
RVTEST_RV64M
18+
RVTEST_CODE_BEGIN
19+
20+
# Turn on VM
21+
li a0, (SATP_MODE & ~(SATP_MODE<<1)) * SATP_MODE_SV39
22+
la a1, page_table_1
23+
srl a1, a1, RISCV_PGSHIFT
24+
or a1, a1, a0
25+
csrw sptbr, a1
26+
sfence.vma
27+
28+
# Set up MPRV with MPP=S, so loads and stores use S-mode
29+
li a1, ((MSTATUS_MPP & ~(MSTATUS_MPP<<1)) * PRV_S) | MSTATUS_MPRV
30+
csrs mstatus, a1
31+
32+
# Try a faulting store to make sure dirty bit is not set
33+
li TESTNUM, 2
34+
li t2, 1
35+
sw t2, dummy - DRAM_BASE, a0
36+
37+
# Set SUM=1 so user memory access is permitted
38+
li TESTNUM, 3
39+
li a1, ((MSTATUS_MPP & ~(MSTATUS_MPP<<1)) * PRV_S) | MSTATUS_SUM
40+
csrs mstatus, a1
41+
42+
# Make sure SUM=1 works
43+
lw t0, dummy - DRAM_BASE
44+
bnez t0, die
45+
46+
# Try a non-faulting store to make sure dirty bit is set
47+
sw t2, dummy - DRAM_BASE, a0
48+
49+
# Make sure it succeeded
50+
lw t0, dummy - DRAM_BASE
51+
bne t0, t2, die
52+
53+
# Leave MPRV
54+
li t0, MSTATUS_MPRV
55+
csrc mstatus, t0
56+
57+
# Make sure D bit is set
58+
lw t0, page_table_1
59+
li a0, PTE_A | PTE_D
60+
and t0, t0, a0
61+
bne t0, a0, die
62+
63+
# Enter MPRV again
64+
li t0, MSTATUS_MPRV
65+
csrs mstatus, t0
66+
67+
# Make sure that superpage entries trap when PPN LSBs are set.
68+
li TESTNUM, 4
69+
lw a0, page_table_1 - DRAM_BASE
70+
or a0, a0, 1 << PTE_PPN_SHIFT
71+
sw a0, page_table_1 - DRAM_BASE, t0
72+
sfence.vma
73+
sw a0, page_table_1 - DRAM_BASE, t0
74+
j die
75+
76+
RVTEST_PASS
77+
78+
TEST_PASSFAIL
79+
80+
.align 2
81+
.global mtvec_handler
82+
mtvec_handler:
83+
csrr t0, mcause
84+
add t0, t0, -CAUSE_STORE_PAGE_FAULT
85+
bnez t0, die
86+
87+
li t1, 2
88+
bne TESTNUM, t1, 1f
89+
# Make sure D bit is clear
90+
lw t0, page_table_1
91+
and t1, t0, PTE_D
92+
bnez t1, die
93+
skip:
94+
csrr t0, mepc
95+
add t0, t0, 4
96+
csrw mepc, t0
97+
mret
98+
99+
1:
100+
li t1, 3
101+
bne TESTNUM, t1, 1f
102+
# The implementation doesn't appear to set D bits in HW.
103+
# Make sure the D bit really is clear.
104+
lw t0, page_table_1
105+
and t1, t0, PTE_D
106+
bnez t1, die
107+
# Set the D bit.
108+
or t0, t0, PTE_D
109+
sw t0, page_table_1, t1
110+
sfence.vma
111+
mret
112+
113+
1:
114+
li t1, 4
115+
bne TESTNUM, t1, 1f
116+
j pass
117+
118+
1:
119+
die:
120+
RVTEST_FAIL
121+
122+
RVTEST_CODE_END
123+
124+
.data
125+
RVTEST_DATA_BEGIN
126+
127+
TEST_DATA
128+
129+
.align 12
130+
page_table_1: .dword (DRAM_BASE/RISCV_PGSIZE << PTE_PPN_SHIFT) | PTE_V | PTE_U | PTE_R | PTE_W | PTE_X | PTE_A
131+
dummy: .dword 0
132+
133+
RVTEST_DATA_END

0 commit comments

Comments
 (0)