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

Subversion Repositories mlite

[/] [mlite/] [trunk/] [vhdl/] [ram.vhd] - Blame information for rev 11

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

Line No. Rev Author Line
1 2 rhoads
---------------------------------------------------------------------
2
-- TITLE: Random Access Memory
3
-- AUTHOR: Steve Rhoads (rhoadss@yahoo.com)
4
-- DATE CREATED: 4/21/01
5
-- FILENAME: ram.vhd
6
-- PROJECT: MIPS CPU core
7
-- COPYRIGHT: Software placed into the public domain by the author.
8
--    Software 'as is' without warranty.  Author liable for nothing.
9
-- DESCRIPTION:
10
--    Implements the RAM, reads the executable from "code.txt",
11
--    and saves a character to "output.txt" upon a write to 0xffff.
12
--    Modified from "The Designer's Guide to VHDL" by Peter J. Ashenden
13
---------------------------------------------------------------------
14
library ieee;
15
use ieee.std_logic_1164.all;
16
use ieee.std_logic_misc.all;
17
use ieee.std_logic_arith.all;
18
use ieee.std_logic_textio.all;
19
use std.textio.all;
20
 
21
use ieee.std_logic_unsigned.all;
22
use work.mips_pack.all;
23
 
24
entity ram is
25
   generic(load_file_name : string);
26
   port(clk          : in std_logic;
27
        mem_byte_sel : in std_logic_vector(3 downto 0);
28
        mem_write    : in std_logic;
29
        mem_address  : in std_logic_vector;
30
        mem_data_w   : in std_logic_vector(31 downto 0);
31
        mem_data_r   : out std_logic_vector(31 downto 0));
32
end; --entity ram
33
 
34
architecture logic of ram is
35
begin
36
 
37
ram_proc: process
38
   variable data : std_logic_vector(31 downto 0);
39
   variable d    : std_logic_vector(31 downto 0);
40
   variable datab : std_logic_vector(31 downto 0);
41
   variable value : natural;
42
   subtype word is std_logic_vector(mem_data_w'length-1 downto 0);
43
   type storage_array is
44
      array(natural range 0 to 2**mem_address'length-1) of word;
45
   variable storage : storage_array;
46
   variable index : natural;
47
   file load_file : text is in load_file_name;
48
   file store_file : text is out "output.txt";
49
   variable hex_file_line : line;
50
   variable c : character;
51
   variable line_length : natural := 0;
52
begin
53
   --load in the ram executable image
54
   index := 0;
55
   while not endfile(load_file) loop
56
      readline(load_file, hex_file_line);
57
      hread(hex_file_line, data);
58
      storage(index) := data;
59
      index := index + 1;
60
   end loop;
61 7 rhoads
   --assert false report "done reading code" severity note;
62 2 rhoads
 
63
   wait on clk;  --wait for line noise to go away
64 7 rhoads
   wait on mem_address;
65 2 rhoads
 
66
   loop
67
      wait on clk, mem_address, mem_write;
68
 
69
      --support putchar() when writing to address 0xffff
70
      if rising_edge(clk) then
71 7 rhoads
         if mem_byte_sel(0) = '1' and mem_address = ONES(15 downto 0) then
72 2 rhoads
            index := conv_integer(mem_data_w(6 downto 0));
73
            if index /= 10 then
74
               c := character'val(index);
75
               write(hex_file_line, c);
76
               line_length := line_length + 1;
77
            end if;
78 11 rhoads
            --line_length:=100;  --DEBUG mode
79 2 rhoads
            if index = 10 or line_length >= 72 then
80
               writeline(store_file, hex_file_line);
81
               line_length := 0;
82
            end if;
83
         end if;
84
      end if;
85
 
86
      index := conv_integer(mem_address(mem_address'length-1 downto 2));
87
      data := storage(index);
88
 
89
      if mem_write = '0' then
90
         mem_data_r <= data;
91 7 rhoads
      else
92
         mem_data_r <= HIGH_Z; --ZERO;
93 2 rhoads
      end if;
94
      if mem_byte_sel(0) = '1' then
95
         data(7 downto 0) := mem_data_w(7 downto 0);
96
      end if;
97
      if mem_byte_sel(1) = '1' then
98
         data(15 downto 8) := mem_data_w(15 downto 8);
99
      end if;
100
      if mem_byte_sel(2) = '1' then
101
         data(23 downto 16) := mem_data_w(23 downto 16);
102
      end if;
103
      if mem_byte_sel(3) = '1' then
104
         data(31 downto 24) := mem_data_w(31 downto 24);
105
      end if;
106
 
107
      if rising_edge(clk) then
108
         if mem_write = '1' then
109
            storage(index) := data;
110
         end if;
111
      end if;
112
   end loop;
113
end process;
114
 
115
end; --architecture logic
116
 
117
 

powered by: WebSVN 2.1.0

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