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

Subversion Repositories neorv32

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

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