-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathControllerFSM.vhd
More file actions
319 lines (266 loc) · 12.1 KB
/
Copy pathControllerFSM.vhd
File metadata and controls
319 lines (266 loc) · 12.1 KB
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
----------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Create Date: 17.03.2018 23:51:17
-- Design Name:
-- Module Name: ControllerFSM - 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 ControllerFSM is
Port ( clk : in STD_LOGIC;
reset : in STD_LOGIC;
start : in STD_LOGIC;
ins24to20 : in STD_LOGIC_VECTOR(4 downto 0);
ins_type : in STD_LOGIC_VECTOR (1 downto 0);
ins_subtype : in STD_LOGIC_VECTOR (2 downto 0);
ins_variant : in STD_LOGIC_VECTOR (1 downto 0);
Hready : in STD_LOGIC;
skip_ins : in STD_LOGIC;
state : out STD_LOGIC_VECTOR(4 downto 0);
SWI_state : out STD_LOGIC_VECTOR(3 downto 0));
end ControllerFSM;
architecture Behavioral of ControllerFSM is
TYPE State_type IS (
InstructionFetch_PCincrement, --00000
PCupdate_LoadAB, --00001
Branch_IncrementPCby4, --00010
Branch_updatePC_addOffset, --00011
Branch_updatePCafterOffset, --00100
Branch_updateLR, --00101
DP_shiftOp2_updateRES_flags, --00110
DP_writeBack, --00111
MulMla_loadRs, --01000
MulMla_updateM, --01001
MulMla_loadRn, --01010
MulMla_updateRES_flags, --01011
MulMla_writeBack, --01100
DT_preIndex_CalcAddress, --01101
DT_str_loadRd, --01110
DT_str, --01111
DT_writeBack, --10000
DT_loadDR, --10001
DT_ldr_writeIntoRF, --10010
DT_postIndex_CalcAddress, --10011
InstructionFetch_memoryWait, --10100
InstructionFetch_instructionStore, --10101
DT_str_nonseq, --10110
DT_loadDR_nonseq, --10111
DT_loadDR_idle, --11000
Branch_IncrementPCby4_SavePC, --11001
DT_str_idle, --11010
DP_calculateResult, --11011
SWI_saveCPSR, --11100, 0001
SWI_updatePC, --11100, 0010
SWI_retrieveCPSR, --11100, 0011
SWI_writeIns, --11100, 0100
SWI_writeIns_memWait1, --11100, 0101
SWI_writeIns_memWait2, --11100, 0110
Idle --11111
);
signal currentState : State_Type := Idle; -- Create a signal that uses
begin
with currentState select state <=
"00000" when InstructionFetch_PCincrement, --00000
"00001" when PCupdate_LoadAB, --00001
"00010" when Branch_IncrementPCby4, --00010
"00011" when Branch_updatePC_addOffset, --00011
"00100" when Branch_updatePCafterOffset, --00100
"00101" when Branch_updateLR, --00101
"00110" when DP_shiftOp2_updateRES_flags, --00110
"00111" when DP_writeBack, --00111
"01000" when MulMla_loadRs, --01000
"01001" when MulMla_updateM, --01001
"01010" when MulMla_loadRn, --01010
"01011" when MulMla_updateRES_flags, --01011
"01100" when MulMla_writeBack, --01100
"01101" when DT_preIndex_CalcAddress, --01101
"01110" when DT_str_loadRd, --01110
"01111" when DT_str, --01111
"10000" when DT_writeBack, --10000
"10001" when DT_loadDR, --10001
"10010" when DT_ldr_writeIntoRF, --10010
"10011" when DT_postIndex_CalcAddress, --10011
"10100" when InstructionFetch_memoryWait,
"10101" when InstructionFetch_instructionStore,
"10110" when DT_str_nonseq,
"10111" when DT_loadDR_nonseq,
"11000" when DT_loadDR_idle,
"11001" when Branch_IncrementPCby4_SavePC,
"11010" when DT_str_idle,
"11011" when DP_calculateResult,
"11100" when SWI_saveCPSR,
"11100" when SWI_updatePC,
"11100" when SWI_retrieveCPSR,
"11100" when SWI_writeIns,
"11100" when SWI_writeIns_memWait1,
"11100" when SWI_writeIns_memWait2,
"11111" when Idle; --11111
with currentState select SWI_state <=
"0001" when SWI_saveCPSR,
"0010" when SWI_updatePC,
"0011" when SWI_retrieveCPSR,
"0100" when SWI_writeIns,
"0101" when SWI_writeIns_memWait1,
"0110" when SWI_writeIns_memWait2,
"0000" when others;
process(clk,reset)
begin
if reset = '1' then
currentState <= Idle;
elsif rising_edge(clk) then
case currentState is
when Idle =>
if start = '1' then
currentState <= InstructionFetch_PCincrement;
else
currentState <= Idle;
end if;
when InstructionFetch_PCincrement =>
currentState <= InstructionFetch_memoryWait;
when InstructionFetch_memoryWait =>
currentState <= InstructionFetch_instructionStore;
when InstructionFetch_instructionStore =>
currentState <= PCupdate_LoadAB;
when PCupdate_LoadAB =>
if skip_ins = '1' then
currentState <= InstructionFetch_PCincrement;
else
if ins_type = "00" then
currentState <= DP_calculateResult;
elsif (ins_type = "01" and ins24to20(4) = '1') then
currentState <= DT_preIndex_CalcAddress;
elsif (ins_type = "01" and ins24to20(4) = '0') then
currentState <= DT_postIndex_CalcAddress;
elsif ins_type = "10" then
currentState <= MulMla_LoadRn;
elsif ins_type = "11" and ins_subtype = "010" then
currentState <= SWI_saveCPSR;
elsif ins_type = "11" and ins_subtype = "011" then
currentState <= SWI_retrieveCPSR;
elsif ins_type = "11" and ins_subtype = "100" then
currentState <= SWI_writeIns;
elsif ins_type = "11" and ins_subtype = "111" then
currentState <= Idle;
elsif ins_type = "11" then
currentState <= Branch_IncrementPCby4;
else
currentState <= InstructionFetch_PCincrement;
end if;
end if;
when Branch_IncrementPCby4 =>
currentState <= Branch_IncrementPCby4_SavePC;
when Branch_IncrementPCby4_SavePC =>
currentState <= Branch_updatePC_addOffset;
when Branch_updatePC_addOffset =>
currentState <= Branch_updatePCafterOffset;
when Branch_updatePCafterOffset =>
if ins_subtype = "001" then
currentState <= Branch_updateLR;
else
currentState <= InstructionFetch_PCincrement;
end if;
when Branch_updateLR =>
currentState <= InstructionFetch_PCincrement;
when SWI_saveCPSR =>
currentState <= SWI_updatePC;
when SWI_updatePC =>
currentState <= InstructionFetch_PCincrement;
when SWI_retrieveCPSR =>
currentState <= InstructionFetch_PCincrement;
when SWI_writeIns =>
currentState <= SWI_writeIns_memWait1;
when SWI_writeIns_memWait1 =>
currentState <= SWI_writeIns_memWait2;
when SWI_writeIns_memWait2 =>
currentState <= InstructionFetch_PCincrement;
when DP_calculateResult =>
currentState <= DP_shiftOp2_updateRES_flags;
when DP_shiftOp2_updateRES_flags =>
if ins_subtype = "001" then
currentState <= DP_writeBack;
else
currentState <= InstructionFetch_PCincrement;
end if;
when DP_writeBack =>
currentState <= InstructionFetch_PCincrement;
when MulMla_loadRn =>
currentState <= MulMla_updateM;
when MulMla_updateM =>
currentState <= MulMla_loadRs;
when MulMla_loadRs =>
currentState <= MulMla_updateRES_flags;
when MulMla_updateRES_flags =>
currentState <= MulMla_writeBack;
when MulMla_writeBack =>
currentState <= InstructionFetch_PCincrement;
when DT_preIndex_CalcAddress =>
if ins_subtype ="101" or ins_subtype = "111" or ins_subtype = "110" then
currentState <= DT_str_loadRd;
else
currentState <= DT_loadDR_nonseq;
end if;
when DT_loadDR_nonseq =>
if Hready = '1' then
currentState <= DT_loadDR_idle;
end if;
when DT_loadDR_idle =>
if Hready = '1' then
currentState <= DT_loadDR;
end if;
when DT_loadDR =>
currentState <= DT_ldr_writeIntoRF;
when DT_ldr_writeIntoRF =>
if ins24to20(4) = '1' then
currentState <= DT_writeBack;
else
currentState <= InstructionFetch_PCincrement;
end if;
when DT_str_loadRd =>
currentState <= DT_str_nonseq;
when DT_str_nonseq =>
if Hready = '1' then
currentState <= DT_str_idle;
end if;
when DT_str_idle =>
if Hready = '1' then
currentState <= DT_str;
end if;
when DT_str =>
if ins24to20(4) = '1' then
currentState <= DT_writeBack;
else
currentState <= InstructionFetch_PCincrement;
end if;
when DT_writeBack =>
currentState <= InstructionFetch_PCincrement;
when DT_postIndex_CalcAddress =>
if ins_subtype ="101" or ins_subtype = "111" or ins_subtype = "110" then
currentState <= DT_str_loadRd;
else
currentState <= DT_loadDR;
end if;
when others => currentState <= Idle;
end case;
end if;
end process;
end Behavioral;