1 |
8 |
jlechner |
-------------------------------------------------------------------------------
|
2 |
|
|
-- File: ex_stage.vhd
|
3 |
|
|
-- Author: Jakob Lechner, Urban Stadler, Harald Trinkl, Christian Walter
|
4 |
|
|
-- Created: 2006-11-29
|
5 |
|
|
-- Last updated: 2006-11-29
|
6 |
|
|
|
7 |
|
|
-- Description:
|
8 |
|
|
-- Execute stage
|
9 |
|
|
-------------------------------------------------------------------------------
|
10 |
|
|
|
11 |
|
|
library ieee;
|
12 |
|
|
use ieee.std_logic_1164.all;
|
13 |
|
|
use ieee.std_logic_signed.all;
|
14 |
|
|
use ieee.numeric_std.all;
|
15 |
|
|
use IEEE.STD_LOGIC_ARITH.all;
|
16 |
|
|
use work.rise_pack.all;
|
17 |
71 |
jlechner |
use work.RISE_PACK_SPECIFIC.all;
|
18 |
8 |
jlechner |
|
19 |
|
|
entity tb_ex_stage_unit_vhd is
|
20 |
|
|
end tb_ex_stage_unit_vhd;
|
21 |
|
|
|
22 |
|
|
architecture behavior of tb_ex_stage_unit_vhd is
|
23 |
|
|
|
24 |
|
|
-- component Declaration for the Unit Under Test (UUT)
|
25 |
|
|
component ex_stage is
|
26 |
|
|
|
27 |
|
|
port (
|
28 |
|
|
clk : in std_logic;
|
29 |
|
|
reset : in std_logic;
|
30 |
|
|
|
31 |
|
|
id_ex_register : in ID_EX_REGISTER_T;
|
32 |
|
|
ex_mem_register : out EX_MEM_REGISTER_T;
|
33 |
|
|
|
34 |
|
|
branch : out std_logic;
|
35 |
|
|
stall_in : in std_logic;
|
36 |
|
|
clear_in : in std_logic;
|
37 |
|
|
clear_out : out std_logic);
|
38 |
|
|
|
39 |
|
|
end component;
|
40 |
|
|
|
41 |
|
|
constant clk_period : time := 10 ns;
|
42 |
|
|
|
43 |
|
|
--inputs
|
44 |
|
|
signal clk : std_logic := '0';
|
45 |
|
|
signal reset : std_logic := '0';
|
46 |
|
|
signal id_ex_register : ID_EX_REGISTER_T;
|
47 |
|
|
|
48 |
|
|
signal stall_in : std_logic := '0';
|
49 |
|
|
signal clear_in : std_logic := '0';
|
50 |
|
|
|
51 |
|
|
--Outputs
|
52 |
|
|
signal ex_mem_register : EX_MEM_REGISTER_T;
|
53 |
|
|
signal branch : std_logic;
|
54 |
|
|
signal clear_out : std_logic;
|
55 |
|
|
|
56 |
|
|
begin
|
57 |
|
|
|
58 |
|
|
-- instantiate the Unit Under Test (UUT)
|
59 |
|
|
uut : ex_stage port map(
|
60 |
|
|
clk => clk,
|
61 |
|
|
reset => reset,
|
62 |
|
|
|
63 |
|
|
id_ex_register => id_ex_register,
|
64 |
|
|
ex_mem_register => ex_mem_register,
|
65 |
|
|
|
66 |
|
|
branch => branch,
|
67 |
|
|
stall_in => stall_in,
|
68 |
|
|
clear_in => clear_in,
|
69 |
|
|
clear_out => clear_out);
|
70 |
|
|
|
71 |
|
|
|
72 |
|
|
cg : process
|
73 |
|
|
begin
|
74 |
|
|
clk <= '1';
|
75 |
|
|
wait for clk_period/2;
|
76 |
|
|
clk <= '0';
|
77 |
|
|
wait for clk_period/2;
|
78 |
|
|
end process;
|
79 |
|
|
|
80 |
|
|
tb : process
|
81 |
|
|
begin
|
82 |
|
|
reset <= '0';
|
83 |
|
|
wait for 10 * clk_period;
|
84 |
|
|
reset <= '1';
|
85 |
|
|
|
86 |
|
|
|
87 |
|
|
id_ex_register.sr <= (others => '0');
|
88 |
|
|
id_ex_register.pc <= CONV_STD_LOGIC_VECTOR(3, PC_WIDTH);
|
89 |
|
|
id_ex_register.opcode <= OPCODE_NOP;
|
90 |
|
|
id_ex_register.cond <= COND_UNCONDITIONAL;
|
91 |
|
|
id_ex_register.rX_addr <= CONV_STD_LOGIC_VECTOR(2, REGISTER_ADDR_WIDTH);
|
92 |
|
|
id_ex_register.rX <= CONV_STD_LOGIC_VECTOR(0, REGISTER_WIDTH);
|
93 |
|
|
id_ex_register.rY <= CONV_STD_LOGIC_VECTOR(0, REGISTER_WIDTH);
|
94 |
|
|
id_ex_register.rZ <= CONV_STD_LOGIC_VECTOR(0, REGISTER_WIDTH);
|
95 |
|
|
id_ex_register.immediate <= CONV_STD_LOGIC_VECTOR(0, IMMEDIATE_WIDTH);
|
96 |
|
|
|
97 |
|
|
|
98 |
|
|
---------------------------------------------------------------------------
|
99 |
|
|
-- test computation results
|
100 |
|
|
---------------------------------------------------------------------------
|
101 |
|
|
-- load/store
|
102 |
|
|
wait for clk_period;
|
103 |
|
|
id_ex_register.opcode <= OPCODE_LD_IMM;
|
104 |
|
|
id_ex_register.immediate <= CONV_STD_LOGIC_VECTOR(1, REGISTER_WIDTH);
|
105 |
|
|
wait for clk_period;
|
106 |
|
|
id_ex_register.opcode <= OPCODE_LD_IMM_HB;
|
107 |
|
|
id_ex_register.rX <= CONV_STD_LOGIC_VECTOR(1, REGISTER_WIDTH);
|
108 |
|
|
id_ex_register.immediate <= CONV_STD_LOGIC_VECTOR(2, REGISTER_WIDTH);
|
109 |
|
|
wait for clk_period;
|
110 |
|
|
id_ex_register.opcode <= OPCODE_LD_DISP;
|
111 |
|
|
id_ex_register.rY <= CONV_STD_LOGIC_VECTOR(4, REGISTER_WIDTH);
|
112 |
|
|
id_ex_register.rZ <= CONV_STD_LOGIC_VECTOR(1, REGISTER_WIDTH);
|
113 |
|
|
wait for clk_period;
|
114 |
|
|
id_ex_register.opcode <= OPCODE_LD_DISP_MS;
|
115 |
|
|
id_ex_register.rY <= CONV_STD_LOGIC_VECTOR(4, REGISTER_WIDTH);
|
116 |
|
|
id_ex_register.rZ <= CONV_STD_LOGIC_VECTOR(1, REGISTER_WIDTH);
|
117 |
|
|
wait for clk_period;
|
118 |
|
|
id_ex_register.opcode <= OPCODE_LD_REG;
|
119 |
|
|
id_ex_register.rY <= CONV_STD_LOGIC_VECTOR(6, REGISTER_WIDTH);
|
120 |
|
|
wait for clk_period;
|
121 |
|
|
id_ex_register.opcode <= OPCODE_ST_DISP;
|
122 |
|
|
id_ex_register.rY <= CONV_STD_LOGIC_VECTOR(4, REGISTER_WIDTH);
|
123 |
|
|
id_ex_register.rZ <= CONV_STD_LOGIC_VECTOR(1, REGISTER_WIDTH);
|
124 |
|
|
wait for clk_period;
|
125 |
|
|
-- arithmetic opcodes
|
126 |
|
|
id_ex_register.opcode <= OPCODE_ADD;
|
127 |
|
|
id_ex_register.rX <= CONV_STD_LOGIC_VECTOR(8, REGISTER_WIDTH);
|
128 |
|
|
id_ex_register.rY <= CONV_STD_LOGIC_VECTOR(3, REGISTER_WIDTH);
|
129 |
|
|
wait for clk_period;
|
130 |
|
|
id_ex_register.opcode <= OPCODE_ADD;
|
131 |
|
|
id_ex_register.rX <= CONV_STD_LOGIC_VECTOR(-8, REGISTER_WIDTH);
|
132 |
|
|
id_ex_register.rY <= CONV_STD_LOGIC_VECTOR(2, REGISTER_WIDTH);
|
133 |
|
|
wait for clk_period;
|
134 |
|
|
id_ex_register.opcode <= OPCODE_ADD_IMM;
|
135 |
|
|
id_ex_register.rX <= CONV_STD_LOGIC_VECTOR(3, REGISTER_WIDTH);
|
136 |
|
|
id_ex_register.immediate <= CONV_STD_LOGIC_VECTOR(2, REGISTER_WIDTH);
|
137 |
|
|
wait for clk_period;
|
138 |
|
|
id_ex_register.opcode <= OPCODE_ADD_IMM;
|
139 |
|
|
id_ex_register.rX <= CONV_STD_LOGIC_VECTOR(3, REGISTER_WIDTH);
|
140 |
|
|
id_ex_register.immediate <= CONV_STD_LOGIC_VECTOR(-2, REGISTER_WIDTH);
|
141 |
|
|
wait for clk_period;
|
142 |
|
|
id_ex_register.opcode <= OPCODE_SUB;
|
143 |
|
|
id_ex_register.rX <= CONV_STD_LOGIC_VECTOR(4, REGISTER_WIDTH);
|
144 |
|
|
id_ex_register.rY <= CONV_STD_LOGIC_VECTOR(2, REGISTER_WIDTH);
|
145 |
|
|
wait for clk_period;
|
146 |
|
|
id_ex_register.opcode <= OPCODE_SUB;
|
147 |
|
|
id_ex_register.rX <= CONV_STD_LOGIC_VECTOR(4, REGISTER_WIDTH);
|
148 |
|
|
id_ex_register.rY <= CONV_STD_LOGIC_VECTOR(6, REGISTER_WIDTH);
|
149 |
|
|
wait for clk_period;
|
150 |
|
|
id_ex_register.opcode <= OPCODE_SUB_IMM;
|
151 |
|
|
id_ex_register.rX <= CONV_STD_LOGIC_VECTOR(-4, REGISTER_WIDTH);
|
152 |
|
|
id_ex_register.immediate <= CONV_STD_LOGIC_VECTOR(6, REGISTER_WIDTH);
|
153 |
|
|
wait for clk_period;
|
154 |
|
|
id_ex_register.opcode <= OPCODE_SUB_IMM;
|
155 |
|
|
id_ex_register.rX <= CONV_STD_LOGIC_VECTOR(4, REGISTER_WIDTH);
|
156 |
|
|
id_ex_register.immediate <= CONV_STD_LOGIC_VECTOR(2, REGISTER_WIDTH);
|
157 |
|
|
wait for clk_period;
|
158 |
|
|
id_ex_register.opcode <= OPCODE_NEG;
|
159 |
|
|
id_ex_register.rY <= CONV_STD_LOGIC_VECTOR(4, REGISTER_WIDTH);
|
160 |
|
|
wait for clk_period;
|
161 |
|
|
id_ex_register.opcode <= OPCODE_ARS;
|
162 |
|
|
id_ex_register.rY <= CONV_STD_LOGIC_VECTOR(4, REGISTER_WIDTH);
|
163 |
|
|
wait for clk_period;
|
164 |
|
|
id_ex_register.opcode <= OPCODE_ALS;
|
165 |
|
|
id_ex_register.rY <= CONV_STD_LOGIC_VECTOR(4, REGISTER_WIDTH);
|
166 |
|
|
-- als with overflow
|
167 |
|
|
wait for clk_period;
|
168 |
|
|
id_ex_register.opcode <= OPCODE_ALS;
|
169 |
|
|
id_ex_register.rY <= CONV_STD_LOGIC_VECTOR(30000, REGISTER_WIDTH);
|
170 |
|
|
-- als with overflow
|
171 |
|
|
wait for clk_period;
|
172 |
|
|
id_ex_register.opcode <= OPCODE_ALS;
|
173 |
|
|
id_ex_register.rY <= CONV_STD_LOGIC_VECTOR(-30000, REGISTER_WIDTH);
|
174 |
|
|
|
175 |
|
|
-- logical opcodes
|
176 |
|
|
wait for clk_period;
|
177 |
|
|
id_ex_register.opcode <= OPCODE_AND;
|
178 |
|
|
id_ex_register.rX <= CONV_STD_LOGIC_VECTOR(4, REGISTER_WIDTH);
|
179 |
|
|
id_ex_register.rY <= CONV_STD_LOGIC_VECTOR(2, REGISTER_WIDTH);
|
180 |
|
|
wait for clk_period;
|
181 |
|
|
id_ex_register.opcode <= OPCODE_NOT;
|
182 |
|
|
id_ex_register.rY <= CONV_STD_LOGIC_VECTOR(2, REGISTER_WIDTH);
|
183 |
|
|
wait for clk_period;
|
184 |
|
|
id_ex_register.opcode <= OPCODE_EOR;
|
185 |
|
|
id_ex_register.rX <= CONV_STD_LOGIC_VECTOR(4, REGISTER_WIDTH);
|
186 |
|
|
id_ex_register.rY <= CONV_STD_LOGIC_VECTOR(2, REGISTER_WIDTH);
|
187 |
|
|
wait for clk_period;
|
188 |
|
|
id_ex_register.opcode <= OPCODE_LS;
|
189 |
80 |
cwalter |
id_ex_register.rX <= CONV_STD_LOGIC_VECTOR(3, REGISTER_WIDTH);
|
190 |
8 |
jlechner |
id_ex_register.rY <= CONV_STD_LOGIC_VECTOR(2, REGISTER_WIDTH);
|
191 |
|
|
wait for clk_period;
|
192 |
|
|
id_ex_register.opcode <= OPCODE_RS;
|
193 |
80 |
cwalter |
id_ex_register.rX <= CONV_STD_LOGIC_VECTOR(73, REGISTER_WIDTH);
|
194 |
|
|
id_ex_register.rY <= CONV_STD_LOGIC_VECTOR(1, REGISTER_WIDTH);
|
195 |
8 |
jlechner |
|
196 |
|
|
-- other
|
197 |
|
|
wait for clk_period;
|
198 |
|
|
id_ex_register.opcode <= OPCODE_JMP;
|
199 |
|
|
id_ex_register.rX <= CONV_STD_LOGIC_VECTOR(8, REGISTER_WIDTH);
|
200 |
|
|
|
201 |
|
|
---------------------------------------------------------------------------
|
202 |
|
|
-- test stall/clear
|
203 |
|
|
---------------------------------------------------------------------------
|
204 |
|
|
wait for clk_period;
|
205 |
|
|
stall_in <= '1';
|
206 |
|
|
id_ex_register.opcode <= OPCODE_JMP;
|
207 |
|
|
id_ex_register.rX <= CONV_STD_LOGIC_VECTOR(8, REGISTER_WIDTH);
|
208 |
|
|
wait for clk_period;
|
209 |
|
|
stall_in <= '0';
|
210 |
|
|
id_ex_register.rX_addr <= CONV_STD_LOGIC_VECTOR(6, REGISTER_ADDR_WIDTH);
|
211 |
|
|
id_ex_register.opcode <= OPCODE_LD_REG;
|
212 |
|
|
id_ex_register.rY <= CONV_STD_LOGIC_VECTOR(6, REGISTER_WIDTH);
|
213 |
|
|
wait for clk_period;
|
214 |
|
|
clear_in <= '1';
|
215 |
|
|
wait for clk_period;
|
216 |
|
|
clear_in <= '0';
|
217 |
|
|
|
218 |
|
|
---------------------------------------------------------------------------
|
219 |
|
|
-- branch (i.e. load instruction with PC as destination)
|
220 |
|
|
---------------------------------------------------------------------------
|
221 |
|
|
wait for clk_period;
|
222 |
|
|
id_ex_register.rX_addr <= PC_ADDR;
|
223 |
|
|
id_ex_register.opcode <= OPCODE_LD_REG;
|
224 |
|
|
id_ex_register.rY <= CONV_STD_LOGIC_VECTOR(6, REGISTER_WIDTH);
|
225 |
|
|
|
226 |
|
|
wait for clk_period;
|
227 |
|
|
id_ex_register.rX_addr <= CONV_STD_LOGIC_VECTOR(6, REGISTER_ADDR_WIDTH);
|
228 |
|
|
id_ex_register.opcode <= OPCODE_LD_REG;
|
229 |
|
|
id_ex_register.rY <= CONV_STD_LOGIC_VECTOR(6, REGISTER_WIDTH);
|
230 |
|
|
|
231 |
|
|
---------------------------------------------------------------------------
|
232 |
|
|
-- test conditionals
|
233 |
|
|
---------------------------------------------------------------------------
|
234 |
|
|
wait for clk_period;
|
235 |
|
|
id_ex_register.cond <= COND_ZERO;
|
236 |
|
|
id_ex_register.sr <= (SR_ZERO_BIT => '0', others => '0');
|
237 |
|
|
id_ex_register.opcode <= OPCODE_ADD;
|
238 |
|
|
id_ex_register.rX <= CONV_STD_LOGIC_VECTOR(8, REGISTER_WIDTH);
|
239 |
|
|
id_ex_register.rY <= CONV_STD_LOGIC_VECTOR(3, REGISTER_WIDTH);
|
240 |
|
|
wait for clk_period;
|
241 |
|
|
id_ex_register.cond <= COND_UNCONDITIONAL;
|
242 |
|
|
id_ex_register.opcode <= OPCODE_ADD;
|
243 |
|
|
id_ex_register.rX <= CONV_STD_LOGIC_VECTOR(2, REGISTER_WIDTH);
|
244 |
|
|
id_ex_register.rY <= CONV_STD_LOGIC_VECTOR(2, REGISTER_WIDTH);
|
245 |
|
|
|
246 |
|
|
wait; -- will wait forever
|
247 |
|
|
end process;
|
248 |
|
|
|
249 |
|
|
end;
|