Project

General

Profile

Download (8.46 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_15_mem-fl.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,
30
  std.textio.all;
31

    
32
architecture file_loaded of memory is
33
begin
34

    
35
  mem_behavior : process is
36

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

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

    
42
                         variable mem : memory_array;
43

    
44
                         variable byte_address, word_address : natural;
45
                         variable write_access : boolean;
46

    
47
                         procedure load is
48

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

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

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

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

    
108
                         procedure do_write is
109
                           subtype ls_2_bits is bit_vector(1 downto 0);
110
                         begin
111
                           case width is
112
                             when dlx_mem_width_word =>
113
                               mem(word_address) := to_bitvector(d);
114
                             when dlx_mem_width_halfword =>
115
                               if To_bit(a(1)) = '0' then  -- ms half word
116
                                 mem(word_address)(0 to 15) := to_bitvector( d(0 to 15) );
117
                               else  -- ls half word
118
                                 mem(word_address)(16 to 31) := to_bitvector( d(16 to 31) );
119
                               end if;
120
                             when dlx_mem_width_byte =>
121
                               case ls_2_bits'(To_bitvector(a(1 downto 0))) is
122
                                 when b"00" =>
123
                                   mem(word_address)(0 to 7) := to_bitvector( d(0 to 7) );
124
                                 when b"01" =>
125
                                   mem(word_address)(8 to 15) := to_bitvector( d(8 to 15) );
126
                                 when b"10" =>
127
                                   mem(word_address)(16 to 23) := to_bitvector( d(16 to 23) );
128
                                 when b"11" =>
129
                                   mem(word_address)(24 to 31) := to_bitvector( d(24 to 31) );
130
                               end case;
131
                             when others =>
132
                               report "illegal width indicator in write" severity error;
133
                           end case;
134
                         end do_write;
135

    
136
                         procedure do_read is
137
                         begin
138
                           d <= To_X01( mem(word_address) );
139
                         end do_read;
140

    
141
  begin
142
    load;  -- read binary memory image into memory array
143
    -- initialize outputs
144
    d <= disabled_dlx_word;
145
    ready <= '0';
146

    
147
    -- process memory cycles
148
    loop
149
      -- wait for a command, valid on leading edge of phi2
150
      wait on phi2 until rising_edge(phi2) and To_bit(mem_enable) = '1';
151

    
152
      -- decode address and perform command if selected
153
      byte_address := bv_to_natural(To_bitvector(a));
154
      write_access := To_bit(write_enable) = '1';
155
      if byte_address <= high_address then
156
        word_address := byte_address / 4;
157
        if write_access then -- write cycle
158
          do_write;
159
          wait for Tac_first;  -- write access time, 1st cycle
160
        else -- read cycle
161
          wait for Tac_first;  -- read access time, 1st cycle
162
          do_read;
163
        end if;
164
        -- ready synchronous with phi2
165
        wait until rising_edge(phi2);
166
        ready <= '1' after Tpd_clk_out;
167
        wait until falling_edge(phi2);
168
        ready <= '0' after Tpd_clk_out;
169
        --  do subsequent cycles in burst
170
        while To_bit(burst) = '1' loop
171
          word_address := (word_address + 1) mod (mem_size / 4);
172
          wait until rising_edge(phi2);
173
          if write_access then -- write cycle
174
            do_write;
175
            wait for Tac_burst;  -- write access time, burst cycle
176
          else -- read cycle
177
            wait for Tac_burst;  -- read access time, burst cycle
178
            do_read;
179
          end if;
180
          -- ready synchronous with phi2
181
          wait until rising_edge(phi2);
182
          ready <= '1' after Tpd_clk_out;
183
          wait until falling_edge(phi2);
184
          ready <= '0' after Tpd_clk_out;
185
        end loop;
186
        if not write_access then  -- was read
187
          d <= disabled_dlx_word after Tpd_clk_out;
188
        end if;
189
      end if;
190
    end loop;
191
  end process mem_behavior;
192

    
193
end architecture file_loaded;
(97-97/171)