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

Subversion Repositories neorv32

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

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