summaryrefslogtreecommitdiffstats
path: root/src/build/debug/ecmd-debug-framework.pl
blob: d5da4ceb60ecfa2e1abe4ceda39c561bef595212 (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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
#!/usr/bin/perl
# IBM_PROLOG_BEGIN_TAG
# This is an automatically generated prolog.
#
# $Source: src/build/debug/ecmd-debug-framework.pl $
#
# IBM CONFIDENTIAL
#
# COPYRIGHT International Business Machines Corp. 2013,2014
#
# p1
#
# Object Code Only (OCO) source materials
# Licensed Internal Code Source Materials
# IBM HostBoot Licensed Internal Code
#
# The source code for this program is not published or otherwise
# divested of its trade secrets, irrespective of what has been
# deposited with the U.S. Copyright Office.
#
# Origin: 30
#
# IBM_PROLOG_END_TAG

use Getopt::Long;
use Pod::Usage;
use IO::Seekable;
use File::Temp ( 'tempfile' );
use File::Basename;
use lib dirname (__FILE__);

use Hostboot::_DebugFramework;

use constant DEFAULT_HRMOR => 128*1024*1024; # 128 MB.
use constant PER_NODE_OFFSET => 32*1024*1024*1024*1024; # 32 TB.

my $filename = basename (__FILE__);
my $self = ($0 =~ m/$filename/);

my $tool = "";
my $testImage = 0;
my $toolOptions = "";
my $cfgHelp = 0;
my $cfgMan = 0;
my $toolHelp = 0;
my $forceHRMOR = DEFAULT_HRMOR;
my $node = 0;  # -nX parm to ecmd
my $proc = 0;  # -pX parm to ecmd

my $imgPath = "";
my $hbDir = $ENV{'HB_IMGDIR'};
if (defined ($hbDir))
{
    if ($hbDir ne "")
    {
        $imgPath = "$hbDir/";
    }
}

if (not $self)
{
    $tool = basename $0;
}

GetOptions("tool:s" => \$tool,
           "tool-options:s" => \$toolOptions,
           "test" => \$testImage,
           "img-path:s" => \$imgPath,
           "help" => \$cfgHelp,
           "toolhelp" => \$toolHelp,
           "force-hrmor:o" => \$forceHRMOR,
           "node:i" => \$node,
           "proc:i" => \$proc,
           "man" => \$cfgMan) || pod2usage(-verbose => 0);
pod2usage(-verbose => 1) if $cfgHelp;
pod2usage(-verbose => 2) if $cfgMan;
pod2usage(-verbose => 0) if ($tool eq "");

if ($toolHelp)
{
    callToolModuleHelp($tool);
}
else
{
    # Determine the full image path.
    $imgPath = determineImagePath($imgPath);

    # Parse tool options and call module.
    parseToolOpts($toolOptions);
    callToolModule($tool);
}

exit 0;

# @sub userDisplay
#
# Display parameters to the user.
#
# @param varargs - Items to display to the user.
#
sub userDisplay
{
    foreach my $value (@_)
    {
        print $value;
    }
}


# @sub getImgPath
#
# Return file-system path to .../img/ subdirectory containin debug files.
#
sub getImgPath
{
    return $imgPath;
}

# @sub getIsTest
#
# Return boolean to determine if tools should look at test debug files or
# normal debug files.
#
sub getIsTest
{
    return $testImage;
}

# @sub getEnv
#
# Return the environment that we are running in.
#
sub getEnv
{
    return "hw";
}

# @sub getHRMOR
#
# Returns the HRMOR (128MB for a real system).
#
sub getHRMOR
{
    return $forceHRMOR + ($node * PER_NODE_OFFSET);
}

# @sub readData
#
# Reads a data blob from the system.
#
# @param addr - Address to read at.
# @param size - Size (in bytes) to read.
#
# @return The blob of data requested.
#
sub readData
{
    my $addr = shift;
    my $size = shift;

    $addr = translateHRMOR($addr);

    my (undef, $debugfile) = tempfile(OPEN => 0);
    my (undef, $filename) = tempfile(OPEN => 0);
    my $command = sprintf("cipgetmempba -n%d -p%d -fb %s %x %d -quiet > %s",
                          $node,
                          $proc,
                          $filename,
                          $addr,
                          $size,
                          $debugfile);
    if (system($command) != 0)
    {
        system("cat $debugfile");
    }
    unlink $debugfile;

    my $result;
    open FILE, $filename or die
        "ERROR: $filename not found attempting getmempba";
    binmode FILE;
    read FILE, $result, $size;
    close FILE;
    unlink $filename;

    return $result;
}

# @sub writeData
#
# Write a data blob to the system.
#
# @param addr - Address to read at.
# @param size - Size (in bytes) to read.
# @param value - Value to write.
#
sub writeData
{
    my $addr = shift;
    my $size = shift;
    my $value = shift;

    $addr = translateHRMOR($addr);

    my (undef, $debugfile) = tempfile(OPEN => 0);
    my ($file, $filename) = tempfile();
    binmode $file;
    print $file $value;
    close $file;

    my $command = sprintf("cipputmempba -n%d -p%d -cft -fb %s %x -quiet -mode inj > %s",
                          $node,
                          $proc,
                          $filename,
                          $addr,
                          $debugfile);
    ::userDisplay($command);
    if (system($command) != 0)
    {
        system("cat $debugfile");
    }
    unlink $debugfile;

    unlink $filename;

    return;
}

# @sub readScom
#
# Perform a getscom operation.
#
# @param addr - Address to read at.
# @param size - Size (in bytes) to read.
#
# @return Data from scom.
#
sub readScom
{
    my $addr = shift;
    my $size = shift;

    my $command = sprintf("getscom pu -n%d -p%d %x -quiet -ox",
                          $node, $proc, $addr);
    open OUTPUT, "$command |";
    my $result = <OUTPUT>;
    close OUTPUT;

    $result =~ s/.*0x//;
    $result = hex $result;

    return $result;
}

# @sub writeScom
#
# Perform a putscom operation.
#
# @param addr - Address to write at.
# @param size - Size (in bytes) to write.
# @param data - Data to write.
#
sub writeScom
{
    my $addr = shift;
    my $size = shift;
    my $data = shift;

    my $command = sprintf("putscom pu -n%d -p%d %x %x -quiet > /dev/null",
                          $node, $proc, $addr, $data);

    system($command);

    return;
}

# @sub executeInstrCycles
#
# Execute a number of cycles.
#
# @param cycles - Number of cycles to execute.
#
sub executeInstrCycles
{
    my $cycles = shift;

    #No op on real HW
}

# @sub readyForInstructions
#
# Determines if system can execute cycles.
#
sub readyForInstructions
{
    return 1;
}

# @sub readExtImage
#
# Reads from the extended image file.
#
# @param addr - Address to read.
# @param size - Size to read.
sub readExtImage
{
    my $addr = shift;
    my $size = shift;

    my $extImage = extImageFile();

    seek $extImage, $addr, SEEK_SET;

    my $result = "";
    read $extImage, $result, $size;

    return $result;
}

# @sub extImageFile
#
# Returns a file descriptor to the extended image file.
#
my $extImage = 0;
sub extImageFile
{
    if ($extImage == 0)
    {
        my $path = determineImagePath(getImgPath());

        if (getIsTest())
        {
            $path = $path . "hbicore_test_extended.bin";
        }
        else
        {
            $path = $path . "hbicore_extended.bin";
        }

        print $path."\n";

        open($extImage, "< $path") or die "Cannot find extended image";
        binmode($extImage);
    }

    return $extImage;
}

##
##  Dummy function to match continuous trace call in VPO
##
sub checkContTrace
{

}


__END__

=head1 NAME

ecmd-debug-framework.pl

=head1 SYNOPSIS

ecmd-debug-framework.pl [options] --tool=<module>

=head1 OPTIONS

=over 8

=item B<--tool>=MODULE

Identify the tool module to execute.

=item B<--tool-options>="OPTIONS"

List of arguments to pass to the tool as options.

=item B<--force-hrmor>=value

Set the HRMOR to be a non-default value.  The default is 128MB.

=item B<--toolhelp>

Displays the help message for a specific debug tool.

=item B<--test>

Use the hbicore_test.syms file instead of the default.

=item B<--img-path>=PATH

The path to the "img" directory where the syms file, etc is located.
User can also set the env variable HBDIR to the path of the "img"
directory instead of using this option.

=item B<--help>

Print a brief help message and exits.

=item B<--man>

Prints the manual page and exits.

=back

=head1 DESCRIPTION

Executes a debug tool module against an ecmd target.

=cut
OpenPOWER on IntegriCloud