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

Subversion Repositories neorv32

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

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
-- # RISC-V M extension is enabled. R0 output is hardwired to zero.                                #
6
-- # ********************************************************************************************* #
7
-- # BSD 3-Clause License                                                                          #
8
-- #                                                                                               #
9
-- # Copyright (c) 2020, Stephan Nolting. All rights reserved.                                     #
10
-- #                                                                                               #
11
-- # Redistribution and use in source and binary forms, with or without modification, are          #
12
-- # permitted provided that the following conditions are met:                                     #
13
-- #                                                                                               #
14
-- # 1. Redistributions of source code must retain the above copyright notice, this list of        #
15
-- #    conditions and the following disclaimer.                                                   #
16
-- #                                                                                               #
17
-- # 2. Redistributions in binary form must reproduce the above copyright notice, this list of     #
18
-- #    conditions and the following disclaimer in the documentation and/or other materials        #
19
-- #    provided with the distribution.                                                            #
20
-- #                                                                                               #
21
-- # 3. Neither the name of the copyright holder nor the names of its contributors may be used to  #
22
-- #    endorse or promote products derived from this software without specific prior written      #
23
-- #    permission.                                                                                #
24
-- #                                                                                               #
25
-- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS   #
26
-- # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF               #
27
-- # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE    #
28
-- # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,     #
29
-- # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE #
30
-- # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED    #
31
-- # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING     #
32
-- # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED  #
33
-- # OF THE POSSIBILITY OF SUCH DAMAGE.                                                            #
34
-- # ********************************************************************************************* #
35
-- # The NEORV32 Processor - https://github.com/stnolting/neorv32              (c) Stephan Nolting #
36
-- #################################################################################################
37
 
38
library ieee;
39
use ieee.std_logic_1164.all;
40
use ieee.numeric_std.all;
41
 
42
library neorv32;
43
use neorv32.neorv32_package.all;
44
 
45
entity neorv32_cpu_regfile is
46
  generic (
47
    CPU_EXTENSION_RISCV_E : boolean := false -- implement embedded RF extension?
48
  );
49
  port (
50
    -- global control --
51
    clk_i  : in  std_ulogic; -- global clock, rising edge
52
    ctrl_i : in  std_ulogic_vector(ctrl_width_c-1 downto 0); -- main control bus
53
    -- data input --
54
    mem_i  : in  std_ulogic_vector(data_width_c-1 downto 0); -- memory read data
55
    alu_i  : in  std_ulogic_vector(data_width_c-1 downto 0); -- ALU result
56
    csr_i  : in  std_ulogic_vector(data_width_c-1 downto 0); -- CSR read data
57
    pc_i   : in  std_ulogic_vector(data_width_c-1 downto 0); -- current pc
58
    -- data output --
59
    rs1_o  : out std_ulogic_vector(data_width_c-1 downto 0); -- operand 1
60
    rs2_o  : out std_ulogic_vector(data_width_c-1 downto 0)  -- operand 2
61
  );
62
end neorv32_cpu_regfile;
63
 
64
architecture neorv32_cpu_regfile_rtl of neorv32_cpu_regfile is
65
 
66
  -- register file --
67
  type   reg_file_t is array (31 downto 0) of std_ulogic_vector(data_width_c-1 downto 0);
68
  type   reg_file_emb_t is array (15 downto 0) of std_ulogic_vector(data_width_c-1 downto 0);
69
  signal reg_file      : reg_file_t;
70
  signal reg_file_emb  : reg_file_emb_t;
71
  signal rf_write_data : std_ulogic_vector(data_width_c-1 downto 0); -- actual write-back data
72
  signal rs1_read      : std_ulogic_vector(data_width_c-1 downto 0); -- internal operand rs1
73
  signal rs2_read      : std_ulogic_vector(data_width_c-1 downto 0); -- internal operand rs2
74
 
75
  -- reading from r0? --
76
  signal rs1_clear, rs2_clear : std_ulogic;
77
 
78
begin
79
 
80
  -- Input mux ------------------------------------------------------------------------------
81
  -- -------------------------------------------------------------------------------------------
82
  input_mux: process(ctrl_i, mem_i, alu_i, pc_i, csr_i)
83
  begin
84
    case ctrl_i(ctrl_rf_in_mux_msb_c downto ctrl_rf_in_mux_lsb_c) is
85
      when "00"   => rf_write_data <= alu_i;
86
      when "01"   => rf_write_data <= mem_i;
87
      when "10"   => rf_write_data <= pc_i;
88
      when others => rf_write_data <= csr_i;
89
    end case;
90
  end process input_mux;
91
 
92
 
93
  -- Register file read/write access --------------------------------------------------------
94
  -- -------------------------------------------------------------------------------------------
95
  rf_access: process(clk_i)
96
  begin
97 9 zero_gravi
    if rising_edge(clk_i) then -- sync read and write
98 2 zero_gravi
      if (CPU_EXTENSION_RISCV_E = false) then -- normal register file with 32 entries
99
        -- check if reading from r0 --
100
        rs1_clear <= '0';
101
        rs2_clear <= '0';
102
        if (ctrl_i(ctrl_rf_rs1_adr4_c downto ctrl_rf_rs1_adr0_c) = "00000") then
103
          rs1_clear <= '1';
104
        end if;
105
        if (ctrl_i(ctrl_rf_rs2_adr4_c downto ctrl_rf_rs2_adr0_c) = "00000") then
106
          rs2_clear <= '1';
107
        end if;
108
        -- write --
109
        if (ctrl_i(ctrl_rf_wb_en_c) = '1') then -- valid write-back
110
          reg_file(to_integer(unsigned(ctrl_i(ctrl_rf_rd_adr4_c downto ctrl_rf_rd_adr0_c)))) <= rf_write_data;
111
        end if;
112
        -- read --
113
        rs1_read <= reg_file(to_integer(unsigned(ctrl_i(ctrl_rf_rs1_adr4_c downto ctrl_rf_rs1_adr0_c))));
114
        rs2_read <= reg_file(to_integer(unsigned(ctrl_i(ctrl_rf_rs2_adr4_c downto ctrl_rf_rs2_adr0_c))));
115
 
116
      else -- embedded register file with 16 entries
117
        -- check if reading from r0 --
118
        rs1_clear <= '0';
119
        rs2_clear <= '0';
120
        if (ctrl_i(ctrl_rf_rs1_adr3_c downto ctrl_rf_rs1_adr0_c) = "0000") then
121
          rs1_clear <= '1';
122
        end if;
123
        if (ctrl_i(ctrl_rf_rs2_adr3_c downto ctrl_rf_rs2_adr0_c) = "0000") then
124
          rs2_clear <= '1';
125
        end if;
126
        -- write --
127
        if (ctrl_i(ctrl_rf_wb_en_c) = '1') then -- valid write-back
128
          reg_file_emb(to_integer(unsigned(ctrl_i(ctrl_rf_rd_adr3_c downto ctrl_rf_rd_adr0_c)))) <= rf_write_data;
129
        end if;
130
        -- read --
131
        rs1_read <= reg_file_emb(to_integer(unsigned(ctrl_i(ctrl_rf_rs1_adr3_c downto ctrl_rf_rs1_adr0_c))));
132
        rs2_read <= reg_file_emb(to_integer(unsigned(ctrl_i(ctrl_rf_rs2_adr3_c downto ctrl_rf_rs2_adr0_c))));
133
      end if;
134
    end if;
135
  end process rf_access;
136
 
137
 
138
  -- Check if reading from r0 ---------------------------------------------------------------
139
  -- -------------------------------------------------------------------------------------------
140
  rs1_o <= (others => '0') when ((rs1_clear or ctrl_i(ctrl_rf_clear_rs1_c)) = '1') else rs1_read;
141
  rs2_o <= (others => '0') when ((rs2_clear or ctrl_i(ctrl_rf_clear_rs2_c)) = '1') else rs2_read;
142
 
143
 
144
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.