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

Subversion Repositories zap

[/] [zap/] [trunk/] [src/] [scripts/] [run_sim.pl] - Blame information for rev 41

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

Line No. Rev Author Line
1 26 Revanth
#!/usr/bin/perl -w
2
 
3 41 Revanth
#// -----------------------------------------------------------------------------
4
#// --                                                                         --
5
#// --                   (C) 2016-2018 Revanth Kamaraj.                        --
6
#// --                                                                         -- 
7
#// -- --------------------------------------------------------------------------
8
#// --                                                                         --
9
#// -- This program is free software; you can redistribute it and/or           --
10
#// -- modify it under the terms of the GNU General Public License             --
11
#// -- as published by the Free Software Foundation; either version 2          --
12
#// -- of the License, or (at your option) any later version.                  --
13
#// --                                                                         --
14
#// -- This program is distributed in the hope that it will be useful,         --
15
#// -- but WITHOUT ANY WARRANTY; without even the implied warranty of          --
16
#// -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           --
17
#// -- GNU General Public License for more details.                            --
18
#// --                                                                         --
19
#// -- You should have received a copy of the GNU General Public License       --
20
#// -- along with this program; if not, write to the Free Software             --
21
#// -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA           --
22
#// -- 02110-1301, USA.                                                        --
23
#// --                                                                         --
24
#// -----------------------------------------------------------------------------
25
 
26
 
27 26 Revanth
my $HELP = "
28
###############################################################################
29
 
30
Perl script to simulate the ZAP processor. This script itself calls other
31
scripts and programs.
32
 
33
Usage :
34
perl run_sim.pl
35
+test+<test_case>           -- Run a specific test case.
36 38 Revanth
+irq_en                     -- Configure TB to use IRQ.
37 26 Revanth
 
38
###############################################################################
39
";
40
 
41
use strict;
42
use warnings;
43
 
44
my $FH;
45
 
46
my %Config = do "./Config.cfg";
47
 
48
# Env setup.
49
my $RAM_SIZE                    = $Config{'EXT_RAM_SIZE'};
50
my $SEED                        = $Config{'SEED'};
51
my $SYNTHESIS                   = $Config{'SYNTHESIS'};
52
my $DUMP_START                  = $Config{'DUMP_START'};
53
my $DUMP_SIZE                   = $Config{'DUMP_SIZE'};
54
my $MAX_CLOCK_CYCLES            = $Config{'MAX_CLOCK_CYCLES'};
55
my $TLB_DEBUG                   = $Config{'DEFINE_TLB_DEBUG'};
56
my $STALL                       = $Config{'ALLOW_STALLS'};
57 34 Revanth
my $TX_TERM                     = $Config{'UART_TX_TERMINAL'};
58 38 Revanth
my $IRQ_EN                      = $Config{'IRQ_EN'};
59 26 Revanth
 
60
# System configuration.
61
my $DATA_CACHE_SIZE             = $Config{'DATA_CACHE_SIZE'};
62
my $CODE_CACHE_SIZE             = $Config{'CODE_CACHE_SIZE'};
63
my $CODE_SECTION_TLB_ENTRIES    = $Config{'CODE_SECTION_TLB_ENTRIES'};
64
my $CODE_SPAGE_TLB_ENTRIES      = $Config{'CODE_SPAGE_TLB_ENTRIES'};
65
my $CODE_LPAGE_TLB_ENTRIES      = $Config{'CODE_LPAGE_TLB_ENTRIES'};
66
my $DATA_SECTION_TLB_ENTRIES    = $Config{'DATA_SECTION_TLB_ENTRIES'};
67
my $DATA_SPAGE_TLB_ENTRIES      = $Config{'DATA_SPAGE_TLB_ENTRIES'};
68
my $DATA_LPAGE_TLB_ENTRIES      = $Config{'DATA_LPAGE_TLB_ENTRIES'};
69
my $BP                          = $Config{'BP_DEPTH'};
70
my $FIFO                        = $Config{'INSTR_FIFO_DEPTH'};
71
my $SBUF_DEPTH                  = $Config{'STORE_BUFFER_DEPTH'};
72
 
73
# Leave this as is.
74
my $ZAP_HOME                    = "../../../";
75
my $TEST                        = "null";
76
my $SCRATCH                     = "/dev/null";
77 29 Revanth
my $FIQ_EN                      = 0;
78 26 Revanth
 
79
if ( $SEED == -1 ) {
80
                $SEED = randSeed();
81
}
82
 
83
sub randSeed {
84
        return int rand (0xffffffff);
85
}
86
 
87
foreach(@ARGV) {
88
        if (/^\+test\+(.*)/)
89
        {
90
                $SCRATCH = "$ZAP_HOME/obj/ts/$1"; $TEST = $1;
91
        }
92
        elsif (/help/)
93
        {
94
                print "$HELP"; exit 0
95
        }
96
        else
97
        {
98
                die "Unrecognized $_  $HELP";
99
        }
100
}
101
 
102
if ( $TEST eq "null" ) {
103
        print "$HELP";
104
        die "ERROR: +test+<testname> not specified!";
105
}
106
 
107
my $LOG_FILE_PATH   = "$SCRATCH/zap.log";
108
my $VVP_PATH        = "$SCRATCH/zap.vvp";
109
my $VCD_PATH        = "$SCRATCH/zap.vcd";
110
my $PROG_PATH       = "$SCRATCH/zap_mem.v";
111
my $TARGET_BIN_PATH = "$SCRATCH/zap.bin";
112
my $UART_PATH       = "$SCRATCH/zapuart.fifo";
113
 
114
# Generate IVL options.
115 29 Revanth
my $IVL_OPTIONS .=
116
" -I$ZAP_HOME/src/rtl/cpu -I$ZAP_HOME/obj/ts/$TEST -I$ZAP_HOME/src/testbench/cpu/uart16550/rtl $ZAP_HOME/src/testbench/cpu/uart16550/rtl/*.v $ZAP_HOME/src/testbench/cpu/timer/timer.v  $ZAP_HOME/src/testbench/cpu/vic/vic.v";
117
 
118 26 Revanth
   $IVL_OPTIONS .= " $ZAP_HOME/src/rtl/*/*.v $ZAP_HOME/src/testbench/cpu/*.v -o $VVP_PATH -gstrict-ca-eval -Wall -g2001 -Winfloop -DSEED=$SEED -DMEMORY_IMAGE=\\\"$PROG_PATH\\\" ";
119
 
120
$IVL_OPTIONS .= " -DVCD_FILE_PATH=\\\"$VCD_PATH\\\" ";
121 34 Revanth
 
122
if ( $TX_TERM) {
123
        $IVL_OPTIONS .= " -DUART_FILE_PATH=\\\"$UART_PATH\\\" ";
124
} else {
125
        $IVL_OPTIONS .= " -DUART_FILE_PATH=\\\"/dev/null\\\" ";
126
}
127
 
128 26 Revanth
$IVL_OPTIONS .= " -Pzap_test.RAM_SIZE=$RAM_SIZE -Pzap_test.START=$DUMP_START -Pzap_test.COUNT=$DUMP_SIZE -DLINUX -Pzap_test.STORE_BUFFER_DEPTH=$SBUF_DEPTH ";
129
$IVL_OPTIONS .= " -Pzap_test.BP_ENTRIES=$BP -Pzap_test.FIFO_DEPTH=$FIFO ";
130
$IVL_OPTIONS .= " -Pzap_test.DATA_SECTION_TLB_ENTRIES=$DATA_SECTION_TLB_ENTRIES ";
131
$IVL_OPTIONS .= " -Pzap_test.DATA_LPAGE_TLB_ENTRIES=$DATA_LPAGE_TLB_ENTRIES -Pzap_test.DATA_SPAGE_TLB_ENTRIES=$DATA_SPAGE_TLB_ENTRIES -Pzap_test.DATA_CACHE_SIZE=$DATA_CACHE_SIZE ";
132
$IVL_OPTIONS .= " -Pzap_test.CODE_SECTION_TLB_ENTRIES=$CODE_SECTION_TLB_ENTRIES -Pzap_test.CODE_LPAGE_TLB_ENTRIES=$CODE_LPAGE_TLB_ENTRIES -Pzap_test.CODE_SPAGE_TLB_ENTRIES=$CODE_SPAGE_TLB_ENTRIES ";
133
$IVL_OPTIONS .= " -Pzap_test.CODE_CACHE_SIZE=$CODE_CACHE_SIZE ";
134
$IVL_OPTIONS .= "-DMAX_CLOCK_CYCLES=$MAX_CLOCK_CYCLES ";
135
 
136 38 Revanth
if ( $IRQ_EN )          {        print "Script: IRQ defined.\n" ; $IVL_OPTIONS .= "-DIRQ_EN ";   }
137 26 Revanth
if ( $FIQ_EN )          {        $IVL_OPTIONS .= "-DFIQ_EN ";   }
138 38 Revanth
if ( $STALL )           {        print "Script: Stall defined.\n" ; $IVL_OPTIONS .= "-DSTALL ";    }
139 26 Revanth
if ( $SYNTHESIS )       {        $IVL_OPTIONS .= "-DSYNTHESIS ";}
140
 
141
if ( $MAX_CLOCK_CYCLES == 0 )   {  die "*E: MAX_CLOCK_CYCLES set to 0. Ending script...";  }
142
if ( $TLB_DEBUG )               {  print "Warning: TLB_DEBUG defined. Do not use for unattended systems!"; $IVL_OPTIONS .= "-DTLB_DEBUG ";}
143
 
144
open(HH, ">$ZAP_HOME/obj/ts/$TEST/zap_check.vh") or die "Could not write to ../../../obj/ts/$TEST/zap_check.vh";
145
 
146
my $X = $Config{'FINAL_CHECK'};
147
 
148
foreach(keys (%$X)) {
149
        my $string = "$_, $$X{$_}, U_MODEL_RAM_DATA.ram[$_]";
150
        print    "if ( U_MODEL_RAM_DATA.ram[$_/4] != ", $$X{"$_"}, ') begin $display("Error: Memory values not matched. PTR = %d EXP = %x REC = %x", ', $string , ' ); $finish; end else $display("RAM check passed!");',"\n";
151
        print HH "if ( U_MODEL_RAM_DATA.ram[$_/4] != ", $$X{"$_"}, ') begin $display("Error: Memory values not matched. PTR = %d EXP = %x REC = %x", ', $string , ' ); $finish; end else $display("RAM check passed!");',"\n";
152
}
153
 
154
$X = $Config{'REG_CHECK'};
155
 
156
my $REG_HIER = "u_zap_top.u_zap_core.u_zap_writeback.u_zap_register_file";
157
 
158
foreach(keys (%$X)) {
159
        my $string = "\"$_\", $$X{$_}, $REG_HIER.$_";
160
        print    "if ( $REG_HIER.$_ != ", $$X{"$_"}, ') begin $display("Error: Register values not matched. PTR = %s EXP = %x REC = %x", ', $string , ' ); $finish; end else $display("Reg check passed!");',"\n";
161
        print HH "if ( $REG_HIER.$_ != ", $$X{"$_"}, ') begin $display("Error: Register values not matched. PTR = %s EXP = %x REC = %x", ', $string , ' ); $finish; end else $display("Reg check passed!");',"\n";
162
}
163
 
164
print HH '$display("Simulation Complete. All checks (if any) passed.");$finish;';
165
 
166
print "*I: Rand is $SEED...\n";
167
print "iverilog $IVL_OPTIONS\n";
168
 
169 34 Revanth
if ( $TX_TERM ) {
170
        system("rm -f $UART_PATH");    # Remove UART file.
171
        system("mknod $UART_PATH p");  # Create a UART output FIFO file.
172
}
173 26 Revanth
 
174
# UART output monitor.
175 27 Revanth
die "Error: XTerm could not be found!" if system("which xterm");
176
die "Error: Icarus Verilog could not be found!" if system("which iverilog");
177
 
178 34 Revanth
if ( $TX_TERM == 1 ) {
179
        print "Setting up UART output monitor\n";
180
        system("xterm -T 'TB UART Output' -hold -e 'cat $UART_PATH ; echo ; echo ------------------ ; echo UART_Output_Complete ; echo ------------------' &");
181
}
182 26 Revanth
 
183
die "*E: Verilog Compilation Failed!\n" if system("iverilog $IVL_OPTIONS");
184
die "*E: VVP execution error!\n" if system("vvp $VVP_PATH | tee $LOG_FILE_PATH");
185
 
186
die "*E: Errors occurred! Please grep for Errors in $LOG_FILE_PATH\n"       unless system("grep Error   $LOG_FILE_PATH");
187
die "*E: There were Warnings! Please grep for Warnings in $LOG_FILE_PATH\n" unless system("grep Warning $LOG_FILE_PATH");
188
 
189
exit 0;
190
 
191
 

powered by: WebSVN 2.1.0

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