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

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [rtl/] [core/] [mem/] [neorv32_imem.default.vhd] - Blame information for rev 70

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

Line No. Rev Author Line
1 64 zero_gravi
-- #################################################################################################
2
-- # << NEORV32 - Processor-internal instruction memory (IMEM) >>                                  #
3
-- # ********************************************************************************************* #
4
-- # This memory optionally includes the in-place executable image of the application. See the     #
5
-- # processor's documentary to get more information.                                              #
6
-- # ********************************************************************************************* #
7
-- # BSD 3-Clause License                                                                          #
8
-- #                                                                                               #
9
-- # Copyright (c) 2021, 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
use neorv32.neorv32_application_image.all; -- this file is generated by the image generator
45
 
46
architecture neorv32_imem_rtl of neorv32_imem is
47
 
48
  -- IO space: module base address --
49
  constant hi_abb_c : natural := 31; -- high address boundary bit
50
  constant lo_abb_c : natural := index_size_f(IMEM_SIZE); -- low address boundary bit
51
 
52
  -- local signals --
53
  signal acc_en : std_ulogic;
54
  signal rdata  : std_ulogic_vector(31 downto 0);
55
  signal rden   : std_ulogic;
56
  signal addr   : std_ulogic_vector(index_size_f(IMEM_SIZE/4)-1 downto 0);
57
 
58
  -- --------------------------- --
59
  -- IMEM as pre-initialized ROM --
60
  -- --------------------------- --
61
 
62
  -- application (image) size in bytes --
63
  constant imem_app_size_c : natural := (application_init_image'length)*4;
64
 
65
  -- ROM - initialized with executable code --
66
  constant mem_rom : mem32_t(0 to IMEM_SIZE/4-1) := mem32_init_f(application_init_image, IMEM_SIZE/4);
67
 
68
  -- read data --
69
  signal mem_rom_rd : std_ulogic_vector(31 downto 0);
70
 
71
  -- -------------------------------------------------------------------------------------------------------------- --
72
  -- The memory (RAM) is built from 4 individual byte-wide memories b0..b3, since some synthesis tools have         --
73
  -- problems with 32-bit memories that provide dedicated byte-enable signals AND/OR with multi-dimensional arrays. --
74
  -- -------------------------------------------------------------------------------------------------------------- --
75
 
76
  -- RAM - not initialized at all --
77
  signal mem_ram_b0 : mem8_t(0 to IMEM_SIZE/4-1);
78
  signal mem_ram_b1 : mem8_t(0 to IMEM_SIZE/4-1);
79
  signal mem_ram_b2 : mem8_t(0 to IMEM_SIZE/4-1);
80
  signal mem_ram_b3 : mem8_t(0 to IMEM_SIZE/4-1);
81
 
82
  -- read data --
83
  signal mem_b0_rd, mem_b1_rd, mem_b2_rd, mem_b3_rd : std_ulogic_vector(7 downto 0);
84
 
85
begin
86
 
87
  -- Sanity Checks --------------------------------------------------------------------------
88
  -- -------------------------------------------------------------------------------------------
89 68 zero_gravi
  assert false report "NEORV32 PROCESSOR CONFIG NOTE: Using DEFAULT platform-agnostic IMEM." severity note;
90 64 zero_gravi
  assert not (IMEM_AS_IROM = true)  report "NEORV32 PROCESSOR CONFIG NOTE: Implementing processor-internal IMEM as ROM (" & natural'image(IMEM_SIZE) &
91
  " bytes), pre-initialized with application (" & natural'image(imem_app_size_c) & " bytes)." severity note;
92
  --
93
  assert not (IMEM_AS_IROM = false) report "NEORV32 PROCESSOR CONFIG NOTE: Implementing processor-internal IMEM as blank RAM (" & natural'image(IMEM_SIZE) &
94
  " bytes)." severity note;
95
  --
96
  assert not ((IMEM_AS_IROM = true) and (imem_app_size_c > IMEM_SIZE)) report "NEORV32 PROCESSOR CONFIG ERROR: Application (image = " & natural'image(imem_app_size_c) &
97
  " bytes) does not fit into processor-internal IMEM (ROM = " & natural'image(IMEM_SIZE) & " bytes)!" severity error;
98
 
99
 
100
  -- Access Control -------------------------------------------------------------------------
101
  -- -------------------------------------------------------------------------------------------
102
  acc_en <= '1' when (addr_i(hi_abb_c downto lo_abb_c) = IMEM_BASE(hi_abb_c downto lo_abb_c)) else '0';
103
  addr   <= addr_i(index_size_f(IMEM_SIZE/4)+1 downto 2); -- word aligned
104
 
105
 
106
  -- Implement IMEM as pre-initialized ROM --------------------------------------------------
107
  -- -------------------------------------------------------------------------------------------
108
  imem_rom:
109
  if (IMEM_AS_IROM = true) generate
110
    mem_access: process(clk_i)
111
    begin
112
      if rising_edge(clk_i) then
113
        if (acc_en = '1') then -- reduce switching activity when not accessed
114
          mem_rom_rd <= mem_rom(to_integer(unsigned(addr)));
115
        end if;
116
      end if;
117
    end process mem_access;
118
    -- read data --
119
    rdata <= mem_rom_rd;
120
  end generate;
121
 
122
 
123
  -- Implement IMEM as not-initialized RAM --------------------------------------------------
124
  -- -------------------------------------------------------------------------------------------
125
  imem_ram:
126
  if (IMEM_AS_IROM = false) generate
127
    mem_access: process(clk_i)
128
    begin
129
      if rising_edge(clk_i) then
130
        -- this RAM style should not require "no_rw_check" attributes as the read-after-write behavior
131
        -- is intended to be defined implicitly via the if-WRITE-else-READ construct
132
        if (acc_en = '1') then -- reduce switching activity when not accessed
133
          if (wren_i = '1') and (ben_i(0) = '1') then -- byte 0
134
            mem_ram_b0(to_integer(unsigned(addr))) <= data_i(07 downto 00);
135
          else
136
            mem_b0_rd <= mem_ram_b0(to_integer(unsigned(addr)));
137
          end if;
138
          if (wren_i = '1') and (ben_i(1) = '1') then -- byte 1
139
            mem_ram_b1(to_integer(unsigned(addr))) <= data_i(15 downto 08);
140
          else
141
            mem_b1_rd <= mem_ram_b1(to_integer(unsigned(addr)));
142
          end if;
143
          if (wren_i = '1') and (ben_i(2) = '1') then -- byte 2
144
            mem_ram_b2(to_integer(unsigned(addr))) <= data_i(23 downto 16);
145
          else
146
            mem_b2_rd <= mem_ram_b2(to_integer(unsigned(addr)));
147
          end if;
148
          if (wren_i = '1') and (ben_i(3) = '1') then -- byte 3
149
            mem_ram_b3(to_integer(unsigned(addr))) <= data_i(31 downto 24);
150
          else
151
            mem_b3_rd <= mem_ram_b3(to_integer(unsigned(addr)));
152
          end if;
153
        end if;
154
      end if;
155
    end process mem_access;
156
    -- read data --
157
    rdata <= mem_b3_rd & mem_b2_rd & mem_b1_rd & mem_b0_rd;
158
  end generate;
159
 
160
 
161
  -- Bus Feedback ---------------------------------------------------------------------------
162
  -- -------------------------------------------------------------------------------------------
163
  bus_feedback: process(clk_i)
164
  begin
165
    if rising_edge(clk_i) then
166
      rden <= acc_en and rden_i;
167
      if (IMEM_AS_IROM = true) then
168
        ack_o <= acc_en and rden_i;
169
      else
170
        ack_o <= acc_en and (rden_i or wren_i);
171
      end if;
172
    end if;
173
  end process bus_feedback;
174
 
175
  -- output gate --
176
  data_o <= rdata when (rden = '1') else (others => '0');
177
 
178
 
179
end neorv32_imem_rtl;

powered by: WebSVN 2.1.0

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