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

Subversion Repositories ion

[/] [ion/] [trunk/] [src/] [mips_tb0_template.vhdl] - Blame information for rev 155

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

Line No. Rev Author Line
1 122 ja_rd
--##############################################################################
2
-- This file was generated automatically from '/src/mips_tb0_template.vhdl'.
3
-- 
4
--------------------------------------------------------------------------------
5
-- Simulation test bench TB0 -- not synthesizable.
6
--
7
-- Simulates the CPU core connected to a single memory block initialized with
8
-- the program object code and (initialized) data. The makefile for the source 
9
-- samples include targets to build simulation test benches using this template.
10
--
11
-- The memory setup is meant to test the 'bare' cpu, without cache and with 
12
-- all object code in a single 3-port memory block. 
13
-- Address decoding is harcoded to that of Plasma system, for the time being.
14
-- 
15
-- Console output (at addresses compatible to Plasma's) is logged to text file
16
-- "hw_sim_console_log.txt".
17
-- IMPORTANT: The code that echoes UART TX data to the simulation console does
18
-- line buffering; it will not print anything until it gets a CR (0x0d), and
19
-- will ifnore LFs (0x0a). Bear this in mind if you see no output when you 
20
-- expect it.
21
--
22
-- WARNING: Will only work on Modelsim; uses custom library SignalSpy.
23
--##############################################################################
24
 
25
library ieee;
26
use ieee.std_logic_1164.all;
27
use ieee.std_logic_arith.all;
28
use ieee.std_logic_unsigned.all;
29
use std.textio.all;
30
 
31
use work.mips_pkg.all;
32
use work.mips_tb_pkg.all;
33
use work.txt_util.all;
34
 
35
 
36
entity @entity_name@ is
37
end @entity_name@;
38
 
39
architecture @arch_name@ of @entity_name@ is
40
 
41
--------------------------------------------------------------------------------
42
-- Simulation parameters
43
 
44
-- Master clock period
45
constant T : time           := 20 ns;
46
-- Time the UART is unavailable after writing to the TX register
47
-- WARNING: slite does not simulate this. The logs may be different when > 0.0!
48
constant SIMULATED_UART_TX_TIME : time := 0.0 us;
49
 
50
-- Simulation length in clock cycles 
51
-- 2000 is enough for 'hello' sample, 22000 enough for 10 digits of pi
52
constant SIMULATION_LENGTH : integer := @sim_len@;
53
 
54
 
55
--------------------------------------------------------------------------------
56
-- UUT & interface signals
57
 
58
signal data_addr :          std_logic_vector(31 downto 0);
59
signal prev_rd_addr :       std_logic_vector(31 downto 0);
60
signal vma_data :           std_logic;
61
signal vma_code :           std_logic;
62
signal full_rd_addr :       std_logic_vector(31 downto 0);
63
signal full_wr_addr :       std_logic_vector(31 downto 0);
64
signal byte_we :            std_logic_vector(3 downto 0);
65
signal data_r :             std_logic_vector(31 downto 0);
66
signal data_ram :           std_logic_vector(31 downto 0);
67
signal data_uart :          std_logic_vector(31 downto 0);
68
signal data_uart_status :   std_logic_vector(31 downto 0);
69
signal uart_tx_rdy :        std_logic := '1';
70
signal uart_rx_rdy :        std_logic := '1';
71
signal data_w :             std_logic_vector(31 downto 0);
72
signal mem_wait :           std_logic := '0';
73
signal interrupt :          std_logic := '0';
74
signal code_addr :          std_logic_vector(31 downto 2);
75
signal full_code_addr :     std_logic_vector(31 downto 0);
76
signal code_r :             std_logic_vector(31 downto 0);
77
 
78
--------------------------------------------------------------------------------
79
 
80
signal clk :                std_logic := '0';
81
signal reset :              std_logic := '1';
82
signal done :               std_logic := '0';
83
signal test :               integer := 0;
84
 
85
--------------------------------------------------------------------------------
86
-- Logging signals
87
 
88
-- These are internal CPU signal mirrored using Modelsim's SignalSpy
89
--signal rbank :              t_rbank;
90
--signal pc, cp0_epc :        std_logic_vector(31 downto 2);
91
--signal reg_hi, reg_lo :     t_word;
92
--signal negate_reg_lo :      std_logic;
93
--signal ld_upper_byte :      std_logic;
94
--signal ld_upper_hword :     std_logic;
95
 
96
signal log_info :           t_log_info;
97
 
98
-- Log file
99
file log_file: TEXT open write_mode is "hw_sim_log.txt";
100
 
101
-- Console output log file
102
file con_file: TEXT open write_mode is "hw_sim_console_log.txt";
103
 
104
-- Maximum line size of for console output log. Lines longer than this will be
105
-- truncated.
106
constant CONSOLE_LOG_LINE_SIZE : integer := 1024*4;
107
 
108
-- Console log line buffer
109
signal con_line_buf :       string(1 to CONSOLE_LOG_LINE_SIZE);
110
signal con_line_ix :        integer := 1;
111
 
112
 
113
--------------------------------------------------------------------------------
114
 
115
constant MEM_SIZE : integer := @code_table_size@;
116
constant ADDR_SIZE : integer := @code_addr_size@;
117
 
118
subtype t_address is std_logic_vector(ADDR_SIZE-1 downto 0);
119
 
120
signal addr_rd, addr_wr :   t_address;
121
signal addr_code :          t_address;
122
 
123
type t_code_ram is array(0 to MEM_SIZE-1) of std_logic_vector(7 downto 0);
124
 
125
subtype t_data_address is std_logic_vector(ADDR_SIZE-1 downto 0);
126
signal data_addr_rd :       t_data_address;
127
signal data_addr_wr :       t_data_address;
128
signal code_addr_rd :       t_data_address;
129
 
130
 
131
-- ram0 is LSB, ram3 is MSB
132
signal ram3 : t_code_ram := (@code3@);
133
signal ram2 : t_code_ram := (@code2@);
134
signal ram1 : t_code_ram := (@code1@);
135
signal ram0 : t_code_ram := (@code0@);
136
 
137
begin
138
 
139
    cpu: entity work.mips_cpu
140
    port map (
141
        interrupt   => interrupt,
142
 
143
        data_addr   => data_addr,
144
        data_rd_vma => vma_data,
145
        data_rd     => data_r,
146
 
147
        code_rd_addr=> code_addr,
148
        code_rd     => code_r,
149
        code_rd_vma => vma_code,
150
 
151
        data_wr     => data_w,
152
        byte_we     => byte_we,
153
 
154
        mem_wait    => mem_wait,
155
 
156
        clk         => clk,
157
        reset       => reset
158
    );
159
 
160
    ---------------------------------------------------------------------------
161
    -- Master clock: free running clock used as main module clock
162
    run_master_clock:
163
    process(done, clk)
164
    begin
165
        if done = '0' then
166
            clk <= not clk after T/2;
167
        end if;
168
    end process run_master_clock;
169
 
170
    drive_uut:
171
    process
172
    variable l : line;
173
    begin
174
        wait for T*4;
175
        reset <= '0';
176
 
177
        wait for T*SIMULATION_LENGTH;
178
 
179
        -- Flush console output to log console file (in case the end of the
180
        -- simulation caugh an unterminated line in the buffer)
181
        if con_line_ix > 1 then
182
            write(l, con_line_buf(1 to con_line_ix));
183
            writeline(con_file, l);
184
        end if;
185
 
186
        print("TB0 finished");
187
        done <= '1';
188
        wait;
189
 
190
    end process drive_uut;
191
 
192
    mem_wait <= '0'; -- memory wait input not simulated in this test bench
193
 
194
 
195
    -- RAM vs. IO data read mux
196
    data_r <= data_ram when prev_rd_addr(31 downto 28)/=X"2" else data_uart;
197
 
198
    -- UART read registers; only status, and hardwired, for the time being
199
    data_uart <= data_uart_status;
200
    data_uart_status <= X"0000000" & "00" & uart_tx_rdy & uart_rx_rdy;
201
 
202
 
203
    -- 'full' read address, used for simulation display only
204
    full_rd_addr <= data_addr;
205
    full_wr_addr <= data_addr(31 downto 2) & "00";
206
    full_code_addr <= code_addr & "00";
207
 
208
    data_addr_rd <= full_rd_addr(ADDR_SIZE-1+2 downto 2);
209
    addr_wr <= full_wr_addr(ADDR_SIZE-1+2 downto 2);
210
    code_addr_rd <= full_code_addr(ADDR_SIZE-1+2 downto 2);
211
 
212
 
213
    write_process:
214
    process(clk)
215
    variable i : integer;
216
    variable uart_data : integer;
217
    begin
218
        if clk'event and clk='1' then
219
            if reset='1' then
220
                data_ram <= (others =>'0');
221
            else
222
                prev_rd_addr <= data_addr;
223
 
224
                data_ram <=
225
                  ram3(conv_integer(unsigned(data_addr_rd))) &
226
                  ram2(conv_integer(unsigned(data_addr_rd))) &
227
                  ram1(conv_integer(unsigned(data_addr_rd))) &
228
                  ram0(conv_integer(unsigned(data_addr_rd)));
229
 
230
                code_r <=
231
                  ram3(conv_integer(unsigned(code_addr_rd))) &
232
                  ram2(conv_integer(unsigned(code_addr_rd))) &
233
                  ram1(conv_integer(unsigned(code_addr_rd))) &
234
                  ram0(conv_integer(unsigned(code_addr_rd)));
235
            end if;
236
 
237
            if byte_we/="0000" then
238
                if full_wr_addr(31 downto 28)=X"2" then
239
                    -- Write to UART
240
 
241
                    -- If we're simulating the UART TX time, pulse RDY low
242
                    if SIMULATED_UART_TX_TIME > 0 us then
243
                        uart_tx_rdy <= '0', '1' after SIMULATED_UART_TX_TIME;
244
                    end if;
245
 
246
                    -- TX data may come from the high or low byte (opcodes.s
247
                    -- uses high byte, no_op.c uses low)
248
                    if byte_we(0)='1' then
249
                        uart_data := conv_integer(unsigned(data_w(7 downto 0)));
250
                    else
251
                        uart_data := conv_integer(unsigned(data_w(31 downto 24)));
252
                    end if;
253
 
254
                    -- UART TX data goes to output after a bit of line-buffering
255
                    -- and editing
256
                    if uart_data = 10 then
257
                        -- CR received: print output string and clear it
258
                        print(con_file, con_line_buf(1 to con_line_ix));
259
                        con_line_ix <= 1;
260
                        for i in 1 to con_line_buf'high loop
261
                           con_line_buf(i) <= ' ';
262
                        end loop;
263
                    elsif uart_data = 13 then
264
                        -- ignore LF
265
                    else
266
                        -- append char to output string
267
                        if con_line_ix < con_line_buf'high then
268
                            con_line_buf(con_line_ix) <= character'val(uart_data);
269
                            con_line_ix <= con_line_ix + 1;
270
                        end if;
271
                    end if;
272
                else
273
                    -- Write to RAM
274
                    if byte_we(3)='1' then
275
                        ram3(conv_integer(unsigned(addr_wr))) <= data_w(31 downto 24);
276
                    end if;
277
                    if byte_we(2)='1' then
278
                        ram2(conv_integer(unsigned(addr_wr))) <= data_w(23 downto 16);
279
                    end if;
280
                    if byte_we(1)='1' then
281
                        ram1(conv_integer(unsigned(addr_wr))) <= data_w(15 downto  8);
282
                    end if;
283
                    if byte_we(0)='1' then
284
                        ram0(conv_integer(unsigned(addr_wr))) <= data_w( 7 downto  0);
285
                    end if;
286
                end if;
287
            end if;
288
        end if;
289
    end process write_process;
290
 
291
    log_execution:
292
    process
293
    begin
294
        log_cpu_activity(clk, reset, done,
295
                         "@entity_name@/cpu", log_info, "log_info",
296
                         @log_trigger_addr@, log_file);
297
        wait;
298
    end process log_execution;
299
 
300
 
301
end @arch_name@;

powered by: WebSVN 2.1.0

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