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

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [rtl/] [core/] [neorv32_boot_rom.vhd] - Blame information for rev 23

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

Line No. Rev Author Line
1 2 zero_gravi
-- #################################################################################################
2
-- # << NEORV32 - Processor-internal bootloader ROM (BOOTROM) >>                                   #
3
-- # ********************************************************************************************* #
4
-- # BSD 3-Clause License                                                                          #
5
-- #                                                                                               #
6
-- # Copyright (c) 2020, Stephan Nolting. All rights reserved.                                     #
7
-- #                                                                                               #
8
-- # Redistribution and use in source and binary forms, with or without modification, are          #
9
-- # permitted provided that the following conditions are met:                                     #
10
-- #                                                                                               #
11
-- # 1. Redistributions of source code must retain the above copyright notice, this list of        #
12
-- #    conditions and the following disclaimer.                                                   #
13
-- #                                                                                               #
14
-- # 2. Redistributions in binary form must reproduce the above copyright notice, this list of     #
15
-- #    conditions and the following disclaimer in the documentation and/or other materials        #
16
-- #    provided with the distribution.                                                            #
17
-- #                                                                                               #
18
-- # 3. Neither the name of the copyright holder nor the names of its contributors may be used to  #
19
-- #    endorse or promote products derived from this software without specific prior written      #
20
-- #    permission.                                                                                #
21
-- #                                                                                               #
22
-- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS   #
23
-- # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF               #
24
-- # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE    #
25
-- # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,     #
26
-- # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE #
27
-- # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED    #
28
-- # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING     #
29
-- # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED  #
30
-- # OF THE POSSIBILITY OF SUCH DAMAGE.                                                            #
31
-- # ********************************************************************************************* #
32
-- # The NEORV32 Processor - https://github.com/stnolting/neorv32              (c) Stephan Nolting #
33
-- #################################################################################################
34
 
35
library ieee;
36
use ieee.std_logic_1164.all;
37
use ieee.numeric_std.all;
38
 
39
library neorv32;
40
use neorv32.neorv32_package.all;
41
use neorv32.neorv32_bootloader_image.all; -- this file is generated by the image generator
42
 
43
entity neorv32_boot_rom is
44 23 zero_gravi
  generic (
45
    BOOTROM_BASE : std_ulogic_vector(31 downto 0) := x"FFFF0000"; -- boot ROM base address
46
    BOOTROM_SIZE : natural := 4*1024  -- processor-internal boot ROM memory size in bytes
47
  );
48 2 zero_gravi
  port (
49
    clk_i  : in  std_ulogic; -- global clock line
50
    rden_i : in  std_ulogic; -- read enable
51
    addr_i : in  std_ulogic_vector(31 downto 0); -- address
52
    data_o : out std_ulogic_vector(31 downto 0); -- data out
53
    ack_o  : out std_ulogic -- transfer acknowledge
54
  );
55
end neorv32_boot_rom;
56
 
57
architecture neorv32_boot_rom_rtl of neorv32_boot_rom is
58
 
59
  -- local types --
60 23 zero_gravi
  type boot_img_t is array (0 to BOOTROM_SIZE/4-1) of std_ulogic_vector(31 downto 0);
61 2 zero_gravi
 
62
  -- init function --
63 22 zero_gravi
  -- impure function: returns NOT the same result every time it is evaluated with the same arguments since the source file might have changed
64 2 zero_gravi
  impure function init_boot_rom(init : bootloader_init_image_t) return boot_img_t is
65
    variable mem_v : boot_img_t;
66
  begin
67 22 zero_gravi
    mem_v := (others => (others => '0'));
68
    for i in 0 to init'length-1 loop -- init only in range of source data array
69 2 zero_gravi
      mem_v(i) := init(i);
70
    end loop; -- i
71
    return mem_v;
72
  end function init_boot_rom;
73
 
74
  -- local signals --
75
  signal acc_en : std_ulogic;
76
  signal rden   : std_ulogic;
77
  signal rdata  : std_ulogic_vector(31 downto 0);
78 23 zero_gravi
  signal addr   : std_ulogic_vector(index_size_f(BOOTROM_SIZE/4)-1 downto 0);
79 2 zero_gravi
 
80
  -- bootloader image --
81
  constant boot_img : boot_img_t := init_boot_rom(bootloader_init_image);
82
 
83
begin
84
 
85
  -- Access Control -------------------------------------------------------------------------
86
  -- -------------------------------------------------------------------------------------------
87 23 zero_gravi
  acc_en <= '1' when (addr_i >= BOOTROM_BASE) and (addr_i < std_ulogic_vector(unsigned(BOOTROM_BASE) + BOOTROM_SIZE)) else '0';
88
  addr   <= addr_i(index_size_f(BOOTROM_SIZE/4)+1 downto 2); -- word aligned
89 2 zero_gravi
 
90
 
91
  -- Memory Access --------------------------------------------------------------------------
92
  -- -------------------------------------------------------------------------------------------
93
  mem_file_access: process(clk_i)
94
  begin
95
    if rising_edge(clk_i) then
96
      rden <= rden_i and acc_en;
97
      if (acc_en = '1') then -- reduce switching activity when not accessed
98
        rdata <= boot_img(to_integer(unsigned(addr)));
99
      end if;
100
    end if;
101
  end process mem_file_access;
102
 
103
  -- output gate --
104
  data_o <= rdata when (rden = '1') else (others => '0');
105
  ack_o  <= rden;
106
 
107
 
108
end neorv32_boot_rom_rtl;

powered by: WebSVN 2.1.0

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