Project

General

Profile

Download (5.66 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-pl.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

    
31
architecture preloaded of memory is
32

    
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
                           := ( X"20020000",	 --           addi  r2, r0, 0
44
                                X"ac020018",  -- loop:     sw    counter(r0), r2
45
                                X"20420001",  --           addi  r2, r2, 1
46
                                X"6441000a",  --           snei  r1, r2, 10
47
                                X"1420fff0",  --           bnez  r1, loop
48
                                X"44000000",  --           trap  0
49
                                X"00000000",  -- counter:  .word 0
50
                                others => X"00000000" );
51

    
52
                         variable byte_address, word_address : natural;
53
                         variable write_access : boolean;
54

    
55

    
56
                         procedure do_write is
57
                           subtype ls_2_bits is bit_vector(1 downto 0);
58
                         begin
59
                           case width is
60
                             when dlx_mem_width_word =>
61
                               mem(word_address) := to_bitvector(d);
62
                             when dlx_mem_width_halfword =>
63
                               if To_bit(a(1)) = '0' then  -- ms half word
64
                                 mem(word_address)(0 to 15) := to_bitvector( d(0 to 15) );
65
                               else  -- ls half word
66
                                 mem(word_address)(16 to 31) := to_bitvector( d(16 to 31) );
67
                               end if;
68
                             when dlx_mem_width_byte =>
69
                               case ls_2_bits'(To_bitvector(a(1 downto 0))) is
70
                                 when b"00" =>
71
                                   mem(word_address)(0 to 7) := to_bitvector( d(0 to 7) );
72
                                 when b"01" =>
73
                                   mem(word_address)(8 to 15) := to_bitvector( d(8 to 15) );
74
                                 when b"10" =>
75
                                   mem(word_address)(16 to 23) := to_bitvector( d(16 to 23) );
76
                                 when b"11" =>
77
                                   mem(word_address)(24 to 31) := to_bitvector( d(24 to 31) );
78
                               end case;
79
                             when others =>
80
                               report "illegal width indicator in write" severity error;
81
                           end case;
82
                         end do_write;
83

    
84
                         procedure do_read is
85
                         begin
86
                           d <= To_X01( mem(word_address) );
87
                         end do_read;
88

    
89
  begin
90
    -- initialize outputs
91
    d <= disabled_dlx_word;
92
    ready <= '0';
93

    
94
    -- process memory cycles
95
    loop
96
      -- wait for a command, valid on leading edge of phi2
97
      wait on phi2 until rising_edge(phi2) and To_bit(mem_enable) = '1';
98

    
99
      -- decode address and perform command if selected
100
      byte_address := bv_to_natural(To_bitvector(a));
101
      write_access := To_bit(write_enable) = '1';
102
      if byte_address <= high_address then
103
        word_address := byte_address / 4;
104
        if write_access then -- write cycle
105
          do_write;
106
          wait for Tac_first;  -- write access time, 1st cycle
107
        else -- read cycle
108
          wait for Tac_first;  -- read access time, 1st cycle
109
          do_read;
110
        end if;
111
        -- ready synchronous with phi2
112
        wait until rising_edge(phi2);
113
        ready <= '1' after Tpd_clk_out;
114
        wait until falling_edge(phi2);
115
        ready <= '0' after Tpd_clk_out;
116
        --  do subsequent cycles in burst
117
        while To_bit(burst) = '1' loop
118
	  word_address := (word_address + 1) mod (mem_size / 4);
119
          wait until rising_edge(phi2);
120
          if write_access then -- write cycle
121
            do_write;
122
            wait for Tac_burst;  -- write access time, burst cycle
123
          else -- read cycle
124
            wait for Tac_burst;  -- read access time, burst cycle
125
            do_read;
126
          end if;
127
          -- ready synchronous with phi2
128
          wait until rising_edge(phi2);
129
          ready <= '1' after Tpd_clk_out;
130
          wait until falling_edge(phi2);
131
          ready <= '0' after Tpd_clk_out;
132
        end loop;
133
        if not write_access then  -- was read
134
          d <= disabled_dlx_word after Tpd_clk_out;
135
        end if;
136
      end if;
137
    end loop;
138
  end process mem_behavior;
139

    
140
end architecture preloaded;
(25-25/42)