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

Subversion Repositories neorv32

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

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

Line No. Rev Author Line
1 70 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
  signal addr_ff : std_ulogic_vector(index_size_f(IMEM_SIZE/4)-1 downto 0);
58
 
59
  -- --------------------------- --
60
  -- IMEM as pre-initialized ROM --
61
  -- --------------------------- --
62
 
63
  -- application (image) size in bytes --
64
  constant imem_app_size_c : natural := (application_init_image'length)*4;
65
 
66
  -- ROM - initialized with executable code --
67
  constant mem_rom : mem32_t(0 to IMEM_SIZE/4-1) := mem32_init_f(application_init_image, IMEM_SIZE/4);
68
 
69
  -- read data --
70
  signal mem_rom_rd : std_ulogic_vector(31 downto 0);
71
 
72
  -- -------------------------------------------------------------------------------------------------------------- --
73
  -- The memory (RAM) is built from 4 individual byte-wide memories b0..b3, since some synthesis tools have         --
74
  -- problems with 32-bit memories that provide dedicated byte-enable signals AND/OR with multi-dimensional arrays. --
75
  -- -------------------------------------------------------------------------------------------------------------- --
76
 
77
  -- RAM - not initialized at all --
78
  signal mem_ram_b0 : mem8_t(0 to IMEM_SIZE/4-1);
79
  signal mem_ram_b1 : mem8_t(0 to IMEM_SIZE/4-1);
80
  signal mem_ram_b2 : mem8_t(0 to IMEM_SIZE/4-1);
81
  signal mem_ram_b3 : mem8_t(0 to IMEM_SIZE/4-1);
82
 
83
  -- read data --
84
  signal mem_b0_rd, mem_b1_rd, mem_b2_rd, mem_b3_rd : std_ulogic_vector(7 downto 0);
85
 
86
begin
87
 
88
  -- Sanity Checks --------------------------------------------------------------------------
89
  -- -------------------------------------------------------------------------------------------
90
  assert false report "NEORV32 PROCESSOR CONFIG NOTE: Using legacy HDL style IMEM." severity note;
91
  assert not (IMEM_AS_IROM = true)  report "NEORV32 PROCESSOR CONFIG NOTE: Implementing processor-internal IMEM as ROM (" & natural'image(IMEM_SIZE) &
92
  " bytes), pre-initialized with application (" & natural'image(imem_app_size_c) & " bytes)." severity note;
93
  --
94
  assert not (IMEM_AS_IROM = false) report "NEORV32 PROCESSOR CONFIG NOTE: Implementing processor-internal IMEM as blank RAM (" & natural'image(IMEM_SIZE) &
95
  " bytes)." severity note;
96
  --
97
  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) &
98
  " bytes) does not fit into processor-internal IMEM (ROM = " & natural'image(IMEM_SIZE) & " bytes)!" severity error;
99
 
100
 
101
  -- Access Control -------------------------------------------------------------------------
102
  -- -------------------------------------------------------------------------------------------
103
  acc_en <= '1' when (addr_i(hi_abb_c downto lo_abb_c) = IMEM_BASE(hi_abb_c downto lo_abb_c)) else '0';
104
  addr   <= addr_i(index_size_f(IMEM_SIZE/4)+1 downto 2); -- word aligned
105
 
106
 
107
  -- Implement IMEM as pre-initialized ROM --------------------------------------------------
108
  -- -------------------------------------------------------------------------------------------
109
  imem_rom:
110
  if (IMEM_AS_IROM = true) generate
111
    mem_access: process(clk_i)
112
    begin
113
      if rising_edge(clk_i) then
114
        if (acc_en = '1') then -- reduce switching activity when not accessed
115
          mem_rom_rd <= mem_rom(to_integer(unsigned(addr)));
116
        end if;
117
      end if;
118
    end process mem_access;
119
    -- read data --
120
    rdata <= mem_rom_rd;
121
  end generate;
122
 
123
 
124
  -- Implement IMEM as not-initialized RAM --------------------------------------------------
125
  -- -------------------------------------------------------------------------------------------
126
  imem_ram:
127
  if (IMEM_AS_IROM = false) generate
128
    mem_access: process(clk_i)
129
    begin
130
      if rising_edge(clk_i) then
131
        addr_ff <= addr;
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
          end if;
136
          if (wren_i = '1') and (ben_i(1) = '1') then -- byte 1
137
            mem_ram_b1(to_integer(unsigned(addr))) <= data_i(15 downto 08);
138
          end if;
139
          if (wren_i = '1') and (ben_i(2) = '1') then -- byte 2
140
            mem_ram_b2(to_integer(unsigned(addr))) <= data_i(23 downto 16);
141
          end if;
142
          if (wren_i = '1') and (ben_i(3) = '1') then -- byte 3
143
            mem_ram_b3(to_integer(unsigned(addr))) <= data_i(31 downto 24);
144
          end if;
145
        end if;
146
      end if;
147
    end process mem_access;
148
    -- sync(!) read - alternative HDL style --
149
    mem_b0_rd <= mem_ram_b0(to_integer(unsigned(addr_ff)));
150
    mem_b1_rd <= mem_ram_b1(to_integer(unsigned(addr_ff)));
151
    mem_b2_rd <= mem_ram_b2(to_integer(unsigned(addr_ff)));
152
    mem_b3_rd <= mem_ram_b3(to_integer(unsigned(addr_ff)));
153
    -- pack --
154
    rdata <= mem_b3_rd & mem_b2_rd & mem_b1_rd & mem_b0_rd;
155
  end generate;
156
 
157
 
158
  -- Bus Feedback ---------------------------------------------------------------------------
159
  -- -------------------------------------------------------------------------------------------
160
  bus_feedback: process(clk_i)
161
  begin
162
    if rising_edge(clk_i) then
163
      rden <= acc_en and rden_i;
164
      if (IMEM_AS_IROM = true) then
165
        ack_o <= acc_en and rden_i;
166
      else
167
        ack_o <= acc_en and (rden_i or wren_i);
168
      end if;
169
    end if;
170
  end process bus_feedback;
171
 
172
  -- output gate --
173
  data_o <= rdata when (rden = '1') else (others => '0');
174
 
175
 
176
end neorv32_imem_rtl;

powered by: WebSVN 2.1.0

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