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
|
#!/usr/bin/perl
# IBM_PROLOG_BEGIN_TAG
# This is an automatically generated prolog.
#
# $Source: src/build/debug/Hostboot/ContTrace.pm $
#
# IBM CONFIDENTIAL
#
# COPYRIGHT International Business Machines Corp. 2012
#
# 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 other-
# wise divested of its trade secrets, irrespective of what has
# been deposited with the U.S. Copyright Office.
#
# Origin: 30
#
# IBM_PROLOG_END_TAG
use strict;
package Hostboot::ContTrace;
use Exporter;
our @EXPORT_OK = ('main');
use constant MAX_NUM_CONT_TRACE_CTL_STRUCT => 2;
use constant CONT_TRACE_CTL_STRUCT_SIZE => 16;
use constant CONT_TRACE_ENABLE_FLAG_OFFSET => MAX_NUM_CONT_TRACE_CTL_STRUCT * CONT_TRACE_CTL_STRUCT_SIZE;
use constant MAX_NUM_CONT_TRACE_BUFFERS => 2;
use constant DDWORD_SIZE => 8;
use constant WORD_SIZE => 4;
use constant TRIG_BIT => 0x8000000000000000;
use File::Temp ('tempfile');
sub main
{
my ($packName,$args) = @_;
#::userDisplay("args fsp-trace ".$args->{"fsp-trace"}."\n");
#::userDisplay("args with-file-names ".$args->{"with-file-names"}."\n");
#::userDisplay("args last ".$args->{"last"}."\n");
if (not defined $args->{"fsp-trace"})
{
$args->{"fsp-trace"} = "fsp-trace";
}
my $dbgMsg = 0;
if (defined $args->{"debug"})
{
$dbgMsg = 1;
}
my $fsptrace_options = "";
if (defined $args->{"with-file-names"})
{
$fsptrace_options = $fsptrace_options."-f ";
}
my $last = 0;
if (defined $args->{"last"})
{
$last = 1;
}
my $on2off = 0;
my $symAddr = 0;
my $symSize = 0;
if (defined $args->{"enable-cont-trace"})
{
my $new_enable = $args->{"enable-cont-trace"};
$new_enable = $new_enable ? 2 : 0;
($symAddr, $symSize) =
::findSymbolAddress("TRACE::g_cont_trace_trigger_info");
if (not defined $symAddr)
{
::userDisplay "Cannot find symbol.\n"; die;
}
my $enable = ::read64($symAddr + CONT_TRACE_ENABLE_FLAG_OFFSET);
if ($dbgMsg)
{
::userDisplay("current Cont Trace Enable Flag = $enable\n");
}
if (($enable < 2) && ($new_enable == 2))
{
# truncate tracMERG to 0
system( "cp /dev/null tracMERG" );
::write64($symAddr + CONT_TRACE_ENABLE_FLAG_OFFSET, $new_enable);
if ($dbgMsg)
{
$new_enable = ::read64($symAddr+CONT_TRACE_ENABLE_FLAG_OFFSET);
::userDisplay("new Cont Trace Enable Flag = $new_enable\n");
}
return;
}
elsif (($enable == 2) && ($new_enable == 0))
{
$on2off = 1;
$last = 0;
}
else
{
return;
}
}
my $trigger = "simGETFAC B0.C0.S0.P0.E8.TPC.FSI.FSI_MAILBOX.FSXCOMP." .
"FSXLOG.LBUS_MAILBOX.Q_GMB2E0.NLC.L2 32";
$trigger = `$trigger`;
$trigger =~ s/.*\n0xr(.*)\n.*/$1/g;
$trigger =~ s/\n//g;
if ($dbgMsg)
{
::userDisplay("$trigger...\n");
my $cycles = `simgetcurrentcycle`;
$cycles =~ s/\n//g;
$cycles =~ s/.*is ([0-9]*).*/$1/g;
::userDisplay("$cycles\n");
$cycles = `date`;
::userDisplay("$cycles");
}
if (($trigger !~ /[1-9a-fA-F]+/) && ($last == 0))
{
if ($on2off)
{
::write64($symAddr + CONT_TRACE_ENABLE_FLAG_OFFSET, 0);
if ($dbgMsg)
{
$on2off = ::read64($symAddr + CONT_TRACE_ENABLE_FLAG_OFFSET);
::userDisplay("new Cont Trace Enable Flag = $on2off\n");
}
}
if ($dbgMsg)
{
my $cycles = `date`;
::userDisplay("$cycles");
}
return;
}
($symAddr, $symSize) =
::findSymbolAddress("TRACE::g_cont_trace_trigger_info");
if (not defined $symAddr) { ::userDisplay "Cannot find symbol.\n"; die; }
my @fh;
my @fname;
($fh[0],$fname[0]) = tempfile();
binmode($fh[0]);
($fh[1],$fname[1]) = tempfile();
binmode($fh[1]);
# read the g_cont_trace_trigger_info structure
my $result = ::readData($symAddr, $symSize);
my $addrOff = 0;
my $lenOff = $addrOff + DDWORD_SIZE;
my $seqOff = $lenOff + WORD_SIZE;
my $foundBuffer = 0;
my @seqNum;
for (my $i = 0; $i < MAX_NUM_CONT_TRACE_BUFFERS; $i++)
{
# get the pointer to the continuous trace buffer
my $buffAddr = substr $result, $addrOff, DDWORD_SIZE;
$buffAddr= hex (unpack('H*',$buffAddr));
my $buffLen = substr $result, $lenOff, WORD_SIZE;
$buffLen= hex (unpack('H*',$buffLen));
$seqNum[$i] = substr $result, $seqOff, WORD_SIZE;
$seqNum[$i]= hex (unpack('H*',$seqNum[$i]));
if ($dbgMsg)
{
::userDisplay("Trigger [".$i."] = $buffAddr\n");
::userDisplay("Length [".$i."] = $buffLen\n");
::userDisplay("SeqNum [".$i."] = $seqNum[$i]\n");
}
my $fhandle = $fh[$i];
# If trigger bit is set, or last call and buffer has trace data
if ((0 != ($buffAddr & TRIG_BIT)) || (($last == 1) && ($buffLen > 1)))
{
$foundBuffer |= (1 << $i);
$buffAddr &= ~TRIG_BIT;
print $fhandle (::readData($buffAddr, $buffLen));
# reset trigger bit
::write64($symAddr + $addrOff, $buffAddr);
# reset count to 1
::write32($symAddr + $lenOff, 1);
}
# increment to next element in g_cont_trace_trigger_info.triggers[]
$addrOff += (2 * DDWORD_SIZE);
$lenOff = $addrOff + DDWORD_SIZE;
$seqOff = $lenOff + WORD_SIZE;
}
if ($dbgMsg)
{
my $cycles = `simgetcurrentcycle`;
$cycles =~ s/\n//g;
$cycles =~ s/.*is ([0-9]*).*/$1/g;
::userDisplay("$cycles\n");
}
if ($on2off)
{
::write64($symAddr + CONT_TRACE_ENABLE_FLAG_OFFSET, 0);
if ($dbgMsg)
{
$on2off = ::read64($symAddr + CONT_TRACE_ENABLE_FLAG_OFFSET);
::userDisplay("new Cont Trace Enable Flag = $on2off\n");
}
}
if (($foundBuffer == 3) && ($seqNum[1] < $seqNum[0]))
{
my $tmp = $fname[0];
$fname[0] =$fname[1];
$fname[1] = $tmp;
}
for (my $i = 0; $i < MAX_NUM_CONT_TRACE_BUFFERS; $i++)
{
if (($foundBuffer & (1 << $i)))
{
#my $cmd = "cp " . $fname[$i] . " tracMERG." . $seqNum[$i];
#system ( $cmd );
open TRACE, ($args->{"fsp-trace"}." -s ".
::getImgPath()."hbotStringFile $fsptrace_options $fname[$i] |");
while (my $line = <TRACE>)
{
::userDisplay $line;
}
}
unlink($fname[$i]);
}
if ($dbgMsg)
{
my $cycles = `date`;
::userDisplay("$cycles");
}
}
sub helpInfo
{
my %info = (
name => "ContTrace",
intro => ["Displays the continuous trace buffers."],
options => {
"fsp-trace=<path>" => ["Path to non-default fsp-trace utility."],
"with-file-names" => ["Trace statements will include file name of place the",
"trace was defined."],
"last" => ["Shutdown call to offload remaining traces."],
"enable-cont-trace=<1|0>" => ["Turn on|off continuous trace"],
"debug" => ["Turn on debug messages"],
}
);
}
|