dcache: Implement load-reserve and store-conditional instructions
[microwatt.git] / icache_tb.vhdl
1 library ieee;
2 use ieee.std_logic_1164.all;
3
4 library work;
5 use work.common.all;
6 use work.wishbone_types.all;
7
8 entity icache_tb is
9 end icache_tb;
10
11 architecture behave of icache_tb is
12 signal clk : std_ulogic;
13 signal rst : std_ulogic;
14
15 signal i_out : Fetch1ToIcacheType;
16 signal i_in : IcacheToFetch2Type;
17
18 signal wb_bram_in : wishbone_master_out;
19 signal wb_bram_out : wishbone_slave_out;
20
21 constant clk_period : time := 10 ns;
22 begin
23 icache0: entity work.icache
24 generic map(
25 LINE_SIZE => 64,
26 NUM_LINES => 4
27 )
28 port map(
29 clk => clk,
30 rst => rst,
31 i_in => i_out,
32 i_out => i_in,
33 flush_in => '0',
34 wishbone_out => wb_bram_in,
35 wishbone_in => wb_bram_out
36 );
37
38 -- BRAM Memory slave
39 bram0: entity work.wishbone_bram_wrapper
40 generic map(
41 MEMORY_SIZE => 1024,
42 RAM_INIT_FILE => "icache_test.bin"
43 )
44 port map(
45 clk => clk,
46 rst => rst,
47 wishbone_in => wb_bram_in,
48 wishbone_out => wb_bram_out
49 );
50
51 clk_process: process
52 begin
53 clk <= '0';
54 wait for clk_period/2;
55 clk <= '1';
56 wait for clk_period/2;
57 end process;
58
59 rst_process: process
60 begin
61 rst <= '1';
62 wait for 2*clk_period;
63 rst <= '0';
64 wait;
65 end process;
66
67 stim: process
68 begin
69 i_out.req <= '0';
70 i_out.nia <= (others => '0');
71 i_out.stop_mark <= '0';
72
73 wait until rising_edge(clk);
74 wait until rising_edge(clk);
75 wait until rising_edge(clk);
76 wait until rising_edge(clk);
77
78 i_out.req <= '1';
79 i_out.nia <= x"0000000000000004";
80
81 wait for 30*clk_period;
82 wait until rising_edge(clk);
83
84 assert i_in.valid = '1' severity failure;
85 assert i_in.insn = x"00000001"
86 report "insn @" & to_hstring(i_out.nia) &
87 "=" & to_hstring(i_in.insn) &
88 " expected 00000001"
89 severity failure;
90
91 i_out.req <= '0';
92
93 wait until rising_edge(clk);
94
95 -- hit
96 i_out.req <= '1';
97 i_out.nia <= x"0000000000000008";
98 wait until rising_edge(clk);
99 wait until rising_edge(clk);
100 assert i_in.valid = '1' severity failure;
101 assert i_in.insn = x"00000002"
102 report "insn @" & to_hstring(i_out.nia) &
103 "=" & to_hstring(i_in.insn) &
104 " expected 00000002"
105 severity failure;
106 wait until rising_edge(clk);
107
108 -- another miss
109 i_out.req <= '1';
110 i_out.nia <= x"0000000000000040";
111
112 wait for 30*clk_period;
113 wait until rising_edge(clk);
114
115 assert i_in.valid = '1' severity failure;
116 assert i_in.insn = x"00000010"
117 report "insn @" & to_hstring(i_out.nia) &
118 "=" & to_hstring(i_in.insn) &
119 " expected 00000010"
120 severity failure;
121
122 -- test something that aliases
123 i_out.req <= '1';
124 i_out.nia <= x"0000000000000100";
125 wait until rising_edge(clk);
126 wait until rising_edge(clk);
127 assert i_in.valid = '0' severity failure;
128 wait until rising_edge(clk);
129
130 wait for 30*clk_period;
131 wait until rising_edge(clk);
132
133 assert i_in.valid = '1' severity failure;
134 assert i_in.insn = x"00000040"
135 report "insn @" & to_hstring(i_out.nia) &
136 "=" & to_hstring(i_in.insn) &
137 " expected 00000040"
138 severity failure;
139
140 i_out.req <= '0';
141
142 assert false report "end of test" severity failure;
143 wait;
144
145 end process;
146 end;