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

Subversion Repositories minimips

[/] [minimips/] [trunk/] [miniMIPS/] [bench/] [rom.vhd] - Blame information for rev 17

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

Line No. Rev Author Line
1 2 poppy
------------------------------------------------------------------------------------
2
--                                                                                --
3
--    Copyright (c) 2004, Hangouet Samuel                                         --
4
--                  , Jan Sebastien                                               --
5
--                  , Mouton Louis-Marie                                          --
6
--                  , Schneider Olivier     all rights reserved                   --
7
--                                                                                --
8
--    This file is part of miniMIPS.                                              --
9
--                                                                                --
10
--    miniMIPS is free software; you can redistribute it and/or modify            --
11 6 poppy
--    it under the terms of the GNU Lesser General Public License as published by --
12
--    the Free Software Foundation; either version 2.1 of the License, or         --
13 2 poppy
--    (at your option) any later version.                                         --
14
--                                                                                --
15
--    miniMIPS is distributed in the hope that it will be useful,                 --
16
--    but WITHOUT ANY WARRANTY; without even the implied warranty of              --
17
--    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               --
18 6 poppy
--    GNU Lesser General Public License for more details.                         --
19 2 poppy
--                                                                                --
20 6 poppy
--    You should have received a copy of the GNU Lesser General Public License    --
21 2 poppy
--    along with miniMIPS; if not, write to the Free Software                     --
22
--    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   --
23
--                                                                                --
24
------------------------------------------------------------------------------------
25
 
26
 
27
-- If you encountered any problem, please contact :
28
--
29
--   lmouton@enserg.fr
30
--   oschneid@enserg.fr
31
--   shangoue@enserg.fr
32
--
33
 
34
 
35
 
36
library ieee;
37
use ieee.std_logic_1164.all;
38
use ieee.numeric_std.all;
39
use ieee.std_logic_textio.all;
40
use std.textio.all;
41
 
42
library work;
43
use work.pack_mips.all;
44
 
45
entity rom is
46
   generic (mem_size : natural := 256; -- Size of the memory in words
47
            start : natural := 32768;
48
            latency : time := 0 ns);
49
   port(
50
       adr : in bus32;
51
       donnee : out bus32;
52
       ack : out std_logic;
53
       load : in std_logic;
54
       fname : in string
55
   );
56
end;
57
 
58
 
59
architecture bench of rom is
60
    type storage_array is array(natural range start to start+4*mem_size - 1) of bus8;
61
    signal storage : storage_array := (others => (others => '0'));    -- The memory
62
    signal adresse : bus16;
63
    signal taille : bus16;
64
begin
65
 
66
 
67
    process (load)
68
        -- Variables for loading the memory
69
        -- The reading is done by blocks
70
        type bin is file of integer;                    -- Binary type file
71
        file load_file : bin;
72
 
73
        variable c : integer ;                          -- Integer (32 bits) read in the file
74
        variable index : integer range storage'range;   -- Index for loading
75
        variable word : bus32;                          -- Word read in the file
76
        variable taille_bloc : integer;                 -- Current size of the block to load
77
        variable tmp : bus16;
78
        variable status : file_open_status;
79
 
80
        variable s : line;
81
        variable big_endian : boolean := true;          -- Define if the processor (on which we work) is little or big endian
82
    begin
83
 
84
    if load='1' then
85
 
86
        -- Reading of the file de fill the memory at the defined address
87
        file_open(status, load_file, fname, read_mode);
88
 
89
        if status=open_ok then
90
 
91
            while not endfile(load_file) loop
92
 
93
                -- Read the header of the block
94
                read(load_file, c);                             -- Read a 32 bit long word
95
                word := bus32(to_unsigned(c, 32));              -- Conversion to a bit vector
96
 
97
                if big_endian then
98
                    tmp := word(7 downto 0) & word(15 downto 8);
99
                else
100
                    tmp := word(31 downto 16);
101
                end if;
102
 
103
                index := to_integer(unsigned(tmp));
104
                adresse <= tmp;
105
 
106
                if big_endian then
107
                    tmp := word(23 downto 16) & word(31 downto 24);
108
                else
109
                    tmp := word(15 downto 0);
110
                end if;
111
 
112
 
113
                taille_bloc := to_integer(unsigned(tmp)) / 4;
114
                taille <= tmp;
115
 
116
                -- Load the block in the ROM
117
                for n in 1 to taille_bloc loop
118
 
119
                    -- The header file is not correct (block too small, ROM to small ...)
120
                    -- The simulation is stopped
121
                    assert (not endfile(load_file) and (index<=storage'high))
122
                        report "L'image n'a pas le bon format ou ne rentre pas dans la rom."
123
                        severity error;
124
 
125
                    if not endfile(load_file) and (index<=storage'high) then
126
                        read(load_file, c);
127
                        word := bus32(to_unsigned(c, 32));
128
                        if (c < 0) then
129
                          word := not(word);
130
                          word := std_logic_vector(unsigned(word)+1);
131
                        end if;
132
                        for i in 0 to 3 loop
133
 
134
                            if big_endian then
135
                                storage(index+i) <= word(8*(i+1)-1 downto 8*i);
136
                            else
137
                                storage(index+(3-i)) <= word(8*(i+1)-1 downto 8*i);
138
                            end if;
139
 
140
                        end loop;
141
                        index := index + 4;
142
                    end if;
143
                end loop;
144
 
145
            end loop;
146
 
147
            file_close(load_file);
148
 
149
        else
150
            assert false
151
                report "Impossible d'ouvrir le fichier specifie."
152
                severity error;
153
 
154
        end if;
155
 
156
    end if;
157
 
158
    end process;
159
 
160
 
161
 
162
 
163
    process(adr) -- Request for reading the ROM
164
        variable inadr : integer;
165
        variable i : natural;
166
    begin
167
            inadr := to_integer(unsigned(adr));
168
 
169
            if (inadr>=storage'low) and (inadr<=storage'high) then
170
                for i in 0 to 3 loop
171
                    donnee(8*(i+1)-1 downto 8*i) <= storage(inadr+3-i) after latency;
172
                end loop;
173
                ack <= '0', '1' after latency;
174
            else
175
                donnee <= (others => 'Z');
176
                ack <= 'L';
177
            end if;
178
    end process;
179
 
180
end bench;
181
 
182
 
183
 

powered by: WebSVN 2.1.0

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