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

Subversion Repositories neorv32

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

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

Line No. Rev Author Line
1 2 zero_gravi
-- #################################################################################################
2
-- # << NEORV32 - CPU Register File >>                                                             #
3
-- # ********************************************************************************************* #
4
-- # General purpose data registers. 32 entries for normal mode, 16 entries for embedded mode when #
5 25 zero_gravi
-- # RISC-V "E" extension is enabled. Register zero (r0/x0) is a normal physical registers, that   #
6
-- # has to be initialized to zero by the CPU control system. For normal operations, x0 cannot be  #
7
-- # written.                                                                                      #
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
    pc_i   : in  std_ulogic_vector(data_width_c-1 downto 0); -- current pc
60
    -- data output --
61
    rs1_o  : out std_ulogic_vector(data_width_c-1 downto 0); -- operand 1
62
    rs2_o  : out std_ulogic_vector(data_width_c-1 downto 0)  -- operand 2
63
  );
64
end neorv32_cpu_regfile;
65
 
66
architecture neorv32_cpu_regfile_rtl of neorv32_cpu_regfile is
67
 
68
  -- register file --
69
  type   reg_file_t is array (31 downto 0) of std_ulogic_vector(data_width_c-1 downto 0);
70
  type   reg_file_emb_t is array (15 downto 0) of std_ulogic_vector(data_width_c-1 downto 0);
71
  signal reg_file      : reg_file_t;
72
  signal reg_file_emb  : reg_file_emb_t;
73
  signal rf_write_data : std_ulogic_vector(data_width_c-1 downto 0); -- actual write-back data
74 13 zero_gravi
  signal valid_wr      : std_ulogic; -- writing not to r0
75 2 zero_gravi
 
76
 
77 12 zero_gravi
  -- attributes - these are *NOT mandatory*; just for footprint / timing optimization --
78
  -- -------------------------------------------------------------------------------- --
79
 
80
  -- lattice radiant --
81
  attribute syn_ramstyle : string;
82
  attribute syn_ramstyle of reg_file     : signal is "no_rw_check";
83
  attribute syn_ramstyle of reg_file_emb : signal is "no_rw_check";
84
 
85
  -- intel quartus prime --
86
  attribute ramstyle : string;
87
  attribute ramstyle of reg_file     : signal is "no_rw_check";
88
  attribute ramstyle of reg_file_emb : signal is "no_rw_check";
89
 
90 2 zero_gravi
begin
91
 
92
  -- Input mux ------------------------------------------------------------------------------
93
  -- -------------------------------------------------------------------------------------------
94
  input_mux: process(ctrl_i, mem_i, alu_i, pc_i, csr_i)
95
  begin
96
    case ctrl_i(ctrl_rf_in_mux_msb_c downto ctrl_rf_in_mux_lsb_c) is
97
      when "00"   => rf_write_data <= alu_i;
98
      when "01"   => rf_write_data <= mem_i;
99
      when "10"   => rf_write_data <= pc_i;
100
      when others => rf_write_data <= csr_i;
101
    end case;
102
  end process input_mux;
103
 
104 25 zero_gravi
  -- only write if destination is not x0; except we are forcing a r0 write access --
105
  valid_wr <= or_all_f(ctrl_i(ctrl_rf_rd_adr4_c downto ctrl_rf_rd_adr0_c)) or ctrl_i(ctrl_rf_r0_we_c) when (CPU_EXTENSION_RISCV_E = false) else
106
              or_all_f(ctrl_i(ctrl_rf_rd_adr3_c downto ctrl_rf_rd_adr0_c)) or ctrl_i(ctrl_rf_r0_we_c);
107 2 zero_gravi
 
108 13 zero_gravi
 
109 2 zero_gravi
  -- Register file read/write access --------------------------------------------------------
110
  -- -------------------------------------------------------------------------------------------
111
  rf_access: process(clk_i)
112
  begin
113 9 zero_gravi
    if rising_edge(clk_i) then -- sync read and write
114 2 zero_gravi
      if (CPU_EXTENSION_RISCV_E = false) then -- normal register file with 32 entries
115
        -- write --
116 25 zero_gravi
        if (ctrl_i(ctrl_rf_wb_en_c) = '1') and ((valid_wr = '1') or (rf_r0_is_reg_c = false)) then -- valid write-back
117 2 zero_gravi
          reg_file(to_integer(unsigned(ctrl_i(ctrl_rf_rd_adr4_c downto ctrl_rf_rd_adr0_c)))) <= rf_write_data;
118
        end if;
119
        -- read --
120 25 zero_gravi
        rs1_o <= reg_file(to_integer(unsigned(ctrl_i(ctrl_rf_rs1_adr4_c downto ctrl_rf_rs1_adr0_c))));
121
        rs2_o <= reg_file(to_integer(unsigned(ctrl_i(ctrl_rf_rs2_adr4_c downto ctrl_rf_rs2_adr0_c))));
122 2 zero_gravi
      else -- embedded register file with 16 entries
123
        -- write --
124 25 zero_gravi
        if (ctrl_i(ctrl_rf_wb_en_c) = '1') and ((valid_wr = '1') or (rf_r0_is_reg_c = false)) then -- valid write-back
125 2 zero_gravi
          reg_file_emb(to_integer(unsigned(ctrl_i(ctrl_rf_rd_adr3_c downto ctrl_rf_rd_adr0_c)))) <= rf_write_data;
126
        end if;
127
        -- read --
128 25 zero_gravi
        rs1_o <= reg_file_emb(to_integer(unsigned(ctrl_i(ctrl_rf_rs1_adr3_c downto ctrl_rf_rs1_adr0_c))));
129
        rs2_o <= reg_file_emb(to_integer(unsigned(ctrl_i(ctrl_rf_rs2_adr3_c downto ctrl_rf_rs2_adr0_c))));
130 2 zero_gravi
      end if;
131
    end if;
132
  end process rf_access;
133
 
134
 
135
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.