-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDecode.vhd
217 lines (196 loc) · 6.51 KB
/
Decode.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
--new decode
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity Decode is
port(
clk:in std_logic;
rst:in std_logic;
--inputs from left to right
InstrD: in std_logic_vector(31 downto 0);
PCPlus4D:in std_logic_vector(31 downto 0);
ResultW:in std_logic_vector(31 downto 0);
WriteRegW:in std_logic_vector(4 downto 0);
RegWriteW:in std_logic;
-- ForwardAD:in std_logic;
-- ForwardBD:in std_logic;
FlushE:in std_logic;
ALUOutM:in std_logic_vector(31 downto 0);
--outputs from left to right
RegWriteE:out std_logic;
MemToRegE:out std_logic;
MemWriteE:out std_logic;
MemReadE:out std_logic;
ALUControlE: out std_logic_vector(5 downto 0); --gets R_Type_to_functD
ALUSrcE:out std_logic;
RegDstE:out std_logic;
RD1E: out std_logic_vector(31 downto 0);
RD2E: out std_logic_vector(31 downto 0);
RsD: out std_logic_vector(4 downto 0);
RtD: out std_logic_vector(4 downto 0);
RdD: out std_logic_vector(4 downto 0);
RsE: out std_logic_vector(4 downto 0);
RtE: out std_logic_vector(4 downto 0);
RdE: out std_logic_vector(4 downto 0);
BranchD:out std_logic;
SignImmE:out std_logic_vector(31 downto 0);
jump:out std_logic;
PCSrcD:out std_logic;
PCBranchD:out std_logic_vector(31 downto 0));
end entity;
architecture decode_logic of Decode is
signal RegWriteD: std_logic;
signal MemToRegD: std_logic;
signal MemWriteD: std_logic;
signal MemReadD: std_logic;
signal R_Type_to_functD: std_logic_vector(5 downto 0);
signal ALUSrcD: std_logic;
signal RegDstD: std_logic;
signal RD1D: std_logic_vector(31 downto 0);
signal RD2D: std_logic_vector(31 downto 0);
signal clk_sig: std_logic;
signal rst_sig: std_logic;
signal SignImmD: std_logic_vector(31 downto 0);
--signal shiftSignImmD: std_logic_vector(31 downto 0);
signal EquaD: std_logic;
signal mux1o: std_logic_vector(31 downto 0);
signal mux2o: std_logic_vector(31 downto 0);
signal RsD_sig: std_logic_vector(4 downto 0);
signal RtD_sig: std_logic_vector(4 downto 0);
signal RdD_sig: std_logic_vector(4 downto 0);
signal BranchD_sig: std_logic;
--signal ForwardAD_sig: std_logic:= '0';
--signal ForwardBD_sig: std_logic:='0';
component bor is
port(
clk : in std_logic;
rst : in std_logic;
-- write side
reg_write : in std_logic;
write_reg : in std_logic_vector(4 downto 0);
write_data : in std_logic_vector(31 downto 0);
-- read side
read_reg1 : in std_logic_vector(4 downto 0);
read_data1 : out std_logic_vector(31 downto 0);
read_reg2 : in std_logic_vector(4 downto 0);
read_data2 : out std_logic_vector(31 downto 0)
);
end component bor;
component ControlUnit is
port(
--inputs
OP :in std_logic_vector(5 downto 0);
funct: in std_logic_vector(5 downto 0);
--outputs
jump: out std_logic;
RegWriteD: out std_logic;
MemToRegD: out std_logic;
MemWriteD: out std_logic;
MemReadD : out std_logic;
--ALUControlD: out std_logic_vector(3 downto 0);
ALUSrcD: out std_logic;
RegDstD: out std_logic;
BranchD: out std_logic;
R_Type_to_funct: out std_logic_vector(5 downto 0) -- Because the small egg is inside the execute stage, we need to check if R_Type function is envoked. if so, we read the funct value for the ALUControl
);
end component ControlUnit;
begin
------------------------------Port maps------------------------------------------
RegFile: bor port map(
clk => clk,
rst => rst,
-- write side
reg_write => RegWriteW , -- A3 in scheme
write_reg => WriteRegW, -- enable write
write_data => ResultW, -- WD3 in scheme
-- read side
read_reg1 => InstrD(25 downto 21), -- A1 in scheme
read_data1 => RD1D,
read_reg2 => InstrD(20 downto 16), -- A2 in scheme
read_data2 => RD2D
);
CtrlUnit: ControlUnit port map(
OP => InstrD (31 downto 26),
funct => InstrD (5 downto 0),
jump => jump ,
RegWriteD => RegWriteD,
MemToRegD => MemToRegD,
MemWriteD => MemWriteD,
MemReadD => MemReadD,
ALUSrcD => ALUSrcD,
RegDstD => RegDstD,
BranchD => BranchD_sig,
R_Type_to_funct => R_Type_to_functD
);
------------------------------ end if port maps------------------------------------
SignImmD <= X"0000" & InstrD(15 downto 0) when InstrD(15) = '0' else -- pad with 16 zeros --should be moved to process
X"FFFF" & InstrD(15 downto 0); -- pad with 1 if the number sign is negative (1)
--shiftSignImmD<=SignImmD(29 downto 0) & "00";
PCBranchD(31 downto 0) <= (PCPlus4D + (SignImmD(29 downto 0) & "00"));
RsD<=InstrD(25 downto 21);
RtD<=InstrD(20 downto 16);
RdD<=InstrD(15 downto 11);
RsD_sig<=InstrD(25 downto 21);
RtD_sig<=InstrD(20 downto 16);
RdD_sig<=InstrD(15 downto 11);
EquaD<= '1' when mux1o=mux2o else '0';
BranchD<= BranchD_sig;
PCSrcD<= '1' when BranchD_sig = '1' and EquaD = '1' else '0';
--first_mux_bhv: process (ForwardAD_sig) is
-- begin
-- if (ForwardAD_sig = '0') then
mux1o <= RD1D;
-- else
-- mux1o <= ALUOutM;
-- end if;
--end process first_mux_bhv;
--second_mux_bhv: process (ForwardBD_sig) is
-- begin
-- if (ForwardBD_sig = '0') then
mux2o <= RD2D;
-- else
-- mux2o <= ALUOutM;
-- end if;
--end process second_mux_bhv;
--SYNC_ID_EX:process(clk,FlushE)
SYNC_ID_EX:process(clk,FlushE,RegWriteD ,MemToRegD ,MemWriteD ,MemReadD ,RegDstD ,ALUSrcD)
begin --asynchronous rst
if (FlushE = '0') then
RegWriteE <= '0';
MemToRegE <= '0';
MemWriteE <= '0';
MemReadE <= '0';
ALUSrcE <= '0';
RegDstE <= '0';
ALUControlE <= (others => '0');
RD1E <= (others => '0');
RD2E <= (others => '0');
RsE <= (others => '0');
RtE <= (others => '0');
RdE <= (others => '0');
--SignImmD <= (others => '0');
SignImmE<= (others => '0');
--elsif rising_edge(clk) then -- the register READS, thus the falling edge
elsif rising_edge(clk) then
RegWriteE <= RegWriteD;
MemToRegE <= MemToRegD;
MemWriteE <= MemWriteD;
MemReadE <= MemReadD;
ALUSrcE <= ALUSrcD;
RegDstE <= RegDstD;
RD1E <= RD1D;
RD2E <= RD2D;
RsE <= RsD_sig;
RtE <= RtD_sig;
RdE <= RdD_sig;
--if InstrD(15)= '1' then
-- SignImmD <= x"1111" & InstrD(15 downto 0);
--else
-- SignImmD <= x"0000" & InstrD(15 downto 0);
--end if;
SignImmE<= SignImmD;
ALUControlE <= R_Type_to_functD;
end if;
end process;
end architecture;