Add Tercel PHY reset synchronization
[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 : IcacheToDecode1Type;
17
18 signal m_out : MmuToIcacheType;
19
20 signal wb_bram_in : wishbone_master_out;
21 signal wb_bram_out : wishbone_slave_out;
22
23 constant clk_period : time := 10 ns;
24 begin
25 icache0: entity work.icache
26 generic map(
27 LINE_SIZE => 64,
28 NUM_LINES => 4
29 )
30 port map(
31 clk => clk,
32 rst => rst,
33 i_in => i_out,
34 i_out => i_in,
35 m_in => m_out,
36 stall_in => '0',
37 flush_in => '0',
38 inval_in => '0',
39 wishbone_out => wb_bram_in,
40 wishbone_in => wb_bram_out
41 );
42
43 -- BRAM Memory slave
44 bram0: entity work.wishbone_bram_wrapper
45 generic map(
46 MEMORY_SIZE => 1024,
47 RAM_INIT_FILE => "icache_test.bin"
48 )
49 port map(
50 clk => clk,
51 rst => rst,
52 wishbone_in => wb_bram_in,
53 wishbone_out => wb_bram_out
54 );
55
56 clk_process: process
57 begin
58 clk <= '0';
59 wait for clk_period/2;
60 clk <= '1';
61 wait for clk_period/2;
62 end process;
63
64 rst_process: process
65 begin
66 rst <= '1';
67 wait for 2*clk_period;
68 rst <= '0';
69 wait;
70 end process;
71
72 stim: process
73 begin
74 i_out.req <= '0';
75 i_out.nia <= (others => '0');
76 i_out.stop_mark <= '0';
77
78 m_out.tlbld <= '0';
79 m_out.tlbie <= '0';
80 m_out.addr <= (others => '0');
81 m_out.pte <= (others => '0');
82
83 wait until rising_edge(clk);
84 wait until rising_edge(clk);
85 wait until rising_edge(clk);
86 wait until rising_edge(clk);
87
88 i_out.req <= '1';
89 i_out.nia <= x"0000000000000004";
90
91 wait for 30*clk_period;
92 wait until rising_edge(clk);
93
94 assert i_in.valid = '1' severity failure;
95 assert i_in.insn = x"00000001"
96 report "insn @" & to_hstring(i_out.nia) &
97 "=" & to_hstring(i_in.insn) &
98 " expected 00000001"
99 severity failure;
100
101 i_out.req <= '0';
102
103 wait until rising_edge(clk);
104
105 -- hit
106 i_out.req <= '1';
107 i_out.nia <= x"0000000000000008";
108 wait until rising_edge(clk);
109 wait until rising_edge(clk);
110 assert i_in.valid = '1' severity failure;
111 assert i_in.insn = x"00000002"
112 report "insn @" & to_hstring(i_out.nia) &
113 "=" & to_hstring(i_in.insn) &
114 " expected 00000002"
115 severity failure;
116 wait until rising_edge(clk);
117
118 -- another miss
119 i_out.req <= '1';
120 i_out.nia <= x"0000000000000040";
121
122 wait for 30*clk_period;
123 wait until rising_edge(clk);
124
125 assert i_in.valid = '1' severity failure;
126 assert i_in.insn = x"00000010"
127 report "insn @" & to_hstring(i_out.nia) &
128 "=" & to_hstring(i_in.insn) &
129 " expected 00000010"
130 severity failure;
131
132 -- test something that aliases
133 i_out.req <= '1';
134 i_out.nia <= x"0000000000000100";
135 wait until rising_edge(clk);
136 wait until rising_edge(clk);
137 assert i_in.valid = '0' severity failure;
138 wait until rising_edge(clk);
139
140 wait for 30*clk_period;
141 wait until rising_edge(clk);
142
143 assert i_in.valid = '1' severity failure;
144 assert i_in.insn = x"00000040"
145 report "insn @" & to_hstring(i_out.nia) &
146 "=" & to_hstring(i_in.insn) &
147 " expected 00000040"
148 severity failure;
149
150 i_out.req <= '0';
151
152 std.env.finish;
153 end process;
154 end;