Repository navigation
Expand file tree
/
Copy pathDataPath.vhd
More file actions
479 lines (368 loc) · 27.8 KB
/
Copy pathDataPath.vhd
File metadata and controls
479 lines (368 loc) · 27.8 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
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
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.numeric_std.all;
use WORK.constants.all;
use WORK.functions.all;
entity DataPath is
PORT(
CLK: IN std_logic;
RST: IN std_logic;
--CU signals.
--stage1
RF1: IN std_logic;
RF2: IN std_logic;
EN1: IN std_logic;
--stage2
S1: IN std_logic;
S2: IN std_logic;
ALU3: IN std_logic;
ALU2: IN std_logic;
ALU1: IN std_logic;
ALU0: IN std_logic;
--stage3
LnS: IN std_logic;
EN3: IN std_logic;
--stage4
S3: IN std_logic;
WF1: IN std_logic;
Ld: IN std_logic;
instr: IN std_logic_vector(IR_size-1 downto 0); -- instruction read from the IRAM
IRAM_addr: OUT std_logic_vector(31 downto 0); -- IRAM address
--DRAM
DRAM_data_out: IN std_logic_vector(31 downto 0); -- data coming from the DRAM
DRAM_addr: OUT std_logic_vector(31 downto 0); -- DRAM address
DRAM_data_in: OUT std_logic_vector(31 downto 0); -- data sent to the DRAM
opcode: OUT std_logic_vector(OP_CODE_SIZE-1 downto 0); -- opcode towards CU
func: OUT std_logic_vector(FUNC_SIZE-1 downto 0) -- func towards CU
);
end DataPath;
architecture Structural of DataPath is
component FETCH is
port(
PC : IN std_logic_vector(PC_size-1 downto 0); -- PC read from the PC pipeline register
hazard_PC : IN std_logic_vector(PC_size-1 downto 0); -- PC given from the stall_detection_Unit in case there is the need to re-fetch the instr
PC_sel : IN std_logic; -- Selection signal to select between the PC and the hazard_PC
IRAM_addr : OUT std_logic_vector(IR_SIZE-1 downto 0); -- address that will be used to fetch the instr from the IRAM (external to the DP)
NPC : OUT std_logic_vector(PC_size-1 downto 0)); -- The NPC is passed to the IF/DEC pipeline register to be used in case of jumps
end component;
component DEC is
port(
instr: IN std_logic_vector(IR_SIZE-1 downto 0); -- The instruction just fetched
RST: IN std_logic; -- The reset signal, used to reset all the components in DEC stage like the RF
RFdata_in: IN std_logic_vector(data_size-1 downto 0); -- input data to the Register file
RFWA: IN std_logic_vector(Log2(num_reg)-1 downto 0); -- write address for the Register file
--Stall detection
NPC_in: IN std_logic_vector(PC_size-1 downto 0); -- The NPC taken from the IF/DEC pipeline register
EXE_RD: IN std_logic_vector(Log2(num_reg)-1 downto 0); -- destination register read from the DEC/EXE pipeline register
Ld: IN std_logic; -- signal that tells if there is a load instruction in the EXE stage
ALU_regout:IN std_logic_vector(data_size-1 downto 0); -- ALUout register read from EXE/MEM pipeline register
MEM_RD: IN std_logic_vector(Log2(num_reg)-1 downto 0); -- destination register read from the EXE/MEM pipeline register
WB_RD: IN std_logic_vector(Log2(num_reg)-1 downto 0); -- destination register read from the MEM/WB pipeline register
--controls
RF1: IN std_logic; -- control signal from the CU
RF2: IN std_logic; -- control signal from the CU
WF1: IN std_logic; -- control signal from the CU
EN1: IN std_logic; -- control signal from the CU
opcode: OUT std_logic_vector(OP_CODE_SIZE-1 downto 0); -- opcode extracted from the istruction and provided to the CU
func: OUT std_logic_vector(FUNC_SIZE-1 downto 0); -- func extracted from the istruction and provided to the CU
IMM: OUT std_logic_vector(data_size-1 downto 0); -- IMM value extracted from the istruction and passed to the DEC/EXE pipeline register
RA: OUT std_logic_vector(data_size-1 downto 0); -- first value loaded from the RF and passed to the DEC/EXE pipeline register
RB: OUT std_logic_vector(data_size-1 downto 0); -- second value loaded from the RF and passed to the DEC/EXE pipeline register
RSA: OUT std_logic_vector(Log2(num_reg)-1 downto 0); -- source register extracted from the istruction and passed to the DEC/EXE pipeline register
RSB: OUT std_logic_vector(Log2(num_reg)-1 downto 0); -- source register extracted from the istruction and passed to the DEC/EXE pipeline register
RD: OUT std_logic_vector(Log2(num_reg)-1 downto 0); -- destination register extracted from the istruction and passed to the DEC/EXE pipeline register
stall_NPC: OUT std_logic_vector(PC_size-1 downto 0); -- Value of NPC obtained from the Stall detection logic.
PC_sel: OUT std_logic; -- selection signal towards the mux in the FETCH stage that selects between the stall NPC and the pipeline register PC
dec_flag: OUT std_logic; -- any time we have a jump instruction, we rise this flag to 1
NPC_jump: OUT std_logic_vector(PC_size-1 downto 0)); -- when we have a jump, we use it as next PC to be fetched
end component;
component EXE is
PORT(
IMM: IN std_logic_vector(data_size-1 downto 0); -- immediate value taken from DEC/EXE pipeline register
RA: IN std_logic_vector(data_size-1 downto 0); -- operand_1 value taken from DEC/EXE pipeline register
RB: IN std_logic_vector(data_size-1 downto 0); -- operand_2 value taken from DEC/EXE pipeline register
WA: IN std_logic_vector(log2(num_reg)-1 downto 0); -- destination address taken from DEC/EXE pipeline register
-- FORWARDING
RSA: IN std_logic_vector(log2(num_reg)-1 downto 0); -- source of operand_1 taken from DEC/EXE pipeline register
RSB: IN std_logic_vector(log2(num_reg)-1 downto 0); -- source of operand_2 taken from DEC/EXE pipeline register
ALU_outmem: IN std_logic_vector(data_size-1 downto 0); -- value from the EXE/MEM pipeline register containing the ALU value currently in MEM
WB_out: IN std_logic_vector(data_size-1 downto 0); -- value from the MEM/WB pipeline register containing the ALU value currently in WB
MEM_RD: IN std_logic_vector(log2(num_reg)-1 downto 0); -- value from the EXE/MEM pipeline register containing destination addr. currently in MEM
WB_RD: IN std_logic_vector(log2(num_reg)-1 downto 0); -- value from the EXE/MEM pipeline register containing destination addr. currently in WB
LD_EN: IN std_logic; -- signal that tells if there is a load instruction in MEM stage
WB_EN: IN std_logic; -- signal that tells if the data in wb must be written in MEM (indicates a load instruction in WB stage)
--control
S1: IN std_logic; -- control signal from the CU
S2: IN std_logic; -- control signal from the CU
ALU3: IN std_logic; -- control signal from the CU
ALU2: IN std_logic; -- control signal from the CU
ALU1: IN std_logic; -- control signal from the CU
ALU0: IN std_logic; -- control signal from the CU
output: OUT std_logic_vector(data_size-1 downto 0); -- result from the ALU operation
ME: OUT std_logic_vector(data_size-1 downto 0); -- value to be stored in case of a store instruction
WAout: OUT std_logic_vector(log2(num_reg)-1 downto 0)); -- destination address to be passed to the next stage
end component;
component MEM is
Port(
ALUout: IN std_logic_vector(data_size-1 downto 0); -- result of the EXE stage
MEout: IN std_logic_vector(data_size-1 downto 0); -- value to be written in memory in case of a store instruction
RDin: IN std_logic_vector(Log2(num_reg)-1 downto 0); -- destination address, in register file, taken from the EXE/MEM pipeline register
DRAM_data_out: IN std_logic_vector(data_size-1 downto 0);
--control
LnS: IN std_logic; -- control signal from the CU
--to DRAM memory
DRAM_addr: OUT std_logic_vector(31 downto 0); -- DRAM address
DRAM_data_in: OUT std_logic_vector(data_size-1 downto 0); -- value to be written in DRAM
output: OUT std_logic_vector(data_size-1 downto 0); -- data read from the memory
alu_out: OUT std_logic_vector(data_size-1 downto 0); -- the result of the EXE stage
RDout: OUT std_logic_vector(Log2(num_reg)-1 downto 0)); -- destination address
end component;
component WB is
PORT(
mem_out : IN std_logic_vector(data_size-1 downto 0); -- output from the memory of MEM stage
alu_out : IN std_logic_vector(data_size-1 downto 0); -- output from the memory of EXE stage
--control
S3 : IN std_logic; -- control signal from the CU that selects between the two input signals
output : OUT std_logic_vector(data_size-1 downto 0)); -- output of the mux
end component;
----------------------------
--==========================
----------------------------
--pipeline signals to connect components to the pipeline registers.
--FETCH
signal PC_muxout: std_logic_vector(PC_size-1 downto 0); -- output of the mux which selects between NPC and jump NPC
signal PC_regout: std_logic_vector(PC_size-1 downto 0); -- output of the PC register
signal NPC_fetchout: std_logic_vector(PC_size-1 downto 0); -- output of the computation for the NPC (PC+4)
signal NOP_MUX_OUT: std_logic_vector(IR_size-1 downto 0);
--DEC
signal NPC_regout: std_logic_vector(PC_size-1 downto 0); -- output of the NPC reg in IF/DEC pipeline register
signal IR_regout: std_logic_vector(IR_SIZE-1 downto 0); -- output of the IR reg in IF/DEC pipeline register
signal RA_decout: std_logic_vector(data_size-1 downto 0); -- the value read from the RF at address RSA to be passed from DEC to EXE
signal RB_decout: std_logic_vector(data_size-1 downto 0); -- the value read from the RF at address RSB to be passed from DEC to EXE
signal RSA_decout: std_logic_vector(Log2(num_reg)-1 downto 0); -- the address RSA to be passed from DEC to EXE
signal RSB_decout: std_logic_vector(Log2(num_reg)-1 downto 0); -- the address RSB to be passed from DEC to EXE
signal RD_decout: std_logic_vector(Log2(num_reg)-1 downto 0); -- the destination address to be passed from DEC to EXE
signal IMM_decout: std_logic_vector(data_size-1 downto 0); -- the immediate value to be passed from DEC to EXE
signal s_NPC_jump: std_logic_vector(PC_size-1 downto 0);
signal flag_signal: std_logic;
--DEC->FETCH
signal hazard_NPC: std_logic_vector(PC_size-1 downto 0); -- NPC output of the hazard detection logic to be passed from DEC to FETCH
signal hazard_NPC_sel: std_logic; -- selection signal output of the hazard detection logic to be passed from DEC to FETCH and there select between the hazard PC and the normally computed PC
--EXE
signal IMM_regout: std_logic_vector(data_size-1 downto 0); -- output of the IMM reg in DEC/EXE pipeline register
signal RA_regout: std_logic_vector(data_size-1 downto 0); -- output of the operand_1 value reg in DEC/EXE pipeline register
signal RB_regout: std_logic_vector(data_size-1 downto 0); -- output of the operand_2 value reg in DEC/EXE pipeline register
signal RSA_regout: std_logic_vector(log2(num_reg)-1 downto 0); -- output of the operand_1 address reg in DEC/EXE pipeline register
signal RSB_regout: std_logic_vector(log2(num_reg)-1 downto 0); -- output of the operand_2 address reg in DEC/EXE pipeline register
signal RD_regoutexe: std_logic_vector(log2(num_reg)-1 downto 0); -- output of the destination address reg in DEC/EXE pipeline register
signal ALU_exeout: std_logic_vector(data_size-1 downto 0); -- result of the ALU
signal ME_exeout: std_logic_vector(data_size-1 downto 0); -- data value to be passed to the MEM stage (relevant in case of a store instruction)
signal RD_exeout: std_logic_vector(log2(num_reg)-1 downto 0); -- destination address to be passed from EXE to MEM
--MEM
signal ALU_regout: std_logic_vector(data_size-1 downto 0); -- output of the ALUout reg in EXE/MEM pipeline register
signal ME_regout: std_logic_vector(data_size-1 downto 0); -- output of the data_to_store reg in EXE/MEM pipeline register
signal RD_regoutmem: std_logic_vector(log2(num_reg)-1 downto 0); -- output of the destination address reg in EXE/MEM pipeline register
signal mem_out: std_logic_vector(data_size-1 downto 0); -- data read from memory to be passed from MEM to WB (relevant in case of load instruction)
signal ALU_memout: std_logic_vector(data_size-1 downto 0); -- value of ALU to be passed from MEM to WB
signal RD_memout: std_logic_vector(log2(num_reg)-1 downto 0); -- destination address to be passed from MEM to WB
--WB
signal MEM_regout: std_logic_vector(data_size-1 downto 0); -- output of the MEMout reg in MEM/WB pipeline register
signal MEM_aluregout: std_logic_vector(data_size-1 downto 0); -- output of the ALUout reg in MEM/WB pipeline register
signal RD_regoutwb: std_logic_vector(log2(num_reg)-1 downto 0); -- output of the destination address regin MEM/WB pipeline register
signal WB_addr: std_logic_vector(log2(num_reg)-1 downto 0); -- RF address in which to write the write back value
signal WB_data: std_logic_vector(data_size-1 downto 0); -- data that must be written in address WB_addr
--pipeline registers
--FETCH
signal PC_reg: std_logic_vector(PC_size-1 downto 0); -- PC register in FETCH pipeline register
--DEC
signal NPC_reg: std_logic_vector(PC_size-1 downto 0); -- NPC register in IF/DEC pipeline register
signal IR_reg: std_logic_vector(IR_SIZE-1 downto 0); -- IR register in IF/DEC pipeline register
--EXE
signal Imm_reg: std_logic_vector(data_size-1 downto 0); -- IMM register in DEC/EXE pipeline register
signal RA_reg: std_logic_vector(data_size-1 downto 0); -- RA(operand_1) register in DEC/EXE pipeline register
signal RB_reg: std_logic_vector(data_size-1 downto 0); -- RB(operand_2) register in DEC/EXE pipeline register
signal RSA_reg: std_logic_vector(log2(num_reg)-1 downto 0); -- RA(operand_1) address register in DEC/EXE pipeline register
signal RSB_reg: std_logic_vector(log2(num_reg)-1 downto 0); -- RB(operand_2) address register in DEC/EXE pipeline register
signal RD_regexe: std_logic_vector(log2(num_reg)-1 downto 0); -- destination address register in DEC/EXE pipeline register
--MEM
signal ALU_reg: std_logic_vector(data_size-1 downto 0); -- destination address register in EXE/MEM pipeline register
signal ME_reg: std_logic_vector(data_size-1 downto 0); -- data_to_store register in EXE/MEM pipeline register
signal RD_regmem: std_logic_vector(log2(num_reg)-1 downto 0); -- destination address register in EXE/MEM pipeline register
--WB
signal LMD_reg: std_logic_vector(data_size-1 downto 0); -- MEMout value register in MEM/WB pipeline register
signal ALU_regmem: std_logic_vector(data_size-1 downto 0); -- ALUout value register in MEM/WB pipeline register
signal RD_regwb: std_logic_vector(log2(num_reg)-1 downto 0 -- destination address register in MEM/WB pipeline register
);
----------------------------
--==========================
----------------------------
begin
clk_proc: process(CLK,RST)
begin
if(RST = '0') then -- active low
--reset all pipeline register to 0 and the IR to a NOP instruction
PC_reg <=(others=>'0');
NPC_reg <=(others=>'0');
IR_reg <= NOP_instr;
IMM_reg <=(others=>'0');
RA_reg <=(others=>'0');
RB_reg <=(others=>'0');
RSA_reg <=(others=>'0');
RSB_reg <=(others=>'0');
RD_regexe <=(others=>'0');
ALU_reg <=(others=>'0');
ME_reg <=(others=>'0');
RD_regmem <=(others=>'0');
LMD_reg <=(others=>'0');
ALU_regmem <=(others=>'0');
RD_regwb <=(others=>'0');
elsif(rising_edge(CLK)) then
-- update stages input
-- at each rising edge of the clock the pipeline registers are updated to their input values and the output of the register is also updated to the new content value
-- FETCH
PC_reg <=PC_muxout; --assign value to the PC register
-- FETCH->DEC
NPC_reg <=NPC_fetchout; --assign value to the NPC register
IR_reg <=NOP_MUX_OUT; --assign value to the IR register
-- DEC->EXE
IMM_reg <=IMM_decout; --assign value to the IMM register
RA_reg <=RA_decout; --assign value to the RA register
RB_reg <=RB_decout; --assign value to the RB register
RD_regexe <=RD_decout; --assign value to the RD register
RSA_reg <=RSA_decout; --assign value to the RSA register
RSB_reg <=RSB_decout; --assign value to the RSB register
-- EXE->MEM
ALU_reg <=ALU_exeout; --assign value to the ALUout register
ME_reg <=ME_exeout; --assign value to the ME register
RD_regmem <=RD_exeout; --assign value to the RD register
-- MEM->WB
LMD_reg <=mem_out; --assign value to the MEMout register
ALU_regmem <=ALU_memout; --assign value to the ALUout register
RD_regwb <=RD_memout; --assign value to the RD register
end if;
end process clk_proc;
-- Mapping of the components and use of the signals defined in the architecture to connect them
-- MUX that selects between NPC and jump NPC
-- if we have a jump instruction, the flag is 1 and NPC_jump would be chosen
-- otherwise the normal one will be chosen
PC_muxout <= NPC_fetchout when(flag_signal = '0')else
s_NPC_jump;
--stage 0 (FETCH)
PC_regout <=PC_reg; -- Update the line connecting the PC register to the FETCH stage. The value of the PC register is updated at the rising edge of the clock
fetch_stage: FETCH -- assign inputs and outputs to the fetch block that contains all the fetch components
port map(
PC =>PC_regout, -- input: PC value
hazard_PC =>hazard_NPC, -- input: PC value given by the stall detection logic(in case the dec instr must be re-fetched)
PC_sel =>hazard_NPC_sel, -- input: selection signal given by the stall detection logic to select between PC and hazard PC
IRAM_addr =>IRAM_addr, -- output: instruction loaded from the instruction memory
NPC =>NPC_fetchout -- output: NPC value calculated by adding 4 in fetch stage
);
-- MUX selecting between instructions found in address PC of the instruction memory and NOP_instr
-- if we have a jump instruction, we need to enter a NOP in pipline to create the branch delay slot
-- so the same flag of the jump is used to enter the NOP instruction
NOP_MUX_OUT <= instr when(flag_signal = '0')else
NOP_instr;
--stage1 (DEC)
NPC_regout <=NPC_reg; -- Update the line connecting the NPC register to the DEC stage. The value of the NPC register is updated at the rising edge of the clock
IR_regout <=IR_reg; -- Update the line connecting the IR register to the DEC stage. The value of the IR register is updated at the rising edge of the clock
dec_stage: DEC -- assign inputs and outputs to the DEC block that contains all the decode components
port map(
instr => IR_regout, -- input: instraction fetched
RST => RST, -- input: reset of internal components
RFdata_in => WB_data, -- input: data to be written in the register file
RFWA => WB_addr, -- input: address where the input data must be written
NPC_in => NPC_regout, -- input: NPC obtained from the fetch stage, loaded from pipeline register
EXE_RD => RD_regoutexe, -- input: destination address currently in EXE stage, loaded from pipeline register(used for stalls and forwarding(jumps))
MEM_RD => RD_regoutmem, -- input: destination address currently in MEM stage, loaded from pipeline register(used for stalls and forwarding(jumps))
WB_RD => RD_regoutwb, -- input: destination address currently in WB stage, loaded from pipeline register(used for stalls and forwarding(jumps))
Ld =>Ld, -- input: flag showing if there is a load instr. in EXE stage(used in the hazard detection logic)
ALU_regout =>ALU_regout, -- input: result of the exe stage that is now in mem stage, loaded from pipeline register(used in the forwarding logic(jumps))
--control
RF1 => RF1, -- input: control signal from the CU (enables read on port_1)
RF2 => RF2, -- input: control signal from the CU (enables read on port_2)
WF1 => WF1, -- input: control signal from the CU (enables write port)
EN1 => EN1, -- input: control signal from the CU (enables the register file)
--output
opcode => opcode, -- output: opcode towards the CU
func => func, -- output: func towards the CU
IMM => IMM_decout, -- output: IMM value towards the DEC/EXE pipeline register
RA => RA_decout, -- output: RA value towards the DEC/EXE pipeline register
RB => RB_decout, -- output: RB value towards the DEC/EXE pipeline register
RSA => RSA_decout, -- output: RSA value towards the DEC/EXE pipeline register
RSB => RSB_decout, -- output: RSB value towards the DEC/EXE pipeline register
RD => RD_decout, -- output: RD value towards the DEC/EXE pipeline register
stall_NPC => hazard_NPC, -- output: NPC generated by the hazard detection logic sent towards the fetch stage
PC_sel => hazard_NPC_sel, -- output: PC slection signal generated by the hazard detection logic sent towards the fetch stage
dec_flag => flag_signal, -- output: jump flag
NPC_jump => s_NPC_jump -- output: NPC calculated based on the jump
);
--stage2 (EXE)
--update stage status
Imm_regout <= IMM_reg; -- Update the line connecting the IMM register to the EXE stage. The value of the RSB register is updated at the rising edge of the clock
RA_regout <= RA_reg; -- Update the line connecting the RA register to the EXE stage. The value of the RSB register is updated at the rising edge of the clock
RB_regout <= RB_reg; -- Update the line connecting the RB register to the EXE stage. The value of the RSB register is updated at the rising edge of the clock
RSA_regout <= RSA_reg; -- Update the line connecting the RSA register to the EXE stage. The value of the RSB register is updated at the rising edge of the clock
RSB_regout <= RSB_reg; -- Update the line connecting the RSB register to the EXE stage. The value of the RSB register is updated at the rising edge of the clock
RD_regoutexe <= RD_regexe; -- Update the line connecting the RD register to the EXE stage. The value of the RD register is updated at the rising edge of the clock
exe_stage: EXE -- assign inputs and outputs to the EXE block that contains all the execute components
port map(
IMM =>Imm_regout, -- input: decoded immediate value
RA =>RA_regout, -- input: operand_1 loaded from pipeline register
RB =>RB_regout, -- input: operand_2 loaded from pipeline register
WA =>RD_regoutexe, -- input: decode return address value loaded from pipeline register
RSA => RSA_regout, -- input: decoded operand_1 source address loaded from pipeline register
RSB => RSB_regout, -- input: decoded operand_2 source address loaded from pipeline register
ALU_outmem => ALU_regout, -- input: ALU out of the instruction currently in mem stage loaded from pipeline register(used in forwarding)
WB_out => WB_data, -- input: data to be written back in WB stage(used in forwarding)
MEM_RD => RD_regoutmem, -- input: destination address of instruction currently in mem stage loaded from pipeline register(used in forwarding)
WB_RD => RD_regoutwb, -- input: destination address of instruction currently in wb stage loaded from pipeline register(used in forwarding)
Ld_EN => EN3, -- input: flag that tells if there is a load instruction in the mem stage(used in forwarding)
WB_EN => WF1, -- signal that tells if the data in wb must be written in MEM
--control
S1 => S1, -- input: control signal from the CU (selects between operand_1(1) and IMM(0))
S2 => S2, -- input: control signal from the CU (selects between operand_2(0) and IMM(1))
ALU3 => ALU3, -- input: control signal from the CU (LSB+3 of alu function selection)
ALU2 => ALU2, -- input: control signal from the CU (LSB+2 of alu function selection)
ALU1 => ALU1, -- input: control signal from the CU (LSB+1 of alu function selection)
ALU0 => ALU0, -- input: control signal from the CU (LSB of alu function selection)
--output
output => ALU_exeout, -- output: result of the ALU
me => ME_exeout, -- output: value to be stored in memory in case of a store instruction
WAout => RD_exeout -- output: destination address of the instruction
);
--stage3 (MEM)
--update stage status
ALU_regout <=ALU_reg; -- Update the line connecting the ALU register to the MEM stage. The value of the ALU register is updated at the rising edge of the clock
ME_regout <=ME_reg; -- Update the line connecting the ME register to the MEM stage. The value of the ME register is updated at the rising edge of the clock
RD_regoutmem <=RD_regmem; -- Update the line connecting the RD register to the MEM stage. The value of the RD register is updated at the rising edge of the clock
mem_stage: MEM -- assign inputs and outputs to the MEM block that contains all the memory components
port map(
ALUout =>ALU_regout, -- input: EXE stage result loaded from pipeline register
MEout =>ME_regout, -- input: data to be stored loaded from pipeline register(in case of a store instruction)
RDin =>RD_regoutmem, -- input: destination address loaded from pipeline register
DRAM_data_out=>DRAM_data_out, -- input: data read from the memory
--control
LnS =>LnS, -- input: control signal from the CU (Loan notStore signal for the memory)
-- output
DRAM_addr => DRAM_addr, -- output: address in memory from where to load data or store data
DRAM_data_in=> DRAM_data_in, -- output: Data sent to the DRAM to be stored
output =>mem_out, -- output: output of memory from MEM stage
alu_out =>ALU_memout, -- output: ALU out value, pass through from EXE to WB
RDout =>RD_memout -- output: destination address
);
--stage4 (WB)
--update stage status
MEM_regout <= LMD_reg; -- Update the line connecting the LMD register to the WB stage. The value of the LMD register is updated at the rising edge of the clock
MEM_aluregout <= ALU_regmem; -- Update the line connecting the ALU register to the WB stage. The value of the ALU register is updated at the rising edge of the clock
RD_regoutwb <= RD_regwb; -- Update the line connecting the RD register to the WB stage. The value of the RD register is updated at the rising edge of the clock
wb_stage: WB -- assign inputs and outputs to the WB block that contains all the write-back components
port map(
mem_out =>MEM_regout, -- input: memory output loaded from pipeline register
alu_out =>MEM_aluregout, -- input: Alu out loaded from MEM/WB pipeline register
--control
S3 =>S3, -- input: control signal from the CU (selects the writeback value between MEMout and ALUout)
--output
output =>WB_data -- output: the definitive data to be written back
);
WB_addr <=RD_regoutwb; -- Update the line connecting the RD register to the DEC stage. The value of the RD register is updated at the rising edge of the clock
end Structural;