summaryrefslogtreecommitdiffstats
path: root/src/occ/tools/start_occ_simics.pl
blob: 15c8890617e1fc8b121da10d144fba2639d9c1fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#!/usr/bin/perl -w

#----------------------------------------------------------------------------
use strict;
use Cwd;

#use Getopt::Long;
#use File::Basename;
#use Time::Local;
#use POSIX qw(strftime);
#use Carp;
#use FindBin;		# std
#use Cwd 'abs_path';

#use Time::Local;

use lib "$ENV{'sb'}/simu/fsp/perl/CPAN";
use lib "$ENV{'bb'}/src/simu/fsp/perl/CPAN";

# Setup/declare some of our initial variables
my $configuration_file = "$ENV{'HOME'}/.occ_simics_config";
my $cur_dir = getcwd();
my $use_gdb = 0;	# Default to not allowing GDB in simics
my $verbose = 0;	# Default to non-verbose output
my $commands = "";

my $target = "occ-simple-common.simics";
my $binary_file = "validation/apps/ocb_irq/ocb_irq.out";
my $simics_workspace = "";
my @search_paths;

# Read in the configuration file
read_configuration_file();

#start by handling the command line arguments
process_command_line();

# Add $simics_workspace and $cur_dir to @search_paths
push @search_paths, $simics_workspace;
push @search_paths, $cur_dir;

# Now put all our read in options together...
$target = find_full_path($target);
$binary_file = find_full_path($binary_file);


# And setup our command line arguments
my $binary_cmd = "oci_space.load-binary $binary_file";
my $symtable_cmd = "new-symtable st $binary_file";
my $gdb_cmd = "new-gdb-remote";

my $full_command = "\"" . $binary_cmd . ";" . $symtable_cmd . ";" . $commands;
if($use_gdb)
{
    $full_command .= $gdb_cmd . ";";
}
$full_command .= "\"";

# Create the simics command
if($verbose)
{
    print "Target: $target\n";
    print "Binary: $binary_file\n";
}
my $simics_command = "ulimit -c unlimited; $simics_workspace/simics -verbose $target -e $full_command"; 


# Run the simics command
if($verbose)
{
    print "\nRunning $simics_command\n";
}

system("$simics_command");

exit 0;




###############################################################################
#			Helper Functions    				      #
###############################################################################


################################################################################
#
# Processes any command line arguments.  
#
################################################################################
sub process_command_line
{
    my $n = 0;

    while ( $n < @ARGV )
    {
	$_ = $ARGV[$n];
	chomp($_);

	if (/^-h$/i || /^--h$/i || /^-help$/i || /^--help$/i)
	{
	    print "start_occ_simics.pl [options] [binary .out file]\n\n";
	    print "Based on your \$HOME/.occ_simics_config and passed in arguments, it will start\n";
	    print "a simics session.  The parameters in the EXAMPLE_.occ_simics_config file:\n";
	    print "\tSIMICS_WORKSPACE: Path to simics workspace\n";
	    print "\tDEFAULT_TARGET: Target you wish you to use in the target directory under simics-workspace\n";
	    print "\tDEFAULT_BINARY: Binary value to use like occ.out\n";
	    print "\tPATH: Paths to check when looking for target/binary files.  Checked recursively\n";
	    print "\tCOMMAND: Comands to run immediately when starting simics.  Can add directories, set output-radix, etc\n";
	    print "\n";
	    print "Arguments to start_occ_simics.pl\n";
	    print "-t  Modifies the target\n";
	    print "-g  Automatically enables GDB\n";
	    print "-v  Verbose option\n";
	    print "\n";   	   
	    exit 0;
	}
	elsif(/^-t$/i || /^--target$/i)
	{
	    $target = $ARGV[$n + 1] or die "Bad command line variable: expecting a target\n";
	    $n++;
	}
	elsif(/\.out/)
	{
	    $binary_file = $ARGV[$n];	    
	}
	elsif(/^-g$/i)
	{
	    $use_gdb = 1;
	}
	elsif(/^-v/)
	{
	    $verbose = 1;
	}
	else
	{
	    print ("Unrecognized command: $_ \n");
	    print ("To view all the options and help text run \'start_simics -h\' \n");
	    exit 1;
	}

	$n++;
    }
}

################################################################################
#
# Parses the configuration file located at $configuration_file
#
################################################################################
sub read_configuration_file
{
    
    open(CONFIG_FILE, "$configuration_file") || warn "Could not read $configuration_file\n";

    
    while(<CONFIG_FILE>)
    {
	#print $_;
	if(/^SIMICS_WORKSPACE\s*=\s*(\/.*)/)
	{
	    $simics_workspace = $1;
	    chomp $simics_workspace;

	    my $last_char = substr $simics_workspace,-1,1;
	    if($last_char ne '/')
	    {
		$simics_workspace .= "/";
	    }
	}
	elsif(/^PATH\s*=\s*(\/.*)/)
	{
	    my $path = $1;
	    chomp $path;

	    my $last_char = substr $path,-1,1;
	    if($last_char ne '/')
	    {
		$path .= "/";
	    }
	   
	    push @search_paths, $path;
	}
	elsif(/^DEFAULT_TARGET\s*=\s*(\/.*)/)
	{
	    $target = $1;
	    chomp $target;
	}
	elsif(/^DEFAULT_BINARY\s*=\s*(\/.*)/)
	{
	    $binary_file = $1;
	    chomp $binary_file;
	}
	elsif(/^COMMAND\s*=\s*(.*)/)
	{
	    my $tmp_cmd = $1;
	    chomp $tmp_cmd;
	    #print "Saw $tmp_cmd\n";
	    $commands .= $1 . ";";
	}
    }

    close(CONFIG_FILE);
}



################################################################################
#
# Finds the full path for a passed in file using @search_paths
#
################################################################################
sub find_full_path
{
    my $arg = shift;

    # If $arg starts with "/" assume we were given the full path
    if($arg =~ /^\//)
    {
	# Do nothing
    }
    else
    {
	my $entry_found = 0;

	foreach my $path (@search_paths)
	{
	    # Need to find the file based off either our $cur_dir or $simics_workspace
	    my @output = `find $path 2>&1 | grep $arg `;
	    foreach my $entry (@output)
	    {
		chomp $entry;
		if($entry =~ /$arg$/)
		{
		    $arg = $entry;		# $arg now has the full path
		    $entry_found = 1;
		    last;
		}
	    }

	    if($entry_found)
	    {
		last;
	    }
	}

	$entry_found or die "Could not find $arg";    
    }

    return $arg;
}
OpenPOWER on IntegriCloud