OpenCores
URL https://opencores.org/ocsvn/am9080_cpu_based_on_microcoded_am29xx_bit-slices/am9080_cpu_based_on_microcoded_am29xx_bit-slices/trunk

Subversion Repositories am9080_cpu_based_on_microcoded_am29xx_bit-slices

[/] [am9080_cpu_based_on_microcoded_am29xx_bit-slices/] [trunk/] [Am9080/] [rom512x56.vhd] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 zpekic
----------------------------------------------------------------------------------
2
-- Company: 
3
-- Engineer: 
4
-- 
5
-- Create Date:    16:51:58 02/19/2017 
6
-- Design Name: 
7
-- Module Name:    tinyrom - Behavioral 
8
-- Project Name: 
9
-- Target Devices: 
10
-- Tool versions: 
11
-- Description: 
12
--
13
-- Dependencies: 
14
--
15
-- Revision: 
16
-- Revision 0.01 - File Created
17
-- Additional Comments: 
18
--
19
----------------------------------------------------------------------------------
20
library IEEE;
21
use IEEE.STD_LOGIC_1164.ALL;
22
use STD.textio.all;
23
use ieee.std_logic_textio.all;
24
 
25
-- Uncomment the following library declaration if using
26
-- arithmetic functions with Signed or Unsigned values
27
use IEEE.NUMERIC_STD.ALL;
28
 
29
-- Uncomment the following library declaration if instantiating
30
-- any Xilinx primitives in this code.
31
--library UNISIM;
32
--use UNISIM.VComponents.all;
33
 
34
--use work.tinycpu_common.all;
35
 
36
entity rom512x56 is
37
    Port ( address : in  STD_LOGIC_VECTOR (8 downto 0);
38
           data : out STD_LOGIC_VECTOR (55 downto 0));
39
end rom512x56;
40
 
41
architecture Behavioral of rom512x56 is
42
 
43
--type t_uinstruction is array (55 downto 0) of std_logic;
44
type t_word is array(15 downto 0) of std_logic;
45
type t_byte is array(7 downto 0) of std_logic;
46
type t_uinstruction512 is array(0 to 511) of std_logic_vector(55 downto 0);
47
constant uCode_nop: std_logic_vector(55 downto 0) := "11000000001011111010100111110000001101010101010001000000";
48
constant uCode_default: std_logic_vector(55 downto 0) := "11111111111111111111111111111111111111111111111111111111";
49
 
50
type t_string16x4 is array(0 to 15) of string(1 to 4);
51
type t_string8x3 is array(0 to 7) of string(1 to 3);
52
type t_string8x5 is array(0 to 7) of string(1 to 5);
53
type t_string8x6 is array(0 to 7) of string(1 to 6);
54
type t_string4x4 is array(0 to 3) of string(1 to 4);
55
type t_string4x2 is array(0 to 3) of string(1 to 2);
56
type t_string2x2 is array(0 to 1) of string(1 to 2);
57
type t_string2x1 is array(0 to 1) of string(1 to 1);
58
constant cond_decode: t_string16x4 := ("Z   ", "CY  ", "P   ", "S   ", "AC  ", "?(5)", "?(6)", "?(7)", "INT ", "RDY ", "HOLD", "?(B)", "F3  ", "F=0 ", "CN4 ", "TRUE");
59
constant reg_decode: t_string16x4 :=  ("R_BC", "R_CB", "R_DE", "R_ED", "R_HL", "R_LH", "R_?A", "R_A?", "R_SP", "R_9?", "RAS1", "RBS2", "RZ38", "R38Z", "RES3", "R_PC");
60
constant src_decode: t_string8x3 :=  ("AQ ", "AB ", "ZQ ", "ZB ", "ZA ", "DA ", "DQ ", "DZ ");
61
constant fct_decode: t_string8x5 :=  ("ADD  ", "SUBR ", "SUBS ", "OR   ", "AND  ", "NOTRS", "EXOR ", "EXNOR");
62
constant dst_decode: t_string8x5 :=  ("QREG ", "NOP  ", "RAMA ", "RAMF ", "RAMQD", "RAMD ", "RAMQU", "RAMU ");
63
constant next_decode: t_string8x6 := ("C/R   ", "D/R   ", "C/SBR ", "R/RTN ", "F/SBR ", "POP/PR", "R/PUSH", "R/F   ");
64
constant databusenable_decode: t_string4x2 := ("--", "YL", "YH", "FL");
65
constant outputsteer_decode: t_string4x4 := ("----", "DATA", "ADDR", "INTE");
66
constant immediatedatabus_decode: t_string2x1 := ("m", "-");
67
constant size_decode: t_string2x2 := ("8 ", "16");
68
constant instregenable_decode: t_string2x1 := ("i", "-");
69
constant condpolarity_decode: t_string2x1 := ("-", "!");
70
 
71
alias a8: std_logic_vector(8 downto 0) is address(8 downto 0);
72
 
73
 
74
impure function char2hex(char: in character) return integer is
75
begin
76
        case char is
77
                when '0' to '9' =>
78
                        return character'pos(char) - character'pos('0');
79
                when 'a' to 'f' =>
80
                        return character'pos(char) - character'pos('a') + 10;
81
                when 'A' to 'F' =>
82
                        return character'pos(char) - character'pos('A') + 10;
83
                when others =>
84
                        assert false report "char2hex(): unexpected character '" & char & "'" severity failure;
85
        end case;
86
        return 0;
87
end char2hex;
88
 
89
impure function decode_buscontrol(buscontrol: in std_logic_vector(5 downto 0)) return string is
90
begin
91
        case buscontrol is
92
                when "111110" => return "NOC   ";
93
                when "111100" => return "MEMW  ";
94
                when "111010" => return "MEMR  ";
95
                when "110110" => return "IOW   ";
96
                when "101110" => return "IOR   ";
97
                when "011110" => return "INTA  ";
98
                when "111111" => return "HLDA  ";
99
        when others =>
100
                return "??????";
101
        end case;
102
end decode_buscontrol;
103
 
104
impure function decode_reg(reg: in std_logic_vector(3 downto 0)) return string is
105
begin
106
        return reg_decode(to_integer(unsigned(reg)));
107
end decode_reg;
108
 
109
impure function decode_cond(cond: in std_logic_vector(3 downto 0)) return string is
110
begin
111
        return cond_decode(to_integer(unsigned(cond)));
112
end decode_cond;
113
 
114
impure function decode_src(src: in std_logic_vector(2 downto 0)) return string is
115
begin
116
        return src_decode(to_integer(unsigned(src)));
117
end decode_src;
118
 
119
impure function decode_fct(fct: in std_logic_vector(2 downto 0)) return string is
120
begin
121
        return fct_decode(to_integer(unsigned(fct)));
122
end decode_fct;
123
 
124
impure function decode_dst(dst: in std_logic_vector(2 downto 0)) return string is
125
begin
126
        return dst_decode(to_integer(unsigned(dst)));
127
end decode_dst;
128
 
129
impure function decode_next(nxt: in std_logic_vector(2 downto 0)) return string is
130
begin
131
        return next_decode(to_integer(unsigned(nxt)));
132
end decode_next;
133
 
134
impure function decode_databusenable(busenable: in std_logic_vector(1 downto 0)) return string is
135
begin
136
        return databusenable_decode(to_integer(unsigned(busenable)));
137
end decode_databusenable;
138
 
139
impure function decode_outputsteer(outputsteer: in std_logic_vector(1 downto 0)) return string is
140
begin
141
        return outputsteer_decode(to_integer(unsigned(outputsteer)));
142
end decode_outputsteer;
143
 
144
impure function decode_immediatedatabus(immediatedatabus: in std_logic) return string is
145
begin
146
        return immediatedatabus_decode(to_integer(unsigned'("" & immediatedatabus)));
147
end decode_immediatedatabus;
148
 
149
impure function decode_size(size: in std_logic) return string is
150
begin
151
        return size_decode(to_integer(unsigned'("" & size)));
152
end decode_size;
153
 
154
impure function decode_instregenable(instregenable: in std_logic) return string is
155
begin
156
        return instregenable_decode(to_integer(unsigned'("" & instregenable)));
157
end decode_instregenable;
158
 
159
impure function decode_condpolarity(condpolarity: in std_logic) return string is
160
begin
161
        return condpolarity_decode(to_integer(unsigned'("" & condpolarity)));
162
end decode_condpolarity;
163
 
164
procedure dump_wordmemory(out_file_name: in string; depth: in integer; temp_mem: in t_uinstruction512; base: in integer) is
165
    file out_file : text open write_mode is out_file_name;
166
    variable out_line : line;
167
 
168
begin
169
        -- dump memory content in <address> <word> format for verification
170
    for i in 0 to (depth - 1) loop
171
 
172
                  if ((i mod 32 = 0) and not ((base = 8) or (base = 16))) then
173
                                write(out_line, string'("-----------------------------------------------------------------------------------------"));writeline(out_file, out_line);
174
                                write(out_line, string'("     I D DIRECT-VALUE NXT    P COND B SYSCTL OE OS   A UK S C W  AADR BADR DST   FCT  SRC"));writeline(out_file, out_line);
175
                                write(out_line, string'("-----------------------------------------------------------------------------------------"));writeline(out_file, out_line);
176
                  end if;
177
 
178
        hwrite(out_line, std_logic_vector(to_unsigned(i, 16)));
179
        write(out_line, string'(" "));
180
                  if (temp_mem(i) = ucode_default) then
181
                                write(out_line, string'("(uninitialized)"));
182
                  else
183
                          case base is
184
                                        when 2 =>
185
                                                 write(out_line, temp_mem(i)(55));write(out_line, string'(" "));
186
                                                 write(out_line, temp_mem(i)(54));write(out_line, string'(" "));
187
                                                 write(out_line, temp_mem(i)(53 downto 42));write(out_line, string'(" "));
188
                                                 write(out_line, temp_mem(i)(41 downto 39));write(out_line, string'("    "));
189
                                                 write(out_line, temp_mem(i)(38));write(out_line, string'(" "));
190
                                                 write(out_line, temp_mem(i)(37 downto 34));write(out_line, string'(" "));
191
                                                 write(out_line, temp_mem(i)(33));write(out_line, string'(" "));
192
                                                 write(out_line, temp_mem(i)(32 downto 27));write(out_line, string'(" "));
193
                                                 write(out_line, temp_mem(i)(26 downto 25));write(out_line, string'(" "));
194
                                                 write(out_line, temp_mem(i)(24 downto 23));write(out_line, string'("   "));
195
                                                 write(out_line, temp_mem(i)(22));write(out_line, string'(" "));
196
                                                 write(out_line, temp_mem(i)(21 downto 20));write(out_line, string'(" "));
197
                                                 write(out_line, temp_mem(i)(19));write(out_line, string'(" "));
198
                                                 write(out_line, temp_mem(i)(18));write(out_line, string'(" "));
199
                                                 write(out_line, temp_mem(i)(17));write(out_line, string'("  "));
200
                                                 write(out_line, temp_mem(i)(16 downto 13));write(out_line, string'(" "));
201
                                                 write(out_line, temp_mem(i)(12 downto 9));write(out_line, string'(" "));
202
                                                 write(out_line, temp_mem(i)(8 downto 6));write(out_line, string'("   "));
203
                                                 write(out_line, temp_mem(i)(5 downto 3));write(out_line, string'("   "));
204
                                                 write(out_line, temp_mem(i)(2 downto 0));
205
                                        when 8 =>
206
                                                 owrite(out_line, temp_mem(i));
207
                                        when 16 =>
208
                                                 hwrite(out_line, temp_mem(i));
209
                                        when others => -- any other value will dump microcode "mnemonics"
210
                                                 write(out_line, decode_instregenable(temp_mem(i)(55)));write(out_line, string'(" "));
211
                                                 write(out_line, decode_immediatedatabus(temp_mem(i)(54)));write(out_line, string'(" "));
212
                                                 if (unsigned(temp_mem(i)(53 downto 42)) = i) then
213
                                                        write(out_line, string'("= location = "));
214
                                                 else
215
                                                        write(out_line, temp_mem(i)(53 downto 42));write(out_line, string'(" "));
216
                                                 end if;
217
                                                 write(out_line, decode_next(temp_mem(i)(41 downto 39)));write(out_line, string'(" "));
218
                                                 write(out_line, decode_condpolarity(temp_mem(i)(38)));write(out_line, string'(" "));
219
                                                 write(out_line, decode_cond(temp_mem(i)(37 downto 34)));write(out_line, string'(" "));
220
                                                 write(out_line, temp_mem(i)(33));write(out_line, string'(" "));
221
                                                 write(out_line, decode_buscontrol(temp_mem(i)(32 downto 27)));write(out_line, string'(" "));
222
                                                 write(out_line, decode_databusenable(temp_mem(i)(26 downto 25)));write(out_line, string'(" "));
223
                                                 write(out_line, decode_outputsteer(temp_mem(i)(24 downto 23)));write(out_line, string'(" "));
224
                                                 write(out_line, temp_mem(i)(22));write(out_line, string'(" "));
225
                                                 write(out_line, temp_mem(i)(21 downto 20));write(out_line, string'(" "));
226
                                                 write(out_line, temp_mem(i)(19));write(out_line, string'(" "));
227
                                                 write(out_line, temp_mem(i)(18));write(out_line, string'(" "));
228
                                                 write(out_line, decode_size(temp_mem(i)(17)));write(out_line, string'(" "));
229
                                                 write(out_line, decode_reg(temp_mem(i)(16 downto 13)));write(out_line, string'(" "));
230
                                                 write(out_line, decode_reg(temp_mem(i)(12 downto 9)));write(out_line, string'(" "));
231
                                                 write(out_line, decode_dst(temp_mem(i)(8 downto 6)));write(out_line, string'(" "));
232
                                                 write(out_line, decode_fct(temp_mem(i)(5 downto 3)));write(out_line, string'(" "));
233
                                                 write(out_line, decode_src(temp_mem(i)(2 downto 0)));
234
                          end case;
235
                  end if;
236
        writeline(out_file, out_line);
237
    end loop;
238
    file_close(out_file);
239
end dump_wordmemory;
240
 
241
impure function parseHex16(hex_str: in string) return std_logic_vector is
242
        variable intVal: integer := 0;
243
begin
244
        --report "parseHex16(" & hex_str & ")" severity note;
245
 
246
        for i in hex_str'left to hex_str'right loop
247
                intVal := 16 * intVal + char2hex(hex_str(i));
248
        end loop;
249
        return std_logic_vector(to_unsigned(intVal, 16));
250
end parseHex16;
251
 
252
impure function parseBinary8(bin_str: in string) return std_logic_vector is
253
        variable val: std_logic_vector(7 downto 0) := "00000000";
254
begin
255
        --report "parseBinary8(" & bin_str & ")" severity note;
256
        for i in bin_str'left to bin_str'right loop
257
                case bin_str(i) is
258
                        when '0' =>
259
                                val := val(6 downto 0) & "0";
260
                        when '1'|'X' => -- interpret X as '1' due to bus signal being low active - this way is undefined microinstruction is executed, bus won't short!
261
                                val := val(6 downto 0) & "1";
262
                        when others =>
263
                                assert false report "parseBinary8(): unexpected character '" & bin_str(i) & "'" severity failure;
264
                end case;
265
        end loop;
266
 
267
        return val;
268
end parseBinary8;
269
 
270
impure function parseBinary16(bin_str: in string) return std_logic_vector is
271
begin
272
        --report "parseBinary16(" & bin_str & ")" severity note;
273
        return parseBinary8(bin_str(1 to 8)) & parseBinary8(bin_str(9 to 16));
274
end parseBinary16;
275
 
276
 
277
impure function init_wordmemory(input_file_name : in string; dump_file_name: in string; dump_file_base: in integer; depth: in integer; default_value: std_logic_vector(55 downto 0)) return t_uinstruction512 is
278
    variable temp_mem : t_uinstruction512;-- := (others => (others => default_value));
279
         -- mif file variables
280
    file input_file : text open read_mode is input_file_name;
281
    variable input_line : line;
282
         variable line_current: integer := 0;
283
         variable line_cnt_accepted, line_cnt_ignored: integer := 0;
284
         variable address: std_logic_vector(15 downto 0);
285
         variable word: std_logic_vector(55 downto 0);
286
         variable addr_str: string(1 to 3);
287
         variable data16_str1, data16_str2, data16_str3: string(1 to 16);
288
         variable data8_str: string(1 to 8);
289
         variable addr_ok, data16_ok1, data16_ok2, data16_ok3, data8_ok : boolean;
290
         variable firstChar: character;
291
 
292
begin
293
         -- fill with default value
294
         for i in 0 to depth - 1 loop
295
                temp_mem(i) := default_value;
296
                --temp_mem(i) := std_logic_vector(to_unsigned(i, 9)) & "00000000000000000000000000000000000000000000000";
297
         end loop;
298
         assert false report "init_bytememory(): initialized " & integer'image(depth) & " words of memory to default value " severity note;
299
 
300
         -- parse the file for the data
301
         assert false report "init_bytememory(): loading memory from file " & input_file_name severity note;
302
         loop
303
                exit when endfile(input_file); --till the end of file is reached continue.
304
                line_current := line_current + 1;
305
      readline (input_file, input_line);
306
                --next when input_line'length = 0;  -- Skip empty lines
307
                report "init_mem(): parsing line " & integer'image(line_current) severity note;
308
                --report "[" & integer'image(input_line'left) & "]" severity note;
309
                address := X"0000";
310
                word := X"00000000000000";
311
 
312
                read(input_line, firstChar);
313
                --exit when endline(input_line);
314
                addr_ok := true;
315
                report "addr_str='" & firstChar & "'" severity note;
316
                case firstChar is
317
                when ';' =>
318
                        --report "Semicolon detected, line is treated as comment" severity note;
319
                        line_cnt_ignored := line_cnt_ignored + 1;
320
                when '0' to '9' | 'A' to 'F' =>
321
                        read(input_line, addr_str, addr_ok);
322
                        read(input_line, data16_str1, data16_ok1);
323
                        read(input_line, data16_str2, data16_ok2);
324
                        read(input_line, data16_str3, data16_ok3);
325
                        read(input_line, data8_str, data8_ok);
326
                        --if (addr_ok and data16_ok1 and data16_ok2 and data16_ok3 and data8_ok) then
327
                                address := parseHex16(firstChar & addr_str);
328
                                word := parseBinary16(data16_str1) & parseBinary16(data16_str2) & parseBinary16(data16_str3) & parseBinary8(data8_str);
329
 
330
                                temp_mem(to_integer(unsigned(address))) := word;
331
                                line_cnt_accepted := line_cnt_accepted + 1;
332
                                report "init_bytememory(): line " & integer'image(line_current) & " parsed and accepted for address " & integer'image(to_integer(unsigned(address))) severity note;
333
                        --else
334
                        --      report "init_bytememory(): line " & integer'image(line_current) & " is ignored due to missing data" severity note;
335
                        --      line_cnt_ignored := line_cnt_ignored + 1;
336
                        --end if;
337
                when others =>
338
                        report "init_bytememory(): line " & integer'image(line_current) & " is ignored due to unrecognized 1st char" severity note;
339
                        line_cnt_ignored := line_cnt_ignored + 1;
340
                end case;
341
        end loop; -- next line in file
342
 
343
        file_close(input_file);
344
 
345
        report "init_bytememory(): " & integer'image(line_cnt_accepted) & " total lines parsed and accepted from file " & input_file_name severity note;
346
        report "init_bytememory(): " & integer'image(line_cnt_ignored) & " total lines parsed and ignored from file " & input_file_name severity note;
347
 
348
        dump_wordmemory(dump_file_name, depth, temp_mem, dump_file_base);
349
 
350
   return temp_mem;
351
end init_wordmemory;
352
 
353
constant data_from_file: t_uinstruction512 := init_wordmemory("./prom/microcode.mif", "./prom/microcode.lst", 0, 512, uCode_default);
354
--constant data_from_file: rom_array := init_wordmemory("./prom/microcode.mif", "./prom/microcode.hex", 2, 512, uCode_default);
355
 
356
constant data_from_inline: t_uinstruction512 :=
357
(
358
 
359
        others => uCode_nop
360
);
361
 
362
begin
363
        data <= data_from_file(to_integer(unsigned(a8)));
364
 
365
end Behavioral;
366
 

powered by: WebSVN 2.1.0

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