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

Subversion Repositories zap

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

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
my $HELP = "
4
###############################################################################
5
 
6
Perl script to simulate the ZAP processor. This script itself calls other
7
scripts and programs.
8
 
9
Usage :
10
perl run_sim.pl
11
+test+<test_case>           -- Run a specific test case.
12 38 Revanth
+irq_en                     -- Configure TB to use IRQ.
13 26 Revanth
 
14
###############################################################################
15
";
16
 
17
use strict;
18
use warnings;
19
 
20
my $FH;
21
 
22
my %Config = do "./Config.cfg";
23
 
24
# Env setup.
25
my $RAM_SIZE                    = $Config{'EXT_RAM_SIZE'};
26
my $SEED                        = $Config{'SEED'};
27
my $SYNTHESIS                   = $Config{'SYNTHESIS'};
28
my $DUMP_START                  = $Config{'DUMP_START'};
29
my $DUMP_SIZE                   = $Config{'DUMP_SIZE'};
30
my $MAX_CLOCK_CYCLES            = $Config{'MAX_CLOCK_CYCLES'};
31
my $TLB_DEBUG                   = $Config{'DEFINE_TLB_DEBUG'};
32
my $STALL                       = $Config{'ALLOW_STALLS'};
33 34 Revanth
my $TX_TERM                     = $Config{'UART_TX_TERMINAL'};
34 38 Revanth
my $IRQ_EN                      = $Config{'IRQ_EN'};
35 26 Revanth
 
36
# System configuration.
37
my $DATA_CACHE_SIZE             = $Config{'DATA_CACHE_SIZE'};
38
my $CODE_CACHE_SIZE             = $Config{'CODE_CACHE_SIZE'};
39
my $CODE_SECTION_TLB_ENTRIES    = $Config{'CODE_SECTION_TLB_ENTRIES'};
40
my $CODE_SPAGE_TLB_ENTRIES      = $Config{'CODE_SPAGE_TLB_ENTRIES'};
41
my $CODE_LPAGE_TLB_ENTRIES      = $Config{'CODE_LPAGE_TLB_ENTRIES'};
42
my $DATA_SECTION_TLB_ENTRIES    = $Config{'DATA_SECTION_TLB_ENTRIES'};
43
my $DATA_SPAGE_TLB_ENTRIES      = $Config{'DATA_SPAGE_TLB_ENTRIES'};
44
my $DATA_LPAGE_TLB_ENTRIES      = $Config{'DATA_LPAGE_TLB_ENTRIES'};
45
my $BP                          = $Config{'BP_DEPTH'};
46
my $FIFO                        = $Config{'INSTR_FIFO_DEPTH'};
47
my $SBUF_DEPTH                  = $Config{'STORE_BUFFER_DEPTH'};
48
 
49
# Leave this as is.
50
my $ZAP_HOME                    = "../../../";
51
my $TEST                        = "null";
52
my $SCRATCH                     = "/dev/null";
53 29 Revanth
my $FIQ_EN                      = 0;
54 26 Revanth
 
55
if ( $SEED == -1 ) {
56
                $SEED = randSeed();
57
}
58
 
59
sub randSeed {
60
        return int rand (0xffffffff);
61
}
62
 
63
foreach(@ARGV) {
64
        if (/^\+test\+(.*)/)
65
        {
66
                $SCRATCH = "$ZAP_HOME/obj/ts/$1"; $TEST = $1;
67
        }
68
        elsif (/help/)
69
        {
70
                print "$HELP"; exit 0
71
        }
72
        else
73
        {
74
                die "Unrecognized $_  $HELP";
75
        }
76
}
77
 
78
if ( $TEST eq "null" ) {
79
        print "$HELP";
80
        die "ERROR: +test+<testname> not specified!";
81
}
82
 
83
my $LOG_FILE_PATH   = "$SCRATCH/zap.log";
84
my $VVP_PATH        = "$SCRATCH/zap.vvp";
85
my $VCD_PATH        = "$SCRATCH/zap.vcd";
86
my $PROG_PATH       = "$SCRATCH/zap_mem.v";
87
my $TARGET_BIN_PATH = "$SCRATCH/zap.bin";
88
my $UART_PATH       = "$SCRATCH/zapuart.fifo";
89
 
90
# Generate IVL options.
91 29 Revanth
my $IVL_OPTIONS .=
92
" -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";
93
 
94 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\\\" ";
95
 
96
$IVL_OPTIONS .= " -DVCD_FILE_PATH=\\\"$VCD_PATH\\\" ";
97 34 Revanth
 
98
if ( $TX_TERM) {
99
        $IVL_OPTIONS .= " -DUART_FILE_PATH=\\\"$UART_PATH\\\" ";
100
} else {
101
        $IVL_OPTIONS .= " -DUART_FILE_PATH=\\\"/dev/null\\\" ";
102
}
103
 
104 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 ";
105
$IVL_OPTIONS .= " -Pzap_test.BP_ENTRIES=$BP -Pzap_test.FIFO_DEPTH=$FIFO ";
106
$IVL_OPTIONS .= " -Pzap_test.DATA_SECTION_TLB_ENTRIES=$DATA_SECTION_TLB_ENTRIES ";
107
$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 ";
108
$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 ";
109
$IVL_OPTIONS .= " -Pzap_test.CODE_CACHE_SIZE=$CODE_CACHE_SIZE ";
110
$IVL_OPTIONS .= "-DMAX_CLOCK_CYCLES=$MAX_CLOCK_CYCLES ";
111
 
112 38 Revanth
if ( $IRQ_EN )          {        print "Script: IRQ defined.\n" ; $IVL_OPTIONS .= "-DIRQ_EN ";   }
113 26 Revanth
if ( $FIQ_EN )          {        $IVL_OPTIONS .= "-DFIQ_EN ";   }
114 38 Revanth
if ( $STALL )           {        print "Script: Stall defined.\n" ; $IVL_OPTIONS .= "-DSTALL ";    }
115 26 Revanth
if ( $SYNTHESIS )       {        $IVL_OPTIONS .= "-DSYNTHESIS ";}
116
 
117
if ( $MAX_CLOCK_CYCLES == 0 )   {  die "*E: MAX_CLOCK_CYCLES set to 0. Ending script...";  }
118
if ( $TLB_DEBUG )               {  print "Warning: TLB_DEBUG defined. Do not use for unattended systems!"; $IVL_OPTIONS .= "-DTLB_DEBUG ";}
119
 
120
open(HH, ">$ZAP_HOME/obj/ts/$TEST/zap_check.vh") or die "Could not write to ../../../obj/ts/$TEST/zap_check.vh";
121
 
122
my $X = $Config{'FINAL_CHECK'};
123
 
124
foreach(keys (%$X)) {
125
        my $string = "$_, $$X{$_}, U_MODEL_RAM_DATA.ram[$_]";
126
        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";
127
        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";
128
}
129
 
130
$X = $Config{'REG_CHECK'};
131
 
132
my $REG_HIER = "u_zap_top.u_zap_core.u_zap_writeback.u_zap_register_file";
133
 
134
foreach(keys (%$X)) {
135
        my $string = "\"$_\", $$X{$_}, $REG_HIER.$_";
136
        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";
137
        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";
138
}
139
 
140
print HH '$display("Simulation Complete. All checks (if any) passed.");$finish;';
141
 
142
print "*I: Rand is $SEED...\n";
143
print "iverilog $IVL_OPTIONS\n";
144
 
145 34 Revanth
if ( $TX_TERM ) {
146
        system("rm -f $UART_PATH");    # Remove UART file.
147
        system("mknod $UART_PATH p");  # Create a UART output FIFO file.
148
}
149 26 Revanth
 
150
# UART output monitor.
151 27 Revanth
die "Error: XTerm could not be found!" if system("which xterm");
152
die "Error: Icarus Verilog could not be found!" if system("which iverilog");
153
 
154 34 Revanth
if ( $TX_TERM == 1 ) {
155
        print "Setting up UART output monitor\n";
156
        system("xterm -T 'TB UART Output' -hold -e 'cat $UART_PATH ; echo ; echo ------------------ ; echo UART_Output_Complete ; echo ------------------' &");
157
}
158 26 Revanth
 
159
die "*E: Verilog Compilation Failed!\n" if system("iverilog $IVL_OPTIONS");
160
die "*E: VVP execution error!\n" if system("vvp $VVP_PATH | tee $LOG_FILE_PATH");
161
 
162
die "*E: Errors occurred! Please grep for Errors in $LOG_FILE_PATH\n"       unless system("grep Error   $LOG_FILE_PATH");
163
die "*E: There were Warnings! Please grep for Warnings in $LOG_FILE_PATH\n" unless system("grep Warning $LOG_FILE_PATH");
164
 
165
exit 0;
166
 
167
 

powered by: WebSVN 2.1.0

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