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
|
#!/usr/bin/perl
# IBM_PROLOG_BEGIN_TAG
# This is an automatically generated prolog.
#
# $Source: src/build/debug/simics-debug-framework.pl $
#
# OpenPOWER HostBoot Project
#
# Contributors Listed Below - COPYRIGHT 2011,2016
# [+] Google Inc.
# [+] International Business Machines Corp.
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied. See the License for the specific language governing
# permissions and limitations under the License.
#
# IBM_PROLOG_END_TAG
# @file simics-debug-framework.pl
# @brief Implementation of the common debug framework for running in simics.
#
# Simics uses Python for all debug. This file is a Perl bridge between Python
# and the framework tool modules. The Python side will create a sub-process of
# this script using STDIN/STDOUT as an IPC message pipe. This side will
# execute the Perl module and send data / output across the pipe to the Python
# side.
use strict;
use lib $ENV{HB_TOOLPATH};
use Hostboot::_DebugFramework;
$| = 1; # Disable buffering on STDIN/STDOUT.
# @sub sendIPCMsg
# @brief Sends a message to the Python side of the framework over STDOUT.
#
# Messages are of the format:
# [ "type", "data-in-ascii-encoded-hex" ]
# Example:
# The message...
# [ "display", "48656c6c6f20576f726c642e0a" ]
# means 'display "Hello World.\n"'
sub sendIPCMsg
{
my ($type, $data) = @_;
print "[ \"$type\", \"".unpack("H*",$data)."\" ]\n";
}
# @sub recvIPCMsg
# @brief Watis for a message from the Python side of the framework from STDIN.
#
# See sendIPCMsg for message format.
sub recvIPCMsg
{
my $type = "";
my $data = "";
if (my $string = <STDIN>)
{
if ($string =~ m/\[ \"([^\"]+)\", \"([0-9a-f]*)\" ]\n/)
{
$type = $1;
$data = pack("H*", $2);
}
}
return ($type, $data);
}
# @sub userDisplay
# @brief Send a 'display' type message to Python.
sub userDisplay
{
my $string = "";
foreach my $value (@_)
{
$string = $string . $value;
}
sendIPCMsg("display", $string);
}
# @sub readData
# @brief Send a 'read-data' type message to Python.
sub readData
{
my $addr = shift;
my $size = shift;
$addr = translateHRMOR($addr);
sendIPCMsg("read-data", "$addr,$size");
my ($type, $data) = recvIPCMsg();
if (length($data) == $size)
{
return $data;
}
return "";
}
# @sub writeData
# @brief Send a 'write-data' type message to Python.
sub writeData
{
my $addr = shift;
my $size = shift;
my $value = shift;
$addr = translateHRMOR($addr);
my $value = unpack("H*", $value);
sendIPCMsg("write-data", "$addr,$size,$value");
return;
}
# @sub executeInstrCycles
# @brief Send a 'execute-instrs' type message to Python.
sub executeInstrCycles
{
my $cycles = shift;
sendIPCMsg("execute-instrs", "$cycles");
}
# @sub readyForInstructions
# @brief Send a 'ready-for-instr' type message to Python.
# @returns 0 - Not ready or 1 - Ready
sub readyForInstructions
{
sendIPCMsg("ready-for-instr", "");
my ($type, $data) = recvIPCMsg();
if ("1" eq $data)
{
return 1;
}
return 0;
}
# Image path global.
my $imgPath = "";
sub getImgPath
{
return $imgPath;
}
# Tool location override.
sub getToolOverride
{
return $ENV{'HB_TOOLPATH'}
}
# Simics always uses the non-test named files.
sub getIsTest
{
return 0;
}
# @sub getEnv
#
# Return the environment that we are running in, simics or vpo
#
sub getEnv
{
return "simics";
}
#
# @sub translateAddr
# Do scom -> "phys_mem.read" address translation here.
# The xscom address looks like this:
# // Layout of XSCOM address parts
# union
# {
# uint64_t mMmioAddress; // mMmio address
# struct
# {
# uint64_t mReserved1:8; // Not currently used (0:7)
# uint64_t mBaseAddrHi:7; // Base address [8:14] (8:14)
# uint64_t mNodeId:4; // Node where target resides (15:18)
# uint64_t mChipId:3; // Targeted chip ID (19:21)
# uint64_t mBaseAddrLo:8; // Base address [22:29] (22:29)
# uint64_t mSComAddr:31; // PIB Address (30:60)
# uint64_t mAlign:3; // Align (61:63)
# } mAddressParts;
#
# @param[in] - 64-bit scom address
#
# @return = address to send to python to do mm.read
#
# @note: "host_xscom_device_mm.read/write " doesn't seem to work with this
# translated address, use "phys_mem.read/write " (in python) instead.
#
sub translateAddr
{
my $addr = shift;
my $simicsaddr = 0;
$simicsaddr = ( 0x000603fc00000000 ## Base addr
| (($addr & 0x000000007fffffff) << 3 ) ## 31 bits, shift 3
);
return $simicsaddr;
}
# @sub readScom
# @brief Send a 'read-scom' type message to Python.
#
# @param[in] scom address to read
# @param[in] data size IN BYTES
#
# @return hex string containing data read
#
# @todo: handle littleendian
#
sub readScom
{
my $addr = shift;
my $size = shift;
my $simicsaddr = translateAddr( $addr);
## debug
## ::userDisplay "--- readScom: ", (sprintf("0x%x-->0x%x, 0x%x",$addr,$simicsaddr,$size)), "\n";
sendIPCMsg("read-scom", "$simicsaddr,$size");
my ($type, $data) = recvIPCMsg();
return hex $data;
}
# @sub writeScom
# @brief Send a 'write-scom' type message to Python.
#
# @param[in] - xscom address
# @param[in] - data size IN BYTES
# @param[in] - binary data value. Scom value is aways assumed to be 64bits
#
# @return none
#
# @todo: handle littleendian
#
sub writeScom
{
my $addr = shift;
my $size = shift;
my $value = shift;
my $simicsaddr = translateAddr( $addr);
## debug
## ::userDisplay "--- writeScom: ", (sprintf("0x%x-->0x%x, 0x%x, 0x%x",$addr,$simicsaddr,$size,$value)), "\n";
my $ipctype = "write-scom";
my $ipcdata = "$simicsaddr,$size,$value";
sendIPCMsg( $ipctype, $ipcdata );
## $$ debug
## $$my $debugstr = "[ \"$ipctype\", \"".unpack("H*",$ipcdata)."\" ]\n";
## $$::userDisplay "--- $debugstr\n";
return;
}
# @sub getHRMOR
# @brief Retrieve the HRMOR value
#
my $cached_HRMOR = "";
sub getHRMOR
{
if ($cached_HRMOR eq "")
{
sendIPCMsg("get-hrmor","");
my ($unused, $hrmor) = recvIPCMsg();
$cached_HRMOR = $hrmor;
return $hrmor;
}
return $cached_HRMOR;
}
use constant PNOR_RP_HBEXT_SECTION => 1;
use constant PNOR_RP_SECTIONDATA_SIZE => 3 * 8 + 2;
use constant PNOR_RP_SECTIONDATA_FLASHADDR_OFFSET => 2 * 8;
# @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 ($pnorRPAddr, $pnorRPSize) =
::findSymbolAddress("Singleton<PnorRP>::instance()::instance");
my $extImageOffset +=
read32($pnorRPAddr +
(PNOR_RP_SECTIONDATA_SIZE * PNOR_RP_HBEXT_SECTION) +
PNOR_RP_SECTIONDATA_FLASHADDR_OFFSET);
$addr += $extImageOffset;
sendIPCMsg("read-pnor", "$addr,$size");
my ($type, $data) = recvIPCMsg();
if (length($data) == $size)
{
return $data;
}
return "";
}
# Get tool name.
sendIPCMsg("get-tool","");
my ($unused, $tool) = recvIPCMsg();
# Get image path.
sendIPCMsg("get-img-path");
($unused, $imgPath) = recvIPCMsg();
$imgPath = determineImagePath($imgPath);
# If we were called with --usage, send tool help instead of executing.
if ((-1 != $#ARGV) && ("--usage" eq $ARGV[0]))
{
callToolModuleHelp($tool);
exit;
}
# Get tool options.
sendIPCMsg("get-tool-options","");
my ($unused, $toolOpts) = recvIPCMsg();
parseToolOpts($toolOpts);
# Execute module.
callToolModule($tool);
##
## Dummy function to match continuous trace call in VPO
##
sub checkContTrace
{
}
|