summaryrefslogtreecommitdiffstats
path: root/src/build/debug/simics-debug-framework.pl
blob: c83ed905fb00fda867d1e53c33651bc4dd96a230 (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
#!/usr/bin/perl
# IBM_PROLOG_BEGIN_TAG
# This is an automatically generated prolog.
# 
# $Source: src/build/debug/simics-debug-framework.pl $
# 
# IBM CONFIDENTIAL
# 
# COPYRIGHT International Business Machines Corp. 2011,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 otherwise
# divested of its trade secrets, irrespective of what has been
# deposited with the U.S. Copyright Office.
# 
# Origin: 30
# 
# 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 += getHRMOR();

    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 += getHRMOR();

    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:18;     // Not currently used (0:17)
#            uint64_t mBaseAddress:5;    // Base address (18:22)
#            uint64_t mNodeId:3;         // Node where target resides (23:25)
#            uint64_t mChipId:3;         // Targeted chip ID (26:28)
#            uint64_t mSComAddrHi:27;    // PCB Address High (29:55)
#            uint64_t mCacheLine:1;      // Cached line (56)
#            uint64_t mSComAddrLo:4;     // PCB Address low (57: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;

    my  $mSComAddrHi    =   ( $addr >> 4 );
    my  $mSComAddrLo    =   ( $addr & 0x000000000000000f ) ;

    $simicsaddr =   (    0x0003FC0000000000                         ## Base addr
                      | (($mSComAddrHi & 0x0000000007ffffff) << 8 ) ## 27 bits, shift 8
                      | (($mSComAddrLo & 0x000000000000000f) << 3 ) ## 4 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 $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;
}


##
##  Dummy module to match continuous trace call in VPO
##
sub checkContTrace()
{

}


##
##  Retrieve the HRMOR value
##
sub getHRMOR()
{
    sendIPCMsg("get-hrmor","");
    my ($unused, $hrmor) = recvIPCMsg();
    return $hrmor;
}

# 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);

OpenPOWER on IntegriCloud