2 use ieee.std_logic_1164.all;
6 use work.wishbone_types.all;
11 architecture behave of dcache_tb is
12 signal clk : std_ulogic;
13 signal rst : std_ulogic;
15 signal d_in : Loadstore1ToDcacheType;
16 signal d_out : DcacheToLoadstore1Type;
18 signal m_in : MmuToDcacheType;
19 signal m_out : DcacheToMmuType;
21 signal wb_bram_in : wishbone_master_out;
22 signal wb_bram_out : wishbone_slave_out;
24 constant clk_period : time := 10 ns;
26 signal stall : std_ulogic;
28 dcache0: entity work.dcache
41 wishbone_out => wb_bram_in,
42 wishbone_in => wb_bram_out
46 bram0: entity work.wishbone_bram_wrapper
49 RAM_INIT_FILE => "icache_test.bin"
54 wishbone_in => wb_bram_in,
55 wishbone_out => wb_bram_out
61 wait for clk_period/2;
63 wait for clk_period/2;
69 wait for 2*clk_period;
83 d_in.virt_mode <= '0';
84 d_in.priv_mode <= '1';
85 d_in.addr <= (others => '0');
86 d_in.data <= (others => '0');
87 d_in.byte_sel <= (others => '1');
89 m_in.addr <= (others => '0');
90 m_in.pte <= (others => '0');
95 wait for 4*clk_period;
96 wait until rising_edge(clk);
98 -- Cacheable read of address 4
99 report "cache read address 4...";
102 d_in.addr <= x"0000000000000004";
104 wait until rising_edge(clk) and stall = '0';
107 wait until rising_edge(clk) and d_out.valid = '1';
108 assert d_out.data = x"0000000100000000"
109 report "data @" & to_hstring(d_in.addr) &
110 "=" & to_hstring(d_out.data) &
111 " expected 0000000100000000"
114 -- Cacheable read of address 30 (hit after hit forward from reload)
115 report "cache read address 30...";
118 d_in.addr <= x"0000000000000030";
120 wait until rising_edge(clk) and stall = '0';
123 wait until rising_edge(clk) and d_out.valid = '1';
124 assert d_out.data = x"0000000D0000000C"
125 report "data @" & to_hstring(d_in.addr) &
126 "=" & to_hstring(d_out.data) &
127 " expected 0000000D0000000C"
130 -- Ensure reload completes
131 wait for 100*clk_period;
132 wait until rising_edge(clk);
134 -- Cacheable read of address 38 (hit on idle cache)
135 report "cache read address 38...";
138 d_in.addr <= x"0000000000000038";
140 wait until rising_edge(clk) and stall = '0';
143 wait until rising_edge(clk) and d_out.valid = '1';
144 assert d_out.data = x"0000000F0000000E"
145 report "data @" & to_hstring(d_in.addr) &
146 "=" & to_hstring(d_out.data) &
147 " expected 0000000F0000000E"
150 -- Cacheable read of address 130 (miss after hit, same index)
151 -- This will use way 2
152 report "cache read address 130...";
155 d_in.addr <= x"0000000000000130";
157 wait until rising_edge(clk) and stall = '0';
160 wait until rising_edge(clk) and d_out.valid = '1';
161 assert d_out.data = x"0000004d0000004c"
162 report "data @" & to_hstring(d_in.addr) &
163 "=" & to_hstring(d_out.data) &
164 " expected 0000004d0000004c"
167 -- Ensure reload completes
168 wait for 100*clk_period;
169 wait until rising_edge(clk);
171 -- Cacheable read again of address 130 (hit in idle cache)
172 -- This should feed from way 2
173 report "cache read address 130...";
176 d_in.addr <= x"0000000000000130";
178 wait until rising_edge(clk) and stall = '0';
181 wait until rising_edge(clk) and d_out.valid = '1';
182 assert d_out.data = x"0000004d0000004c"
183 report "data @" & to_hstring(d_in.addr) &
184 "=" & to_hstring(d_out.data) &
185 " expected 0000004d0000004c"
188 -- Cacheable read of address 40
189 report "cache read address 40...";
192 d_in.addr <= x"0000000000000040";
194 wait until rising_edge(clk);
197 wait until rising_edge(clk) and d_out.valid = '1';
198 assert d_out.data = x"0000001100000010"
199 report "data @" & to_hstring(d_in.addr) &
200 "=" & to_hstring(d_out.data) &
201 " expected 0000001100000010"
204 -- Cacheable read of address 140 (miss after miss, same index)
205 -- This should use way 2
206 report "cache read address 140...";
209 d_in.addr <= x"0000000000000140";
211 wait until rising_edge(clk) and stall = '0';
214 wait until rising_edge(clk) and d_out.valid = '1';
215 assert d_out.data = x"0000005100000050"
216 report "data @" & to_hstring(d_in.addr) &
217 "=" & to_hstring(d_out.data) &
218 " expected 0000005100000050"
221 -- Non-cacheable read of address 200
222 report "non-cache read address 200...";
225 d_in.addr <= x"0000000000000200";
227 wait until rising_edge(clk) and stall = '0';
229 wait until rising_edge(clk) and d_out.valid = '1';
230 assert d_out.data = x"0000008100000080"
231 report "data @" & to_hstring(d_in.addr) &
232 "=" & to_hstring(d_out.data) &
233 " expected 0000008100000080"
236 wait until rising_edge(clk);
237 wait until rising_edge(clk);
238 wait until rising_edge(clk);
239 wait until rising_edge(clk);