forked from antonblanchard/microwatt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dcache_tb.vhdl
243 lines (211 loc) · 7.27 KB
/
dcache_tb.vhdl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
library ieee;
use ieee.std_logic_1164.all;
library work;
use work.common.all;
use work.wishbone_types.all;
entity dcache_tb is
end dcache_tb;
architecture behave of dcache_tb is
signal clk : std_ulogic;
signal rst : std_ulogic;
signal d_in : Loadstore1ToDcacheType;
signal d_out : DcacheToLoadstore1Type;
signal m_in : MmuToDcacheType;
signal m_out : DcacheToMmuType;
signal wb_bram_in : wishbone_master_out;
signal wb_bram_out : wishbone_slave_out;
constant clk_period : time := 10 ns;
signal stall : std_ulogic;
begin
dcache0: entity work.dcache
generic map(
LINE_SIZE => 64,
NUM_LINES => 4
)
port map(
clk => clk,
rst => rst,
d_in => d_in,
d_out => d_out,
stall_out => stall,
m_in => m_in,
m_out => m_out,
wishbone_out => wb_bram_in,
wishbone_in => wb_bram_out
);
-- BRAM Memory slave
bram0: entity work.wishbone_bram_wrapper
generic map(
MEMORY_SIZE => 1024,
RAM_INIT_FILE => "icache_test.bin"
)
port map(
clk => clk,
rst => rst,
wishbone_in => wb_bram_in,
wishbone_out => wb_bram_out
);
clk_process: process
begin
clk <= '0';
wait for clk_period/2;
clk <= '1';
wait for clk_period/2;
end process;
rst_process: process
begin
rst <= '1';
wait for 2*clk_period;
rst <= '0';
wait;
end process;
stim: process
begin
-- Clear stuff
d_in.valid <= '0';
d_in.load <= '0';
d_in.nc <= '0';
d_in.hold <= '0';
d_in.dcbz <= '0';
d_in.reserve <= '0';
d_in.virt_mode <= '0';
d_in.priv_mode <= '1';
d_in.addr <= (others => '0');
d_in.data <= (others => '0');
d_in.byte_sel <= (others => '1');
m_in.valid <= '0';
m_in.addr <= (others => '0');
m_in.pte <= (others => '0');
m_in.tlbie <= '0';
m_in.doall <= '0';
m_in.tlbld <= '0';
wait for 4*clk_period;
wait until rising_edge(clk);
-- Cacheable read of address 4
report "cache read address 4...";
d_in.load <= '1';
d_in.nc <= '0';
d_in.addr <= x"0000000000000004";
d_in.valid <= '1';
wait until rising_edge(clk) and stall = '0';
d_in.valid <= '0';
wait until rising_edge(clk) and d_out.valid = '1';
assert d_out.data = x"0000000100000000"
report "data @" & to_hstring(d_in.addr) &
"=" & to_hstring(d_out.data) &
" expected 0000000100000000"
severity failure;
-- Cacheable read of address 30 (hit after hit forward from reload)
report "cache read address 30...";
d_in.load <= '1';
d_in.nc <= '0';
d_in.addr <= x"0000000000000030";
d_in.valid <= '1';
wait until rising_edge(clk) and stall = '0';
d_in.valid <= '0';
wait until rising_edge(clk) and d_out.valid = '1';
assert d_out.data = x"0000000D0000000C"
report "data @" & to_hstring(d_in.addr) &
"=" & to_hstring(d_out.data) &
" expected 0000000D0000000C"
severity failure;
-- Ensure reload completes
wait for 100*clk_period;
wait until rising_edge(clk);
-- Cacheable read of address 38 (hit on idle cache)
report "cache read address 38...";
d_in.load <= '1';
d_in.nc <= '0';
d_in.addr <= x"0000000000000038";
d_in.valid <= '1';
wait until rising_edge(clk) and stall = '0';
d_in.valid <= '0';
wait until rising_edge(clk) and d_out.valid = '1';
assert d_out.data = x"0000000F0000000E"
report "data @" & to_hstring(d_in.addr) &
"=" & to_hstring(d_out.data) &
" expected 0000000F0000000E"
severity failure;
-- Cacheable read of address 130 (miss after hit, same index)
-- This will use way 2
report "cache read address 130...";
d_in.load <= '1';
d_in.nc <= '0';
d_in.addr <= x"0000000000000130";
d_in.valid <= '1';
wait until rising_edge(clk) and stall = '0';
d_in.valid <= '0';
wait until rising_edge(clk) and d_out.valid = '1';
assert d_out.data = x"0000004d0000004c"
report "data @" & to_hstring(d_in.addr) &
"=" & to_hstring(d_out.data) &
" expected 0000004d0000004c"
severity failure;
-- Ensure reload completes
wait for 100*clk_period;
wait until rising_edge(clk);
-- Cacheable read again of address 130 (hit in idle cache)
-- This should feed from way 2
report "cache read address 130...";
d_in.load <= '1';
d_in.nc <= '0';
d_in.addr <= x"0000000000000130";
d_in.valid <= '1';
wait until rising_edge(clk) and stall = '0';
d_in.valid <= '0';
wait until rising_edge(clk) and d_out.valid = '1';
assert d_out.data = x"0000004d0000004c"
report "data @" & to_hstring(d_in.addr) &
"=" & to_hstring(d_out.data) &
" expected 0000004d0000004c"
severity failure;
-- Cacheable read of address 40
report "cache read address 40...";
d_in.load <= '1';
d_in.nc <= '0';
d_in.addr <= x"0000000000000040";
d_in.valid <= '1';
wait until rising_edge(clk);
d_in.valid <= '0';
wait until rising_edge(clk) and d_out.valid = '1';
assert d_out.data = x"0000001100000010"
report "data @" & to_hstring(d_in.addr) &
"=" & to_hstring(d_out.data) &
" expected 0000001100000010"
severity failure;
-- Cacheable read of address 140 (miss after miss, same index)
-- This should use way 2
report "cache read address 140...";
d_in.load <= '1';
d_in.nc <= '0';
d_in.addr <= x"0000000000000140";
d_in.valid <= '1';
wait until rising_edge(clk) and stall = '0';
d_in.valid <= '0';
wait until rising_edge(clk) and d_out.valid = '1';
assert d_out.data = x"0000005100000050"
report "data @" & to_hstring(d_in.addr) &
"=" & to_hstring(d_out.data) &
" expected 0000005100000050"
severity failure;
-- Non-cacheable read of address 200
report "non-cache read address 200...";
d_in.load <= '1';
d_in.nc <= '1';
d_in.addr <= x"0000000000000200";
d_in.valid <= '1';
wait until rising_edge(clk) and stall = '0';
d_in.valid <= '0';
wait until rising_edge(clk) and d_out.valid = '1';
assert d_out.data = x"0000008100000080"
report "data @" & to_hstring(d_in.addr) &
"=" & to_hstring(d_out.data) &
" expected 0000008100000080"
severity failure;
wait until rising_edge(clk);
wait until rising_edge(clk);
wait until rising_edge(clk);
wait until rising_edge(clk);
std.env.finish;
end process;
end;