Project

General

Profile

Download (5.23 KB) Statistics
| Branch: | Tag: | Revision:
1

    
2
-- Copyright (C) 1996 Morgan Kaufmann Publishers, Inc
3

    
4
-- This file is part of VESTs (Vhdl tESTs).
5

    
6
-- VESTs is free software; you can redistribute it and/or modify it
7
-- under the terms of the GNU General Public License as published by the
8
-- Free Software Foundation; either version 2 of the License, or (at
9
-- your option) any later version. 
10

    
11
-- VESTs is distributed in the hope that it will be useful, but WITHOUT
12
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
-- FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14
-- for more details. 
15

    
16
-- You should have received a copy of the GNU General Public License
17
-- along with VESTs; if not, write to the Free Software Foundation,
18
-- Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
19

    
20
-- ---------------------------------------------------------------------
21
--
22
-- $Id: ch_18_fg_18_09.vhd,v 1.3 2001-10-26 16:29:36 paw Exp $
23
-- $Revision: 1.3 $
24
--
25
-- ---------------------------------------------------------------------
26

    
27
library bv_utilities;
28

    
29
use bv_utilities.bv_arithmetic.all, std.textio.all;
30

    
31
architecture file_loaded of memory is
32
begin
33

    
34
  mem_behavior : process is
35

    
36
                           constant high_address : natural := mem_size - 1;
37

    
38
                         type memory_array is
39
                           array (natural range 0 to high_address / 4) of dlx_bv_word;
40

    
41
                         variable mem : memory_array;
42

    
43
                         -- . . .    -- other variables as in architecture preloaded
44

    
45
                         procedure load is
46

    
47
                           file binary_file : text open read_mode is load_file_name;
48
                           variable L : line;
49
                           variable ch : character;
50
                           variable line_number : natural := 0;
51
                           variable addr : natural;
52
                           variable word : dlx_bv_word;
53

    
54
                           procedure read_hex_natural(L : inout line; n : out natural) is
55
                             variable result : natural := 0;
56
                           begin
57
                             for i in 1 to 8 loop
58
                               read(L, ch);
59
                               if '0' <= ch and ch <= '9' then
60
                                 result := result*16 + character'pos(ch) - character'pos('0');
61
                               elsif 'A' <= ch and ch <= 'F' then
62
                                 result := result*16 + character'pos(ch) - character'pos('A') + 10;
63
                               elsif 'a' <= ch and ch <= 'f' then
64
                                 result := result*16 + character'pos(ch) - character'pos('a') + 10;
65
                               else
66
                                 report "Format error in file " & load_file_name
67
                                   & " on line " & integer'image(line_number) severity error;
68
                               end if;
69
                             end loop;
70
                             n := result;
71
                           end read_hex_natural;
72

    
73
                           procedure read_hex_word(L : inout line; word : out dlx_bv_word) is
74
                             variable digit : natural;
75
                             variable r : natural := 0;
76
                           begin
77
                             for i in 1 to 8 loop
78
                               read(L, ch);
79
                               if '0' <= ch and ch <= '9' then
80
                                 digit := character'pos(ch) - character'pos('0');
81
                               elsif 'A' <= ch and ch <= 'F' then
82
                                 digit := character'pos(ch) - character'pos('A') + 10;
83
                               elsif 'a' <= ch and ch <= 'f' then
84
                                 digit := character'pos(ch) - character'pos('a') + 10;
85
                               else
86
                                 report "Format error in file " & load_file_name
87
                                   & " on line " & integer'image(line_number)
88
                                   severity error;
89
                               end if;
90
                               word(r to r+3) := natural_to_bv(digit, 4);
91
                               r := r + 4;
92
                             end loop;
93
                           end read_hex_word;
94

    
95
                         begin
96
                           while not endfile(binary_file) loop
97
                             readline(binary_file, L);
98
                             line_number := line_number + 1;
99
                             read_hex_natural(L, addr);
100
                             read(L, ch);  -- the space between addr and data
101
                             read_hex_word(L, word);
102
                             mem(addr / 4) := word;
103
                           end loop;
104
                         end load;
105

    
106
                         procedure do_write is -- . . . -- as in architecture preloaded
107

    
108
                           procedure do_read is -- . . .  -- as in architecture preloaded
109

    
110
                           begin
111
                             load;  -- read binary memory image into memory array
112
                             -- . . .       -- as in architecture preloaded
113
                           end process mem_behavior;
114

    
115
                         end architecture file_loaded;
(418-418/510)