1 |
2 |
__alexs__ |
-- --------------------------------------------------------------------------
|
2 |
|
|
-- >>>>>>>>>>>>>>>>>>>>>>>>>>>> COPYRIGHT NOTICE <<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
3 |
|
|
-- --------------------------------------------------------------------------
|
4 |
|
|
-- TITLE: Plasma MEMORY MODEL
|
5 |
|
|
-- AUTHOR: Alex Schoenberger (Alex.Schoenberger@ies.tu-darmstadt.de)
|
6 |
|
|
-- COMMENT: This project is based on Plasma CPU core by Steve Rhoads
|
7 |
|
|
|
8 |
|
|
-- www.ies.tu-darmstadt.de
|
9 |
|
|
-- TU Darmstadt
|
10 |
|
|
-- Institute for Integrated Systems
|
11 |
|
|
-- Merckstr. 25
|
12 |
|
|
|
13 |
|
|
-- 64283 Darmstadt - GERMANY
|
14 |
|
|
-- --------------------------------------------------------------------------
|
15 |
|
|
-- PROJECT: Plasma CPU core with FPU
|
16 |
|
|
-- FILENAME: plasma_memory.vhd
|
17 |
|
|
-- --------------------------------------------------------------------------
|
18 |
|
|
-- COPYRIGHT:
|
19 |
|
|
-- This project is distributed by GPLv2.0
|
20 |
|
|
-- Software placed into the public domain by the author.
|
21 |
|
|
-- Software 'as is' without warranty. Author liable for nothing.
|
22 |
|
|
-- --------------------------------------------------------------------------
|
23 |
|
|
-- DESCRIPTION:
|
24 |
|
|
-- memory interface
|
25 |
|
|
|
26 |
|
|
-- NOT SYNTHESIZABLE
|
27 |
|
|
|
28 |
|
|
-- --------------------------------------------------------------------------
|
29 |
|
|
-- Revision History
|
30 |
|
|
-- --------------------------------------------------------------------------
|
31 |
|
|
-- Revision Date Author CHANGES
|
32 |
|
|
-- 1.0 4/2014 AS initial
|
33 |
|
|
-- --------------------------------------------------------------------------
|
34 |
|
|
library IEEE;
|
35 |
|
|
use IEEE.std_logic_1164.ALL;
|
36 |
|
|
use IEEE.numeric_std.ALL;
|
37 |
|
|
|
38 |
|
|
library STD;
|
39 |
|
|
use STD.textio.ALL;
|
40 |
|
|
|
41 |
|
|
library PLASMA;
|
42 |
|
|
use PLASMA.plasma_pack.ALL;
|
43 |
|
|
|
44 |
|
|
package plasma_memory_pack is
|
45 |
|
|
|
46 |
|
|
constant PLASMA_MEM_RANGE : natural := 25;
|
47 |
|
|
constant PLASMA_MEM_SIZE : std_logic_vector(PLASMA_MEM_RANGE - 1 downto 0) := '1' & x"a2_0014";
|
48 |
|
|
constant PLASMA_MEM_SIZE_RANGE : natural := to_integer(unsigned(PLASMA_MEM_SIZE));
|
49 |
|
|
|
50 |
|
|
type t_plasma_memory is array(PLASMA_MEM_SIZE_RANGE - 1 downto 0) of t_plasma_mem_word;
|
51 |
|
|
|
52 |
|
|
subtype t_prog_addr is std_logic_vector(PLASMA_MEM_RANGE - 1 downto 0);
|
53 |
|
|
subtype t_data_addr is std_logic_vector(PLASMA_MEM_RANGE - 1 downto 0);
|
54 |
|
|
|
55 |
|
|
component plasma_memory is
|
56 |
|
|
port(
|
57 |
|
|
clk : in std_logic;
|
58 |
|
|
reset : in std_logic;
|
59 |
|
|
wr_mask : in t_plasma_mask;
|
60 |
|
|
rd_mask : in t_plasma_mask;
|
61 |
|
|
prog_addr : in t_plasma_word;
|
62 |
|
|
data_addr : in t_plasma_word;
|
63 |
|
|
prog_out : out t_plasma_word;
|
64 |
|
|
data_in : in t_plasma_word;
|
65 |
|
|
data_out : out t_plasma_word
|
66 |
|
|
);
|
67 |
|
|
end component plasma_memory;
|
68 |
|
|
|
69 |
|
|
procedure read_instr( signal instr : out t_plasma_word;
|
70 |
|
|
addr : in t_prog_addr;
|
71 |
|
|
memory : t_plasma_memory );
|
72 |
|
|
|
73 |
|
|
|
74 |
|
|
procedure read_heap( signal data : out t_plasma_word;
|
75 |
|
|
signal data_in : in t_plasma_word;
|
76 |
|
|
addr : in t_data_addr;
|
77 |
|
|
mask : in t_plasma_mask;
|
78 |
|
|
memory : t_plasma_memory );
|
79 |
|
|
|
80 |
|
|
procedure write_heap(signal data : in t_plasma_word;
|
81 |
|
|
addr : in t_data_addr;
|
82 |
|
|
mask : in t_plasma_mask;
|
83 |
|
|
variable memory : out t_plasma_memory );
|
84 |
|
|
|
85 |
|
|
procedure printf( memory : t_plasma_memory );
|
86 |
|
|
|
87 |
|
|
function ascii(int: integer) return character;
|
88 |
|
|
|
89 |
|
|
end package plasma_memory_pack;
|
90 |
|
|
|
91 |
|
|
|
92 |
|
|
package body plasma_memory_pack is
|
93 |
|
|
|
94 |
|
|
procedure read_instr( signal instr : out t_plasma_word;
|
95 |
|
|
addr : in t_prog_addr;
|
96 |
|
|
memory : t_plasma_memory ) is
|
97 |
|
|
variable i_addr : natural := 0;
|
98 |
|
|
begin
|
99 |
|
|
i_addr := to_integer(unsigned(addr));
|
100 |
|
|
|
101 |
|
|
instr(31 downto 24) <= memory(i_addr );
|
102 |
|
|
instr(23 downto 16) <= memory(i_addr + 1);
|
103 |
|
|
instr(15 downto 8) <= memory(i_addr + 2);
|
104 |
|
|
instr( 7 downto 0) <= memory(i_addr + 3);
|
105 |
|
|
end procedure read_instr;
|
106 |
|
|
|
107 |
|
|
procedure read_heap( signal data : out t_plasma_word;
|
108 |
|
|
signal data_in : in t_plasma_word;
|
109 |
|
|
addr : in t_data_addr;
|
110 |
|
|
mask : in t_plasma_mask;
|
111 |
|
|
memory : t_plasma_memory ) is
|
112 |
|
|
variable i_addr : natural := 0;
|
113 |
|
|
begin
|
114 |
|
|
i_addr := to_integer(unsigned(addr));
|
115 |
|
|
|
116 |
|
|
case mask is
|
117 |
|
|
when PLASMA_MASK_READ8 =>
|
118 |
|
|
data(31 downto 24) <= memory(i_addr );
|
119 |
|
|
data(23 downto 16) <= memory(i_addr );
|
120 |
|
|
data(15 downto 8) <= memory(i_addr );
|
121 |
|
|
data( 7 downto 0) <= memory(i_addr );
|
122 |
|
|
|
123 |
|
|
when PLASMA_MASK_READ16 =>
|
124 |
|
|
data(31 downto 24) <= memory(i_addr );
|
125 |
|
|
data(23 downto 16) <= memory(i_addr + 1);
|
126 |
|
|
data(15 downto 8) <= memory(i_addr );
|
127 |
|
|
data( 7 downto 0) <= memory(i_addr + 1);
|
128 |
|
|
|
129 |
|
|
when PLASMA_MASK_READ32L =>
|
130 |
|
|
data(31 downto 24) <= memory(i_addr );
|
131 |
|
|
data(23 downto 16) <= memory(i_addr + 1);
|
132 |
|
|
data(15 downto 0) <= data_in(15 downto 0);
|
133 |
|
|
|
134 |
|
|
when PLASMA_MASK_READ32R =>
|
135 |
|
|
data(31 downto 16) <= data_in(31 downto 16);
|
136 |
|
|
data(15 downto 8) <= memory(i_addr + 2);
|
137 |
|
|
data( 7 downto 0) <= memory(i_addr + 3);
|
138 |
|
|
|
139 |
|
|
when PLASMA_MASK_READ32 =>
|
140 |
|
|
data(31 downto 24) <= memory(i_addr );
|
141 |
|
|
data(23 downto 16) <= memory(i_addr + 1);
|
142 |
|
|
data(15 downto 8) <= memory(i_addr + 2);
|
143 |
|
|
data( 7 downto 0) <= memory(i_addr + 3);
|
144 |
|
|
|
145 |
|
|
when others =>
|
146 |
|
|
data <= (others => '0');
|
147 |
|
|
end case;
|
148 |
|
|
end procedure read_heap;
|
149 |
|
|
|
150 |
|
|
procedure write_heap(signal data : in t_plasma_word;
|
151 |
|
|
addr : in t_data_addr;
|
152 |
|
|
mask : in t_plasma_mask;
|
153 |
|
|
variable memory : out t_plasma_memory ) is
|
154 |
|
|
variable i_addr : natural := 0;
|
155 |
|
|
begin
|
156 |
|
|
i_addr := to_integer(unsigned(addr));
|
157 |
|
|
|
158 |
|
|
case mask is
|
159 |
|
|
when PLASMA_MASK_WRITE8 =>
|
160 |
|
|
memory(i_addr ) := data( 7 downto 0);
|
161 |
|
|
|
162 |
|
|
when PLASMA_MASK_WRITE16 =>
|
163 |
|
|
memory(i_addr + 1) := data( 7 downto 0);
|
164 |
|
|
memory(i_addr ) := data(15 downto 8);
|
165 |
|
|
|
166 |
|
|
when PLASMA_MASK_WRITE32L =>
|
167 |
|
|
memory(i_addr + 1) := data(23 downto 16);
|
168 |
|
|
memory(i_addr ) := data(31 downto 24);
|
169 |
|
|
|
170 |
|
|
when PLASMA_MASK_WRITE32R =>
|
171 |
|
|
memory(i_addr + 3) := data( 7 downto 0);
|
172 |
|
|
memory(i_addr + 2) := data(15 downto 8);
|
173 |
|
|
|
174 |
|
|
when PLASMA_MASK_WRITE32 =>
|
175 |
|
|
memory(i_addr + 3) := data( 7 downto 0);
|
176 |
|
|
memory(i_addr + 2) := data(15 downto 8);
|
177 |
|
|
memory(i_addr + 1) := data(23 downto 16);
|
178 |
|
|
memory(i_addr ) := data(31 downto 24);
|
179 |
|
|
|
180 |
|
|
when others =>
|
181 |
|
|
end case;
|
182 |
|
|
|
183 |
|
|
end procedure write_heap;
|
184 |
|
|
|
185 |
|
|
procedure printf( memory : t_plasma_memory ) is
|
186 |
|
|
|
187 |
|
|
constant ADDR : integer := 27394060;
|
188 |
|
|
|
189 |
|
|
variable message_addr : t_plasma_word;
|
190 |
|
|
variable message_length : t_plasma_word;
|
191 |
|
|
|
192 |
|
|
variable i_addr : integer;
|
193 |
|
|
variable i_length : integer;
|
194 |
|
|
|
195 |
|
|
variable message : line;
|
196 |
|
|
|
197 |
|
|
begin
|
198 |
|
|
|
199 |
|
|
-- get message address and length of the message
|
200 |
|
|
message_addr := memory(ADDR ) & memory(ADDR + 1) & memory(ADDR + 2) & memory(ADDR + 3);
|
201 |
|
|
message_length := memory(ADDR + 4) & memory(ADDR + 5) & memory(ADDR + 6) & memory(ADDR + 7);
|
202 |
|
|
|
203 |
|
|
-- and convert the values to integer
|
204 |
|
|
i_addr := to_integer(unsigned(message_addr));
|
205 |
|
|
i_length := to_integer(unsigned(message_length));
|
206 |
|
|
|
207 |
|
|
-- initialise the message string
|
208 |
|
|
message := new string(1 to i_length);
|
209 |
|
|
|
210 |
|
|
-- read ascii characters, last character is 0
|
211 |
|
|
for i in 0 to i_length - 1 loop
|
212 |
|
|
message(i + 1) := ascii( to_integer(unsigned(memory(i_addr + i))));
|
213 |
|
|
end loop;
|
214 |
|
|
|
215 |
|
|
-- print message text
|
216 |
|
|
report message.ALL;
|
217 |
|
|
|
218 |
|
|
end procedure printf;
|
219 |
|
|
|
220 |
|
|
|
221 |
|
|
function ascii(int: integer) return character is
|
222 |
|
|
variable c: character;
|
223 |
|
|
begin
|
224 |
|
|
case int is
|
225 |
|
|
when 10 => c := ' ';
|
226 |
|
|
when 32 => c := ' ';
|
227 |
|
|
when 33 => c := '!';
|
228 |
|
|
when 34 => c := '"';
|
229 |
|
|
when 35 => c := '#';
|
230 |
|
|
when 36 => c := '$';
|
231 |
|
|
when 37 => c := '%';
|
232 |
|
|
when 38 => c := '&';
|
233 |
|
|
when 39 => c := ''';
|
234 |
|
|
when 40 => c := '(';
|
235 |
|
|
when 41 => c := ')';
|
236 |
|
|
when 42 => c := '*';
|
237 |
|
|
when 43 => c := '+';
|
238 |
|
|
when 44 => c := ',';
|
239 |
|
|
when 45 => c := '-';
|
240 |
|
|
when 46 => c := '.';
|
241 |
|
|
when 47 => c := '/';
|
242 |
|
|
when 48 => c := '0';
|
243 |
|
|
when 49 => c := '1';
|
244 |
|
|
when 50 => c := '2';
|
245 |
|
|
when 51 => c := '3';
|
246 |
|
|
when 52 => c := '4';
|
247 |
|
|
when 53 => c := '5';
|
248 |
|
|
when 54 => c := '6';
|
249 |
|
|
when 55 => c := '7';
|
250 |
|
|
when 56 => c := '8';
|
251 |
|
|
when 57 => c := '9';
|
252 |
|
|
when 58 => c := ':';
|
253 |
|
|
when 59 => c := ';';
|
254 |
|
|
when 60 => c := '<';
|
255 |
|
|
when 61 => c := '=';
|
256 |
|
|
when 62 => c := '>';
|
257 |
|
|
when 63 => c := '?';
|
258 |
|
|
when 64 => c := '@';
|
259 |
|
|
when 65 => c := 'A';
|
260 |
|
|
when 66 => c := 'B';
|
261 |
|
|
when 67 => c := 'C';
|
262 |
|
|
when 68 => c := 'D';
|
263 |
|
|
when 69 => c := 'E';
|
264 |
|
|
when 70 => c := 'F';
|
265 |
|
|
when 71 => c := 'G';
|
266 |
|
|
when 72 => c := 'H';
|
267 |
|
|
when 73 => c := 'I';
|
268 |
|
|
when 74 => c := 'J';
|
269 |
|
|
when 75 => c := 'K';
|
270 |
|
|
when 76 => c := 'L';
|
271 |
|
|
when 77 => c := 'M';
|
272 |
|
|
when 78 => c := 'N';
|
273 |
|
|
when 79 => c := 'O';
|
274 |
|
|
when 80 => c := 'P';
|
275 |
|
|
when 81 => c := 'Q';
|
276 |
|
|
when 82 => c := 'R';
|
277 |
|
|
when 83 => c := 'S';
|
278 |
|
|
when 84 => c := 'T';
|
279 |
|
|
when 85 => c := 'U';
|
280 |
|
|
when 86 => c := 'V';
|
281 |
|
|
when 87 => c := 'W';
|
282 |
|
|
when 88 => c := 'X';
|
283 |
|
|
when 89 => c := 'Y';
|
284 |
|
|
when 90 => c := 'Z';
|
285 |
|
|
when 91 => c := '[';
|
286 |
|
|
when 92 => c := '\';
|
287 |
|
|
when 93 => c := ']';
|
288 |
|
|
when 94 => c := '^';
|
289 |
|
|
when 95 => c := '_';
|
290 |
|
|
when 96 => c := '`';
|
291 |
|
|
when 97 => c := 'a';
|
292 |
|
|
when 98 => c := 'b';
|
293 |
|
|
when 99 => c := 'c';
|
294 |
|
|
when 100 => c := 'd';
|
295 |
|
|
when 101 => c := 'e';
|
296 |
|
|
when 102 => c := 'f';
|
297 |
|
|
when 103 => c := 'g';
|
298 |
|
|
when 104 => c := 'h';
|
299 |
|
|
when 105 => c := 'i';
|
300 |
|
|
when 106 => c := 'j';
|
301 |
|
|
when 107 => c := 'k';
|
302 |
|
|
when 108 => c := 'l';
|
303 |
|
|
when 109 => c := 'm';
|
304 |
|
|
when 110 => c := 'n';
|
305 |
|
|
when 111 => c := 'o';
|
306 |
|
|
when 112 => c := 'p';
|
307 |
|
|
when 113 => c := 'q';
|
308 |
|
|
when 114 => c := 'r';
|
309 |
|
|
when 115 => c := 's';
|
310 |
|
|
when 116 => c := 't';
|
311 |
|
|
when 117 => c := 'u';
|
312 |
|
|
when 118 => c := 'v';
|
313 |
|
|
when 119 => c := 'w';
|
314 |
|
|
when 120 => c := 'x';
|
315 |
|
|
when 121 => c := 'y';
|
316 |
|
|
when 122 => c := 'z';
|
317 |
|
|
when 123 => c := '{';
|
318 |
|
|
when 124 => c := '|';
|
319 |
|
|
when 125 => c := '}';
|
320 |
|
|
when 126 => c := '~';
|
321 |
|
|
when others => c := '?'; report "Could not decode this ASCII integer value " & integer'image(int);
|
322 |
|
|
end case;
|
323 |
|
|
return c;
|
324 |
|
|
end ascii;
|
325 |
|
|
|
326 |
|
|
end package body plasma_memory_pack;
|
327 |
|
|
|
328 |
|
|
|
329 |
|
|
-- _____ _ _____ __ __ __ __ ______ __ __ ____ _______ __
|
330 |
|
|
-- | __ \| | /\ / ____| \/ | /\ | \/ | ____| \/ |/ __ \| __ \ \ / /
|
331 |
|
|
-- | |__) | | / \ | (___ | \ / | / \ | \ / | |__ | \ / | | | | |__) \ \_/ /
|
332 |
|
|
-- | ___/| | / /\ \ \___ \| |\/| | / /\ \ | |\/| | __| | |\/| | | | | _ / \ /
|
333 |
|
|
-- | | | |____ / ____ \ ____) | | | |/ ____ \ | | | | |____| | | | |__| | | \ \ | |
|
334 |
|
|
-- |_| |______/_/ \_\_____/|_| |_/_/ \_\ |_| |_|______|_| |_|\____/|_| \_\ |_|
|
335 |
|
|
library IEEE;
|
336 |
|
|
use IEEE.std_logic_1164.ALL;
|
337 |
|
|
use IEEE.numeric_std.ALL;
|
338 |
|
|
|
339 |
|
|
library PLASMA;
|
340 |
|
|
use PLASMA.plasma_pack.ALL;
|
341 |
|
|
|
342 |
|
|
library MEMORY;
|
343 |
|
|
use MEMORY.plasma_memory_pack.ALL;
|
344 |
|
|
|
345 |
|
|
entity plasma_memory is
|
346 |
|
|
port(
|
347 |
|
|
clk : in std_logic;
|
348 |
|
|
reset : in std_logic;
|
349 |
|
|
wr_mask : in t_plasma_mask;
|
350 |
|
|
rd_mask : in t_plasma_mask;
|
351 |
|
|
prog_addr : in t_plasma_word;
|
352 |
|
|
data_addr : in t_plasma_word;
|
353 |
|
|
prog_out : out t_plasma_word;
|
354 |
|
|
data_in : in t_plasma_word;
|
355 |
|
|
data_out : out t_plasma_word
|
356 |
|
|
);
|
357 |
|
|
end entity plasma_memory;
|
358 |
|
|
|
359 |
|
|
|
360 |
|
|
architecture behav_plasma_memory of plasma_memory is
|
361 |
|
|
|
362 |
|
|
shared variable ram : t_plasma_memory;
|
363 |
|
|
|
364 |
|
|
alias inst_addr : t_prog_addr is prog_addr(PLASMA_MEM_RANGE - 1 downto 0);
|
365 |
|
|
alias heap_addr : t_data_addr is data_addr(PLASMA_MEM_RANGE - 1 downto 0);
|
366 |
|
|
|
367 |
|
|
begin
|
368 |
|
|
|
369 |
|
|
memory_access:
|
370 |
|
|
process( clk )
|
371 |
|
|
begin
|
372 |
|
|
if falling_edge( clk ) then
|
373 |
|
|
|
374 |
|
|
-- ########### READ INSTRUCTION ###################
|
375 |
|
|
read_instr( prog_out, inst_addr, ram );
|
376 |
|
|
|
377 |
|
|
-- ########### READ HEAP ##########################
|
378 |
|
|
read_heap( data_out, data_in, heap_addr, rd_mask, ram );
|
379 |
|
|
|
380 |
|
|
-- ########### WRITE HEAP #########################
|
381 |
|
|
write_heap( data_in, heap_addr, wr_mask, ram );
|
382 |
|
|
|
383 |
|
|
-- ########### PRINTF FUNCTION ####################
|
384 |
|
|
if i_sim_control.print_message = '1' then
|
385 |
|
|
printf( ram );
|
386 |
|
|
end if;
|
387 |
|
|
|
388 |
|
|
end if;
|
389 |
|
|
end process;
|
390 |
|
|
|
391 |
|
|
end behav_plasma_memory;
|