1 |
2 |
Bregalad |
-- This file is part of ARM4U CPU
|
2 |
|
|
--
|
3 |
|
|
-- This is a creation of the Laboratory of Processor Architecture
|
4 |
|
|
-- of Ecole Polytechnique Fédérale de Lausanne ( http://lap.epfl.ch )
|
5 |
|
|
--
|
6 |
|
|
-- cpu.vhd -- The top level module of the CPU
|
7 |
|
|
--
|
8 |
|
|
-- Written By - Jonathan Masur and Xavier Jimenez (2013)
|
9 |
|
|
--
|
10 |
|
|
-- This program is free software; you can redistribute it and/or modify it
|
11 |
|
|
-- under the terms of the GNU General Public License as published by the
|
12 |
|
|
-- Free Software Foundation; either version 2, or (at your option) any
|
13 |
|
|
-- later version.
|
14 |
|
|
--
|
15 |
|
|
-- This program is distributed in the hope that it will be useful,
|
16 |
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18 |
|
|
-- GNU General Public License for more details.
|
19 |
|
|
--
|
20 |
|
|
-- In other words, you are welcome to use, share and improve this program.
|
21 |
|
|
-- You are forbidden to forbid anyone else to use, share and improve
|
22 |
|
|
-- what you give them. Help stamp out software-hoarding!
|
23 |
|
|
|
24 |
|
|
library ieee;
|
25 |
|
|
use ieee.std_logic_1164.all;
|
26 |
|
|
use ieee.numeric_std.all;
|
27 |
|
|
use ieee.math_real.all;
|
28 |
|
|
use work.arm_types.all;
|
29 |
|
|
|
30 |
|
|
entity cpu is
|
31 |
|
|
generic(
|
32 |
|
|
CACHE_BLOCK_BITWIDTH : natural := 5 -- byte address range of a block (hence C_BLOCK_SIZE = 2**BLOCK_BITWIDTH)
|
33 |
|
|
);
|
34 |
|
|
port(
|
35 |
|
|
-- Globals
|
36 |
|
|
clk : in std_logic;
|
37 |
|
|
reset : in std_logic;
|
38 |
|
|
|
39 |
|
|
--Avalon Master Interface for instructions
|
40 |
|
|
avm_inst_waitrequest : in std_logic;
|
41 |
|
|
avm_inst_readdatavalid : in std_logic;
|
42 |
|
|
avm_inst_readdata : in std_logic_vector(31 downto 0);
|
43 |
|
|
avm_inst_read : out std_logic;
|
44 |
|
|
avm_inst_burstcount : out std_logic_vector(CACHE_BLOCK_BITWIDTH-2 downto 0);
|
45 |
|
|
avm_inst_address : out std_logic_vector(31 downto 0);
|
46 |
|
|
|
47 |
|
|
--Avalon Master Interface for data
|
48 |
|
|
avm_data_waitrequest : in std_logic;
|
49 |
|
|
avm_data_readdatavalid : in std_logic;
|
50 |
|
|
avm_data_readdata : in std_logic_vector(31 downto 0);
|
51 |
|
|
avm_data_read : out std_logic;
|
52 |
|
|
avm_data_writedata : out std_logic_vector(31 downto 0);
|
53 |
|
|
avm_data_write : out std_logic;
|
54 |
|
|
avm_data_byteen : out std_logic_vector(3 downto 0);
|
55 |
|
|
avm_data_burstcount : out std_logic_vector(4 downto 0);
|
56 |
|
|
avm_data_address : out std_logic_vector(31 downto 0);
|
57 |
|
|
|
58 |
|
|
--Interrupt interface
|
59 |
|
|
inr_irq : in std_logic_vector(31 downto 0) := (others => '0')
|
60 |
|
|
);
|
61 |
|
|
end entity;
|
62 |
|
|
|
63 |
|
|
architecture bench of cpu is
|
64 |
|
|
|
65 |
|
|
signal n_reset : std_logic := '0';
|
66 |
|
|
signal fiq, irq : std_logic;
|
67 |
|
|
signal inst_cache_adr, inst_data : std_logic_vector(31 downto 0);
|
68 |
|
|
signal inst_cache_miss, pc_wr : std_logic := '0';
|
69 |
|
|
signal pc_wrdata : unsigned(31 downto 0) := (others => 'Z');
|
70 |
|
|
signal fetch_stage_en, fetch_latch_enable : std_logic;
|
71 |
|
|
signal inst_cache_rd, flush, decode_stage_valid, decode_blocked_n, decode_latch_enable: std_logic;
|
72 |
|
|
signal low_flags : std_logic_vector(5 downto 0);
|
73 |
|
|
signal rfile_A_adr, rfile_B_adr, rfile_C_adr : std_logic_vector(4 downto 0);
|
74 |
|
|
signal dec_pc_plus_8, dec_pc_plus_4, exe_pc_plus_8, exe_pc_plus_4 : unsigned(31 downto 0);
|
75 |
|
|
signal exe_A_adr, exe_B_adr, exe_C_adr : std_logic_vector(5 downto 0);
|
76 |
|
|
signal rfile_A_data, rfile_B_data, rfile_C_data : std_logic_vector(31 downto 0);
|
77 |
|
|
signal exe_condition : std_logic_vector(3 downto 0);
|
78 |
|
|
signal exe_stage_valid, exe_barrelshift_operand, exe_opb_is_literal, exe_opb_sel, exe_affect_sflags, exe_data_sel, exe_rdest_wren, exe_branch_en, exe_wb_sel, exe_latch_enable : std_logic;
|
79 |
|
|
signal exe_barrelshift_type : std_logic_vector(1 downto 0);
|
80 |
|
|
signal exe_literal_shift_amnt, exe_rdest_adr : std_logic_vector(4 downto 0);
|
81 |
|
|
signal exe_literal_data : std_logic_vector(23 downto 0);
|
82 |
|
|
signal exe_alu_operation : ALU_OPERATION;
|
83 |
|
|
signal exe_mem_ctrl : MEM_OPERATION;
|
84 |
|
|
signal exe_mem_burstcount : std_logic_vector(3 downto 0);
|
85 |
|
|
signal exe_PC_wrdata : unsigned(31 downto 0);
|
86 |
|
|
signal exe_pc_wr, exe_blocked_n : std_logic;
|
87 |
|
|
signal mem_stage_valid, mem_rdest_wren, mem_branch_en, mem_wb_sel : std_logic;
|
88 |
|
|
signal mem_rdest_adr : std_logic_vector(4 downto 0);
|
89 |
|
|
signal mem_exe_data, mem_wrdata : std_logic_vector(31 downto 0);
|
90 |
|
|
signal mem_mem_ctrl : MEM_OPERATION;
|
91 |
|
|
signal mem_mem_burstcount : std_logic_vector(3 downto 0);
|
92 |
|
|
signal mem_blocked_n, mem_latch_enable, fwd_mem_enable : std_logic;
|
93 |
|
|
signal fwd_mem_address : std_logic_vector(4 downto 0);
|
94 |
|
|
signal fwd_mem_data : std_logic_vector(31 downto 0);
|
95 |
|
|
signal wb_stage_valid, wb_rdest_wren, wb_branch_en, wb_wb_sel : std_logic;
|
96 |
|
|
signal wb_rdest_adr : std_logic_vector(4 downto 0);
|
97 |
|
|
signal wb_exe_data : std_logic_vector(31 downto 0);
|
98 |
|
|
signal wb_mem_ctrl : MEM_OPERATION;
|
99 |
|
|
signal rfile_wr_enable, wb_pc_wr, wb_blocked_n : std_logic;
|
100 |
|
|
signal rfile_address : std_logic_vector(4 downto 0);
|
101 |
|
|
signal wb_data : std_logic_vector(31 downto 0);
|
102 |
|
|
signal fwd_wb2_enable : std_logic;
|
103 |
|
|
signal fwd_wb2_address : std_logic_vector(4 downto 0);
|
104 |
|
|
signal fwd_wb2_data : std_logic_vector(31 downto 0);
|
105 |
|
|
|
106 |
|
|
begin
|
107 |
|
|
|
108 |
|
|
n_reset <= not reset;
|
109 |
|
|
|
110 |
|
|
c: entity work.cache(synth) generic map(
|
111 |
|
|
INSTR_BADDR_BITWDTH => 32, -- input coe_cpu_address width in bits
|
112 |
|
|
BLOCK_BITWIDTH => CACHE_BLOCK_BITWIDTH, -- byte address range of a block (hence C_BLOCK_SIZE = 2**BLOCK_BITWIDTH)
|
113 |
|
|
CACHE_WAYS => 1, -- number of ways in the cache (power of 2), for now only direct-mapped
|
114 |
|
|
CACHE_SIZE => 4096 -- cache size in bytes, must be a factor of C_BLOCK_SIZE * CACHE_WAYS
|
115 |
|
|
) port map(
|
116 |
|
|
-- Globals
|
117 |
|
|
clk => clk,
|
118 |
|
|
reset => reset,
|
119 |
|
|
|
120 |
|
|
-- CPU conduit extern
|
121 |
|
|
coe_cpu_enabled => inst_cache_rd, -- fetches a new instruction. If deactivated, the last read is kept on the output.
|
122 |
|
|
coe_cpu_address => inst_cache_adr, -- byte address
|
123 |
|
|
coe_cpu_readdata => inst_data,
|
124 |
|
|
coe_cpu_miss => inst_cache_miss,
|
125 |
|
|
|
126 |
|
|
--Avalon Master Interface
|
127 |
|
|
avm_waitrequest => avm_inst_waitrequest,
|
128 |
|
|
avm_readdatavalid => avm_inst_readdatavalid,
|
129 |
|
|
avm_readdata => avm_inst_readdata,
|
130 |
|
|
avm_read => avm_inst_read,
|
131 |
|
|
avm_burstcount => avm_inst_burstcount,
|
132 |
|
|
avm_address => avm_inst_address
|
133 |
|
|
);
|
134 |
|
|
|
135 |
|
|
f : entity work.fetch(rtl) port map
|
136 |
|
|
(
|
137 |
|
|
clk => clk,
|
138 |
|
|
n_reset => n_reset,
|
139 |
|
|
decode_stage_valid => decode_stage_valid,
|
140 |
|
|
dec_pc_plus_8 => dec_pc_plus_8,
|
141 |
|
|
dec_pc_plus_4 => dec_pc_plus_4,
|
142 |
|
|
flush => flush,
|
143 |
|
|
inst_cache_adr => inst_cache_adr,
|
144 |
|
|
inst_cache_rd => inst_cache_rd,
|
145 |
|
|
pc_wr => pc_wr,
|
146 |
|
|
pc_wrdata => pc_wrdata,
|
147 |
|
|
fetch_stage_en => fetch_stage_en,
|
148 |
|
|
|
149 |
|
|
fetch_latch_enable => fetch_latch_enable
|
150 |
|
|
);
|
151 |
|
|
|
152 |
|
|
d : entity work.decode(rtl) port map
|
153 |
|
|
(
|
154 |
|
|
clk => clk,
|
155 |
|
|
reset_n => n_reset,
|
156 |
|
|
fiq => fiq,
|
157 |
|
|
irq => irq,
|
158 |
|
|
flush => flush,
|
159 |
|
|
low_flags => low_flags,
|
160 |
|
|
decode_stage_valid => decode_stage_valid,
|
161 |
|
|
inst_cache_miss => inst_cache_miss,
|
162 |
|
|
dec_pc_plus_8 => dec_pc_plus_8,
|
163 |
|
|
dec_pc_plus_4 => dec_pc_plus_4,
|
164 |
|
|
|
165 |
|
|
inst_data => inst_data,
|
166 |
|
|
decode_blocked_n => decode_blocked_n,
|
167 |
|
|
|
168 |
|
|
rfile_A_adr => rfile_A_adr,
|
169 |
|
|
rfile_B_adr => rfile_B_adr,
|
170 |
|
|
rfile_C_adr => rfile_C_adr,
|
171 |
|
|
|
172 |
|
|
exe_A_adr => exe_A_adr,
|
173 |
|
|
exe_B_adr => exe_B_adr,
|
174 |
|
|
exe_C_adr => exe_C_adr,
|
175 |
|
|
exe_pc_plus_4 => exe_pc_plus_4,
|
176 |
|
|
exe_pc_plus_8 => exe_pc_plus_8,
|
177 |
|
|
|
178 |
|
|
exe_stage_valid => exe_stage_valid,
|
179 |
|
|
exe_barrelshift_operand => exe_barrelshift_operand,
|
180 |
|
|
exe_barrelshift_type => exe_barrelshift_type,
|
181 |
|
|
exe_literal_shift_amnt => exe_literal_shift_amnt,
|
182 |
|
|
exe_literal_data => exe_literal_data,
|
183 |
|
|
exe_opb_is_literal => exe_opb_is_literal,
|
184 |
|
|
exe_opb_sel => exe_opb_sel,
|
185 |
|
|
exe_alu_operation => exe_alu_operation,
|
186 |
|
|
exe_condition => exe_condition,
|
187 |
|
|
exe_affect_sflags => exe_affect_sflags,
|
188 |
|
|
exe_data_sel => exe_data_sel,
|
189 |
|
|
exe_rdest_wren => exe_rdest_wren,
|
190 |
|
|
exe_rdest_adr => exe_rdest_adr,
|
191 |
|
|
exe_branch_en => exe_branch_en,
|
192 |
|
|
exe_wb_sel => exe_wb_sel,
|
193 |
|
|
exe_mem_ctrl => exe_mem_ctrl,
|
194 |
|
|
exe_mem_burstcount => exe_mem_burstcount,
|
195 |
|
|
|
196 |
|
|
decode_latch_enable => decode_latch_enable
|
197 |
|
|
);
|
198 |
|
|
|
199 |
|
|
e : entity work.execute(rtl) port map
|
200 |
|
|
(
|
201 |
|
|
clk => clk,
|
202 |
|
|
n_reset => n_reset,
|
203 |
|
|
|
204 |
|
|
exe_A_adr => exe_A_adr,
|
205 |
|
|
exe_B_adr => exe_B_adr,
|
206 |
|
|
exe_C_adr => exe_C_adr,
|
207 |
|
|
exe_stage_valid => exe_stage_valid,
|
208 |
|
|
exe_barrelshift_operand => exe_barrelshift_operand,
|
209 |
|
|
exe_barrelshift_type => exe_barrelshift_type,
|
210 |
|
|
exe_literal_shift_amnt => exe_literal_shift_amnt,
|
211 |
|
|
exe_literal_data => exe_literal_data,
|
212 |
|
|
exe_opb_is_literal => exe_opb_is_literal,
|
213 |
|
|
exe_opb_sel => exe_opb_sel,
|
214 |
|
|
exe_alu_operation => exe_alu_operation,
|
215 |
|
|
exe_condition => exe_condition,
|
216 |
|
|
exe_affect_sflags => exe_affect_sflags,
|
217 |
|
|
exe_data_sel => exe_data_sel,
|
218 |
|
|
exe_rdest_wren => exe_rdest_wren,
|
219 |
|
|
exe_rdest_adr => exe_rdest_adr,
|
220 |
|
|
exe_branch_en => exe_branch_en,
|
221 |
|
|
exe_wb_sel => exe_wb_sel,
|
222 |
|
|
exe_mem_ctrl => exe_mem_ctrl,
|
223 |
|
|
exe_mem_burstcount => exe_mem_burstcount,
|
224 |
|
|
|
225 |
|
|
exe_pc_plus_4 => exe_pc_plus_4,
|
226 |
|
|
exe_pc_plus_8 => exe_pc_plus_8,
|
227 |
|
|
|
228 |
|
|
rfile_A_data => rfile_A_data,
|
229 |
|
|
rfile_B_data => rfile_B_data,
|
230 |
|
|
rfile_C_data => rfile_C_data,
|
231 |
|
|
|
232 |
|
|
fwd_wb2_enable => fwd_wb2_enable,
|
233 |
|
|
fwd_wb2_address => fwd_wb2_address,
|
234 |
|
|
fwd_wb2_data => fwd_wb2_data,
|
235 |
|
|
fwd_wb1_enable => rfile_wr_enable,
|
236 |
|
|
fwd_wb1_address => rfile_address,
|
237 |
|
|
fwd_wb1_data => wb_exe_data,
|
238 |
|
|
fwd_wb1_is_invalid => wb_wb_sel,
|
239 |
|
|
fwd_mem_enable => fwd_mem_enable,
|
240 |
|
|
fwd_mem_address => fwd_mem_address,
|
241 |
|
|
fwd_mem_data => fwd_mem_data,
|
242 |
|
|
fwd_mem_is_invalid => mem_wb_sel,
|
243 |
|
|
|
244 |
|
|
mem_stage_valid => mem_stage_valid,
|
245 |
|
|
mem_rdest_wren => mem_rdest_wren,
|
246 |
|
|
mem_rdest_adr => mem_rdest_adr,
|
247 |
|
|
mem_branch_en => mem_branch_en,
|
248 |
|
|
mem_wb_sel => mem_wb_sel,
|
249 |
|
|
mem_exe_data => mem_exe_data,
|
250 |
|
|
mem_wrdata => mem_wrdata,
|
251 |
|
|
mem_mem_ctrl => mem_mem_ctrl,
|
252 |
|
|
mem_mem_burstcount => mem_mem_burstcount,
|
253 |
|
|
|
254 |
|
|
low_flags => low_flags,
|
255 |
|
|
exe_PC_wrdata => exe_PC_wrdata,
|
256 |
|
|
exe_PC_wr => exe_PC_wr,
|
257 |
|
|
|
258 |
|
|
exe_blocked_n => exe_blocked_n,
|
259 |
|
|
exe_latch_enable => exe_latch_enable
|
260 |
|
|
);
|
261 |
|
|
|
262 |
|
|
m : entity work.memory(rtl) port map
|
263 |
|
|
(
|
264 |
|
|
|
265 |
|
|
clk => clk,
|
266 |
|
|
reset_n => n_reset,
|
267 |
|
|
|
268 |
|
|
mem_stage_valid => mem_stage_valid,
|
269 |
|
|
mem_rdest_wren => mem_rdest_wren,
|
270 |
|
|
mem_rdest_adr => mem_rdest_adr,
|
271 |
|
|
mem_branch_en => mem_branch_en,
|
272 |
|
|
mem_wb_sel => mem_wb_sel,
|
273 |
|
|
mem_exe_data => mem_exe_data,
|
274 |
|
|
mem_wrdata => mem_wrdata,
|
275 |
|
|
mem_mem_ctrl => mem_mem_ctrl,
|
276 |
|
|
mem_mem_burstcount => mem_mem_burstcount,
|
277 |
|
|
|
278 |
|
|
wb_stage_valid => wb_stage_valid,
|
279 |
|
|
wb_rdest_wren => wb_rdest_wren,
|
280 |
|
|
wb_rdest_adr => wb_rdest_adr,
|
281 |
|
|
wb_branch_en => wb_branch_en,
|
282 |
|
|
wb_wb_sel => wb_wb_sel,
|
283 |
|
|
wb_exe_data => wb_exe_data,
|
284 |
|
|
wb_mem_ctrl => wb_mem_ctrl,
|
285 |
|
|
|
286 |
|
|
fwd_mem_enable => fwd_mem_enable,
|
287 |
|
|
fwd_mem_address => fwd_mem_address,
|
288 |
|
|
fwd_mem_data => fwd_mem_data,
|
289 |
|
|
|
290 |
|
|
avm_data_waitrequest => avm_data_waitrequest,
|
291 |
|
|
avm_data_read => avm_data_read,
|
292 |
|
|
avm_data_writedata => avm_data_writedata,
|
293 |
|
|
avm_data_write => avm_data_write,
|
294 |
|
|
avm_data_byteen => avm_data_byteen,
|
295 |
|
|
avm_data_burstcount => avm_data_burstcount,
|
296 |
|
|
avm_data_address => avm_data_address,
|
297 |
|
|
|
298 |
|
|
mem_blocked_n => mem_blocked_n,
|
299 |
|
|
mem_latch_enable => mem_latch_enable
|
300 |
|
|
);
|
301 |
|
|
|
302 |
|
|
w : entity work.writeback(rtl) port map
|
303 |
|
|
(
|
304 |
|
|
clk => clk,
|
305 |
|
|
|
306 |
|
|
wb_stage_valid => wb_stage_valid,
|
307 |
|
|
wb_rdest_wren => wb_rdest_wren,
|
308 |
|
|
wb_rdest_adr => wb_rdest_adr,
|
309 |
|
|
wb_branch_en => wb_branch_en,
|
310 |
|
|
wb_wb_sel => wb_wb_sel,
|
311 |
|
|
wb_exe_data => wb_exe_data,
|
312 |
|
|
wb_mem_ctrl => wb_mem_ctrl,
|
313 |
|
|
|
314 |
|
|
rfile_wr_enable => rfile_wr_enable,
|
315 |
|
|
rfile_address => rfile_address,
|
316 |
|
|
wb_data => wb_data,
|
317 |
|
|
|
318 |
|
|
fwd_wb2_enable => fwd_wb2_enable,
|
319 |
|
|
fwd_wb2_address => fwd_wb2_address,
|
320 |
|
|
fwd_wb2_data => fwd_wb2_data,
|
321 |
|
|
|
322 |
|
|
avm_data_readdatavalid => avm_data_readdatavalid,
|
323 |
|
|
avm_data_readdata => avm_data_readdata,
|
324 |
|
|
|
325 |
|
|
wb_pc_wr => wb_pc_wr,
|
326 |
|
|
wb_blocked_n => wb_blocked_n
|
327 |
|
|
);
|
328 |
|
|
|
329 |
|
|
rf : entity work.register_file(synth) port map
|
330 |
|
|
(
|
331 |
|
|
clk => clk,
|
332 |
|
|
aa => rfile_A_adr,
|
333 |
|
|
ab => rfile_B_adr,
|
334 |
|
|
ac => rfile_C_adr,
|
335 |
|
|
aw => rfile_address,
|
336 |
|
|
wren => rfile_wr_enable,
|
337 |
|
|
wrdata => wb_data,
|
338 |
|
|
a => rfile_A_data,
|
339 |
|
|
b => rfile_B_data,
|
340 |
|
|
c => rfile_C_data,
|
341 |
|
|
rd_clken => decode_latch_enable
|
342 |
|
|
);
|
343 |
|
|
|
344 |
|
|
fiq <= inr_irq(0);
|
345 |
|
|
irq <= '0' when inr_irq(31 downto 1) = (31 downto 1 => '0') else '1';
|
346 |
|
|
|
347 |
|
|
|
348 |
|
|
fetch_stage_en <= fetch_latch_enable;
|
349 |
|
|
fetch_latch_enable <= decode_latch_enable and decode_blocked_n;
|
350 |
|
|
decode_latch_enable <= exe_latch_enable and exe_blocked_n;
|
351 |
|
|
exe_latch_enable <= mem_latch_enable and mem_blocked_n;
|
352 |
|
|
mem_latch_enable <= wb_blocked_n;
|
353 |
|
|
|
354 |
|
|
pc_wrdata <= exe_pc_wrdata when exe_pc_wr = '1' else unsigned(wb_data);
|
355 |
|
|
pc_wr <= exe_pc_wr or wb_pc_wr;
|
356 |
|
|
end architecture bench;
|