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
|
#!/usr/bin/perl
# IBM_PROLOG_BEGIN_TAG
# This is an automatically generated prolog.
#
# $Source: src/build/debug/Hostboot/Trace.pm $
#
# IBM CONFIDENTIAL
#
# COPYRIGHT International Business Machines Corp. 2011,2013
#
# 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 strict;
package Hostboot::Trace;
use Hostboot::_DebugFrameworkVMM qw(NotFound NotPresent getPhysicalAddr);
use Exporter;
our @EXPORT_OK = ('main');
use constant TRACE_BUFFER_COUNT => 2;
use constant DAEMON_FIRST_BUFFER_PAGE_OFFSET => 8;
use constant DAEMON_FIRST_TEMP_BUFFER_PAGE_OFFSET =>
DAEMON_FIRST_BUFFER_PAGE_OFFSET + 16;
use constant BUFFER_FIRST_PAGE_OFFSET => 16;
use constant BUFFER_PAGE_NEXT_OFFSET => 0;
use constant BUFFER_PAGE_PREV_OFFSET => BUFFER_PAGE_NEXT_OFFSET + 8;
use constant BUFFER_PAGE_SIZE_OFFSET => BUFFER_PAGE_PREV_OFFSET + 12;
use constant BUFFER_PAGE_DATA_OFFSET => BUFFER_PAGE_SIZE_OFFSET + 4;
use constant ENTRY_COMP_OFFSET => 0;
use constant ENTRY_SIZE_OFFSET => 26;
use constant ENTRY_SIZE => 28;
use constant BIN_ENTRY_SIZE_OFFSET => 12;
use constant BIN_ENTRY_SIZE => 24;
use File::Temp qw(tempfile tempdir);
sub main
{
my ($packName,$args) = @_;
if (not defined $args->{"fsp-trace"})
{
$args->{"fsp-trace"} = "fsp-trace";
}
my $fsptrace_options = "";
if (defined $args->{"with-file-names"})
{
$fsptrace_options = $fsptrace_options."-f ";
}
my $traceBuffers = $args->{"components"};
if (defined $traceBuffers)
{
$traceBuffers = uc $traceBuffers;
}
my $tmpdir = tempdir(CLEANUP => 1);
open (my $fh, ">", $tmpdir."/tracBINARY");
binmode($fh);
my $foundBuffer = 0;
print $fh "\2";
my ($daemonAddr, $daemonSize) =
::findSymbolAddress("Singleton<TRACEDAEMON::Daemon>::instance()::instance");
my ($serviceAddr, $serviceSize) =
::findSymbolAddress("Singleton<TRACE::Service>::instance()::instance");
if ((not defined $daemonAddr) || (not defined $serviceAddr))
{
::userDisplay "Cannot find trace daemon and/or service.\n";
die;
}
my @bufferPages = ();
my %components = ();
$daemonAddr = getPhysicalAddr($daemonAddr);
unless (($daemonAddr eq NotFound) || ($daemonAddr eq NotPresent))
{
my $firstPage = ::read64($daemonAddr + DAEMON_FIRST_BUFFER_PAGE_OFFSET);
readPage($firstPage, BUFFER_PAGE_PREV_OFFSET, \@bufferPages);
for(my $i = 0; $i < TRACE_BUFFER_COUNT; $i++)
{
my $page =
::read64($daemonAddr + DAEMON_FIRST_TEMP_BUFFER_PAGE_OFFSET +
8*$i);
readPage($page, BUFFER_PAGE_PREV_OFFSET, \@bufferPages);
}
}
for(my $i = 0; $i < TRACE_BUFFER_COUNT; $i++)
{
my $buffer = ::read64($serviceAddr + 8*$i);
my $page = ::read64($buffer + BUFFER_FIRST_PAGE_OFFSET);
readPage($page, BUFFER_PAGE_PREV_OFFSET, \@bufferPages);
}
while(@bufferPages)
{
my $page = shift @bufferPages;
my $size = readBuf32($page, BUFFER_PAGE_SIZE_OFFSET) +
BUFFER_PAGE_DATA_OFFSET;
my $offset = BUFFER_PAGE_DATA_OFFSET;
# Read each entry.
while($offset < $size)
{
my $entry_size = readBuf16($page, ENTRY_SIZE_OFFSET + $offset);
my $compAddr = readBuf64($page, ENTRY_COMP_OFFSET + $offset);
if (0 ne $compAddr)
{
my $component = lookupComponent($compAddr,
\%components);
if ((not defined $traceBuffers) ||
($traceBuffers =~ m/$component/))
{
$foundBuffer = 1;
print $fh $component;
print $fh "\0";
my $entry_data =
substr $page, ENTRY_SIZE + $offset, $entry_size;
my $bin_entry_size = BIN_ENTRY_SIZE +
readBuf16($entry_data, BIN_ENTRY_SIZE_OFFSET);
$entry_data = substr $entry_data, 0, $bin_entry_size;
print $fh $entry_data;
}
}
$offset += $entry_size + ENTRY_SIZE;
$offset = round8($offset);
}
}
if ($foundBuffer)
{
open TRACE, ($args->{"fsp-trace"}." $tmpdir -s ".
::getImgPath()."hbotStringFile $fsptrace_options |");
while (my $line = <TRACE>)
{
::userDisplay $line;
}
}
else
{
::userDisplay("No matching buffers found.\n");
}
}
sub readPage
{
my ($addr, $offset, $pageArray) = @_;
return if (0 == $addr);
my $buffer = ::readData($addr, 4096);
my $pointer = readBuf64($buffer, $offset);
push @{$pageArray}, $buffer;
readPage($pointer, $offset, $pageArray);
}
sub readBuf64
{
my ($buffer, $offset) = @_;
my $data = substr $buffer, $offset, 8;
if (::littleendian()) { $data = reverse($data); }
return unpack("Q", $data);
}
sub readBuf32
{
my ($buffer, $offset) = @_;
my $data = substr $buffer, $offset, 4;
if (::littleendian()) { $data = reverse($data); }
return unpack("L", $data);
}
sub readBuf16
{
my ($buffer, $offset) = @_;
my $data = substr $buffer, $offset, 2;
if (::littleendian()) { $data = reverse($data); }
return unpack("S", $data);
}
sub round8
{
my ($val) = @_;
if ($val % 8)
{
$val += (8 - ($val % 8));
}
return $val;
}
sub lookupComponent
{
my ($ptr, $hash) = @_;
if (not defined $hash->{$ptr})
{
$hash->{$ptr} = ::readStr($ptr);
}
return $hash->{$ptr};
}
sub helpInfo
{
my %info = (
name => "Trace",
intro => ["Displays the trace buffer."],
options => {
"fsp-trace=<path>" => ["Path to non-default fsp-trace utility."],
"components=<list>" =>["Comma separated list of components to display trace",
"buffers for."],
"with-file-names" => ["Trace statements will include file name of place the",
"trace was defined."],
},
);
}
|