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

Subversion Repositories plasma

[/] [plasma/] [tags/] [arelease/] [vhdl/] [ram.vhd] - Blame information for rev 397

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
   assert false report "done reading code" severity note;
62
 
63
   wait on clk;  --wait for line noise to go away
64
 
65
   loop
66
      wait on clk, mem_address, mem_write;
67
 
68
      --support putchar() when writing to address 0xffff
69
      if rising_edge(clk) then
70
         if mem_write = '1' and mem_address = ONES(15 downto 0) then
71
            index := conv_integer(mem_data_w(6 downto 0));
72
            if index /= 10 then
73
               c := character'val(index);
74
               write(hex_file_line, c);
75
               line_length := line_length + 1;
76
            end if;
77
            if index = 10 or line_length >= 72 then
78
               writeline(store_file, hex_file_line);
79
               line_length := 0;
80
            end if;
81
         end if;
82
      end if;
83
 
84
      index := conv_integer(mem_address(mem_address'length-1 downto 2));
85
      data := storage(index);
86
 
87
      if mem_write = '0' then
88
         mem_data_r <= data;
89
      end if;
90
      if mem_byte_sel(0) = '1' then
91
         data(7 downto 0) := mem_data_w(7 downto 0);
92
      end if;
93
      if mem_byte_sel(1) = '1' then
94
         data(15 downto 8) := mem_data_w(15 downto 8);
95
      end if;
96
      if mem_byte_sel(2) = '1' then
97
         data(23 downto 16) := mem_data_w(23 downto 16);
98
      end if;
99
      if mem_byte_sel(3) = '1' then
100
         data(31 downto 24) := mem_data_w(31 downto 24);
101
      end if;
102
 
103
      if rising_edge(clk) then
104
         if mem_write = '1' then
105
            storage(index) := data;
106
         end if;
107
      end if;
108
   end loop;
109
end process;
110
 
111
end; --architecture logic
112
 
113
 

powered by: WebSVN 2.1.0

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