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

Subversion Repositories zap

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 26 Revanth
#!/usr/bin/perl -w
2
 
3 43 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 41 Revanth
 
26
 
27 26 Revanth
use strict;
28
use warnings;
29
 
30
my %Config = do "./Config.cfg";
31
 
32 43 Revanth
# Extract from config
33
my $WAVES                       = $Config{'WAVES'};
34 26 Revanth
my $RAM_SIZE                    = $Config{'EXT_RAM_SIZE'};
35
my $SEED                        = $Config{'SEED'};
36
my $SYNTHESIS                   = $Config{'SYNTHESIS'};
37
my $DUMP_START                  = $Config{'DUMP_START'};
38
my $DUMP_SIZE                   = $Config{'DUMP_SIZE'};
39
my $MAX_CLOCK_CYCLES            = $Config{'MAX_CLOCK_CYCLES'};
40
my $TLB_DEBUG                   = $Config{'DEFINE_TLB_DEBUG'};
41 43 Revanth
my $TX_TERM0                    = $Config{'UART0_TX_TERMINAL'};
42
my $TX_TERM1                    = $Config{'UART1_TX_TERMINAL'};
43
my $RX_TERM0                    = $Config{'UART0_RX_TERMINAL'};
44
my $RX_TERM1                    = $Config{'UART1_RX_TERMINAL'};
45 38 Revanth
my $IRQ_EN                      = $Config{'IRQ_EN'};
46 43 Revanth
my $FIQ_EN                      = $Config{'FIQ_EN'};
47 26 Revanth
my $DATA_CACHE_SIZE             = $Config{'DATA_CACHE_SIZE'};
48
my $CODE_CACHE_SIZE             = $Config{'CODE_CACHE_SIZE'};
49
my $CODE_SECTION_TLB_ENTRIES    = $Config{'CODE_SECTION_TLB_ENTRIES'};
50
my $CODE_SPAGE_TLB_ENTRIES      = $Config{'CODE_SPAGE_TLB_ENTRIES'};
51
my $CODE_LPAGE_TLB_ENTRIES      = $Config{'CODE_LPAGE_TLB_ENTRIES'};
52
my $DATA_SECTION_TLB_ENTRIES    = $Config{'DATA_SECTION_TLB_ENTRIES'};
53
my $DATA_SPAGE_TLB_ENTRIES      = $Config{'DATA_SPAGE_TLB_ENTRIES'};
54
my $DATA_LPAGE_TLB_ENTRIES      = $Config{'DATA_LPAGE_TLB_ENTRIES'};
55
my $BP                          = $Config{'BP_DEPTH'};
56
my $FIFO                        = $Config{'INSTR_FIFO_DEPTH'};
57
my $SBUF_DEPTH                  = $Config{'STORE_BUFFER_DEPTH'};
58
 
59
# Leave this as is.
60
my $ZAP_HOME                    = "../../../";
61
my $TEST                        = "null";
62
my $SCRATCH                     = "/dev/null";
63
 
64 43 Revanth
# Generate a random seed if needed
65 26 Revanth
if ( $SEED == -1 ) {
66 43 Revanth
                $SEED = int rand (0xffffffff);
67 26 Revanth
}
68
 
69 43 Revanth
# Parse arguments.
70 26 Revanth
foreach(@ARGV) {
71 43 Revanth
        if (/^\+test\+(.*)/) {
72 26 Revanth
                $SCRATCH = "$ZAP_HOME/obj/ts/$1"; $TEST = $1;
73 43 Revanth
        } else {
74
                die "Unrecognized option to run_sim.pl\n";
75 26 Revanth
        }
76
}
77
 
78 43 Revanth
# Log file - the final file is compressed.
79
my $LOG_FILE_PATH               = "$SCRATCH/zap.log";
80
my $COMPRESSED_LOG_FILE_PATH    = "$SCRATCH/zap.log.gz";
81 26 Revanth
 
82 43 Revanth
# VCD file - the final file is compressed.
83
my $VCD_PATH                    = "$SCRATCH/zap.vcd";
84
my $COMPRESSED_VCD_PATH         = "$SCRATCH/zap.vcd.gz";
85 26 Revanth
 
86 43 Revanth
# Paths
87
my $VVP_PATH                    = "$SCRATCH/zap.vvp";
88
my $PROG_PATH                   = "$SCRATCH/zap_mem.v";
89
my $TARGET_BIN_PATH             = "$SCRATCH/zap.bin";
90
my $UART0_PATH_TX               = "$SCRATCH/zapuart0.tx";
91
my $UART1_PATH_TX               = "$SCRATCH/zapuart1.tx";
92
my $UART0_PATH_RX               = "$SCRATCH/zapuart0.rx";
93
my $UART1_PATH_RX               = "$SCRATCH/zapuart1.rx";
94 29 Revanth
 
95 43 Revanth
# Generate IVL options including VCD generation path.
96
my $IVL_OPTIONS  = "";
97 26 Revanth
 
98 43 Revanth
   # Compile CPU
99
   $IVL_OPTIONS .= " -I$ZAP_HOME/src/rtl/cpu -I$ZAP_HOME/obj/ts/$TEST ";
100
   $IVL_OPTIONS .= "  $ZAP_HOME/src/rtl/cpu/*.v   ";
101 34 Revanth
 
102 43 Revanth
   # Compile other TB components
103
   $IVL_OPTIONS .= " -I$ZAP_HOME/src/testbench/External_IP/uart16550/rtl            ";
104
   $IVL_OPTIONS .= "  $ZAP_HOME/src/testbench/External_IP/uart16550/rtl/*.v ";
105
   $IVL_OPTIONS .= "  $ZAP_HOME/src/testbench/*.v ";
106
   $IVL_OPTIONS .= " -o $VVP_PATH -gstrict-ca-eval -Wall -g2001 -Winfloop -DSEED=$SEED -DMEMORY_IMAGE=\\\"$PROG_PATH\\\" ";
107
   $IVL_OPTIONS .= " -DVCD_FILE_PATH=\\\"$VCD_PATH\\\" ";
108 34 Revanth
 
109 43 Revanth
# Generate UART related defines for both the UARTs.
110
if ( $TX_TERM0 ) { $IVL_OPTIONS .= " -DUART0_FILE_PATH_TX=\\\"$UART0_PATH_TX\\\" "; } else { $IVL_OPTIONS .= " -DUART0_FILE_PATH_TX=\\\"/dev/null\\\" "; }
111
if ( $TX_TERM1 ) { $IVL_OPTIONS .= " -DUART1_FILE_PATH_TX=\\\"$UART1_PATH_TX\\\" "; } else { $IVL_OPTIONS .= " -DUART1_FILE_PATH_TX=\\\"/dev/null\\\" "; }
112
if ( $RX_TERM0 ) { $IVL_OPTIONS .= " -DUART0_FILE_PATH_RX=\\\"$UART0_PATH_RX\\\" "; } else { $IVL_OPTIONS .= " -DUART0_FILE_PATH_RX=\\\"/dev/null\\\" "; }
113
if ( $RX_TERM1 ) { $IVL_OPTIONS .= " -DUART1_FILE_PATH_RX=\\\"$UART1_PATH_RX\\\" "; } else { $IVL_OPTIONS .= " -DUART1_FILE_PATH_RX=\\\"/dev/null\\\" "; }
114
 
115
# CPU / TB configuration related parameters.
116 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 ";
117
$IVL_OPTIONS .= " -Pzap_test.BP_ENTRIES=$BP -Pzap_test.FIFO_DEPTH=$FIFO ";
118
$IVL_OPTIONS .= " -Pzap_test.DATA_SECTION_TLB_ENTRIES=$DATA_SECTION_TLB_ENTRIES ";
119
$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 ";
120
$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 ";
121
$IVL_OPTIONS .= " -Pzap_test.CODE_CACHE_SIZE=$CODE_CACHE_SIZE ";
122
 
123 43 Revanth
# Defines
124
if ( 1       )          {        $IVL_OPTIONS .= " -DMAX_CLOCK_CYCLES=$MAX_CLOCK_CYCLES " }
125
if ( $IRQ_EN )          {        $IVL_OPTIONS .= "-DIRQ_EN ";                             }
126
if ( $FIQ_EN )          {        $IVL_OPTIONS .= "-DFIQ_EN ";                             }
127
if ( $SYNTHESIS )       {        $IVL_OPTIONS .= "-DSYNTHESIS ";                          }
128
if ( $TLB_DEBUG )       {        $IVL_OPTIONS .= "-DTLB_DEBUG ";                          }
129
if ( $WAVES )           {        $IVL_OPTIONS .= "-DWAVES ";                              }
130 26 Revanth
 
131 43 Revanth
###########################################################################################################################################
132
# Create checker assertion verilog include file.
133
###########################################################################################################################################
134 26 Revanth
 
135
open(HH, ">$ZAP_HOME/obj/ts/$TEST/zap_check.vh") or die "Could not write to ../../../obj/ts/$TEST/zap_check.vh";
136
 
137 43 Revanth
my $REG_HIER = "u_chip_top.u_zap_top.u_zap_core.u_zap_writeback.u_zap_register_file";
138
my $RAM_HIER = "u_chip_top.u_ram.ram";
139 26 Revanth
my $X = $Config{'FINAL_CHECK'};
140
 
141
foreach(keys (%$X)) {
142 43 Revanth
        my $string = "$_, $$X{$_}, ${RAM_HIER}[$_/4]";
143
        print    "if ( ${RAM_HIER}[$_/4] != ", $$X{"$_"}, ') begin $display("Error: Memory values not matched. PTR = %d EXP = %x REC = %x", ', $string , ' ); $finish; end else $display("RAM check passed!");',"\n";
144
        print HH "if ( ${RAM_HIER}[$_/4] != ", $$X{"$_"}, ') begin $display("Error: Memory values not matched. PTR = %d EXP = %x REC = %x", ', $string , ' ); $finish; end else $display("RAM check passed!");',"\n";
145 26 Revanth
}
146
 
147
$X = $Config{'REG_CHECK'};
148
 
149
foreach(keys (%$X)) {
150
        my $string = "\"$_\", $$X{$_}, $REG_HIER.$_";
151
        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";
152
        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";
153
}
154
 
155
print HH '$display("Simulation Complete. All checks (if any) passed.");$finish;';
156
 
157 43 Revanth
############################################################################################################################################
158
# Set up UART terminals
159
############################################################################################################################################
160 26 Revanth
 
161 43 Revanth
if ( $TX_TERM0 ) {
162
        system1("rm -f $UART0_PATH_TX");    # Remove UART file.
163
        system1("mknod $UART0_PATH_TX p");  # Create a UART output FIFO file.
164 34 Revanth
}
165 26 Revanth
 
166 43 Revanth
if ( $TX_TERM1 ) {
167
        system1("rm -f $UART1_PATH_TX");    # Remove UART file.
168
        system1("mknod $UART1_PATH_TX p");  # Create a UART output FIFO file.
169
}
170
 
171
if ( $RX_TERM0 ) {
172
        system1("rm -f $UART0_PATH_RX");    # Remove UART file.
173
        system1("touch $UART0_PATH_RX");    # Create file.
174
}
175
 
176
if ( $RX_TERM1 ) {
177
        system1("rm -f $UART1_PATH_RX");    # Remove UART file.
178
        system1("touch $UART1_PATH_RX");    # Create file.
179
}
180
 
181 27 Revanth
die "Error: XTerm could not be found!" if system("which xterm");
182
 
183 43 Revanth
if ( $TX_TERM0 ) {        die "Failed to open UART TX terminal 0." if system1("xterm -T 'TB UART Output' -hold -e 'cat $UART0_PATH_TX' &");                                                }
184
if ( $TX_TERM1 ) {        die "Failed to open UART TX terminal 1." if system1("xterm -T 'TB UART Output' -hold -e 'cat $UART1_PATH_TX' &");                                                }
185
if ( $RX_TERM0 ) {        die "Failed to open UART RX terminal 0." if system1("xterm -T 'TB UART Input'  -hold -e 'bash $ZAP_HOME/src/scripts/uart_input.bash $UART0_PATH_RX' &");         }
186
if ( $RX_TERM1 ) {        die "Failed to open UART RX terminal 1." if system1("xterm -T 'TB UART Input'  -hold -e 'bash $ZAP_HOME/src/scripts/uart_input.bash $UART1_PATH_RX' &");         }
187
 
188
#############################################################################################################################################
189
# Compile using VVP
190
#############################################################################################################################################
191
 
192
die "*E: Verilog Compilation Failed!\n"  if system1("iverilog $IVL_OPTIONS");
193
die "*E: Failed to read out Log FIFO!\n" if system1("rm -f $LOG_FILE_PATH ; mkfifo $LOG_FILE_PATH ; cat $LOG_FILE_PATH | gzip  > $COMPRESSED_LOG_FILE_PATH &");
194
 
195
if ( $WAVES ) {
196
        die "*E: Failed to read out VCD FIFO!\n" if system1("rm -f $VCD_PATH      ; mkfifo $VCD_PATH      ; cat $VCD_PATH      | gzip  > $COMPRESSED_VCD_PATH &");
197 34 Revanth
}
198 26 Revanth
 
199 43 Revanth
die "*E: VVP execution error!\n"         if system1("vvp $VVP_PATH | tee $LOG_FILE_PATH");
200 26 Revanth
 
201 43 Revanth
###############################################################################################################################################
202
# Scan for errors and warnings.
203
###############################################################################################################################################
204 26 Revanth
 
205 43 Revanth
die "*E: Errors occurred! Please grep for Errors in $COMPRESSED_LOG_FILE_PATH\n"       unless system("zcat $COMPRESSED_LOG_FILE_PATH | grep Error");
206
die "*E: There were Warnings! Please grep for Warnings in $COMPRESSED_LOG_FILE_PATH\n" unless system("zcat $COMPRESSED_LOG_FILE_PATH | grep Warning");
207
 
208
###############################################################################################################################################
209
# Functions
210
###############################################################################################################################################
211
 
212
sub system1 {
213
        my $x = $_[0];
214
        print "#SystemCommand: $x\n";
215
        system("$x");
216
}
217
 
218 26 Revanth
exit 0;
219
 
220
 

powered by: WebSVN 2.1.0

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