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

Subversion Repositories neorv32

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 zero_gravi
-- #################################################################################################
2 45 zero_gravi
-- # << NEORV32 - CPU General Purpose Data Register File >>                                        #
3 2 zero_gravi
-- # ********************************************************************************************* #
4 45 zero_gravi
-- # General purpose data register file. 32 entries (= 1024 bit) for normal mode (RV32I),          #
5
-- # 16 entries (= 512 bit) for embedded mode (RV32E) when RISC-V "E" extension is enabled.        #
6
-- #                                                                                               #
7 73 zero_gravi
-- # Register zero (x0) is a "normal" physical register that should be initialized to zero by      #
8
-- # the early boot code. However, it is always set to zero when written.                          #
9 45 zero_gravi
-- #                                                                                               #
10
-- # The register file uses synchronous read accesses and a *single* (multiplexed) address port    #
11 65 zero_gravi
-- # for writing and reading rd/rs1 and a single read-only port for rs2. Therefore, the whole      #
12
-- # register file can be mapped to a single true-dual-port block RAM.                             #
13 2 zero_gravi
-- # ********************************************************************************************* #
14
-- # BSD 3-Clause License                                                                          #
15
-- #                                                                                               #
16 73 zero_gravi
-- # Copyright (c) 2022, Stephan Nolting. All rights reserved.                                     #
17 2 zero_gravi
-- #                                                                                               #
18
-- # Redistribution and use in source and binary forms, with or without modification, are          #
19
-- # permitted provided that the following conditions are met:                                     #
20
-- #                                                                                               #
21
-- # 1. Redistributions of source code must retain the above copyright notice, this list of        #
22
-- #    conditions and the following disclaimer.                                                   #
23
-- #                                                                                               #
24
-- # 2. Redistributions in binary form must reproduce the above copyright notice, this list of     #
25
-- #    conditions and the following disclaimer in the documentation and/or other materials        #
26
-- #    provided with the distribution.                                                            #
27
-- #                                                                                               #
28
-- # 3. Neither the name of the copyright holder nor the names of its contributors may be used to  #
29
-- #    endorse or promote products derived from this software without specific prior written      #
30
-- #    permission.                                                                                #
31
-- #                                                                                               #
32
-- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS   #
33
-- # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF               #
34
-- # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE    #
35
-- # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,     #
36
-- # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE #
37
-- # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED    #
38
-- # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING     #
39
-- # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED  #
40
-- # OF THE POSSIBILITY OF SUCH DAMAGE.                                                            #
41
-- # ********************************************************************************************* #
42
-- # The NEORV32 Processor - https://github.com/stnolting/neorv32              (c) Stephan Nolting #
43
-- #################################################################################################
44
 
45
library ieee;
46
use ieee.std_logic_1164.all;
47
use ieee.numeric_std.all;
48
 
49
library neorv32;
50
use neorv32.neorv32_package.all;
51
 
52
entity neorv32_cpu_regfile is
53
  generic (
54 62 zero_gravi
    CPU_EXTENSION_RISCV_E : boolean -- implement embedded RF extension?
55 2 zero_gravi
  );
56
  port (
57
    -- global control --
58
    clk_i  : in  std_ulogic; -- global clock, rising edge
59
    ctrl_i : in  std_ulogic_vector(ctrl_width_c-1 downto 0); -- main control bus
60
    -- data input --
61 73 zero_gravi
    alu_i  : in  std_ulogic_vector(data_width_c-1 downto 0); -- ALU result
62 2 zero_gravi
    mem_i  : in  std_ulogic_vector(data_width_c-1 downto 0); -- memory read data
63 73 zero_gravi
    csr_i  : in  std_ulogic_vector(data_width_c-1 downto 0); -- CSR read data
64
    pc2_i  : in  std_ulogic_vector(data_width_c-1 downto 0); -- next PC
65 2 zero_gravi
    -- data output --
66
    rs1_o  : out std_ulogic_vector(data_width_c-1 downto 0); -- operand 1
67 65 zero_gravi
    rs2_o  : out std_ulogic_vector(data_width_c-1 downto 0)  -- operand 2
68 2 zero_gravi
  );
69
end neorv32_cpu_regfile;
70
 
71
architecture neorv32_cpu_regfile_rtl of neorv32_cpu_regfile is
72
 
73
  -- register file --
74
  type   reg_file_t is array (31 downto 0) of std_ulogic_vector(data_width_c-1 downto 0);
75
  type   reg_file_emb_t is array (15 downto 0) of std_ulogic_vector(data_width_c-1 downto 0);
76 49 zero_gravi
  signal reg_file     : reg_file_t;
77
  signal reg_file_emb : reg_file_emb_t;
78 2 zero_gravi
 
79 74 zero_gravi
  -- access --
80
  signal rf_wdata : std_ulogic_vector(data_width_c-1 downto 0); -- actual write-back data
81
  signal rd_zero  : std_ulogic; -- writing to x0?
82
  signal opa_addr : std_ulogic_vector(4 downto 0); -- rs1/dst address
83
  signal opb_addr : std_ulogic_vector(4 downto 0); -- rs2 address
84
 
85 2 zero_gravi
begin
86
 
87 45 zero_gravi
  -- Data Input Mux -------------------------------------------------------------------------
88 2 zero_gravi
  -- -------------------------------------------------------------------------------------------
89 74 zero_gravi
  input_mux: process(rd_zero, ctrl_i, alu_i, mem_i, csr_i, pc2_i)
90 62 zero_gravi
  begin
91 74 zero_gravi
    if (rd_zero = '1') then -- write zero if accessing x0 to "emulate" it is hardwired to zero
92 73 zero_gravi
      rf_wdata <= (others => '0'); -- TODO: FIXME! but how???
93 62 zero_gravi
    else
94 73 zero_gravi
      case ctrl_i(ctrl_rf_mux1_c downto ctrl_rf_mux0_c) is
95
        when rf_mux_alu_c => rf_wdata <= alu_i; -- ALU result
96
        when rf_mux_mem_c => rf_wdata <= mem_i; -- memory read data
97
        when rf_mux_csr_c => rf_wdata <= csr_i; -- CSR read data
98
        when rf_mux_npc_c => rf_wdata <= pc2_i; -- next PC (branch return/link address)
99
        when others       => rf_wdata <= alu_i;
100
      end case;
101 62 zero_gravi
    end if;
102
  end process input_mux;
103 45 zero_gravi
 
104 74 zero_gravi
  -- writing to x0? --
105
  rd_zero <= '1' when (ctrl_i(ctrl_rf_rd_adr4_c downto ctrl_rf_rd_adr0_c) = "00000") else '0';
106 45 zero_gravi
 
107 74 zero_gravi
 
108 45 zero_gravi
  -- Register File Access -------------------------------------------------------------------
109
  -- -------------------------------------------------------------------------------------------
110 73 zero_gravi
  reg_file_rv32i: -- normal register file with 32 registers
111
  if (CPU_EXTENSION_RISCV_E = false) generate
112
    rf_access: process(clk_i)
113
    begin
114
      if rising_edge(clk_i) then -- sync read and write
115 62 zero_gravi
        if (ctrl_i(ctrl_rf_wb_en_c) = '1') then
116 49 zero_gravi
          reg_file(to_integer(unsigned(opa_addr(4 downto 0)))) <= rf_wdata;
117 2 zero_gravi
        end if;
118 73 zero_gravi
        rs1_o <= reg_file(to_integer(unsigned(opa_addr(4 downto 0))));
119
        rs2_o <= reg_file(to_integer(unsigned(opb_addr(4 downto 0))));
120
      end if;
121
    end process rf_access;
122
  end generate;
123
 
124
  reg_file_rv32e: -- embedded register file with 16 registers
125
  if (CPU_EXTENSION_RISCV_E = true) generate
126
    rf_access: process(clk_i)
127
    begin
128
      if rising_edge(clk_i) then -- sync read and write
129 62 zero_gravi
        if (ctrl_i(ctrl_rf_wb_en_c) = '1') then
130 49 zero_gravi
          reg_file_emb(to_integer(unsigned(opa_addr(3 downto 0)))) <= rf_wdata;
131 2 zero_gravi
        end if;
132 73 zero_gravi
        rs1_o <= reg_file_emb(to_integer(unsigned(opa_addr(3 downto 0))));
133
        rs2_o <= reg_file_emb(to_integer(unsigned(opb_addr(3 downto 0))));
134 2 zero_gravi
      end if;
135 73 zero_gravi
    end process rf_access;
136
  end generate;
137
 
138 58 zero_gravi
  -- access addresses --
139 73 zero_gravi
  opa_addr <= ctrl_i(ctrl_rf_rd_adr4_c downto ctrl_rf_rd_adr0_c) when (ctrl_i(ctrl_rf_wb_en_c) = '1') else
140
              ctrl_i(ctrl_rf_rs1_adr4_c downto ctrl_rf_rs1_adr0_c); -- rd/rs1
141 45 zero_gravi
  opb_addr <= ctrl_i(ctrl_rf_rs2_adr4_c downto ctrl_rf_rs2_adr0_c); -- rs2
142 39 zero_gravi
 
143
 
144 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.