1 |
64 |
zero_gravi |
-- #################################################################################################
|
2 |
|
|
-- # << NEORV32 - Processor-internal instruction memory (IMEM) >> #
|
3 |
|
|
-- # ********************************************************************************************* #
|
4 |
|
|
-- # This version is intended for SIMULATION ONLY! #
|
5 |
|
|
-- # It implements the IMEM as pre-initialized RAM. #
|
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 |
|
|
-- << SIMULATION ONLY!!! >> IMEM as pre-initialized RAM --
|
60 |
|
|
-- ---------------------------------------------------- --
|
61 |
|
|
|
62 |
|
|
-- application (image) size in bytes --
|
63 |
|
|
constant imem_app_size_c : natural := (application_init_image'length)*4;
|
64 |
|
|
|
65 |
|
|
-- RAM - initialized with executable code --
|
66 |
|
|
signal mem_ram : mem32_t(0 to IMEM_SIZE/4-1) := mem32_init_f(application_init_image, IMEM_SIZE/4);
|
67 |
|
|
|
68 |
|
|
-- read data --
|
69 |
|
|
signal mem_ram_rd : std_ulogic_vector(31 downto 0);
|
70 |
|
|
|
71 |
|
|
begin
|
72 |
|
|
|
73 |
|
|
-- Sanity Checks --------------------------------------------------------------------------
|
74 |
|
|
-- -------------------------------------------------------------------------------------------
|
75 |
|
|
assert false report "NEORV32 PROCESSOR CONFIG NOTE: Implementing processor-internal [SIM-only!] IMEM as RAM (" & natural'image(IMEM_SIZE) &
|
76 |
|
|
" bytes), pre-initialized with application (" & natural'image(imem_app_size_c) & " bytes)." severity note;
|
77 |
|
|
--
|
78 |
|
|
assert not (imem_app_size_c > IMEM_SIZE) report "NEORV32 PROCESSOR CONFIG ERROR: Application (image = " & natural'image(imem_app_size_c) &
|
79 |
|
|
" bytes) does not fit into processor-internal IMEM (" & natural'image(IMEM_SIZE) & " bytes)!" severity error;
|
80 |
|
|
|
81 |
|
|
|
82 |
|
|
-- Access Control -------------------------------------------------------------------------
|
83 |
|
|
-- -------------------------------------------------------------------------------------------
|
84 |
|
|
acc_en <= '1' when (addr_i(hi_abb_c downto lo_abb_c) = IMEM_BASE(hi_abb_c downto lo_abb_c)) else '0';
|
85 |
|
|
addr <= addr_i(index_size_f(IMEM_SIZE/4)+1 downto 2); -- word aligned
|
86 |
|
|
|
87 |
|
|
|
88 |
|
|
-- Implement IMEM as pre-initialized RAM --------------------------------------------------
|
89 |
|
|
-- -------------------------------------------------------------------------------------------
|
90 |
|
|
mem_access: process(clk_i)
|
91 |
|
|
begin
|
92 |
|
|
if rising_edge(clk_i) then
|
93 |
|
|
if (acc_en = '1') then
|
94 |
|
|
if (wren_i = '1') and (ben_i(0) = '1') then -- byte 0
|
95 |
|
|
mem_ram(to_integer(unsigned(addr)))(07 downto 00) <= data_i(07 downto 00);
|
96 |
|
|
else
|
97 |
|
|
mem_ram_rd(07 downto 00) <= mem_ram(to_integer(unsigned(addr)))(07 downto 00);
|
98 |
|
|
end if;
|
99 |
|
|
if (wren_i = '1') and (ben_i(1) = '1') then -- byte 1
|
100 |
|
|
mem_ram(to_integer(unsigned(addr)))(15 downto 08) <= data_i(15 downto 08);
|
101 |
|
|
else
|
102 |
|
|
mem_ram_rd(15 downto 08) <= mem_ram(to_integer(unsigned(addr)))(15 downto 08);
|
103 |
|
|
end if;
|
104 |
|
|
if (wren_i = '1') and (ben_i(2) = '1') then -- byte 2
|
105 |
|
|
mem_ram(to_integer(unsigned(addr)))(23 downto 16) <= data_i(23 downto 16);
|
106 |
|
|
else
|
107 |
|
|
mem_ram_rd(23 downto 16) <= mem_ram(to_integer(unsigned(addr)))(23 downto 16);
|
108 |
|
|
end if;
|
109 |
|
|
if (wren_i = '1') and (ben_i(3) = '1') then -- byte 3
|
110 |
|
|
mem_ram(to_integer(unsigned(addr)))(31 downto 24) <= data_i(31 downto 24);
|
111 |
|
|
else
|
112 |
|
|
mem_ram_rd(31 downto 24) <= mem_ram(to_integer(unsigned(addr)))(31 downto 24);
|
113 |
|
|
end if;
|
114 |
|
|
end if;
|
115 |
|
|
end if;
|
116 |
|
|
end process mem_access;
|
117 |
|
|
|
118 |
|
|
-- read data --
|
119 |
|
|
rdata <= mem_ram_rd;
|
120 |
|
|
|
121 |
|
|
|
122 |
|
|
-- Bus Feedback ---------------------------------------------------------------------------
|
123 |
|
|
-- -------------------------------------------------------------------------------------------
|
124 |
|
|
bus_feedback: process(clk_i)
|
125 |
|
|
begin
|
126 |
|
|
if rising_edge(clk_i) then
|
127 |
|
|
rden <= acc_en and rden_i;
|
128 |
|
|
ack_o <= acc_en and (rden_i or wren_i);
|
129 |
|
|
end if;
|
130 |
|
|
end process bus_feedback;
|
131 |
|
|
|
132 |
|
|
-- output gate --
|
133 |
|
|
data_o <= rdata when (rden = '1') else (others => '0');
|
134 |
|
|
|
135 |
|
|
|
136 |
|
|
end neorv32_imem_rtl;
|