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

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [rtl/] [core/] [neorv32_cpu_regfile.vhd] - Blame information for rev 39

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

Line No. Rev Author Line
1 2 zero_gravi
-- #################################################################################################
2 36 zero_gravi
-- # << NEORV32 - CPU Data Register File >>                                                        #
3 2 zero_gravi
-- # ********************************************************************************************* #
4 36 zero_gravi
-- # General purpose data register file. 32 entries for normal mode (I), 16 entries for embedded   #
5 39 zero_gravi
-- # mode (E) when RISC-V "E" extension is enabled. Register zero (r0) is a "normal" physical reg  #
6
-- # that has to be initialized to zero by the CPU control system. For normal operations r0 cannot #
7
-- # be written. The register file uses synchronous reads so it can be mapped to FPGA block RAM.   #
8 2 zero_gravi
-- # ********************************************************************************************* #
9
-- # BSD 3-Clause License                                                                          #
10
-- #                                                                                               #
11
-- # Copyright (c) 2020, Stephan Nolting. All rights reserved.                                     #
12
-- #                                                                                               #
13
-- # Redistribution and use in source and binary forms, with or without modification, are          #
14
-- # permitted provided that the following conditions are met:                                     #
15
-- #                                                                                               #
16
-- # 1. Redistributions of source code must retain the above copyright notice, this list of        #
17
-- #    conditions and the following disclaimer.                                                   #
18
-- #                                                                                               #
19
-- # 2. Redistributions in binary form must reproduce the above copyright notice, this list of     #
20
-- #    conditions and the following disclaimer in the documentation and/or other materials        #
21
-- #    provided with the distribution.                                                            #
22
-- #                                                                                               #
23
-- # 3. Neither the name of the copyright holder nor the names of its contributors may be used to  #
24
-- #    endorse or promote products derived from this software without specific prior written      #
25
-- #    permission.                                                                                #
26
-- #                                                                                               #
27
-- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS   #
28
-- # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF               #
29
-- # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE    #
30
-- # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,     #
31
-- # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE #
32
-- # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED    #
33
-- # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING     #
34
-- # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED  #
35
-- # OF THE POSSIBILITY OF SUCH DAMAGE.                                                            #
36
-- # ********************************************************************************************* #
37
-- # The NEORV32 Processor - https://github.com/stnolting/neorv32              (c) Stephan Nolting #
38
-- #################################################################################################
39
 
40
library ieee;
41
use ieee.std_logic_1164.all;
42
use ieee.numeric_std.all;
43
 
44
library neorv32;
45
use neorv32.neorv32_package.all;
46
 
47
entity neorv32_cpu_regfile is
48
  generic (
49
    CPU_EXTENSION_RISCV_E : boolean := false -- implement embedded RF extension?
50
  );
51
  port (
52
    -- global control --
53
    clk_i  : in  std_ulogic; -- global clock, rising edge
54
    ctrl_i : in  std_ulogic_vector(ctrl_width_c-1 downto 0); -- main control bus
55
    -- data input --
56
    mem_i  : in  std_ulogic_vector(data_width_c-1 downto 0); -- memory read data
57
    alu_i  : in  std_ulogic_vector(data_width_c-1 downto 0); -- ALU result
58
    csr_i  : in  std_ulogic_vector(data_width_c-1 downto 0); -- CSR read data
59
    -- data output --
60
    rs1_o  : out std_ulogic_vector(data_width_c-1 downto 0); -- operand 1
61
    rs2_o  : out std_ulogic_vector(data_width_c-1 downto 0)  -- operand 2
62
  );
63
end neorv32_cpu_regfile;
64
 
65
architecture neorv32_cpu_regfile_rtl of neorv32_cpu_regfile is
66
 
67
  -- register file --
68
  type   reg_file_t is array (31 downto 0) of std_ulogic_vector(data_width_c-1 downto 0);
69
  type   reg_file_emb_t is array (15 downto 0) of std_ulogic_vector(data_width_c-1 downto 0);
70
  signal reg_file      : reg_file_t;
71
  signal reg_file_emb  : reg_file_emb_t;
72 39 zero_gravi
  signal rf_mux_data   : std_ulogic_vector(data_width_c-1 downto 0);
73 2 zero_gravi
  signal rf_write_data : std_ulogic_vector(data_width_c-1 downto 0); -- actual write-back data
74 36 zero_gravi
  signal rd_is_r0      : std_ulogic; -- writing to r0?
75
  signal rf_we         : std_ulogic;
76
  signal dst_addr      : std_ulogic_vector(4 downto 0); -- destination address
77 2 zero_gravi
 
78
begin
79
 
80
  -- Register file read/write access --------------------------------------------------------
81
  -- -------------------------------------------------------------------------------------------
82
  rf_access: process(clk_i)
83
  begin
84 9 zero_gravi
    if rising_edge(clk_i) then -- sync read and write
85 2 zero_gravi
      if (CPU_EXTENSION_RISCV_E = false) then -- normal register file with 32 entries
86 36 zero_gravi
        if (rf_we = '1') then
87
          reg_file(to_integer(unsigned(dst_addr(4 downto 0)))) <= rf_write_data;
88 39 zero_gravi
        else
89 36 zero_gravi
          rs1_o <= reg_file(to_integer(unsigned(ctrl_i(ctrl_rf_rs1_adr4_c downto ctrl_rf_rs1_adr0_c))));
90
          rs2_o <= reg_file(to_integer(unsigned(ctrl_i(ctrl_rf_rs2_adr4_c downto ctrl_rf_rs2_adr0_c))));
91 2 zero_gravi
        end if;
92
      else -- embedded register file with 16 entries
93 36 zero_gravi
        if (rf_we = '1') then
94
          reg_file_emb(to_integer(unsigned(dst_addr(3 downto 0)))) <= rf_write_data;
95 39 zero_gravi
        else
96 36 zero_gravi
          rs1_o <= reg_file_emb(to_integer(unsigned(ctrl_i(ctrl_rf_rs1_adr3_c downto ctrl_rf_rs1_adr0_c))));
97
          rs2_o <= reg_file_emb(to_integer(unsigned(ctrl_i(ctrl_rf_rs2_adr3_c downto ctrl_rf_rs2_adr0_c))));
98 2 zero_gravi
        end if;
99
      end if;
100
    end if;
101
  end process rf_access;
102
 
103 39 zero_gravi
  -- data input mux --
104
  rf_write_data <= alu_i when (ctrl_i(ctrl_rf_in_mux_msb_c) = '0') else rf_mux_data;
105
  rf_mux_data   <= mem_i when (ctrl_i(ctrl_rf_in_mux_lsb_c) = '0') else csr_i;
106 2 zero_gravi
 
107 39 zero_gravi
  -- check if we are writing to x0 --
108
  rd_is_r0 <= not or_all_f(ctrl_i(ctrl_rf_rd_adr4_c downto ctrl_rf_rd_adr0_c)) when (CPU_EXTENSION_RISCV_E = false) else
109
              not or_all_f(ctrl_i(ctrl_rf_rd_adr3_c downto ctrl_rf_rd_adr0_c));
110
 
111
  -- valid RF write access --
112
  rf_we <= (ctrl_i(ctrl_rf_wb_en_c) and (not rd_is_r0)) or ctrl_i(ctrl_rf_r0_we_c);
113
 
114
  -- destination address --
115
  dst_addr <= ctrl_i(ctrl_rf_rd_adr4_c downto ctrl_rf_rd_adr0_c) when (ctrl_i(ctrl_rf_r0_we_c) = '0') else (others => '0'); -- force dst=r0?
116
 
117
 
118
 
119 2 zero_gravi
end neorv32_cpu_regfile_rtl;

powered by: WebSVN 2.1.0

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