summaryrefslogtreecommitdiffstats
path: root/src/build/simics/hb-simdebug.py
blob: 4a5e690bc55c5f2f0cf6a5626040bd51f1b0d807 (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
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
#  IBM_PROLOG_BEGIN_TAG
#  This is an automatically generated prolog.
#
#  $Source: src/build/simics/hb-simdebug.py $
#
#  IBM CONFIDENTIAL
#
#  COPYRIGHT International Business Machines Corp. 2011
#
#  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

import os,sys
import conf
import configuration
import cli
import binascii
import datetime
import commands     ## getoutput, getstatusoutput

#------------------------------------------------------------------------------
# Function to dump L3
#------------------------------------------------------------------------------
def dumpL3():

    # "constants"
    L3_SIZE = 0x800000;

    print

    # Get a timestamp on when dump was collected
    t = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
    #print t

    #dump L3 to hbdump.<timestamp>
    string = "memory_image_ln0.save hbdump.%s 0 0x%x"%(t, L3_SIZE)
    #print string
    result = run_command(string)
    #print result

    print "HostBoot dump saved to %s/hbdump.%s."%(os.getcwd(),t)

    return


#------------------------------------------------------------------------------
# Functions to run isteps
#------------------------------------------------------------------------------
def print_istep_list( inList ):

    print
    print   "istep commands:."
    print   "   istepmode   -   enable IStep Mode.  Must be executed before simics run command"
    print   "   normalmode  -   disable IStep Mode. "
    print   "   list        -   list all named isteps"
    print   "   sN          -   execute IStep N"
    print   "   sN..M       -   execute IStep N through M"
    print   "   <name1>     -   excute named istep name1"
    print   "   <name1>..<name2>  - execute named isteps name1 through name2"
    print
    print   "-----------------------------------------------------------"
    print   " Supported ISteps:                                         "
    print   " IStep\tSubStep\tStepName                                  "
    print   "-----------------------------------------------------------"

    ## print   len(inList)
    for i in range(0,len(inList)) :
        ##print len(inList[i])
        for j in range( 0, len(inList[i])) :
            print "%d\t%d\t%s"%( i, j, inList[i][j] )

    return None


#   normally this would be a loop to watch for the runningbit.
#   currently simics dumps all sorts of error lines every time a SCOM is
#   read, so HostBoot only updates every 1 sec.  at that rate we only
#   need to sleep for 2 sec and we are sure to get it.
#   redo later after simics is fixed ...
def getStatusReg():
    ##StatusStr   = "salerno_chip.regdump SCOM 0x13012685"
    ##  -f <file> dumps the output to <file>_SCOM_0X13012685
    ## StatusStr   = "salerno_chip.regdump SCOM 0x13012685 -f ./scom.out"
    StatusStr   = "cpu0_0_0_2->scratch"

    ##  get response
    # (result, statusOutput)  =   quiet_run_command( StatusStr, output_modes.regular )
    result  =   conf.cpu0_0_0_2.scratch
    print "0x%x"%(result)

    hiword  = ( ( result & 0xffffffff00000000) >> 32 )
    loword  = ( result & 0x00000000ffffffff )

    return (hiword, loword)



#   normally this would be a loop to watch for the runningbit.
#   currently simics dumps all sorts of error lines every time a SCOM is
#   read, so HostBoot only updates every 1 sec.  at that rate we only
#   need to sleep for 2 sec and we are sure to get it.
#   redo later after simics is fixed ...
def runIStep( istep, substep, inList ):
    print   "------------------------------------------------------------------"
    print   "run  %s :"%( inList[istep][substep] )
    print   "   istep # = 0x%x / substep # = 0x%x :"%(istep, substep)

    ## CommandStr  = "salerno_chip.regwrite SCOM 0x13012684 \"0x80000000_%4.4x%4.4x\" 64"%(istep,substep)
    CommandStr  = "cpu0_0_0_1->scratch=0x80000000_%4.4x%4.4x"%(istep,substep)

    #result  =   run_command( "run" )

    ##  send command to Hostboot
    # print CommandStr
    (result, out) = quiet_run_command(CommandStr, output_modes.regular )
    #print result

    time.sleep(2)

    # result  =   run_command( "stop" )

    (hiword, loword) =   getStatusReg()

    runningbit  =   ( ( hiword & 0x80000000 ) >> 31 )
    readybit    =   ( ( hiword & 0x40000000 ) >> 30 )
    stsIStep    =   ( ( hiword & 0x3fff0000 ) >> 16 )
    stsSubstep  =   ( ( hiword & 0x0000ffff ) )

    taskStatus  =   ( ( loword & 0xffff0000 ) >> 16 )
    istepStatus =   ( ( loword & 0x0000ffff )  )
    print
    print   "%s : returned Status 0x%8.8x_%8.8x : "%( inList[istep][substep], hiword, loword )
    print "runningbit = 0x%x, readybit=0x%x"%(runningbit, readybit)
    print "Istep 0x%x / Substep 0x%x Status: 0x%x 0x%x"%( stsIStep, stsSubstep, taskStatus, istepStatus )
    print   "-----------------------------------------------------------------"

    # result  =   run_command( "run" )

##  run command = "sN"
def sCommand( inList, scommand ) :
    i   =   int(scommand)
    j   =   0
    for substep in inList[i] :
        ## print   "-----------------"
        ##print "run IStep %d %s  ..."%(i, substep)
        ##print   "-----------------"
        runIStep( i, j, inList )
        j = j+1
    return

def find_in_inList( inList, substepname) :
    for i in range(0,len(inList)) :
        for j in range( 0, len(inList[i])) :
            #print "%d %d"%(i,j)
            if ( inList[i][j] == substepname ) :
                #print "%s %d %d"%( inList[i][j], i, j )
                return (i,j, True )
                break;

    return ( len(inList), len(inList[i]), False )


##  possible commands:
##      list
##      istepmode
##      sN
##      sN..M
##      <substepname1>..<substepname2>
def istepHB( str_arg1, inList):
    IStepModeStr    = "cpu0_0_0_3->scratch=0x4057b007_4057b007"
    NormalModeStr   = "cpu0_0_0_3->scratch=0x700b7504_700b7504"

    print   "run isteps...."

    if ( str_arg1 == "list"  ):         ## dump command list
        print_istep_list( inList)
        return

    if ( str_arg1 == "istepmode"  ):    ## set IStep Mode in SCOM reg
        print   "Set Istep Mode"
        (result, out)  =   quiet_run_command(IStepModeStr, output_modes.regular )
        # print result
        return

    if ( str_arg1 == "normalmode"  ):    ## set Normal Mode in SCOM reg
        print   "Set Normal Mode"
        (result, out)  =   quiet_run_command(NormalModeStr, output_modes.regular )
        # print result
        return

    ## check to see if we have an 's' command (string starts with 's')
    if ( str_arg1.startswith('s') ):
        ## run "s" command
        scommand    =   str_arg1.lstrip('s')
        if scommand.isdigit():
            # command = "sN"
            sCommand( inList, scommand )
        else:
            print "multiple ISteps:" + scommand
            #   list of substeps = "sM..N"
            (M, N)  =   scommand.split('..')
            #print M + "-" + N
            for x in range( (int(M,16)), (int(N,16)+1) ) :
                sCommand( inList, x )
        return
    else:
        ## substep name
        ## (ss_nameM, ss_nameN) = str_arg1.split("..")
        namelist    =   str_arg1.split("..")
        if ( len(namelist) ==  1 ) :
            (istepM, substepM, foundit) = find_in_inList( inList, namelist[0] )
            if ( not foundit ) :
                print "Invalid substep %s"%( namelist[0] )
                return
            runIStep( istepM, substepM, inList )
        else:
            ## substep name .. substep name
            (istepM, substepM, foundit) = find_in_inList( inList, namelist[0] )
            if ( not foundit ) :
                print "Invalid substep %s"%( namelist[0] )
                return
            (istepN, substepN, foundit) = find_in_inList( inList, namelist[1] )
            if ( not foundit ) :
                print( "Invalid substep %s"%( namelist[1]) )
                return
            for x in range( istepM, istepN+1 ) :
                for y in range( substepM, substepN+1) :
                    runIStep( x, y, inList )
    return


#===============================================================================
#   HOSTBOOT Commands
#===============================================================================
default_syms  = "hbicore.syms"
default_stringFile = "hbotStringFile"

#------------------------------------------------
#------------------------------------------------
new_command("hb-trace",
    (lambda comp: run_hb_debug_framework("Trace",
                                         ("components="+comp) if comp else "",
                                         outputFile = "hb-trace.output")),
    [arg(str_t, "comp", "?", None),
    ],
    #alias = "hbt",
    type = ["hostboot-commands"],
    #see_also = ["hb_printk"],
    see_also = [ ],
    short = "Display the hostboot trace",
    doc = """
Parameters: \n
        in = component name(s) \n

Defaults: \n
        'comp' = all buffers \n
        'syms' = './hbicore.syms' \n
        'stringFile' = './hbotStringFile' \n\n

Examples: \n
    hb-trace \n
    hb-trace ERRL\n
    hb-trace "ERRL,INITSERVICE" \n
    """)

#------------------------------------------------
#------------------------------------------------
new_command("hb-printk",
    lambda: run_hb_debug_framework("Printk", outputFile = "hb-printk.output"),
    #alias = "hbt",
    type = ["hostboot-commands"],
    #see_also = ["hb-trace"],
    see_also = [ ],
    short = "Display the kernel printk buffer",
    doc = """
Parameters: \n

Defaults: \n
        'syms' = './hbicore.syms' \n\n

Examples: \n
    hb-printk \n
    """)

#------------------------------------------------
#------------------------------------------------
def hb_dump():
    dumpL3()
    return None

new_command("hb-dump",
    hb_dump,
    #alias = "hbt",
    type = ["hostboot-commands"],
    #see_also = ["hb-trace"],
    see_also = [ ],
    short = "Dumps L3 to hbdump.<timestamp>",
    doc = """
Parameters: \n

Defaults: \n

Examples: \n
    hb-dump \n
    """)

#------------------------------------------------
#   implement isteps
#------------------------------------------------
def hb_istep(str_arg1):

    ##  preprocess inputs,
    ##  read in a file and translate to an inList
    ##  TODO read in default file
    #   TODO inPath  =   "istep_list.txt"
    #   TODO inFile = open( inPath, 'rU')
    #   TODO inList = inFile.readlines()
    #   TODO inFile.close()

    ## set up demo inlist
    inList  =   [   [ "na" ],              ## istep 0
                    [ "na" ],              ## istep 1
                    [ "na" ],              ## istep 2
                    [ "na" ],              ## istep 3
                    [ "init_target_states",     ## istep 4
                      "init_fsi",
                      "apply_fsi_info",
                      "apply_dd_presence",
                      "apply_pr_keyword_data",
                      "apply_partial_bad",
                      "apply_gard",
                      "testHWP"
                    ],
                ]

    ## print   flag_t

    if str_arg1 == None:
        print_istep_list( inList )
    else:
        print "args=%s" % str(str_arg1)
        istepHB( str_arg1, inList, )

    return None

new_command("hb-istep",
    hb_istep,
    [ arg(str_t, "syms", "?", None),
      # arg(flag_t,"-s", "?", None),
    ],
    type = ["hostboot-commands"],
    see_also = [ ],
    short = "Run IStep commands using the SPLess HostBoot interface",
    doc = """
Parameters: \n

Defaults: \n

Examples: \n
    hb-istep \n
    hb-istep -s0 \n
    hb-istep -s0..4
    hb-istep poweron
    hb-istep poweron..clock_frequency_set
    """)

#------------------------------------------------
#------------------------------------------------
new_command("hb-errl",
    (lambda logid, logidStr, flg_l, flg_d:
        run_hb_debug_framework("Errl",
                ("display="+(str(logid) if logid else logidStr) if flg_d else ""
                ),
                outputFile = "hb-errl.output")),
    [ arg(int_t, "logid", "?", None),
     arg(str_t, "logidStr", "?", None),
     arg(flag_t, "-l"),
     arg(flag_t, "-d"),
    ],
    #alias = "hbt",
    type = ["hostboot-commands"],
    #see_also = ["hb_printk"],
    see_also = [ ],
    short = "Display the hostboot error logs",
    doc = """
Parameters: \n
        in = option for dumping error logs\n

Defaults: \n
        'flag' = '-l' \n

Examples: \n
    hb_errl [-l]\n
    hb-errl -d 1\n
    hb-errl -d [all]\n
    """)


#------------------------------------------------
#------------------------------------------------
def hb_singlethread():
    run_command("foreach $cpu in (system_cmp0.get-processor-list) {$cpu.disable}")
    run_command("cpu0_0_0_0.enable");
    return

new_command("hb-singlethread",
    hb_singlethread,
    [],
    alias = "hb-st",
    type = ["hostboot-commands"],
    short = "Disable all threads except cpu0_0_0_0.")


#------------------------------------------------
#------------------------------------------------
new_command("hb-callfunc",
    (lambda function, args:
        eval(run_hb_debug_framework("CallFunc",
                ("function='"+function+"' arguments="+
                 (",".join(map(str, args)))),
                outputToString = 1))),
    [
     arg(str_t, "function"),
     arg(list_t, "args", "?", [])
    ],
    type = ["hostboot-commands"],
    see_also = ["hb-debug-CallFunc"],
    short = "Interactively call a hostboot function.",
    doc = """
Parameters: \n
        function = Function to execute.\n
        args = List of arguments.\n

Defaults: \n
        args = [0]\n

Examples: \n
        hb-callfunc "malloc" [8]\n
        hb-callfunc "free" [0x1234]\n

Note:
        This function may only be called with simics stopped.
    """)

OpenPOWER on IntegriCloud