1 |
2 |
jeunes2 |
-- This file is part of the marca processor.
|
2 |
|
|
-- Copyright (C) 2007 Wolfgang Puffitsch
|
3 |
|
|
|
4 |
|
|
-- This program is free software; you can redistribute it and/or modify it
|
5 |
|
|
-- under the terms of the GNU Library General Public License as published
|
6 |
|
|
-- by the Free Software Foundation; either version 2, or (at your option)
|
7 |
|
|
-- any later version.
|
8 |
|
|
|
9 |
|
|
-- This program is distributed in the hope that it will be useful,
|
10 |
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12 |
|
|
-- Library General Public License for more details.
|
13 |
|
|
|
14 |
|
|
-- You should have received a copy of the GNU Library General Public
|
15 |
|
|
-- License along with this program; if not, write to the Free Software
|
16 |
|
|
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
17 |
|
|
|
18 |
|
|
-------------------------------------------------------------------------------
|
19 |
|
|
-- MARCA top level architecture
|
20 |
|
|
-------------------------------------------------------------------------------
|
21 |
|
|
-- architecture of the processor itself
|
22 |
|
|
-------------------------------------------------------------------------------
|
23 |
|
|
|
24 |
|
|
-------------------------------------------------------------------------------
|
25 |
|
|
-- Wolfgang Puffitsch
|
26 |
|
|
-- Computer Architecture Lab, Group 3
|
27 |
|
|
-------------------------------------------------------------------------------
|
28 |
|
|
|
29 |
|
|
library IEEE;
|
30 |
|
|
use IEEE.std_logic_1164.all;
|
31 |
|
|
|
32 |
|
|
use work.marca_pkg.all;
|
33 |
|
|
|
34 |
|
|
architecture behaviour of marca is
|
35 |
|
|
|
36 |
|
|
component fetch
|
37 |
|
|
port (
|
38 |
|
|
clock : in std_logic;
|
39 |
|
|
reset : in std_logic;
|
40 |
|
|
|
41 |
|
|
hold : in std_logic;
|
42 |
|
|
|
43 |
|
|
pcena : in std_logic;
|
44 |
|
|
pc_in : in std_logic_vector(REG_WIDTH-1 downto 0);
|
45 |
|
|
pc_out : out std_logic_vector(REG_WIDTH-1 downto 0);
|
46 |
|
|
|
47 |
|
|
src1 : out std_logic_vector(REG_COUNT_LOG-1 downto 0);
|
48 |
|
|
src2 : out std_logic_vector(REG_COUNT_LOG-1 downto 0);
|
49 |
|
|
dest : out std_logic_vector(REG_COUNT_LOG-1 downto 0);
|
50 |
|
|
instr : out std_logic_vector(PDATA_WIDTH-1 downto 0));
|
51 |
|
|
end component;
|
52 |
|
|
|
53 |
|
|
signal fetch_pc : std_logic_vector(REG_WIDTH-1 downto 0);
|
54 |
|
|
signal fetch_src1 : std_logic_vector(REG_COUNT_LOG-1 downto 0);
|
55 |
|
|
signal fetch_src2 : std_logic_vector(REG_COUNT_LOG-1 downto 0);
|
56 |
|
|
signal fetch_dest : std_logic_vector(REG_COUNT_LOG-1 downto 0);
|
57 |
|
|
signal fetch_instr : std_logic_vector(PDATA_WIDTH-1 downto 0);
|
58 |
|
|
|
59 |
|
|
component decode
|
60 |
|
|
port (
|
61 |
|
|
clock : in std_logic;
|
62 |
|
|
reset : in std_logic;
|
63 |
|
|
|
64 |
|
|
hold : in std_logic;
|
65 |
|
|
stall : in std_logic;
|
66 |
|
|
|
67 |
|
|
pc_in : in std_logic_vector(REG_WIDTH-1 downto 0);
|
68 |
|
|
pc_out : out std_logic_vector(REG_WIDTH-1 downto 0);
|
69 |
|
|
|
70 |
|
|
instr : in std_logic_vector(PDATA_WIDTH-1 downto 0);
|
71 |
|
|
|
72 |
|
|
src1_in : in std_logic_vector(REG_COUNT_LOG-1 downto 0);
|
73 |
|
|
src1_out : out std_logic_vector(REG_COUNT_LOG-1 downto 0);
|
74 |
|
|
src2_in : in std_logic_vector(REG_COUNT_LOG-1 downto 0);
|
75 |
|
|
src2_out : out std_logic_vector(REG_COUNT_LOG-1 downto 0);
|
76 |
|
|
|
77 |
|
|
dest_in : in std_logic_vector(REG_COUNT_LOG-1 downto 0);
|
78 |
|
|
dest_out : out std_logic_vector(REG_COUNT_LOG-1 downto 0);
|
79 |
|
|
|
80 |
|
|
aop : out ALU_OP;
|
81 |
|
|
mop : out MEM_OP;
|
82 |
|
|
iop : out INTR_OP;
|
83 |
|
|
|
84 |
|
|
op1 : out std_logic_vector(REG_WIDTH-1 downto 0);
|
85 |
|
|
op2 : out std_logic_vector(REG_WIDTH-1 downto 0);
|
86 |
|
|
imm : out std_logic_vector(REG_WIDTH-1 downto 0);
|
87 |
|
|
|
88 |
|
|
unit : out UNIT_SELECTOR;
|
89 |
|
|
target : out TARGET_SELECTOR;
|
90 |
|
|
|
91 |
|
|
wr_ena : in std_logic;
|
92 |
|
|
wr_dest : in std_logic_vector(REG_COUNT_LOG-1 downto 0);
|
93 |
|
|
wr_val : in std_logic_vector(REG_WIDTH-1 downto 0));
|
94 |
|
|
end component;
|
95 |
|
|
|
96 |
|
|
signal decode_pc : std_logic_vector(REG_WIDTH-1 downto 0);
|
97 |
|
|
signal decode_op1 : std_logic_vector(REG_WIDTH-1 downto 0);
|
98 |
|
|
signal decode_op2 : std_logic_vector(REG_WIDTH-1 downto 0);
|
99 |
|
|
signal decode_imm : std_logic_vector(REG_WIDTH-1 downto 0);
|
100 |
|
|
signal decode_src1 : std_logic_vector(REG_COUNT_LOG-1 downto 0);
|
101 |
|
|
signal decode_src2 : std_logic_vector(REG_COUNT_LOG-1 downto 0);
|
102 |
|
|
signal decode_dest : std_logic_vector(REG_COUNT_LOG-1 downto 0);
|
103 |
|
|
signal decode_aop : ALU_OP;
|
104 |
|
|
signal decode_mop : MEM_OP;
|
105 |
|
|
signal decode_iop : INTR_OP;
|
106 |
|
|
signal decode_unit : UNIT_SELECTOR;
|
107 |
|
|
signal decode_target : TARGET_SELECTOR;
|
108 |
|
|
signal decode_instr : std_logic_vector(PDATA_WIDTH-1 downto 0);
|
109 |
|
|
|
110 |
|
|
component execute is
|
111 |
|
|
port (
|
112 |
|
|
clock : in std_logic;
|
113 |
|
|
reset : in std_logic;
|
114 |
|
|
|
115 |
|
|
busy : out std_logic;
|
116 |
|
|
stall : in std_logic;
|
117 |
|
|
|
118 |
|
|
pc_in : in std_logic_vector(REG_WIDTH-1 downto 0);
|
119 |
|
|
pcchg : out std_logic;
|
120 |
|
|
pc_out : out std_logic_vector(REG_WIDTH-1 downto 0);
|
121 |
|
|
|
122 |
|
|
dest_in : in std_logic_vector(REG_COUNT_LOG-1 downto 0);
|
123 |
|
|
dest_out : out std_logic_vector(REG_COUNT_LOG-1 downto 0);
|
124 |
|
|
|
125 |
|
|
src1 : in std_logic_vector(REG_COUNT_LOG-1 downto 0);
|
126 |
|
|
src2 : in std_logic_vector(REG_COUNT_LOG-1 downto 0);
|
127 |
|
|
|
128 |
|
|
aop : in ALU_OP;
|
129 |
|
|
mop : in MEM_OP;
|
130 |
|
|
iop : in INTR_OP;
|
131 |
|
|
|
132 |
|
|
op1 : in std_logic_vector(REG_WIDTH-1 downto 0);
|
133 |
|
|
op2 : in std_logic_vector(REG_WIDTH-1 downto 0);
|
134 |
|
|
imm : in std_logic_vector(REG_WIDTH-1 downto 0);
|
135 |
|
|
|
136 |
|
|
unit : in UNIT_SELECTOR;
|
137 |
|
|
target_in : in TARGET_SELECTOR;
|
138 |
|
|
target_out : out TARGET_SELECTOR;
|
139 |
|
|
|
140 |
|
|
result : out std_logic_vector(REG_WIDTH-1 downto 0);
|
141 |
|
|
|
142 |
|
|
fw_ena : in std_logic;
|
143 |
|
|
fw_dest : in std_logic_vector(REG_COUNT_LOG-1 downto 0);
|
144 |
|
|
fw_val : in std_logic_vector(REG_WIDTH-1 downto 0);
|
145 |
|
|
|
146 |
|
|
ext_in : in std_logic_vector(IN_BITS-1 downto 0);
|
147 |
|
|
ext_out : out std_logic_vector(OUT_BITS-1 downto 0));
|
148 |
|
|
end component;
|
149 |
|
|
|
150 |
|
|
signal exec_busy : std_logic;
|
151 |
|
|
signal exec_pcchg : std_logic;
|
152 |
|
|
signal exec_pc : std_logic_vector(REG_WIDTH-1 downto 0);
|
153 |
|
|
signal exec_dest : std_logic_vector(REG_COUNT_LOG-1 downto 0);
|
154 |
|
|
signal exec_target : TARGET_SELECTOR;
|
155 |
|
|
signal exec_result : std_logic_vector(REG_WIDTH-1 downto 0);
|
156 |
|
|
|
157 |
|
|
component writeback is
|
158 |
|
|
port (
|
159 |
|
|
clock : in std_logic;
|
160 |
|
|
reset : in std_logic;
|
161 |
|
|
|
162 |
|
|
hold : in std_logic;
|
163 |
|
|
|
164 |
|
|
pc_in : in std_logic_vector(REG_WIDTH-1 downto 0);
|
165 |
|
|
pcchg : in std_logic;
|
166 |
|
|
pc_out : out std_logic_vector(REG_WIDTH-1 downto 0);
|
167 |
|
|
pcena : out std_logic;
|
168 |
|
|
|
169 |
|
|
dest_in : in std_logic_vector(REG_COUNT_LOG-1 downto 0);
|
170 |
|
|
dest_out : out std_logic_vector(REG_COUNT_LOG-1 downto 0);
|
171 |
|
|
|
172 |
|
|
target : in TARGET_SELECTOR;
|
173 |
|
|
result : in std_logic_vector(REG_WIDTH-1 downto 0);
|
174 |
|
|
|
175 |
|
|
ena : out std_logic;
|
176 |
|
|
val : out std_logic_vector(REG_WIDTH-1 downto 0));
|
177 |
|
|
end component;
|
178 |
|
|
|
179 |
|
|
signal wb_pc : std_logic_vector(REG_WIDTH-1 downto 0);
|
180 |
|
|
signal wb_pcena : std_logic;
|
181 |
|
|
signal wb_dest : std_logic_vector(REG_COUNT_LOG-1 downto 0);
|
182 |
|
|
signal wb_ena : std_logic;
|
183 |
|
|
signal wb_val : std_logic_vector(REG_WIDTH-1 downto 0);
|
184 |
|
|
|
185 |
|
|
signal decode_stall : std_logic;
|
186 |
|
|
|
187 |
|
|
signal reset : std_logic;
|
188 |
|
|
signal meta_reset : std_logic;
|
189 |
|
|
|
190 |
|
|
begin -- behaviour
|
191 |
|
|
|
192 |
|
|
-- in the decode and execution stage we need to stall a little earlier
|
193 |
|
|
decode_stall <= exec_pcchg or wb_pcena;
|
194 |
|
|
|
195 |
|
|
fetch_stage : fetch
|
196 |
|
|
port map (
|
197 |
|
|
clock => clock,
|
198 |
|
|
reset => reset,
|
199 |
|
|
hold => exec_busy,
|
200 |
|
|
pcena => wb_pcena,
|
201 |
|
|
pc_in => wb_pc,
|
202 |
|
|
pc_out => fetch_pc,
|
203 |
|
|
src1 => fetch_src1,
|
204 |
|
|
src2 => fetch_src2,
|
205 |
|
|
dest => fetch_dest,
|
206 |
|
|
instr => fetch_instr);
|
207 |
|
|
|
208 |
|
|
decode_stage : decode
|
209 |
|
|
port map (
|
210 |
|
|
clock => clock,
|
211 |
|
|
reset => reset,
|
212 |
|
|
hold => exec_busy,
|
213 |
|
|
stall => decode_stall,
|
214 |
|
|
pc_in => fetch_pc,
|
215 |
|
|
pc_out => decode_pc,
|
216 |
|
|
instr => fetch_instr,
|
217 |
|
|
src1_in => fetch_src1,
|
218 |
|
|
src1_out => decode_src1,
|
219 |
|
|
src2_in => fetch_src2,
|
220 |
|
|
src2_out => decode_src2,
|
221 |
|
|
dest_in => fetch_dest,
|
222 |
|
|
dest_out => decode_dest,
|
223 |
|
|
aop => decode_aop,
|
224 |
|
|
mop => decode_mop,
|
225 |
|
|
iop => decode_iop,
|
226 |
|
|
op1 => decode_op1,
|
227 |
|
|
op2 => decode_op2,
|
228 |
|
|
imm => decode_imm,
|
229 |
|
|
unit => decode_unit,
|
230 |
|
|
target => decode_target,
|
231 |
|
|
wr_ena => wb_ena,
|
232 |
|
|
wr_dest => wb_dest,
|
233 |
|
|
wr_val => wb_val);
|
234 |
|
|
|
235 |
|
|
execution_stage : execute
|
236 |
|
|
port map (
|
237 |
|
|
clock => clock,
|
238 |
|
|
reset => reset,
|
239 |
|
|
busy => exec_busy,
|
240 |
|
|
stall => exec_pcchg,
|
241 |
|
|
pc_in => decode_pc,
|
242 |
|
|
pcchg => exec_pcchg,
|
243 |
|
|
pc_out => exec_pc,
|
244 |
|
|
dest_in => decode_dest,
|
245 |
|
|
dest_out => exec_dest,
|
246 |
|
|
src1 => decode_src1,
|
247 |
|
|
src2 => decode_src2,
|
248 |
|
|
aop => decode_aop,
|
249 |
|
|
mop => decode_mop,
|
250 |
|
|
iop => decode_iop,
|
251 |
|
|
op1 => decode_op1,
|
252 |
|
|
op2 => decode_op2,
|
253 |
|
|
imm => decode_imm,
|
254 |
|
|
unit => decode_unit,
|
255 |
|
|
target_in => decode_target,
|
256 |
|
|
target_out => exec_target,
|
257 |
|
|
result => exec_result,
|
258 |
|
|
fw_ena => wb_ena,
|
259 |
|
|
fw_dest => wb_dest,
|
260 |
|
|
fw_val => wb_val,
|
261 |
|
|
ext_in => ext_in,
|
262 |
|
|
ext_out => ext_out);
|
263 |
|
|
|
264 |
|
|
writeback_stage : writeback
|
265 |
|
|
port map (
|
266 |
|
|
clock => clock,
|
267 |
|
|
reset => reset,
|
268 |
|
|
hold => exec_busy,
|
269 |
|
|
pc_in => exec_pc,
|
270 |
|
|
pcchg => exec_pcchg,
|
271 |
|
|
pc_out => wb_pc,
|
272 |
|
|
pcena => wb_pcena,
|
273 |
|
|
dest_in => exec_dest,
|
274 |
|
|
dest_out => wb_dest,
|
275 |
|
|
target => exec_target,
|
276 |
|
|
result => exec_result,
|
277 |
|
|
ena => wb_ena,
|
278 |
|
|
val => wb_val);
|
279 |
|
|
|
280 |
|
|
synchronize: process (clock, ext_reset, meta_reset)
|
281 |
|
|
begin
|
282 |
|
|
if clock'event and clock = '1' then
|
283 |
|
|
meta_reset <= ext_reset;
|
284 |
|
|
reset <= meta_reset;
|
285 |
|
|
end if;
|
286 |
|
|
end process synchronize;
|
287 |
|
|
|
288 |
|
|
end behaviour;
|