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

Subversion Repositories neorv32

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

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