-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcontroller.vhd
431 lines (340 loc) · 14.1 KB
/
controller.vhd
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
----------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Create Date: 03/13/2018 01:41:07 PM
-- Design Name:
-- Module Name: controller - Behavioral
-- Project Name:
-- Target Devices:
-- Tool Versions:
-- Description:
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx leaf cells in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity controller is
-- Port ( );
end controller;
architecture Behavioral of controller is
--type STATE_TYPE IS(fetch, rdAB, arith, addr, brn, wrRF, wrM, rdM, M2RF);
signal state: std_logic_vector(3 downto 0);
begin
end Behavioral;
-----------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx leaf cells in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
--type STATE_TYPE IS(fetch 0 , rdAB 1, arith 2, addr 3, brn 4, wrRF 5, wrM 6, rdM 7, M2RF 8, rdRFagain 9);
entity ins_decoder is
Port (
ins: in std_logic_vector(31 downto 0);
ins_states: out std_logic_vector(3 downto 0));
end ins_decoder;
architecture Behavioral of ins_decoder is
begin
ins_states<= "0000" when (ins(27 downto 25)="001") else
"0001" when (ins(27 downto 25)="000" and ins(4)='0') else
"0010" when (ins(27 downto 25)="000" and ins(4)='1' and ins(7)='0' and ins(11 downto 8)/="1111") else
"0011" when (ins(27 downto 23)="00000" and ins(7 downto 4)="1001") else
"0100" when (ins(27 downto 25)="000" and ins(22)='1' and ins(7)='1' and ins(4)='1' and ins(6 downto 5)/="00") else
"0101" when (ins(27 downto 25)="000" and ins(22)='0' and ins(7)='1' and ins(4)='1' and ins(6 downto 5)/="00") else
"0110" when (ins(27 downto 25)="010") else
"0111" when (ins(27 downto 25)="011" and ins(4)='0') else
"1000" when (ins(27 downto 25)="011" and ins(4)='1') else
"1001" when (ins(27 downto 25)="101") else
"1111";
end Behavioral;
--0 -> DP imm
--1 -> DP ShAmt imm
--2 -> DP ShAmt reg
--3 -> MUL,MLA
--4 -> Halfword DT reg offset
--5 -> Halfword DT imm offset
--6 -> DT imm offset
--7 -> DT reg offset
--8 -> undefined
--9 -> B,BL
--15 -> not implemented
-----------------------------------------------------------------------------
-------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx leaf cells in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity BCtrl is
Port ( flags: in std_logic_vector(3 downto 0);
ins: in std_logic_vector(3 downto 0);
p: out std_logic );
end BCtrl;
architecture Behavioral of BCtrl is
begin
-- flags 3-CVNZ-0
with ins select p <=
flags(0) when "0000",
(not flags(0)) when "0001",
(flags(3)) when "0010",
(not flags(3)) when "0011",
(flags(1)) when "0100",
(not flags(1)) when "0101",
(flags(2)) when "0110",
(not flags(2)) when "0111",
(flags(2) and (not flags(0))) when "1000",
(not (flags(2) and (not flags(0)))) when "1001",
(not (flags(2) xor flags(1))) when "1010",
((flags(2) xor flags(1))) when "1011",
((not flags(0)) and (not (flags(2) xor flags(1)))) when "1100",
(not ((not flags(0)) and (not (flags(2) xor flags(1))))) when "1101",
'1' when "1110",
'0' when others;
end Behavioral;
------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx leaf cells in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
--type STATE_TYPE IS(fetch 0 , rdAB 1, arith 2, addr 3, brn 4, wrRF 5, wrM 6, rdM 7, M2RF 8, rdRFagain 9);
entity next_state is
Port ( clock: in std_logic;
state: in std_logic_vector(3 downto 0);
ins2726: in std_logic_vector(1 downto 0);
ins20: in std_logic;
ins: in std_logic_vector(31 downto 0);
outstate: out std_logic_vector(3 downto 0));
end next_state;
architecture Behavioral of next_state is
begin
process(clock) is
begin
if clock='1' and clock'event then
if state="1111" then outstate<="0000";
elsif state="0000" then outstate<="0001";
elsif state="0001" then
if ins2726 = "00" then
if (ins(25 downto 23)="000" and ins(7 downto 4)="1001") then outstate<="1001";
elsif (ins(25)='0' and ins(11 downto 8)/="1111" and ins(7)='0' and ins(4)='1') then outstate<="1001";
else outstate<="0010";
end if;
elsif ins2726="01" then outstate<="0011";
elsif ins2726="10" then outstate<="0100";
end if;
elsif state="0010" then outstate<="0101";
elsif state="0011" then
if ins20='0' then outstate<="0110";
else outstate<="0111";
end if;
elsif state="0100" then outstate<="0000";
elsif state="0101" then outstate<="0000";
elsif state="0110" then outstate<="0000";
elsif state="0111" then outstate<="1000";
elsif state="1000" then outstate<="0000";
elsif state="1001" then outstate<="0010";
end if;
end if;
end process;
end Behavioral;
-----------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx leaf cells in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
--type STATE_TYPE IS(fetch 0 , rdAB 1, arith 2, addr 3, brn 4, wrRF 5, wrM 6, rdM 7, M2RF 8, rdRFagain 9);
entity control_state is
Port ( clock: in std_logic;
state: in std_logic_vector(3 downto 0);
outstate: out std_logic_vector(3 downto 0));
end control_state;
architecture Behavioral of control_state is
begin
process(clock) is
begin
if clock='1' and clock'event then
outstate<=state;
end if;
end process;
end Behavioral;
-----------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx leaf cells in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
--type STATE_TYPE IS(fetch 0 , rdAB 1, arith 2, addr 3, brn 4, wrRF 5, wrM 6, rdM 7, M2RF 8, rdRFagain 9);
entity ACtrl is
Port ( state: in std_logic_vector(3 downto 0);
ins: in std_logic_vector(31 downto 0);
op: out std_logic_vector(3 downto 0));
end ACtrl;
architecture Behavioral of ACtrl is
signal ins_states: std_logic_vector(3 downto 0);
begin
ins_decoder: entity work.ins_decoder port map(ins, ins_states);
op <= "1101" when (ins_states="0011" and state="0010" and ins(21)='0') else
"0100" when (ins_states="0011" and state="0010" and ins(21)='1') else
"0100" when (state="0100") else
"0100" when (state="0011" and ins(23)='1' and (ins_states="0110" or ins_states="0111" or ins_states="0100" or ins_states="0101")) else
"0010" when (state="0011" and ins(23)='0' and (ins_states="0110" or ins_states="0111" or ins_states="0100" or ins_states="0101")) else
"0100" when (state="0000") else
ins(24 downto 21);
end Behavioral;
-----------------------------------------------------------------------------
--0 -> DP imm
--1 -> DP ShAmt imm
--2 -> DP ShAmt reg
--3 -> MUL,MLA
--4 -> Halfword DT reg offset
--5 -> Halfword DT imm offset
--6 -> DT imm offset
--7 -> DT reg offset
--8 -> undefined
--9 -> B,BL
--15 -> not implemented
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx leaf cells in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
--type STATE_TYPE IS(fetch 0 , rdAB 1, arith 2, addr 3, brn 4, wrRF 5, wrM 6, rdM 7, M2RF 8, rdRFagain 9);
entity main_control is
Port (
p: in std_logic;
state: in std_logic_vector(3 downto 0);
ins: in std_logic_vector(31 downto 0);
PCbW, IW, DW, AW, BW, CW, Bnew, MULnew, Fset, ResW, PW, RW, MW, MR, Rsrc2, TD, PinA: out std_logic;
M2R, IorD, Rsrc, Asrc1, Wsrc, Cnew, Carrynew : out std_logic_vector(1 downto 0);
BCnew : out std_logic_vector(2 downto 0);
Shiftcontrol: out std_logic_vector(1 downto 0)
);
end main_control;
architecture Behavioral of main_control is
signal ins_states: std_logic_vector(3 downto 0);
begin
ins_decoder: entity work.ins_decoder port map(ins, ins_states);
PinA <= '1' when (state="0001" and ins_states="1001") else
'0';
TD <= '1' when (state="1000" and ins_states="0110") else
'0';
MR <= '1' when (state="0000" or state="0111") else
'0';
ResW <= ('1' and p) when (state="0010" or state="0011") else
'1' when (state="0000") else
'0';
PW <= ('1') when ((state="0001" and ins_states/="1001") or state="0100") else
'0';
Bnew <= '1' when (ins_states="0000") else
'0';
Fset <= ('1' and p) when (ins(20)='1' and (state="0010" or state="0011")) else
'0';
with state select DW <=
('1' and p) when "0111",
'0' when others;
IorD <= "01" when (state="0110" or state="0111") else
"10" when (ins(24)='0' and ins(27 downto 25)="010" and state="0110" and ins(20)='0') else
"10" when (ins(24)='0' and ins(27 downto 25)="011" and ins(4)='0' and state="0110" and ins(20)='0') else
"00" when (state="0000");
with state select MW <=
('1' and p) when "0110",
'0' when others;
with state select IW <=
'1' when ("0000"),
'0' when others;
RW <= ('1' and p) when (state="0101" or state="1000" or (state="0001" and ins_states="1001") or (state="0110" and (ins_states="0110" or ins_states="0111") and ins(21)='1')) else
'0';
with state select AW <=
('1' and p) when ("0001"),
'0' when others;
with state select BW <=
('1' and p) when ("0001"),
'0' when others;
CW <= ('1' and p) when (state="1001" or (ins_states="0110" and state="0001")) else
'0' ;
PCbW <= ('1' and p) when (state="0001" and ins_states="1001") else
'0';
Wsrc <= "01" when (ins_states="1001" and state="0001") else
"10" when (ins_states="0011" and state="0101") else
"10" when (state="0110" and ins_states="0110" and ins(21)='1') else
"00";
Rsrc <= "01" when (ins_states="0010" and state="1001") else --second state read
"00" when (ins_states="0010" and state="0001") else --first state read
"01" when (ins_states="0011" and state="1001") else --second read
"00" when (ins_states="0011" and state="0001") else --first read
"10" when (ins_states="0110" and state="0001") else
"00";
Rsrc2 <= '1' when (ins_states="0011") else
'0';
Asrc1 <= "01" when (state = "0000") else
"10" when ((ins_states="0011" and ins(21)='0' and state="0010") or ((ins(24 downto 21)="1101" or ins(24 downto 21)="1111") and state="0010")) else
"00" when ((ins_states="1001" and state="0001")) else
"00";
Cnew <= "00" when (ins_states="0010" and state="1001") else
"11" when (ins_states="0000" and state="0001") else
"10" when (ins_states="0001" and state="0001") else
"10" when (ins_states="0111" and state="0011");
--0 -> DP imm
--1 -> DP ShAmt imm
--2 -> DP ShAmt reg
--3 -> MUL,MLA
--4 -> Halfword DT reg offset
--5 -> Halfword DT imm offset
--6 -> DT imm offset
--7 -> DT reg offset
--8 -> undefined
--9 -> B,BL
--15 -> not implemented
BCnew <= "011" when (ins_states="1001" and state/="0000") else
"010" when (ins_states="0011") else
"101" when ((ins_states="0110" and state="0011") or ((ins(24 downto 21)="1101" or ins(24 downto 21)="1111") and state="0010")) else
"001" when (state="0000") else
"000"; --output of shifter - which will be same as B when not workings
M2R <= "10" when (state="0001" and ins_states="1001") else
"01" when (state="1000") else
"00" when (state="0110" and ins_states="0110") else
"00";
Carrynew <= "01" when (ins(31 downto 28)="1101" or ins(31 downto 28)="1111") else
"00";
Shiftcontrol <= "11" when (ins_states="0000" and state="0001") else
"00";
end Behavioral;
----------------------------------------------------------------------------------