OpenCores
URL https://opencores.org/ocsvn/neorv32/neorv32/trunk

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [rtl/] [core/] [neorv32_cpu.vhd] - Blame information for rev 72

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 zero_gravi
-- #################################################################################################
2
-- # << NEORV32 - CPU Top Entity >>                                                                #
3
-- # ********************************************************************************************* #
4 18 zero_gravi
-- # NEORV32 CPU:                                                                                  #
5 47 zero_gravi
-- # * neorv32_cpu.vhd                   - CPU top entity                                          #
6
-- #   * neorv32_cpu_alu.vhd             - Arithmetic/logic unit                                   #
7 63 zero_gravi
-- #     * neorv32_cpu_cp_bitmanip.vhd   - Bit-manipulation co-processor                           #
8 72 zero_gravi
-- #     * neorv32_cpu_cp_cfu.vhd        - Custom instructions co-processor                        #
9 63 zero_gravi
-- #     * neorv32_cpu_cp_fpu.vhd        - Single-precision FPU co-processor                       #
10
-- #     * neorv32_cpu_cp_muldiv.vhd     - Integer multiplier/divider co-processor                 #
11
-- #     * neorv32_cpu_cp_shifter.vhd    - Base ISA shifter unit                                   #
12 47 zero_gravi
-- #   * neorv32_cpu_bus.vhd             - Instruction and data bus interface unit                 #
13 63 zero_gravi
-- #   * neorv32_cpu_control.vhd         - CPU control and CSR system                              #
14 47 zero_gravi
-- #     * neorv32_cpu_decompressor.vhd  - Compressed instructions decoder                         #
15
-- #   * neorv32_cpu_regfile.vhd         - Data register file                                      #
16 56 zero_gravi
-- # * neorv32_package.vhd               - Main CPU & Processor package file                       #
17 38 zero_gravi
-- #                                                                                               #
18 63 zero_gravi
-- # Check out the CPU's online documentation for more information:                                #
19
-- #  HQ:         https://github.com/stnolting/neorv32                                             #
20
-- #  Data Sheet: https://stnolting.github.io/neorv32                                              #
21
-- #  User Guide: https://stnolting.github.io/neorv32/ug                                           #
22 2 zero_gravi
-- # ********************************************************************************************* #
23
-- # BSD 3-Clause License                                                                          #
24
-- #                                                                                               #
25 70 zero_gravi
-- # Copyright (c) 2022, Stephan Nolting. All rights reserved.                                     #
26 2 zero_gravi
-- #                                                                                               #
27
-- # Redistribution and use in source and binary forms, with or without modification, are          #
28
-- # permitted provided that the following conditions are met:                                     #
29
-- #                                                                                               #
30
-- # 1. Redistributions of source code must retain the above copyright notice, this list of        #
31
-- #    conditions and the following disclaimer.                                                   #
32
-- #                                                                                               #
33
-- # 2. Redistributions in binary form must reproduce the above copyright notice, this list of     #
34
-- #    conditions and the following disclaimer in the documentation and/or other materials        #
35
-- #    provided with the distribution.                                                            #
36
-- #                                                                                               #
37
-- # 3. Neither the name of the copyright holder nor the names of its contributors may be used to  #
38
-- #    endorse or promote products derived from this software without specific prior written      #
39
-- #    permission.                                                                                #
40
-- #                                                                                               #
41
-- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS   #
42
-- # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF               #
43
-- # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE    #
44
-- # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,     #
45
-- # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE #
46
-- # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED    #
47
-- # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING     #
48
-- # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED  #
49
-- # OF THE POSSIBILITY OF SUCH DAMAGE.                                                            #
50
-- # ********************************************************************************************* #
51
-- # The NEORV32 Processor - https://github.com/stnolting/neorv32              (c) Stephan Nolting #
52
-- #################################################################################################
53
 
54
library ieee;
55
use ieee.std_logic_1164.all;
56
use ieee.numeric_std.all;
57
 
58
library neorv32;
59
use neorv32.neorv32_package.all;
60
 
61
entity neorv32_cpu is
62
  generic (
63
    -- General --
64 62 zero_gravi
    HW_THREAD_ID                 : natural; -- hardware thread id (32-bit)
65
    CPU_BOOT_ADDR                : std_ulogic_vector(31 downto 0); -- cpu boot address
66
    CPU_DEBUG_ADDR               : std_ulogic_vector(31 downto 0); -- cpu debug mode start address
67 2 zero_gravi
    -- RISC-V CPU Extensions --
68 62 zero_gravi
    CPU_EXTENSION_RISCV_A        : boolean; -- implement atomic extension?
69 66 zero_gravi
    CPU_EXTENSION_RISCV_B        : boolean; -- implement bit-manipulation extension?
70 62 zero_gravi
    CPU_EXTENSION_RISCV_C        : boolean; -- implement compressed extension?
71
    CPU_EXTENSION_RISCV_E        : boolean; -- implement embedded RF extension?
72
    CPU_EXTENSION_RISCV_M        : boolean; -- implement muld/div extension?
73
    CPU_EXTENSION_RISCV_U        : boolean; -- implement user mode extension?
74
    CPU_EXTENSION_RISCV_Zfinx    : boolean; -- implement 32-bit floating-point extension (using INT reg!)
75
    CPU_EXTENSION_RISCV_Zicsr    : boolean; -- implement CSR system?
76 66 zero_gravi
    CPU_EXTENSION_RISCV_Zicntr   : boolean; -- implement base counters?
77
    CPU_EXTENSION_RISCV_Zihpm    : boolean; -- implement hardware performance monitors?
78 62 zero_gravi
    CPU_EXTENSION_RISCV_Zifencei : boolean; -- implement instruction stream sync.?
79
    CPU_EXTENSION_RISCV_Zmmul    : boolean; -- implement multiply-only M sub-extension?
80 72 zero_gravi
    CPU_EXTENSION_RISCV_Zxcfu    : boolean; -- implement custom (instr.) functions unit?
81 62 zero_gravi
    CPU_EXTENSION_RISCV_DEBUG    : boolean; -- implement CPU debug mode?
82 19 zero_gravi
    -- Extension Options --
83 62 zero_gravi
    FAST_MUL_EN                  : boolean; -- use DSPs for M extension's multiplier
84
    FAST_SHIFT_EN                : boolean; -- use barrel shifter for shift operations
85
    CPU_CNT_WIDTH                : natural; -- total width of CPU cycle and instret counters (0..64)
86
    CPU_IPB_ENTRIES              : natural; -- entries is instruction prefetch buffer, has to be a power of 2
87 15 zero_gravi
    -- Physical Memory Protection (PMP) --
88 62 zero_gravi
    PMP_NUM_REGIONS              : natural; -- number of regions (0..64)
89
    PMP_MIN_GRANULARITY          : natural; -- minimal region granularity in bytes, has to be a power of 2, min 8 bytes
90 42 zero_gravi
    -- Hardware Performance Monitors (HPM) --
91 62 zero_gravi
    HPM_NUM_CNTS                 : natural; -- number of implemented HPM counters (0..29)
92
    HPM_CNT_WIDTH                : natural  -- total size of HPM counters (0..64)
93 2 zero_gravi
  );
94
  port (
95
    -- global control --
96 71 zero_gravi
    clk_i         : in  std_ulogic; -- global clock, rising edge
97
    rstn_i        : in  std_ulogic; -- global reset, low-active, async
98
    sleep_o       : out std_ulogic; -- cpu is in sleep mode when set
99
    debug_o       : out std_ulogic; -- cpu is in debug mode when set
100 12 zero_gravi
    -- instruction bus interface --
101 71 zero_gravi
    i_bus_addr_o  : out std_ulogic_vector(data_width_c-1 downto 0); -- bus access address
102
    i_bus_rdata_i : in  std_ulogic_vector(data_width_c-1 downto 0); -- bus read data
103
    i_bus_wdata_o : out std_ulogic_vector(data_width_c-1 downto 0); -- bus write data
104
    i_bus_ben_o   : out std_ulogic_vector(03 downto 0); -- byte enable
105
    i_bus_we_o    : out std_ulogic; -- write enable
106
    i_bus_re_o    : out std_ulogic; -- read enable
107
    i_bus_lock_o  : out std_ulogic; -- exclusive access request
108
    i_bus_ack_i   : in  std_ulogic; -- bus transfer acknowledge
109
    i_bus_err_i   : in  std_ulogic; -- bus transfer error
110
    i_bus_fence_o : out std_ulogic; -- executed FENCEI operation
111
    i_bus_priv_o  : out std_ulogic_vector(1 downto 0); -- privilege level
112 12 zero_gravi
    -- data bus interface --
113 71 zero_gravi
    d_bus_addr_o  : out std_ulogic_vector(data_width_c-1 downto 0); -- bus access address
114
    d_bus_rdata_i : in  std_ulogic_vector(data_width_c-1 downto 0); -- bus read data
115
    d_bus_wdata_o : out std_ulogic_vector(data_width_c-1 downto 0); -- bus write data
116
    d_bus_ben_o   : out std_ulogic_vector(03 downto 0); -- byte enable
117
    d_bus_we_o    : out std_ulogic; -- write enable
118
    d_bus_re_o    : out std_ulogic; -- read enable
119
    d_bus_lock_o  : out std_ulogic; -- exclusive access request
120
    d_bus_ack_i   : in  std_ulogic; -- bus transfer acknowledge
121
    d_bus_err_i   : in  std_ulogic; -- bus transfer error
122
    d_bus_fence_o : out std_ulogic; -- executed FENCE operation
123
    d_bus_priv_o  : out std_ulogic_vector(1 downto 0); -- privilege level
124 11 zero_gravi
    -- system time input from MTIME --
125 71 zero_gravi
    time_i        : in  std_ulogic_vector(63 downto 0); -- current system time
126 14 zero_gravi
    -- interrupts (risc-v compliant) --
127 71 zero_gravi
    msw_irq_i     : in  std_ulogic;-- machine software interrupt
128
    mext_irq_i    : in  std_ulogic;-- machine external interrupt
129
    mtime_irq_i   : in  std_ulogic;-- machine timer interrupt
130 14 zero_gravi
    -- fast interrupts (custom) --
131 71 zero_gravi
    firq_i        : in  std_ulogic_vector(15 downto 0);
132 59 zero_gravi
    -- debug mode (halt) request --
133 71 zero_gravi
    db_halt_req_i : in  std_ulogic
134 2 zero_gravi
  );
135
end neorv32_cpu;
136
 
137
architecture neorv32_cpu_rtl of neorv32_cpu is
138
 
139
  -- local signals --
140 60 zero_gravi
  signal ctrl       : std_ulogic_vector(ctrl_width_c-1 downto 0); -- main control bus
141
  signal comparator : std_ulogic_vector(1 downto 0); -- comparator result
142
  signal imm        : std_ulogic_vector(data_width_c-1 downto 0); -- immediate
143
  signal instr      : std_ulogic_vector(data_width_c-1 downto 0); -- new instruction
144
  signal rs1, rs2   : std_ulogic_vector(data_width_c-1 downto 0); -- source registers
145
  signal alu_res    : std_ulogic_vector(data_width_c-1 downto 0); -- alu result
146
  signal alu_add    : std_ulogic_vector(data_width_c-1 downto 0); -- alu address result
147
  signal mem_rdata  : std_ulogic_vector(data_width_c-1 downto 0); -- memory read data
148 61 zero_gravi
  signal alu_idone  : std_ulogic; -- iterative alu operation done
149 60 zero_gravi
  signal bus_i_wait : std_ulogic; -- wait for current bus instruction fetch
150
  signal bus_d_wait : std_ulogic; -- wait for current bus data access
151
  signal csr_rdata  : std_ulogic_vector(data_width_c-1 downto 0); -- csr read data
152
  signal mar        : std_ulogic_vector(data_width_c-1 downto 0); -- current memory address register
153
  signal ma_instr   : std_ulogic; -- misaligned instruction address
154
  signal ma_load    : std_ulogic; -- misaligned load data address
155
  signal ma_store   : std_ulogic; -- misaligned store data address
156
  signal excl_state : std_ulogic; -- atomic/exclusive access lock status
157
  signal be_instr   : std_ulogic; -- bus error on instruction access
158
  signal be_load    : std_ulogic; -- bus error on load data access
159
  signal be_store   : std_ulogic; -- bus error on store data access
160
  signal fetch_pc   : std_ulogic_vector(data_width_c-1 downto 0); -- pc for instruction fetch
161
  signal curr_pc    : std_ulogic_vector(data_width_c-1 downto 0); -- current pc (for current executed instruction)
162 68 zero_gravi
  signal next_pc    : std_ulogic_vector(data_width_c-1 downto 0); -- next pc (for next executed instruction)
163 60 zero_gravi
  signal fpu_flags  : std_ulogic_vector(4 downto 0); -- FPU exception flags
164 2 zero_gravi
 
165 15 zero_gravi
  -- pmp interface --
166 61 zero_gravi
  signal pmp_addr : pmp_addr_if_t;
167
  signal pmp_ctrl : pmp_ctrl_if_t;
168 15 zero_gravi
 
169 2 zero_gravi
begin
170
 
171 61 zero_gravi
  -- CPU ISA Configuration ---------------------------------------------------------------------------
172
  -- -------------------------------------------------------------------------------------------
173
  assert false report
174
  "NEORV32 CPU ISA Configuration (MARCH): " &
175
  cond_sel_string_f(CPU_EXTENSION_RISCV_E, "RV32E", "RV32I") &
176
  cond_sel_string_f(CPU_EXTENSION_RISCV_M, "M", "") &
177
  cond_sel_string_f(CPU_EXTENSION_RISCV_A, "A", "") &
178
  cond_sel_string_f(CPU_EXTENSION_RISCV_C, "C", "") &
179 66 zero_gravi
  cond_sel_string_f(CPU_EXTENSION_RISCV_B, "B", "") &
180 61 zero_gravi
  cond_sel_string_f(CPU_EXTENSION_RISCV_U, "U", "") &
181
  cond_sel_string_f(CPU_EXTENSION_RISCV_Zicsr, "_Zicsr", "") &
182 66 zero_gravi
  cond_sel_string_f(CPU_EXTENSION_RISCV_Zicntr, "_Zicntr", "") &
183
  cond_sel_string_f(CPU_EXTENSION_RISCV_Zihpm, "_Zihpm", "") &
184 61 zero_gravi
  cond_sel_string_f(CPU_EXTENSION_RISCV_Zifencei, "_Zifencei", "") &
185
  cond_sel_string_f(CPU_EXTENSION_RISCV_Zfinx, "_Zfinx", "") &
186
  cond_sel_string_f(CPU_EXTENSION_RISCV_Zmmul, "_Zmmul", "") &
187 72 zero_gravi
  cond_sel_string_f(CPU_EXTENSION_RISCV_Zxcfu, "_Zxcfu", "") &
188 70 zero_gravi
  cond_sel_string_f(CPU_EXTENSION_RISCV_DEBUG, "_DEBUG", "") &
189 61 zero_gravi
  ""
190
  severity note;
191
 
192
 
193 15 zero_gravi
  -- Sanity Checks --------------------------------------------------------------------------
194
  -- -------------------------------------------------------------------------------------------
195 56 zero_gravi
  -- hardware reset notifier --
196 70 zero_gravi
  assert not (dedicated_reset_c = false) report "NEORV32 CPU CONFIG NOTE: Implementing NO dedicated hardware reset for uncritical registers (default)." severity note;
197 61 zero_gravi
  assert not (dedicated_reset_c = true)  report "NEORV32 CPU CONFIG NOTE: Implementing defined hardware reset for uncritical registers (non-default, reset-to-zero, might increase area)." severity note;
198 56 zero_gravi
  assert not ((def_rst_val_c /= '-') and (def_rst_val_c /= '0')) report "NEORV32 CPU CONFIG ERROR! Invalid configuration of package <def_rst_val_c> constant (has to be '-' or '0')." severity error;
199
 
200 71 zero_gravi
  -- CPU boot address alignment --
201
  assert not (CPU_BOOT_ADDR(1 downto 0) /= "00") report "NEORV32 CPU CONFIG ERROR! <CPU_BOOT_ADDR> has to be 32-bit aligned." severity error;
202
 
203 23 zero_gravi
  -- CSR system --
204 56 zero_gravi
  assert not (CPU_EXTENSION_RISCV_Zicsr = false) report "NEORV32 CPU CONFIG WARNING! No exception/interrupt/trap/privileged features available when <CPU_EXTENSION_RISCV_Zicsr> = false." severity warning;
205
 
206
  -- CPU counters (cycle and instret) --
207 66 zero_gravi
  assert not ((CPU_EXTENSION_RISCV_Zicntr = true) and ((CPU_CNT_WIDTH < 0) or (CPU_CNT_WIDTH > 64))) report "NEORV32 CPU CONFIG ERROR! Invalid <CPU_CNT_WIDTH> configuration. Has to be 0..64." severity error;
208
  assert not ((CPU_EXTENSION_RISCV_Zicntr = true) and (CPU_CNT_WIDTH < 64)) report "NEORV32 CPU CONFIG WARNING! Implementing CPU <cycle> and <instret> CSRs with reduced size (" & integer'image(CPU_CNT_WIDTH) & "-bit instead of 64-bit). This is not RISC-V compliant and might have unintended SW side effects." severity warning;
209 56 zero_gravi
 
210 23 zero_gravi
  -- U-extension requires Zicsr extension --
211 56 zero_gravi
  assert not ((CPU_EXTENSION_RISCV_Zicsr = false) and (CPU_EXTENSION_RISCV_U = true)) report "NEORV32 CPU CONFIG ERROR! User mode requires <CPU_EXTENSION_RISCV_Zicsr> extension to be enabled." severity error;
212 40 zero_gravi
 
213 38 zero_gravi
  -- Instruction prefetch buffer size --
214 62 zero_gravi
  assert not (is_power_of_two_f(CPU_IPB_ENTRIES) = false) report "NEORV32 CPU CONFIG ERROR! Number of entries in instruction prefetch buffer <CPU_IPB_ENTRIES> has to be a power of two." severity error;
215 15 zero_gravi
 
216 40 zero_gravi
  -- PMP regions check --
217 63 zero_gravi
  assert not (PMP_NUM_REGIONS > 64) report "NEORV32 CPU CONFIG ERROR! Number of PMP regions <PMP_NUM_REGIONS> out of valid range (0..64)." severity error;
218 59 zero_gravi
  -- PMP granularity --
219 56 zero_gravi
  assert not ((is_power_of_two_f(PMP_MIN_GRANULARITY) = false) and (PMP_NUM_REGIONS > 0)) report "NEORV32 CPU CONFIG ERROR! <PMP_MIN_GRANULARITY> has to be a power of two." severity error;
220
  assert not ((PMP_MIN_GRANULARITY < 8) and (PMP_NUM_REGIONS > 0)) report "NEORV32 CPU CONFIG ERROR! <PMP_MIN_GRANULARITY> has to be >= 8 bytes." severity error;
221
  assert not ((CPU_EXTENSION_RISCV_Zicsr = false) and (PMP_NUM_REGIONS > 0)) report "NEORV32 CPU CONFIG ERROR! Physical memory protection (PMP) requires <CPU_EXTENSION_RISCV_Zicsr> extension to be enabled." severity error;
222 40 zero_gravi
 
223 42 zero_gravi
  -- HPM counters check --
224 66 zero_gravi
  assert not ((CPU_EXTENSION_RISCV_Zihpm = true) and (HPM_NUM_CNTS > 29)) report "NEORV32 CPU CONFIG ERROR! Number of HPM counters <HPM_NUM_CNTS> out of valid range (0..29)." severity error;
225
  assert not ((CPU_EXTENSION_RISCV_Zihpm = true) and ((HPM_CNT_WIDTH < 0) or (HPM_CNT_WIDTH > 64))) report "NEORV32 CPU CONFIG ERROR! HPM counter width <HPM_CNT_WIDTH> has to be 0..64 bit." severity error;
226
  assert not ((CPU_EXTENSION_RISCV_Zicsr = false) and (CPU_EXTENSION_RISCV_Zihpm = true)) report "NEORV32 CPU CONFIG ERROR! Hardware performance monitors extension <CPU_EXTENSION_RISCV_Zihpm> requires <CPU_EXTENSION_RISCV_Zicsr> extension to be enabled." severity error;
227 41 zero_gravi
 
228 61 zero_gravi
  -- Mul-extension --
229 63 zero_gravi
  assert not ((CPU_EXTENSION_RISCV_Zmmul = true) and (CPU_EXTENSION_RISCV_M = true)) report "NEORV32 CPU CONFIG ERROR! <M> and <Zmmul> extensions cannot co-exist!" severity error;
230 61 zero_gravi
 
231 72 zero_gravi
  -- Custom Functions Unit --
232
  assert not (CPU_EXTENSION_RISCV_Zxcfu = true) report "NEORV32 CPU CONFIG NOTE: Implementing Custom Functions Unit (CFU) as <Zxcfu> ISA extension." severity note;
233
 
234 59 zero_gravi
  -- Debug mode --
235
  assert not ((CPU_EXTENSION_RISCV_DEBUG = true) and (CPU_EXTENSION_RISCV_Zicsr = false)) report "NEORV32 CPU CONFIG ERROR! Debug mode requires <CPU_EXTENSION_RISCV_Zicsr> extension to be enabled." severity error;
236 64 zero_gravi
  assert not ((CPU_EXTENSION_RISCV_DEBUG = true) and (CPU_EXTENSION_RISCV_Zifencei = false)) report "NEORV32 CPU CONFIG ERROR! Debug mode requires <CPU_EXTENSION_RISCV_Zifencei> extension to be enabled." severity error;
237 42 zero_gravi
 
238 63 zero_gravi
  -- fast multiplication option --
239
  assert not (FAST_MUL_EN = true) report "NEORV32 CPU CONFIG NOTE: <FAST_MUL_EN> set. Trying to use DSP blocks for base ISA multiplications." severity note;
240 59 zero_gravi
 
241 63 zero_gravi
  -- fast shift option --
242
  assert not (FAST_SHIFT_EN = true) report "NEORV32 CPU CONFIG NOTE: <FAST_SHIFT_EN> set. Implementing full-parallel logic / barrel shifters." severity note;
243
 
244
 
245 2 zero_gravi
  -- Control Unit ---------------------------------------------------------------------------
246
  -- -------------------------------------------------------------------------------------------
247
  neorv32_cpu_control_inst: neorv32_cpu_control
248
  generic map (
249
    -- General --
250 59 zero_gravi
    HW_THREAD_ID                 => HW_THREAD_ID,                 -- hardware thread id
251
    CPU_BOOT_ADDR                => CPU_BOOT_ADDR,                -- cpu boot address
252
    CPU_DEBUG_ADDR               => CPU_DEBUG_ADDR,               -- cpu debug mode start address
253 2 zero_gravi
    -- RISC-V CPU Extensions --
254 39 zero_gravi
    CPU_EXTENSION_RISCV_A        => CPU_EXTENSION_RISCV_A,        -- implement atomic extension?
255 66 zero_gravi
    CPU_EXTENSION_RISCV_B        => CPU_EXTENSION_RISCV_B,        -- implement bit-manipulation extension?
256 15 zero_gravi
    CPU_EXTENSION_RISCV_C        => CPU_EXTENSION_RISCV_C,        -- implement compressed extension?
257 62 zero_gravi
    CPU_EXTENSION_RISCV_E        => CPU_EXTENSION_RISCV_E,        -- implement embedded RF extension?
258
    CPU_EXTENSION_RISCV_M        => CPU_EXTENSION_RISCV_M,        -- implement mul/div extension?
259 15 zero_gravi
    CPU_EXTENSION_RISCV_U        => CPU_EXTENSION_RISCV_U,        -- implement user mode extension?
260 53 zero_gravi
    CPU_EXTENSION_RISCV_Zfinx    => CPU_EXTENSION_RISCV_Zfinx,    -- implement 32-bit floating-point extension (using INT reg!)
261 15 zero_gravi
    CPU_EXTENSION_RISCV_Zicsr    => CPU_EXTENSION_RISCV_Zicsr,    -- implement CSR system?
262 66 zero_gravi
    CPU_EXTENSION_RISCV_Zicntr   => CPU_EXTENSION_RISCV_Zicntr,   -- implement base counters?
263
    CPU_EXTENSION_RISCV_Zihpm    => CPU_EXTENSION_RISCV_Zihpm,    -- implement hardware performance monitors?
264 15 zero_gravi
    CPU_EXTENSION_RISCV_Zifencei => CPU_EXTENSION_RISCV_Zifencei, -- implement instruction stream sync.?
265 62 zero_gravi
    CPU_EXTENSION_RISCV_Zmmul    => CPU_EXTENSION_RISCV_Zmmul,    -- implement multiply-only M sub-extension?
266 72 zero_gravi
    CPU_EXTENSION_RISCV_Zxcfu    => CPU_EXTENSION_RISCV_Zxcfu,    -- implement custom (instr.) functions unit?
267 59 zero_gravi
    CPU_EXTENSION_RISCV_DEBUG    => CPU_EXTENSION_RISCV_DEBUG,    -- implement CPU debug mode?
268 72 zero_gravi
    -- Tuning Options --
269
    FAST_MUL_EN                  => FAST_MUL_EN,                  -- use DSPs for M extension's multiplier
270
    FAST_SHIFT_EN                => FAST_SHIFT_EN,                -- use barrel shifter for shift operations
271 56 zero_gravi
    CPU_CNT_WIDTH                => CPU_CNT_WIDTH,                -- total width of CPU cycle and instret counters (0..64)
272 62 zero_gravi
    CPU_IPB_ENTRIES              => CPU_IPB_ENTRIES,              -- entries is instruction prefetch buffer, has to be a power of 2
273 15 zero_gravi
    -- Physical memory protection (PMP) --
274 42 zero_gravi
    PMP_NUM_REGIONS              => PMP_NUM_REGIONS,              -- number of regions (0..64)
275
    PMP_MIN_GRANULARITY          => PMP_MIN_GRANULARITY,          -- minimal region granularity in bytes, has to be a power of 2, min 8 bytes
276
    -- Hardware Performance Monitors (HPM) --
277 56 zero_gravi
    HPM_NUM_CNTS                 => HPM_NUM_CNTS,                 -- number of implemented HPM counters (0..29)
278
    HPM_CNT_WIDTH                => HPM_CNT_WIDTH                 -- total size of HPM counters
279 2 zero_gravi
  )
280
  port map (
281
    -- global control --
282
    clk_i         => clk_i,       -- global clock, rising edge
283
    rstn_i        => rstn_i,      -- global reset, low-active, async
284
    ctrl_o        => ctrl,        -- main control bus
285
    -- status input --
286 61 zero_gravi
    alu_idone_i   => alu_idone,   -- ALU iterative operation done
287 12 zero_gravi
    bus_i_wait_i  => bus_i_wait,  -- wait for bus
288
    bus_d_wait_i  => bus_d_wait,  -- wait for bus
289 57 zero_gravi
    excl_state_i  => excl_state,  -- atomic/exclusive access lock status
290 2 zero_gravi
    -- data input --
291
    instr_i       => instr,       -- instruction
292 47 zero_gravi
    cmp_i         => comparator,  -- comparator status
293 36 zero_gravi
    alu_add_i     => alu_add,     -- ALU address result
294
    rs1_i         => rs1,         -- rf source 1
295 2 zero_gravi
    -- data output --
296
    imm_o         => imm,         -- immediate
297 6 zero_gravi
    fetch_pc_o    => fetch_pc,    -- PC for instruction fetch
298
    curr_pc_o     => curr_pc,     -- current PC (corresponding to current instruction)
299 68 zero_gravi
    next_pc_o     => next_pc,     -- next PC (corresponding to next instruction)
300 2 zero_gravi
    csr_rdata_o   => csr_rdata,   -- CSR read data
301 52 zero_gravi
    -- FPU interface --
302
    fpu_flags_i   => fpu_flags,   -- exception flags
303 59 zero_gravi
    -- debug mode (halt) request --
304
    db_halt_req_i => db_halt_req_i,
305 14 zero_gravi
    -- interrupts (risc-v compliant) --
306
    msw_irq_i     => msw_irq_i,   -- machine software interrupt
307
    mext_irq_i    => mext_irq_i,  -- machine external interrupt
308 2 zero_gravi
    mtime_irq_i   => mtime_irq_i, -- machine timer interrupt
309 14 zero_gravi
    -- fast interrupts (custom) --
310 47 zero_gravi
    firq_i        => firq_i,      -- fast interrupt trigger
311 11 zero_gravi
    -- system time input from MTIME --
312
    time_i        => time_i,      -- current system time
313 15 zero_gravi
    -- physical memory protection --
314
    pmp_addr_o    => pmp_addr,    -- addresses
315
    pmp_ctrl_o    => pmp_ctrl,    -- configs
316 2 zero_gravi
    -- bus access exceptions --
317
    mar_i         => mar,         -- memory address register
318
    ma_instr_i    => ma_instr,    -- misaligned instruction address
319
    ma_load_i     => ma_load,     -- misaligned load data address
320
    ma_store_i    => ma_store,    -- misaligned store data address
321
    be_instr_i    => be_instr,    -- bus error on instruction access
322
    be_load_i     => be_load,     -- bus error on load data access
323 12 zero_gravi
    be_store_i    => be_store     -- bus error on store data access
324 2 zero_gravi
  );
325
 
326 47 zero_gravi
  -- CPU is sleeping? --
327
  sleep_o <= ctrl(ctrl_sleep_c); -- set when CPU is sleeping (after WFI)
328 2 zero_gravi
 
329 69 zero_gravi
  -- CPU is in debug mode? --
330
  debug_o <= ctrl(ctrl_debug_running_c);
331 47 zero_gravi
 
332 69 zero_gravi
 
333 2 zero_gravi
  -- Register File --------------------------------------------------------------------------
334
  -- -------------------------------------------------------------------------------------------
335 45 zero_gravi
  neorv32_cpu_regfile_inst: neorv32_cpu_regfile
336 2 zero_gravi
  generic map (
337
    CPU_EXTENSION_RISCV_E => CPU_EXTENSION_RISCV_E -- implement embedded RF extension?
338
  )
339
  port map (
340
    -- global control --
341 70 zero_gravi
    clk_i  => clk_i,     -- global clock, rising edge
342
    ctrl_i => ctrl,      -- main control bus
343 2 zero_gravi
    -- data input --
344 70 zero_gravi
    mem_i  => mem_rdata, -- memory read data
345
    alu_i  => alu_res,   -- ALU result
346 2 zero_gravi
    -- data output --
347 70 zero_gravi
    rs1_o  => rs1,       -- operand 1
348
    rs2_o  => rs2        -- operand 2
349 2 zero_gravi
  );
350
 
351
 
352
  -- ALU ------------------------------------------------------------------------------------
353
  -- -------------------------------------------------------------------------------------------
354
  neorv32_cpu_alu_inst: neorv32_cpu_alu
355 11 zero_gravi
  generic map (
356 61 zero_gravi
    -- RISC-V CPU Extensions --
357 66 zero_gravi
    CPU_EXTENSION_RISCV_B     => CPU_EXTENSION_RISCV_B,     -- implement bit-manipulation extension?
358 61 zero_gravi
    CPU_EXTENSION_RISCV_M     => CPU_EXTENSION_RISCV_M,     -- implement mul/div extension?
359
    CPU_EXTENSION_RISCV_Zmmul => CPU_EXTENSION_RISCV_Zmmul, -- implement multiply-only M sub-extension?
360
    CPU_EXTENSION_RISCV_Zfinx => CPU_EXTENSION_RISCV_Zfinx, -- implement 32-bit floating-point extension (using INT reg!)
361 72 zero_gravi
    CPU_EXTENSION_RISCV_Zxcfu => CPU_EXTENSION_RISCV_Zxcfu, -- implement custom (instr.) functions unit?
362 61 zero_gravi
    -- Extension Options --
363
    FAST_MUL_EN               => FAST_MUL_EN,               -- use DSPs for M extension's multiplier
364
    FAST_SHIFT_EN             => FAST_SHIFT_EN              -- use barrel shifter for shift operations
365 11 zero_gravi
  )
366 2 zero_gravi
  port map (
367
    -- global control --
368 70 zero_gravi
    clk_i       => clk_i,      -- global clock, rising edge
369
    rstn_i      => rstn_i,     -- global reset, low-active, async
370
    ctrl_i      => ctrl,       -- main control bus
371 2 zero_gravi
    -- data input --
372 70 zero_gravi
    rs1_i       => rs1,        -- rf source 1
373
    rs2_i       => rs2,        -- rf source 2
374
    pc_i        => curr_pc,    -- current PC
375
    pc2_i       => next_pc,    -- next PC
376
    imm_i       => imm,        -- immediate
377
    csr_i       => csr_rdata,  -- CSR read data
378 2 zero_gravi
    -- data output --
379 70 zero_gravi
    cmp_o       => comparator, -- comparator status
380
    res_o       => alu_res,    -- ALU result
381
    add_o       => alu_add,    -- address computation result
382
    fpu_flags_o => fpu_flags,  -- FPU exception flags
383 2 zero_gravi
    -- status --
384 70 zero_gravi
    idone_o     => alu_idone   -- iterative processing units done?
385 2 zero_gravi
  );
386
 
387
 
388 12 zero_gravi
  -- Bus Interface Unit ---------------------------------------------------------------------
389 2 zero_gravi
  -- -------------------------------------------------------------------------------------------
390
  neorv32_cpu_bus_inst: neorv32_cpu_bus
391
  generic map (
392 53 zero_gravi
    CPU_EXTENSION_RISCV_A => CPU_EXTENSION_RISCV_A, -- implement atomic extension?
393 11 zero_gravi
    CPU_EXTENSION_RISCV_C => CPU_EXTENSION_RISCV_C, -- implement compressed extension?
394 15 zero_gravi
    -- Physical memory protection (PMP) --
395 42 zero_gravi
    PMP_NUM_REGIONS       => PMP_NUM_REGIONS,       -- number of regions (0..64)
396 57 zero_gravi
    PMP_MIN_GRANULARITY   => PMP_MIN_GRANULARITY    -- minimal region granularity in bytes, has to be a power of 2, min 8 bytes
397 2 zero_gravi
  )
398
  port map (
399
    -- global control --
400 71 zero_gravi
    clk_i         => clk_i,         -- global clock, rising edge
401
    rstn_i        => rstn_i,        -- global reset, low-active, async
402
    ctrl_i        => ctrl,          -- main control bus
403 12 zero_gravi
    -- cpu instruction fetch interface --
404 71 zero_gravi
    fetch_pc_i    => fetch_pc,      -- PC for instruction fetch
405
    instr_o       => instr,         -- instruction
406
    i_wait_o      => bus_i_wait,    -- wait for fetch to complete
407 12 zero_gravi
    --
408 71 zero_gravi
    ma_instr_o    => ma_instr,      -- misaligned instruction address
409
    be_instr_o    => be_instr,      -- bus error on instruction access
410 12 zero_gravi
    -- cpu data access interface --
411 71 zero_gravi
    addr_i        => alu_add,       -- ALU.add result -> access address
412
    wdata_i       => rs2,           -- write data
413
    rdata_o       => mem_rdata,     -- read data
414
    mar_o         => mar,           -- current memory address register
415
    d_wait_o      => bus_d_wait,    -- wait for access to complete
416 12 zero_gravi
    --
417 71 zero_gravi
    excl_state_o  => excl_state,    -- atomic/exclusive access status
418
    ma_load_o     => ma_load,       -- misaligned load data address
419
    ma_store_o    => ma_store,      -- misaligned store data address
420
    be_load_o     => be_load,       -- bus error on load data access
421
    be_store_o    => be_store,      -- bus error on store data access
422 15 zero_gravi
    -- physical memory protection --
423 71 zero_gravi
    pmp_addr_i    => pmp_addr,      -- addresses
424
    pmp_ctrl_i    => pmp_ctrl,      -- configurations
425 12 zero_gravi
    -- instruction bus --
426 71 zero_gravi
    i_bus_addr_o  => i_bus_addr_o,  -- bus access address
427
    i_bus_rdata_i => i_bus_rdata_i, -- bus read data
428
    i_bus_wdata_o => i_bus_wdata_o, -- bus write data
429
    i_bus_ben_o   => i_bus_ben_o,   -- byte enable
430
    i_bus_we_o    => i_bus_we_o,    -- write enable
431
    i_bus_re_o    => i_bus_re_o,    -- read enable
432
    i_bus_lock_o  => i_bus_lock_o,  -- exclusive access request
433
    i_bus_ack_i   => i_bus_ack_i,   -- bus transfer acknowledge
434
    i_bus_err_i   => i_bus_err_i,   -- bus transfer error
435
    i_bus_fence_o => i_bus_fence_o, -- fence operation
436 12 zero_gravi
    -- data bus --
437 71 zero_gravi
    d_bus_addr_o  => d_bus_addr_o,  -- bus access address
438
    d_bus_rdata_i => d_bus_rdata_i, -- bus read data
439
    d_bus_wdata_o => d_bus_wdata_o, -- bus write data
440
    d_bus_ben_o   => d_bus_ben_o,   -- byte enable
441
    d_bus_we_o    => d_bus_we_o,    -- write enable
442
    d_bus_re_o    => d_bus_re_o,    -- read enable
443
    d_bus_lock_o  => d_bus_lock_o,  -- exclusive access request
444
    d_bus_ack_i   => d_bus_ack_i,   -- bus transfer acknowledge
445
    d_bus_err_i   => d_bus_err_i,   -- bus transfer error
446
    d_bus_fence_o => d_bus_fence_o  -- fence operation
447 2 zero_gravi
  );
448
 
449 35 zero_gravi
  -- current privilege level --
450 36 zero_gravi
  i_bus_priv_o <= ctrl(ctrl_priv_lvl_msb_c downto ctrl_priv_lvl_lsb_c);
451
  d_bus_priv_o <= ctrl(ctrl_priv_lvl_msb_c downto ctrl_priv_lvl_lsb_c);
452 2 zero_gravi
 
453 35 zero_gravi
 
454 2 zero_gravi
end neorv32_cpu_rtl;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.