1 |
2 |
zero_gravi |
-- #################################################################################################
|
2 |
|
|
-- # << NEORV32 - CPU Top Entity >> #
|
3 |
|
|
-- # ********************************************************************************************* #
|
4 |
|
|
-- # Top NEORV32 CPU: #
|
5 |
13 |
zero_gravi |
-- # * neorv32_cpu.vhd : CPU top entity #
|
6 |
|
|
-- # * neorv32_cpu_alu.vhd : Arithmetic/logic unit #
|
7 |
|
|
-- # * neorv32_cpu_bus.vhd : Instruction and data bus interface unit #
|
8 |
|
|
-- # * neorv32_cpu_cp_muldiv.vhd : MULDIV co-processor #
|
9 |
|
|
-- # * neorv32_cpu_ctrl.vhd : CPU control and CSR system #
|
10 |
|
|
-- # * neorv32_cpu_decompressor.vhd : Compressed instructions decoder #
|
11 |
|
|
-- # * neorv32_cpu_regfile.vhd : Data register file #
|
12 |
2 |
zero_gravi |
-- # ********************************************************************************************* #
|
13 |
|
|
-- # BSD 3-Clause License #
|
14 |
|
|
-- # #
|
15 |
|
|
-- # Copyright (c) 2020, Stephan Nolting. All rights reserved. #
|
16 |
|
|
-- # #
|
17 |
|
|
-- # Redistribution and use in source and binary forms, with or without modification, are #
|
18 |
|
|
-- # permitted provided that the following conditions are met: #
|
19 |
|
|
-- # #
|
20 |
|
|
-- # 1. Redistributions of source code must retain the above copyright notice, this list of #
|
21 |
|
|
-- # conditions and the following disclaimer. #
|
22 |
|
|
-- # #
|
23 |
|
|
-- # 2. Redistributions in binary form must reproduce the above copyright notice, this list of #
|
24 |
|
|
-- # conditions and the following disclaimer in the documentation and/or other materials #
|
25 |
|
|
-- # provided with the distribution. #
|
26 |
|
|
-- # #
|
27 |
|
|
-- # 3. Neither the name of the copyright holder nor the names of its contributors may be used to #
|
28 |
|
|
-- # endorse or promote products derived from this software without specific prior written #
|
29 |
|
|
-- # permission. #
|
30 |
|
|
-- # #
|
31 |
|
|
-- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS #
|
32 |
|
|
-- # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF #
|
33 |
|
|
-- # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE #
|
34 |
|
|
-- # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, #
|
35 |
|
|
-- # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE #
|
36 |
|
|
-- # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED #
|
37 |
|
|
-- # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING #
|
38 |
|
|
-- # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED #
|
39 |
|
|
-- # OF THE POSSIBILITY OF SUCH DAMAGE. #
|
40 |
|
|
-- # ********************************************************************************************* #
|
41 |
|
|
-- # The NEORV32 Processor - https://github.com/stnolting/neorv32 (c) Stephan Nolting #
|
42 |
|
|
-- #################################################################################################
|
43 |
|
|
|
44 |
|
|
library ieee;
|
45 |
|
|
use ieee.std_logic_1164.all;
|
46 |
|
|
use ieee.numeric_std.all;
|
47 |
|
|
|
48 |
|
|
library neorv32;
|
49 |
|
|
use neorv32.neorv32_package.all;
|
50 |
|
|
|
51 |
|
|
entity neorv32_cpu is
|
52 |
|
|
generic (
|
53 |
|
|
-- General --
|
54 |
12 |
zero_gravi |
CSR_COUNTERS_USE : boolean := true; -- implement RISC-V perf. counters ([m]instret[h], [m]cycle[h], time[h])?
|
55 |
14 |
zero_gravi |
HW_THREAD_ID : std_ulogic_vector(31 downto 0):= (others => '0'); -- hardware thread id
|
56 |
|
|
CPU_BOOT_ADDR : std_ulogic_vector(31 downto 0):= (others => '0'); -- cpu boot address
|
57 |
2 |
zero_gravi |
-- RISC-V CPU Extensions --
|
58 |
12 |
zero_gravi |
CPU_EXTENSION_RISCV_C : boolean := false; -- implement compressed extension?
|
59 |
|
|
CPU_EXTENSION_RISCV_E : boolean := false; -- implement embedded RF extension?
|
60 |
|
|
CPU_EXTENSION_RISCV_M : boolean := false; -- implement muld/div extension?
|
61 |
15 |
zero_gravi |
CPU_EXTENSION_RISCV_U : boolean := false; -- implement user mode extension?
|
62 |
12 |
zero_gravi |
CPU_EXTENSION_RISCV_Zicsr : boolean := true; -- implement CSR system?
|
63 |
|
|
CPU_EXTENSION_RISCV_Zifencei : boolean := true; -- implement instruction stream sync.?
|
64 |
15 |
zero_gravi |
-- Physical Memory Protection (PMP) --
|
65 |
|
|
PMP_USE : boolean := false; -- implement PMP?
|
66 |
|
|
PMP_NUM_REGIONS : natural := 4; -- number of regions (max 16)
|
67 |
|
|
PMP_GRANULARITY : natural := 15; -- region granularity (1=8B, 2=16B, 3=32B, ...) default is 64k
|
68 |
14 |
zero_gravi |
-- Bus Interface --
|
69 |
|
|
BUS_TIMEOUT : natural := 15 -- cycles after which a valid bus access will timeout
|
70 |
2 |
zero_gravi |
);
|
71 |
|
|
port (
|
72 |
|
|
-- global control --
|
73 |
14 |
zero_gravi |
clk_i : in std_ulogic := '0'; -- global clock, rising edge
|
74 |
|
|
rstn_i : in std_ulogic := '0'; -- global reset, low-active, async
|
75 |
12 |
zero_gravi |
-- instruction bus interface --
|
76 |
|
|
i_bus_addr_o : out std_ulogic_vector(data_width_c-1 downto 0); -- bus access address
|
77 |
14 |
zero_gravi |
i_bus_rdata_i : in std_ulogic_vector(data_width_c-1 downto 0) := (others => '0'); -- bus read data
|
78 |
12 |
zero_gravi |
i_bus_wdata_o : out std_ulogic_vector(data_width_c-1 downto 0); -- bus write data
|
79 |
|
|
i_bus_ben_o : out std_ulogic_vector(03 downto 0); -- byte enable
|
80 |
|
|
i_bus_we_o : out std_ulogic; -- write enable
|
81 |
|
|
i_bus_re_o : out std_ulogic; -- read enable
|
82 |
|
|
i_bus_cancel_o : out std_ulogic; -- cancel current bus transaction
|
83 |
14 |
zero_gravi |
i_bus_ack_i : in std_ulogic := '0'; -- bus transfer acknowledge
|
84 |
|
|
i_bus_err_i : in std_ulogic := '0'; -- bus transfer error
|
85 |
12 |
zero_gravi |
i_bus_fence_o : out std_ulogic; -- executed FENCEI operation
|
86 |
|
|
-- data bus interface --
|
87 |
|
|
d_bus_addr_o : out std_ulogic_vector(data_width_c-1 downto 0); -- bus access address
|
88 |
14 |
zero_gravi |
d_bus_rdata_i : in std_ulogic_vector(data_width_c-1 downto 0) := (others => '0'); -- bus read data
|
89 |
12 |
zero_gravi |
d_bus_wdata_o : out std_ulogic_vector(data_width_c-1 downto 0); -- bus write data
|
90 |
|
|
d_bus_ben_o : out std_ulogic_vector(03 downto 0); -- byte enable
|
91 |
|
|
d_bus_we_o : out std_ulogic; -- write enable
|
92 |
|
|
d_bus_re_o : out std_ulogic; -- read enable
|
93 |
|
|
d_bus_cancel_o : out std_ulogic; -- cancel current bus transaction
|
94 |
14 |
zero_gravi |
d_bus_ack_i : in std_ulogic := '0'; -- bus transfer acknowledge
|
95 |
|
|
d_bus_err_i : in std_ulogic := '0'; -- bus transfer error
|
96 |
12 |
zero_gravi |
d_bus_fence_o : out std_ulogic; -- executed FENCE operation
|
97 |
11 |
zero_gravi |
-- system time input from MTIME --
|
98 |
14 |
zero_gravi |
time_i : in std_ulogic_vector(63 downto 0) := (others => '0'); -- current system time
|
99 |
|
|
-- interrupts (risc-v compliant) --
|
100 |
|
|
msw_irq_i : in std_ulogic := '0'; -- machine software interrupt
|
101 |
|
|
mext_irq_i : in std_ulogic := '0'; -- machine external interrupt
|
102 |
|
|
mtime_irq_i : in std_ulogic := '0'; -- machine timer interrupt
|
103 |
|
|
-- fast interrupts (custom) --
|
104 |
|
|
firq_i : in std_ulogic_vector(3 downto 0) := (others => '0')
|
105 |
2 |
zero_gravi |
);
|
106 |
|
|
end neorv32_cpu;
|
107 |
|
|
|
108 |
|
|
architecture neorv32_cpu_rtl of neorv32_cpu is
|
109 |
|
|
|
110 |
|
|
-- local signals --
|
111 |
12 |
zero_gravi |
signal ctrl : std_ulogic_vector(ctrl_width_c-1 downto 0); -- main control bus
|
112 |
|
|
signal alu_cmp : std_ulogic_vector(1 downto 0); -- alu comparator result
|
113 |
|
|
signal imm : std_ulogic_vector(data_width_c-1 downto 0); -- immediate
|
114 |
|
|
signal instr : std_ulogic_vector(data_width_c-1 downto 0); -- new instruction
|
115 |
|
|
signal rs1, rs2 : std_ulogic_vector(data_width_c-1 downto 0); -- source registers
|
116 |
|
|
signal alu_res : std_ulogic_vector(data_width_c-1 downto 0); -- alu result
|
117 |
|
|
signal alu_add : std_ulogic_vector(data_width_c-1 downto 0); -- alu adder result
|
118 |
|
|
signal rdata : std_ulogic_vector(data_width_c-1 downto 0); -- memory read data
|
119 |
|
|
signal alu_wait : std_ulogic; -- alu is busy due to iterative unit
|
120 |
|
|
signal bus_i_wait : std_ulogic; -- wait for current bus instruction fetch
|
121 |
|
|
signal bus_d_wait : std_ulogic; -- wait for current bus data access
|
122 |
|
|
signal csr_rdata : std_ulogic_vector(data_width_c-1 downto 0); -- csr read data
|
123 |
|
|
signal mar : std_ulogic_vector(data_width_c-1 downto 0); -- current memory address register
|
124 |
|
|
signal ma_instr : std_ulogic; -- misaligned instruction address
|
125 |
|
|
signal ma_load : std_ulogic; -- misaligned load data address
|
126 |
|
|
signal ma_store : std_ulogic; -- misaligned store data address
|
127 |
|
|
signal be_instr : std_ulogic; -- bus error on instruction access
|
128 |
|
|
signal be_load : std_ulogic; -- bus error on load data access
|
129 |
|
|
signal be_store : std_ulogic; -- bus error on store data access
|
130 |
|
|
signal fetch_pc : std_ulogic_vector(data_width_c-1 downto 0); -- pc for instruction fetch
|
131 |
|
|
signal curr_pc : std_ulogic_vector(data_width_c-1 downto 0); -- current pc (for current executed instruction)
|
132 |
|
|
signal next_pc : std_ulogic_vector(data_width_c-1 downto 0); -- next pc (for current executed instruction)
|
133 |
2 |
zero_gravi |
|
134 |
|
|
-- co-processor interface --
|
135 |
|
|
signal cp0_data, cp1_data : std_ulogic_vector(data_width_c-1 downto 0);
|
136 |
|
|
signal cp0_valid, cp1_valid : std_ulogic;
|
137 |
|
|
|
138 |
15 |
zero_gravi |
-- pmp interface --
|
139 |
|
|
signal pmp_addr : pmp_addr_if_t;
|
140 |
|
|
signal pmp_maddr : pmp_addr_if_t;
|
141 |
|
|
signal pmp_ctrl : pmp_ctrl_if_t;
|
142 |
|
|
signal priv_mode : std_ulogic_vector(1 downto 0); -- current CPU privilege level
|
143 |
|
|
|
144 |
2 |
zero_gravi |
begin
|
145 |
|
|
|
146 |
15 |
zero_gravi |
-- Sanity Checks --------------------------------------------------------------------------
|
147 |
|
|
-- -------------------------------------------------------------------------------------------
|
148 |
|
|
sanity_check: process(clk_i)
|
149 |
|
|
begin
|
150 |
|
|
if rising_edge(clk_i) then
|
151 |
|
|
-- CSR system --
|
152 |
|
|
if (CPU_EXTENSION_RISCV_Zicsr = false) then
|
153 |
|
|
assert false report "NEORV32 CONFIG WARNING! No exception/interrupt/machine features available when CPU_EXTENSION_RISCV_Zicsr = false." severity warning;
|
154 |
|
|
end if;
|
155 |
|
|
-- U-extension requires Zicsr extension --
|
156 |
|
|
if (CPU_EXTENSION_RISCV_Zicsr = false) and (CPU_EXTENSION_RISCV_U = true) then
|
157 |
|
|
assert false report "NEORV32 CONFIG ERROR! User mode requires CPU_EXTENSION_RISCV_Zicsr = true." severity error;
|
158 |
|
|
end if;
|
159 |
|
|
-- PMP requires Zicsr extension --
|
160 |
|
|
if (CPU_EXTENSION_RISCV_Zicsr = false) and (PMP_USE = true) then
|
161 |
|
|
assert false report "NEORV32 CONFIG ERROR! Physical memory protection (PMP) requires CPU_EXTENSION_RISCV_Zicsr = true." severity error;
|
162 |
|
|
end if;
|
163 |
|
|
-- performance counters requires Zicsr extension --
|
164 |
|
|
if (CPU_EXTENSION_RISCV_Zicsr = false) and (CSR_COUNTERS_USE = true) then
|
165 |
|
|
assert false report "NEORV32 CONFIG ERROR! Performance counter CSRs require CPU_EXTENSION_RISCV_Zicsr = true." severity error;
|
166 |
|
|
end if;
|
167 |
|
|
-- PMP regions --
|
168 |
|
|
if (PMP_NUM_REGIONS > pmp_max_r_c) and (PMP_USE = true) then
|
169 |
|
|
assert false report "NEORV32 CONFIG ERROR! Number of PMP regions out of valid range." severity error;
|
170 |
|
|
end if;
|
171 |
|
|
-- PMP granulartiy --
|
172 |
|
|
if ((PMP_GRANULARITY <= 1) or (PMP_GRANULARITY > 31)) and (PMP_USE = true) then
|
173 |
|
|
assert false report "NEORV32 CONFIG ERROR! Invalid PMP grnaulartiy (1 < G < 32)." severity error;
|
174 |
|
|
end if;
|
175 |
|
|
end if;
|
176 |
|
|
end process sanity_check;
|
177 |
|
|
|
178 |
2 |
zero_gravi |
-- Control Unit ---------------------------------------------------------------------------
|
179 |
|
|
-- -------------------------------------------------------------------------------------------
|
180 |
|
|
neorv32_cpu_control_inst: neorv32_cpu_control
|
181 |
|
|
generic map (
|
182 |
|
|
-- General --
|
183 |
8 |
zero_gravi |
CSR_COUNTERS_USE => CSR_COUNTERS_USE, -- implement RISC-V perf. counters ([m]instret[h], [m]cycle[h], time[h])?
|
184 |
12 |
zero_gravi |
HW_THREAD_ID => HW_THREAD_ID, -- hardware thread id
|
185 |
|
|
CPU_BOOT_ADDR => CPU_BOOT_ADDR, -- cpu boot address
|
186 |
2 |
zero_gravi |
-- RISC-V CPU Extensions --
|
187 |
15 |
zero_gravi |
CPU_EXTENSION_RISCV_C => CPU_EXTENSION_RISCV_C, -- implement compressed extension?
|
188 |
|
|
CPU_EXTENSION_RISCV_E => CPU_EXTENSION_RISCV_E, -- implement embedded RF extension?
|
189 |
|
|
CPU_EXTENSION_RISCV_M => CPU_EXTENSION_RISCV_M, -- implement muld/div extension?
|
190 |
|
|
CPU_EXTENSION_RISCV_U => CPU_EXTENSION_RISCV_U, -- implement user mode extension?
|
191 |
|
|
CPU_EXTENSION_RISCV_Zicsr => CPU_EXTENSION_RISCV_Zicsr, -- implement CSR system?
|
192 |
|
|
CPU_EXTENSION_RISCV_Zifencei => CPU_EXTENSION_RISCV_Zifencei, -- implement instruction stream sync.?
|
193 |
|
|
-- Physical memory protection (PMP) --
|
194 |
|
|
PMP_USE => PMP_USE, -- implement physical memory protection?
|
195 |
|
|
PMP_NUM_REGIONS => PMP_NUM_REGIONS, -- number of regions (1..4)
|
196 |
|
|
PMP_GRANULARITY => PMP_GRANULARITY -- granularity (0=none, 1=8B, 2=16B, 3=32B, ...)
|
197 |
2 |
zero_gravi |
)
|
198 |
|
|
port map (
|
199 |
|
|
-- global control --
|
200 |
|
|
clk_i => clk_i, -- global clock, rising edge
|
201 |
|
|
rstn_i => rstn_i, -- global reset, low-active, async
|
202 |
|
|
ctrl_o => ctrl, -- main control bus
|
203 |
|
|
-- status input --
|
204 |
|
|
alu_wait_i => alu_wait, -- wait for ALU
|
205 |
12 |
zero_gravi |
bus_i_wait_i => bus_i_wait, -- wait for bus
|
206 |
|
|
bus_d_wait_i => bus_d_wait, -- wait for bus
|
207 |
2 |
zero_gravi |
-- data input --
|
208 |
|
|
instr_i => instr, -- instruction
|
209 |
|
|
cmp_i => alu_cmp, -- comparator status
|
210 |
|
|
alu_add_i => alu_add, -- ALU.add result
|
211 |
|
|
-- data output --
|
212 |
|
|
imm_o => imm, -- immediate
|
213 |
6 |
zero_gravi |
fetch_pc_o => fetch_pc, -- PC for instruction fetch
|
214 |
|
|
curr_pc_o => curr_pc, -- current PC (corresponding to current instruction)
|
215 |
|
|
next_pc_o => next_pc, -- next PC (corresponding to current instruction)
|
216 |
2 |
zero_gravi |
-- csr interface --
|
217 |
|
|
csr_wdata_i => alu_res, -- CSR write data
|
218 |
|
|
csr_rdata_o => csr_rdata, -- CSR read data
|
219 |
14 |
zero_gravi |
-- interrupts (risc-v compliant) --
|
220 |
|
|
msw_irq_i => msw_irq_i, -- machine software interrupt
|
221 |
|
|
mext_irq_i => mext_irq_i, -- machine external interrupt
|
222 |
2 |
zero_gravi |
mtime_irq_i => mtime_irq_i, -- machine timer interrupt
|
223 |
14 |
zero_gravi |
-- fast interrupts (custom) --
|
224 |
|
|
firq_i => firq_i,
|
225 |
11 |
zero_gravi |
-- system time input from MTIME --
|
226 |
|
|
time_i => time_i, -- current system time
|
227 |
15 |
zero_gravi |
-- physical memory protection --
|
228 |
|
|
pmp_addr_o => pmp_addr, -- addresses
|
229 |
|
|
pmp_maddr_i => pmp_maddr, -- masked addresses
|
230 |
|
|
pmp_ctrl_o => pmp_ctrl, -- configs
|
231 |
|
|
priv_mode_o => priv_mode, -- current CPU privilege level
|
232 |
2 |
zero_gravi |
-- bus access exceptions --
|
233 |
|
|
mar_i => mar, -- memory address register
|
234 |
|
|
ma_instr_i => ma_instr, -- misaligned instruction address
|
235 |
|
|
ma_load_i => ma_load, -- misaligned load data address
|
236 |
|
|
ma_store_i => ma_store, -- misaligned store data address
|
237 |
|
|
be_instr_i => be_instr, -- bus error on instruction access
|
238 |
|
|
be_load_i => be_load, -- bus error on load data access
|
239 |
12 |
zero_gravi |
be_store_i => be_store -- bus error on store data access
|
240 |
2 |
zero_gravi |
);
|
241 |
|
|
|
242 |
|
|
|
243 |
|
|
-- Register File --------------------------------------------------------------------------
|
244 |
|
|
-- -------------------------------------------------------------------------------------------
|
245 |
|
|
neorv32_regfile_inst: neorv32_cpu_regfile
|
246 |
|
|
generic map (
|
247 |
|
|
CPU_EXTENSION_RISCV_E => CPU_EXTENSION_RISCV_E -- implement embedded RF extension?
|
248 |
|
|
)
|
249 |
|
|
port map (
|
250 |
|
|
-- global control --
|
251 |
|
|
clk_i => clk_i, -- global clock, rising edge
|
252 |
|
|
ctrl_i => ctrl, -- main control bus
|
253 |
|
|
-- data input --
|
254 |
|
|
mem_i => rdata, -- memory read data
|
255 |
|
|
alu_i => alu_res, -- ALU result
|
256 |
|
|
csr_i => csr_rdata, -- CSR read data
|
257 |
13 |
zero_gravi |
pc_i => next_pc, -- next pc (for linking)
|
258 |
2 |
zero_gravi |
-- data output --
|
259 |
|
|
rs1_o => rs1, -- operand 1
|
260 |
|
|
rs2_o => rs2 -- operand 2
|
261 |
|
|
);
|
262 |
|
|
|
263 |
|
|
|
264 |
|
|
-- ALU ------------------------------------------------------------------------------------
|
265 |
|
|
-- -------------------------------------------------------------------------------------------
|
266 |
|
|
neorv32_cpu_alu_inst: neorv32_cpu_alu
|
267 |
11 |
zero_gravi |
generic map (
|
268 |
|
|
CPU_EXTENSION_RISCV_M => CPU_EXTENSION_RISCV_M -- implement muld/div extension?
|
269 |
|
|
)
|
270 |
2 |
zero_gravi |
port map (
|
271 |
|
|
-- global control --
|
272 |
|
|
clk_i => clk_i, -- global clock, rising edge
|
273 |
|
|
rstn_i => rstn_i, -- global reset, low-active, async
|
274 |
|
|
ctrl_i => ctrl, -- main control bus
|
275 |
|
|
-- data input --
|
276 |
|
|
rs1_i => rs1, -- rf source 1
|
277 |
|
|
rs2_i => rs2, -- rf source 2
|
278 |
6 |
zero_gravi |
pc2_i => curr_pc, -- delayed PC
|
279 |
2 |
zero_gravi |
imm_i => imm, -- immediate
|
280 |
|
|
csr_i => csr_rdata, -- csr read data
|
281 |
|
|
-- data output --
|
282 |
|
|
cmp_o => alu_cmp, -- comparator status
|
283 |
|
|
add_o => alu_add, -- OPA + OPB
|
284 |
|
|
res_o => alu_res, -- ALU result
|
285 |
|
|
-- co-processor interface --
|
286 |
|
|
cp0_data_i => cp0_data, -- co-processor 0 result
|
287 |
|
|
cp0_valid_i => cp0_valid, -- co-processor 0 result valid
|
288 |
|
|
cp1_data_i => cp1_data, -- co-processor 1 result
|
289 |
|
|
cp1_valid_i => cp1_valid, -- co-processor 1 result valid
|
290 |
|
|
-- status --
|
291 |
|
|
wait_o => alu_wait -- busy due to iterative processing units
|
292 |
|
|
);
|
293 |
|
|
|
294 |
|
|
|
295 |
|
|
-- Co-Processor 0: MULDIV Unit ------------------------------------------------------------
|
296 |
|
|
-- -------------------------------------------------------------------------------------------
|
297 |
|
|
neorv32_cpu_cp_muldiv_inst_true:
|
298 |
|
|
if (CPU_EXTENSION_RISCV_M = true) generate
|
299 |
|
|
neorv32_cpu_cp_muldiv_inst: neorv32_cpu_cp_muldiv
|
300 |
|
|
port map (
|
301 |
|
|
-- global control --
|
302 |
|
|
clk_i => clk_i, -- global clock, rising edge
|
303 |
|
|
rstn_i => rstn_i, -- global reset, low-active, async
|
304 |
|
|
ctrl_i => ctrl, -- main control bus
|
305 |
|
|
-- data input --
|
306 |
|
|
rs1_i => rs1, -- rf source 1
|
307 |
|
|
rs2_i => rs2, -- rf source 2
|
308 |
|
|
-- result and status --
|
309 |
|
|
res_o => cp0_data, -- operation result
|
310 |
|
|
valid_o => cp0_valid -- data output valid
|
311 |
|
|
);
|
312 |
|
|
end generate;
|
313 |
|
|
|
314 |
|
|
neorv32_cpu_cp_muldiv_inst_false:
|
315 |
|
|
if (CPU_EXTENSION_RISCV_M = false) generate
|
316 |
|
|
cp0_data <= (others => '0');
|
317 |
|
|
cp0_valid <= '0';
|
318 |
|
|
end generate;
|
319 |
|
|
|
320 |
|
|
|
321 |
|
|
-- Co-Processor 1: Not Implemented Yet ----------------------------------------------------
|
322 |
|
|
-- -------------------------------------------------------------------------------------------
|
323 |
|
|
cp1_data <= (others => '0');
|
324 |
|
|
cp1_valid <= '0';
|
325 |
|
|
|
326 |
|
|
|
327 |
12 |
zero_gravi |
-- Bus Interface Unit ---------------------------------------------------------------------
|
328 |
2 |
zero_gravi |
-- -------------------------------------------------------------------------------------------
|
329 |
|
|
neorv32_cpu_bus_inst: neorv32_cpu_bus
|
330 |
|
|
generic map (
|
331 |
11 |
zero_gravi |
CPU_EXTENSION_RISCV_C => CPU_EXTENSION_RISCV_C, -- implement compressed extension?
|
332 |
15 |
zero_gravi |
BUS_TIMEOUT => BUS_TIMEOUT, -- cycles after which a valid bus access will timeout
|
333 |
|
|
-- Physical memory protection (PMP) --
|
334 |
|
|
PMP_USE => PMP_USE, -- implement physical memory protection?
|
335 |
|
|
PMP_NUM_REGIONS => PMP_NUM_REGIONS, -- number of regions (1..4)
|
336 |
|
|
PMP_GRANULARITY => PMP_GRANULARITY -- granularity (0=none, 1=8B, 2=16B, 3=32B, ...)
|
337 |
2 |
zero_gravi |
)
|
338 |
|
|
port map (
|
339 |
|
|
-- global control --
|
340 |
12 |
zero_gravi |
clk_i => clk_i, -- global clock, rising edge
|
341 |
|
|
rstn_i => rstn_i, -- global reset, low-active, async
|
342 |
|
|
ctrl_i => ctrl, -- main control bus
|
343 |
|
|
-- cpu instruction fetch interface --
|
344 |
|
|
fetch_pc_i => fetch_pc, -- PC for instruction fetch
|
345 |
|
|
instr_o => instr, -- instruction
|
346 |
|
|
i_wait_o => bus_i_wait, -- wait for fetch to complete
|
347 |
|
|
--
|
348 |
|
|
ma_instr_o => ma_instr, -- misaligned instruction address
|
349 |
|
|
be_instr_o => be_instr, -- bus error on instruction access
|
350 |
|
|
-- cpu data access interface --
|
351 |
|
|
addr_i => alu_add, -- ALU.add result -> access address
|
352 |
|
|
wdata_i => rs2, -- write data
|
353 |
|
|
rdata_o => rdata, -- read data
|
354 |
|
|
mar_o => mar, -- current memory address register
|
355 |
|
|
d_wait_o => bus_d_wait, -- wait for access to complete
|
356 |
|
|
--
|
357 |
|
|
ma_load_o => ma_load, -- misaligned load data address
|
358 |
|
|
ma_store_o => ma_store, -- misaligned store data address
|
359 |
|
|
be_load_o => be_load, -- bus error on load data access
|
360 |
|
|
be_store_o => be_store, -- bus error on store data access
|
361 |
15 |
zero_gravi |
-- physical memory protection --
|
362 |
|
|
pmp_addr_i => pmp_addr, -- addresses
|
363 |
|
|
pmp_maddr_o => pmp_maddr, -- masked addresses
|
364 |
|
|
pmp_ctrl_i => pmp_ctrl, -- configs
|
365 |
|
|
priv_mode_i => priv_mode, -- current CPU privilege level
|
366 |
12 |
zero_gravi |
-- instruction bus --
|
367 |
|
|
i_bus_addr_o => i_bus_addr_o, -- bus access address
|
368 |
|
|
i_bus_rdata_i => i_bus_rdata_i, -- bus read data
|
369 |
|
|
i_bus_wdata_o => i_bus_wdata_o, -- bus write data
|
370 |
|
|
i_bus_ben_o => i_bus_ben_o, -- byte enable
|
371 |
|
|
i_bus_we_o => i_bus_we_o, -- write enable
|
372 |
|
|
i_bus_re_o => i_bus_re_o, -- read enable
|
373 |
|
|
i_bus_cancel_o => i_bus_cancel_o, -- cancel current bus transaction
|
374 |
|
|
i_bus_ack_i => i_bus_ack_i, -- bus transfer acknowledge
|
375 |
|
|
i_bus_err_i => i_bus_err_i, -- bus transfer error
|
376 |
|
|
i_bus_fence_o => i_bus_fence_o, -- fence operation
|
377 |
|
|
-- data bus --
|
378 |
|
|
d_bus_addr_o => d_bus_addr_o, -- bus access address
|
379 |
|
|
d_bus_rdata_i => d_bus_rdata_i, -- bus read data
|
380 |
|
|
d_bus_wdata_o => d_bus_wdata_o, -- bus write data
|
381 |
|
|
d_bus_ben_o => d_bus_ben_o, -- byte enable
|
382 |
|
|
d_bus_we_o => d_bus_we_o, -- write enable
|
383 |
|
|
d_bus_re_o => d_bus_re_o, -- read enable
|
384 |
|
|
d_bus_cancel_o => d_bus_cancel_o, -- cancel current bus transaction
|
385 |
|
|
d_bus_ack_i => d_bus_ack_i, -- bus transfer acknowledge
|
386 |
|
|
d_bus_err_i => d_bus_err_i, -- bus transfer error
|
387 |
|
|
d_bus_fence_o => d_bus_fence_o -- fence operation
|
388 |
2 |
zero_gravi |
);
|
389 |
|
|
|
390 |
|
|
|
391 |
|
|
end neorv32_cpu_rtl;
|