1 |
2 |
elujan |
--
|
2 |
|
|
-- Entidad Segmented MIPS (Top Level) del procesador MIPS Segmentado
|
3 |
|
|
--
|
4 |
|
|
-- Licencia: Copyright 2008 Emmanuel Luján
|
5 |
|
|
--
|
6 |
|
|
-- This program is free software; you can redistribute it and/or
|
7 |
|
|
-- modify it under the terms of the GNU General Public License as
|
8 |
|
|
-- published by the Free Software Foundation; either version 2 of
|
9 |
|
|
-- the License, or (at your option) any later version. This program
|
10 |
|
|
-- is distributed in the hope that it will be useful, but WITHOUT
|
11 |
|
|
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
12 |
|
|
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
13 |
|
|
-- License for more details. You should have received a copy of the
|
14 |
|
|
-- GNU General Public License along with this program; if not, write
|
15 |
|
|
-- to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
16 |
|
|
-- Boston, MA 02110-1301 USA.
|
17 |
|
|
--
|
18 |
|
|
-- Autor: Emmanuel Luján
|
19 |
|
|
-- Email: info@emmanuellujan.com.ar
|
20 |
|
|
-- Versión: 1.0
|
21 |
|
|
--
|
22 |
|
|
|
23 |
|
|
|
24 |
|
|
library ieee;
|
25 |
|
|
use ieee.std_logic_1164.all;
|
26 |
|
|
use ieee.numeric_std.all;
|
27 |
|
|
|
28 |
|
|
library work;
|
29 |
|
|
use work.records_pkg.all;
|
30 |
|
|
use work.segm_mips_const_pkg.all;
|
31 |
|
|
|
32 |
|
|
|
33 |
|
|
entity SEGMENTED_MIPS is
|
34 |
|
|
port(
|
35 |
|
|
CLK : in STD_LOGIC;
|
36 |
|
|
RESET : in STD_LOGIC
|
37 |
|
|
);
|
38 |
|
|
end SEGMENTED_MIPS;
|
39 |
|
|
|
40 |
|
|
architecture SEGMENTED_MIPS_ARC of SEGMENTED_MIPS is
|
41 |
|
|
|
42 |
|
|
--Declaración de componentes
|
43 |
|
|
component INSTRUCTION_FETCHING is
|
44 |
|
|
port(
|
45 |
|
|
--Entradas
|
46 |
|
|
CLK : in STD_LOGIC; -- Reloj
|
47 |
|
|
RESET : in STD_LOGIC; -- Reset asincrónico
|
48 |
|
|
PCSrc : in STD_LOGIC; -- Señal de habilitación del MUX_PC
|
49 |
|
|
NEW_PC_ADDR_IN : in STD_LOGIC_VECTOR(INST_SIZE-1 downto 0); -- Una de las entradas del MUX_PC
|
50 |
|
|
--Salidas
|
51 |
|
|
NEW_PC_ADDR_OUT : out STD_LOGIC_VECTOR(INST_SIZE-1 downto 0); --Nueva instrucción del PC
|
52 |
|
|
INSTRUCTION : out STD_LOGIC_VECTOR(INST_SIZE-1 downto 0) --La instrucción encontrada en la Memoria de Instrucción
|
53 |
|
|
);
|
54 |
|
|
end component INSTRUCTION_FETCHING;
|
55 |
|
|
|
56 |
|
|
component INSTRUCTION_DECODING is
|
57 |
|
|
port(
|
58 |
|
|
CLK : in STD_LOGIC; --Reloj
|
59 |
|
|
RESET : in STD_LOGIC; --Reset asincrónico asincrónico
|
60 |
|
|
--Entradas de la etapa de Búsqueda de la Instrucción (IF)
|
61 |
|
|
INSTRUCTION : in STD_LOGIC_VECTOR (INST_SIZE-1 downto 0);--Instrucción
|
62 |
|
|
NEW_PC_ADDR_IN : in STD_LOGIC_VECTOR (INST_SIZE-1 downto 0);--Nueva dirección del PC
|
63 |
|
|
--Entradas de la etapa de Post Escritura (WB)
|
64 |
|
|
RegWrite : in STD_LOGIC; --Señal de habilitación de escritura (RegWrite)
|
65 |
|
|
WRITE_DATA : in STD_LOGIC_VECTOR (INST_SIZE-1 downto 0);--Datos a ser escritos
|
66 |
|
|
WRITE_REG : in STD_LOGIC_VECTOR (ADDR_SIZE-1 downto 0);--Dirección del registro Rd
|
67 |
|
|
--Salidas de la etapa de Búsqueda de la Instrucción (IF)
|
68 |
|
|
NEW_PC_ADDR_OUT : out STD_LOGIC_VECTOR (INST_SIZE-1 downto 0);--Nueva dirección del PC
|
69 |
|
|
--Salidas generadas a partir de la instrucción
|
70 |
|
|
OFFSET : out STD_LOGIC_VECTOR (INST_SIZE-1 downto 0);--Offset de la instrucción [15-0]
|
71 |
|
|
RT_ADDR : out STD_LOGIC_VECTOR (ADDR_SIZE-1 downto 0);--Dirección del registro RT [20-16]
|
72 |
|
|
RD_ADDR : out STD_LOGIC_VECTOR (ADDR_SIZE-1 downto 0);--Dirección del registro RD [15-11]
|
73 |
|
|
--Salidas del Banco de Registros
|
74 |
|
|
RS : out STD_LOGIC_VECTOR (INST_SIZE-1 downto 0);--Datos leidos de la dir. Rs
|
75 |
|
|
RT : out STD_LOGIC_VECTOR (INST_SIZE-1 downto 0);--Datos leidos de la dir. Rt
|
76 |
|
|
--Salidas de la Unidad de Control
|
77 |
|
|
WB_CR : out WB_CTRL_REG; --Estas señales se postergarán hasta la etapa WB
|
78 |
|
|
MEM_CR : out MEM_CTRL_REG; --Estas señales se postergarán hasta la etapa MEM
|
79 |
|
|
EX_CR : out EX_CTRL_REG --Estas señales se postergarán hasta la etapa EX
|
80 |
|
|
);
|
81 |
|
|
end component INSTRUCTION_DECODING;
|
82 |
|
|
|
83 |
|
|
component EXECUTION is
|
84 |
|
|
port(
|
85 |
|
|
--Entradas
|
86 |
|
|
CLK : in STD_LOGIC; --Reloj
|
87 |
|
|
RESET : in STD_LOGIC; --Reset asincrónico
|
88 |
|
|
WB_CR : in WB_CTRL_REG; --Estas señales se postergarán hasta la etapa WB
|
89 |
|
|
MEM_CR : in MEM_CTRL_REG; --Estas señales se postergarán hasta la etapa MEM
|
90 |
|
|
EX_CR : in EX_CTRL_REG; --Estas señales se usarán en esta etapa
|
91 |
|
|
NEW_PC_ADDR_IN : in STD_LOGIC_vector (INST_SIZE-1 downto 0); --Nueva dirección del PC
|
92 |
|
|
RS : in STD_LOGIC_vector (INST_SIZE-1 downto 0); --Datos leidos de la dir. Rs
|
93 |
|
|
RT : in STD_LOGIC_vector (INST_SIZE-1 downto 0); --Datos leidos de la dir. Rt
|
94 |
|
|
OFFSET : in STD_LOGIC_vector (INST_SIZE-1 downto 0); --Offset de la instrucción [15-0]
|
95 |
|
|
RT_ADDR : in STD_LOGIC_vector (ADDR_SIZE-1 downto 0); --Dirección del registro RT [20-16]
|
96 |
|
|
RD_ADDR : in STD_LOGIC_vector (ADDR_SIZE-1 downto 0); --Dirección del registro RD [15-11]
|
97 |
|
|
|
98 |
|
|
--Salidas
|
99 |
|
|
WB_CR_OUT : out WB_CTRL_REG; --Estas señales se postergarán hasta la etapa WB
|
100 |
|
|
MEM_CR_OUT : out MEM_CTRL_REG; --Estas señales se postergarán hasta la etapa MEM
|
101 |
|
|
NEW_PC_ADDR_OUT : out STD_LOGIC_vector (INST_SIZE-1 downto 0); --Nueva dirección del PC
|
102 |
|
|
ALU_FLAGS_OUT : out ALU_FLAGS; --Las flags de la ALU
|
103 |
|
|
ALU_RES_OUT : out STD_LOGIC_vector(INST_SIZE-1 downto 0); --El resultado generado por la ALU
|
104 |
|
|
RT_OUT : out STD_LOGIC_vector (INST_SIZE-1 downto 0); --Entrará como Write Data en la etapa MEM
|
105 |
|
|
RT_RD_ADDR_OUT : out STD_LOGIC_vector (ADDR_SIZE-1 downto 0) --Se postergará hasta la etapa WB
|
106 |
|
|
|
107 |
|
|
);
|
108 |
|
|
end component EXECUTION;
|
109 |
|
|
|
110 |
|
|
component MEMORY_ACCESS is
|
111 |
|
|
port(
|
112 |
|
|
--Entradas
|
113 |
|
|
CLK : in STD_LOGIC;
|
114 |
|
|
RESET : in STD_LOGIC; --Reset asincrónico
|
115 |
|
|
WB_IN : in WB_CTRL_REG; --Estas señales se postergarán hasta la etapa WB
|
116 |
|
|
MEM : in MEM_CTRL_REG; --Estas señales serán usadas en esta etapa
|
117 |
|
|
FLAG_ZERO : in STD_LOGIC; --Flag Zero de la ALU
|
118 |
|
|
NEW_PC_ADDR : in STD_LOGIC_vector (INST_SIZE-1 downto 0); --Nueva dirección de pc hacia la etapa de IF
|
119 |
|
|
ADDRESS_IN : in STD_LOGIC_vector (INST_SIZE-1 downto 0); --Salida de la ALU (ALU Result), dirección de la memoria de datos
|
120 |
|
|
WRITE_DATA : in STD_LOGIC_vector (INST_SIZE-1 downto 0); --Datos a ser escritos en la memoria de datos
|
121 |
|
|
WRITE_REG_IN : in STD_LOGIC_vector (ADDR_SIZE-1 downto 0); --WriteRegister de los registros de la etapa de ID
|
122 |
|
|
--Salidas hacia la etapa WB, sincronizadas por registros
|
123 |
|
|
WB_OUT : out WB_CTRL_REG; --Estas señales se postergarán hasta la etapa WB
|
124 |
|
|
READ_DATA : out STD_LOGIC_vector (INST_SIZE-1 downto 0); --Datos leidos de la memoria de datos
|
125 |
|
|
ADDRESS_OUT : out STD_LOGIC_vector (INST_SIZE-1 downto 0); --Resultado de la ALU
|
126 |
|
|
WRITE_REG_OUT : out STD_LOGIC_vector (ADDR_SIZE-1 downto 0); --WriteRegister de los registros de la etapa de ID
|
127 |
|
|
--Salidas hacia la etapas IF, sin sincronización
|
128 |
|
|
NEW_PC_ADDR_OUT : out STD_LOGIC_vector (INST_SIZE-1 downto 0); --Nueva dirección de pc hacia la etapa de IF
|
129 |
|
|
PCSrc : out STD_LOGIC --Señal de habilitación del mux de la etapa de IF
|
130 |
|
|
);
|
131 |
|
|
end component MEMORY_ACCESS;
|
132 |
|
|
|
133 |
|
|
component WRITE_BACK is
|
134 |
|
|
port(
|
135 |
|
|
--Entradas
|
136 |
|
|
RESET : in STD_LOGIC; --Reset asincrónico
|
137 |
|
|
WB : in WB_CTRL_REG; --Señalesde control para esta etapa
|
138 |
|
|
READ_DATA : in STD_LOGIC_vector (INST_SIZE-1 downto 0); --Posible dato a ser escribido en la memoria de registros
|
139 |
|
|
ADDRESS : in STD_LOGIC_vector (INST_SIZE-1 downto 0); --Posible dato a ser escribido en la memoria de registros
|
140 |
|
|
WRITE_REG : in STD_LOGIC_vector (ADDR_SIZE-1 downto 0); --Dirección del registro a ser escrito en la memoria de registros
|
141 |
|
|
--Salidas hacia la etapas ID, sin sincronización
|
142 |
|
|
RegWrite : out STD_LOGIC; --WB_OUT.RegWrite
|
143 |
|
|
WRITE_REG_OUT : out STD_LOGIC_vector (ADDR_SIZE-1 downto 0); --Dirección del registro a ser escrito en la memoria de registros
|
144 |
|
|
WRITE_DATA : out STD_LOGIC_vector (INST_SIZE-1 downto 0) --Este dato representa a READ_DATA o a ADDRESS, según lo decida WB_OUT.MemtoReg
|
145 |
|
|
);
|
146 |
|
|
end component WRITE_BACK;
|
147 |
|
|
|
148 |
|
|
--Declaración de señales
|
149 |
|
|
|
150 |
|
|
-- Buses de datos, representan los datos que se pasan entre las etapas
|
151 |
|
|
|
152 |
|
|
-- MEM/IF
|
153 |
|
|
signal PCSrc_AUX : STD_LOGIC;
|
154 |
|
|
signal NEW_PC_ADDR_AUX4 : STD_LOGIC_vector (INST_SIZE-1 downto 0);
|
155 |
|
|
-- IF/ID
|
156 |
|
|
signal NEW_PC_ADDR_AUX1 : STD_LOGIC_vector (INST_SIZE-1 downto 0);
|
157 |
|
|
signal INSTRUCTION_AUX : STD_LOGIC_vector (INST_SIZE-1 downto 0);
|
158 |
|
|
-- WB/ID
|
159 |
|
|
signal RegWrite_AUX : STD_LOGIC;
|
160 |
|
|
signal WRITE_REG_AUX2 : STD_LOGIC_vector (ADDR_SIZE-1 downto 0);
|
161 |
|
|
signal WRITE_DATA_AUX : STD_LOGIC_vector (INST_SIZE-1 downto 0);
|
162 |
|
|
-- ID/EX
|
163 |
|
|
signal NEW_PC_ADDR_AUX2 : STD_LOGIC_vector (INST_SIZE-1 downto 0);
|
164 |
|
|
signal OFFSET_AUX : STD_LOGIC_vector (INST_SIZE-1 downto 0);
|
165 |
|
|
signal RT_ADDR_AUX : STD_LOGIC_vector (ADDR_SIZE-1 downto 0);
|
166 |
|
|
signal RD_ADDR_AUX : STD_LOGIC_vector (ADDR_SIZE-1 downto 0);
|
167 |
|
|
signal RS_AUX : STD_LOGIC_vector (INST_SIZE-1 downto 0);
|
168 |
|
|
signal RT_AUX1 : STD_LOGIC_vector (INST_SIZE-1 downto 0);
|
169 |
|
|
signal WB_CR_AUX1 : WB_CTRL_REG;
|
170 |
|
|
signal MEM_CR_AUX1 : MEM_CTRL_REG;
|
171 |
|
|
signal EX_CR_AUX : EX_CTRL_REG;
|
172 |
|
|
-- EX/MEM
|
173 |
|
|
signal WB_CR_AUX2 : WB_CTRL_REG;
|
174 |
|
|
signal MEM_CR_AUX2 : MEM_CTRL_REG;
|
175 |
|
|
signal NEW_PC_ADDR_AUX3 : STD_LOGIC_vector (INST_SIZE-1 downto 0);
|
176 |
|
|
signal ALU_FLAGS_AUX : ALU_FLAGS;
|
177 |
|
|
signal ALU_RES_AUX : STD_LOGIC_vector (INST_SIZE-1 downto 0);
|
178 |
|
|
signal RT_AUX2 : STD_LOGIC_vector (INST_SIZE-1 downto 0);
|
179 |
|
|
signal RT_RD_ADDR_AUX : STD_LOGIC_vector (ADDR_SIZE-1 downto 0);
|
180 |
|
|
--MEM/WB
|
181 |
|
|
signal WB_CR_AUX3 : WB_CTRL_REG;
|
182 |
|
|
signal READ_DATA_AUX : STD_LOGIC_vector (INST_SIZE-1 downto 0);
|
183 |
|
|
signal ADDRESS_AUX : STD_LOGIC_vector (INST_SIZE-1 downto 0);
|
184 |
|
|
signal WRITE_REG_AUX1 : STD_LOGIC_vector (ADDR_SIZE-1 downto 0);
|
185 |
|
|
|
186 |
|
|
begin
|
187 |
|
|
|
188 |
|
|
--Port maps
|
189 |
|
|
|
190 |
|
|
INST_FETCH:
|
191 |
|
|
INSTRUCTION_FETCHING port map(
|
192 |
|
|
--Entradas
|
193 |
|
|
CLK => CLK,
|
194 |
|
|
RESET => RESET,
|
195 |
|
|
PCSrc => PCSrc_AUX,
|
196 |
|
|
NEW_PC_ADDR_IN => NEW_PC_ADDR_AUX4,
|
197 |
|
|
--Salidas
|
198 |
|
|
NEW_PC_ADDR_OUT => NEW_PC_ADDR_AUX1,
|
199 |
|
|
INSTRUCTION => INSTRUCTION_AUX
|
200 |
|
|
);
|
201 |
|
|
|
202 |
|
|
INST_DECOD:
|
203 |
|
|
INSTRUCTION_DECODING port map(
|
204 |
|
|
--Entradas
|
205 |
|
|
CLK => CLK,
|
206 |
|
|
RESET => RESET,
|
207 |
|
|
INSTRUCTION => INSTRUCTION_AUX,
|
208 |
|
|
NEW_PC_ADDR_IN => NEW_PC_ADDR_AUX1,
|
209 |
|
|
RegWrite => RegWrite_AUX,
|
210 |
|
|
WRITE_DATA => WRITE_DATA_AUX,
|
211 |
|
|
WRITE_REG => WRITE_REG_AUX2,
|
212 |
|
|
--Salidas
|
213 |
|
|
NEW_PC_ADDR_OUT => NEW_PC_ADDR_AUX2,
|
214 |
|
|
OFFSET => OFFSET_AUX,
|
215 |
|
|
RT_ADDR => RT_ADDR_AUX,
|
216 |
|
|
RD_ADDR => RD_ADDR_AUX,
|
217 |
|
|
RS => RS_AUX,
|
218 |
|
|
RT => RT_AUX1,
|
219 |
|
|
WB_CR => WB_CR_AUX1,
|
220 |
|
|
MEM_CR => MEM_CR_AUX1,
|
221 |
|
|
EX_CR => EX_CR_AUX
|
222 |
|
|
);
|
223 |
|
|
|
224 |
|
|
EXE:
|
225 |
|
|
EXECUTION port map(
|
226 |
|
|
--Entradas
|
227 |
|
|
CLK => CLK,
|
228 |
|
|
RESET => RESET,
|
229 |
|
|
WB_CR => WB_CR_AUX1,
|
230 |
|
|
MEM_CR => MEM_CR_AUX1,
|
231 |
|
|
EX_CR => EX_CR_AUX,
|
232 |
|
|
NEW_PC_ADDR_IN => NEW_PC_ADDR_AUX2,
|
233 |
|
|
RS => RS_AUX,
|
234 |
|
|
RT => RT_AUX1,
|
235 |
|
|
OFFSET => OFFSET_AUX,
|
236 |
|
|
RT_ADDR => RT_ADDR_AUX,
|
237 |
|
|
RD_ADDR => RD_ADDR_AUX,
|
238 |
|
|
--Salidas
|
239 |
|
|
WB_CR_OUT => WB_CR_AUX2,
|
240 |
|
|
MEM_CR_OUT => MEM_CR_AUX2,
|
241 |
|
|
NEW_PC_ADDR_OUT => NEW_PC_ADDR_AUX3,
|
242 |
|
|
ALU_FLAGS_OUT => ALU_FLAGS_AUX,
|
243 |
|
|
ALU_RES_OUT => ALU_RES_AUX,
|
244 |
|
|
RT_OUT => RT_AUX2,
|
245 |
|
|
RT_RD_ADDR_OUT => RT_RD_ADDR_AUX
|
246 |
|
|
);
|
247 |
|
|
|
248 |
|
|
MEM_ACC:
|
249 |
|
|
MEMORY_ACCESS port map(
|
250 |
|
|
--Entradas
|
251 |
|
|
CLK => CLK,
|
252 |
|
|
RESET => RESET,
|
253 |
|
|
WB_IN => WB_CR_AUX2,
|
254 |
|
|
MEM => MEM_CR_AUX2,
|
255 |
|
|
FLAG_ZERO => ALU_FLAGS_AUX.Zero,
|
256 |
|
|
NEW_PC_ADDR => NEW_PC_ADDR_AUX3,
|
257 |
|
|
ADDRESS_IN => ALU_RES_AUX,
|
258 |
|
|
WRITE_DATA => RT_AUX2,
|
259 |
|
|
WRITE_REG_IN => RT_RD_ADDR_AUX,
|
260 |
|
|
--Salidas hacia la etapa WB, sincronizadas por registros
|
261 |
|
|
WB_OUT => WB_CR_AUX3,
|
262 |
|
|
READ_DATA => READ_DATA_AUX,
|
263 |
|
|
ADDRESS_OUT => ADDRESS_AUX,
|
264 |
|
|
WRITE_REG_OUT => WRITE_REG_AUX1,
|
265 |
|
|
--Salidas hacia la etapas IF, sin sincronización
|
266 |
|
|
NEW_PC_ADDR_OUT => NEW_PC_ADDR_AUX4,
|
267 |
|
|
PCSrc => PCSrc_AUX
|
268 |
|
|
);
|
269 |
|
|
|
270 |
|
|
WR_BK:
|
271 |
|
|
WRITE_BACK port map(
|
272 |
|
|
--Entradas
|
273 |
|
|
RESET => RESET,
|
274 |
|
|
WB => WB_CR_AUX3,
|
275 |
|
|
READ_DATA => READ_DATA_AUX,
|
276 |
|
|
ADDRESS => ADDRESS_AUX,
|
277 |
|
|
WRITE_REG => WRITE_REG_AUX1,
|
278 |
|
|
--Salidas hacia la etapas ID, sin sincronización
|
279 |
|
|
RegWrite => RegWrite_AUX,
|
280 |
|
|
WRITE_REG_OUT => WRITE_REG_AUX2,
|
281 |
|
|
WRITE_DATA => WRITE_DATA_AUX
|
282 |
|
|
);
|
283 |
|
|
|
284 |
|
|
|
285 |
|
|
end SEGMENTED_MIPS_ARC;
|