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
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
|
#!/usr/bin/perl
# IBM_PROLOG_BEGIN_TAG
# This is an automatically generated prolog.
#
# $Source: src/build/debug/Hostboot/Istep.pm $
#
# 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 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
#
# Purpose: This perl script works in concert with do_sprint to
# implement isteps on AWAN.
#
# Description:
# The do_sprint script will run first to set up the AWAN environment,
# Then call hb_Istep twice:
# 1) hb_Istep [--]istepmode
# called after loading but before starting HostBoot
# this will check to see if the user has set istep mode, if so
# it will write the Istep_mode signature to L3 memory to put
# HostBoot mode into single-step mode (spless or FSP).
# 2) hb_Istep [--]command
# Periodically call ::executeInstrCycles() to step through HostBoot.
# Checks for status from previous Isteps, and reports status.
#
# Author: Mark Wenning
#
# DEVELOPER NOTES:
# Do NOT put prints or printf's in this script!!!
# simics-debug-framework.pl and simics-debug-framework.py communicate
# (recvIPCmsg and sendIPCmsg) overstdin and stdout -
# if you print to STDOUT you will inadvertently send an empty/corrupted
# "IPC" message to python/simics which will usually cause ugly crashes.
#
#------------------------------------------------------------------------------
# Specify perl modules to use
#------------------------------------------------------------------------------
use strict;
use POSIX; # isdigit
## 64-bit input
use bigint;
no warnings 'portable';
## declare Istep package
package Hostboot::Istep;
use Exporter;
our @EXPORT_OK = ('main');
#------------------------------------------------------------------------------
# Constants
#------------------------------------------------------------------------------
## @todo extract these from splesscommon.H
use constant SPLESS_MODE_SIGNATURE => 0x4057b0074057b007;
use constant FSP_MODE_SIGNATURE => 0x700b7504700b7504;
use constant RUN_ALL_MODE_SIGNATURE => 0xBADC0FFEE0DDF00D;
use constant SPLESS_SINGLE_ISTEP_CMD => 0x00;
use constant SPLESS_RESUME_ISTEP_CMD => 0x01;
use constant SPLESS_CLEAR_TRACE_CMD => 0x02;
use constant SPLESS_SHUTDOWN_CMD => 0x03;
use constant MAX_ISTEPS => 25;
use constant MAX_SUBSTEPS => 25;
## Mailbox Scratchpad regs
use constant MBOX_SCRATCH0 => 0x00050038;
use constant MBOX_SCRATCH1 => 0x00050039;
use constant MBOX_SCRATCH2 => 0x0005003a;
use constant MBOX_SCRATCH3 => 0x0005003b;
## extra parm for ::executeInstrCycles
use constant NOSHOW => 1;
#------------------------------------------------------------------------------
# Globals
#------------------------------------------------------------------------------
my $opt_debug = 0;
my $opt_splessmode = 0;
my $opt_fspmode = 0;
my $opt_command = 0;
my $opt_list = 0;
my $opt_resume = 0;
my $opt_clear_trace = 0;
## deprecated - keep around for now
my $opt_istepmode = 0;
my $command = "";
my @inList;
## initialize the sequence number - 6 bit field, { 0 - 63 }
my $g_SeqNum = int(rand(64));
my $THREAD = "0";
## --------------------------------------------------------------------------
## get any environment variables
## --------------------------------------------------------------------------
## @todo make this an enviroment var?
## NOTE: this is the # cycles used for simics, it is multiplied by 100
## in vpo-debug-framework.pl
my $hbDefaultCycles = 5000000;
my $hbCount = $ENV{'HB_COUNT'};
if ( !defined( $hbCount ) || ( $hbCount eq "" ) )
{
## set default
$hbCount = 0xffffffff; ## effectively infinite ...
}
## init global variables
my $IstepModeReg = "";
my $ShutDownFlag = "";
my $ShutDownSts = "";
my $CommandReg = "";
my $StatusReg = "";
########################################################################
## MAIN ROUTINE, called from debug framework
########################################################################
sub main
{
## $packName is the name of the selected tool
## $args is a hashref to all the command-line arguments
my ($packName,$args) = @_;
## debug - save
while ( my ($k,$v) = each %$args )
{
::userDisplay "args: $k => $v\n";
}
::userDisplay "Welcome to hb-Istep 3.31 .\n";
::userDisplay "Note that in simics, multiple options must be in quotes,";
::userDisplay "separated by spaces\n\n";
## initialize inList to "undefined"
$inList[MAX_ISTEPS][MAX_SUBSTEPS] = ();
for( my $i = 0; $i < MAX_ISTEPS; $i++)
{
for(my $j = 0; $j < MAX_SUBSTEPS; $j++)
{
undef( $inList[$i][$j] );
}
}
## ---------------------------------------------------------------------------
## Fetch the symbols we need from syms file
## ---------------------------------------------------------------------------
$IstepModeReg = getSymbol( "SPLESS::g_SPLess_IStepMode_Reg" );
$CommandReg = getSymbol( "SPLESS::g_SPLess_Command_Reg" );
$StatusReg = getSymbol( "SPLESS::g_SPLess_Status_Reg" );
$ShutDownFlag = getSymbol( "CpuManager::cv_shutdown_requested" );
$ShutDownSts = getSymbol( "CpuManager::cv_shutdown_status" );
## fetch the istep list
get_istep_list();
## $$ debug, dump all the environment vars that we are interested in
dumpEnvVar( "HB_TOOLS" );
dumpEnvVar( "HB_IMGDIR" );
dumpEnvVar( "HB_VBUTOOLS" );
dumpEnvVar( "HB_COUNT" );
##--------------------------------------------------------------------------
## Start processing options
## process the "flag" standard options, then use a loop to go through
## the rest
##--------------------------------------------------------------------------
## Get all the command line options in an array
my @options = ( keys %$args );
## ::userDisplay join( ' ', @options );
if ( !(@options) )
{
::userDisplay "type \"help hb-istep\" for help\n";
exit;
}
##
## find all the standard options, set their flag, and remove them from
## the options list.
## vpo and simics use different command-line styles:
## simics wants you to say " hb-istep "debug s4" ",
## (note that multiple options must be in quotes, separated by spaces)
## and vpo wants you to say "hb-istep --debug --command s4" .
## This should accept both styles.
##
for ( my $i=0; $i <= $#options; $i++ )
{
$_ = $options[$i];
## ::userDisplay ".$_.";
if ( m/^\-{0,2}debug$/ )
{
$opt_debug = 1;
$options[$i] = "";
}
if ( m/^\-{0,2}list$/ )
{
$opt_list = 1;
$options[$i] = "";
}
if ( m/^\-{0,2}istepmode$/ )
{
$opt_istepmode = 1;
$options[$i] = "";
}
if ( m/^\-{0,2}splessmode$/ )
{
$opt_splessmode = 1;
$options[$i] = "";
}
if ( m/^\-{0,2}fspmode$/ )
{
$opt_fspmode = 1;
$options[$i] = "";
}
if ( m/^\-{0,2}command$/ )
{
## doesn't do much, just eats the option
$opt_command = 1;
$options[$i] = "";
}
if ( m/^\-{0,2}resume$/ )
{
$opt_resume = 1;
$options[$i] = "";
}
if ( m/^\-{0,2}clear-trace$/ )
{
$opt_clear_trace = 1;
$options[$i] = "";
}
} ## endfor
## if there's anything left after this, assume it is a single command
$command = join( "", @options );
chomp $command;
## print out debug info
if ( $opt_debug )
{
::userDisplay "\n----- DEBUG: ------------------------------- \n";
::userDisplay "debug = $opt_debug\n";
::userDisplay "list = $opt_list\n";
::userDisplay "splessmode = $opt_splessmode\n";
::userDisplay "fspmode = $opt_fspmode\n";
::userDisplay "resume = $opt_resume\n";
::userDisplay "clear-trace = $opt_clear_trace\n";
::userDisplay "command flag = $opt_command\n";
::userDisplay "command = \"$command\"\n";
::userDisplay "g_SeqNum = ", sprintf("0x%x",$g_SeqNum), "\n";
::userDisplay "IstepModeReg = ", sprintf("0x%x",$IstepModeReg), "\n";
::userDisplay "CommandReg = ", sprintf("0x%x",$CommandReg), "\n";
::userDisplay "StatusReg = ", sprintf("0x%x",$StatusReg), "\n";
::userDisplay "ShutDownFlag = ", sprintf("0x%x",$ShutDownFlag), "\n";
::userDisplay "ShutDownSts = ", sprintf("0x%x",$ShutDownSts), "\n";
::userDisplay "hbCount = ", sprintf("0x%x",$hbCount), "\n";
::userDisplay "\n";
}
if ( $opt_debug ) { ::userDisplay "=== check ShutDown Status...\n"; }
if ( isShutDown() )
{
::userDisplay "Cannot run hb-Istep.\n";
exit;
}
## ----------------------------------------------------------------
## finally, run some commands.
## ----------------------------------------------------------------
if ( $opt_list )
{
::userDisplay "List isteps\n";
print_istep_list();
exit;
}
if ( $opt_istepmode )
{
::userDisplay "istepmode no longer used - use splessmode, or fspmode\n";
exit;
}
if ( $opt_splessmode )
{
::userDisplay "ENable splessmode\n";
setMode( "spless" );
::userDisplay "Done.\n";
exit;
}
if ( $opt_fspmode )
{
::userDisplay "ENable fspmode\n";
setMode( "fsp" );
::userDisplay "Done.\n";
exit;
}
## don't do any other commands unless ready bit is on.
if ( ! isReadyBitOn() )
{
::userDisplay "Ready bit is off, must run splessmode or fspmode first.\n";
exit;
}
if ( $opt_clear_trace )
{
::userDisplay "Clear Trace\n";
clear_trace();
exit;
}
if ( $opt_resume )
{
::userDisplay "Resume\n";
resume_istep();
exit;
}
if ( $opt_command || ( $command ne "" ) )
{
::userDisplay "Process command \"$command\"\n";
process_command( $command );
exit;
}
::userDisplay "Done.\n";
exit 0;
} ## end main
########################################################################
## SUBROUTINES
########################################################################
##
sub helpInfo
{
my %info = (
name => "Istep",
intro => ["Executes isteps."],
options => { "list" => [" list out all supported isteps "],
"splessmode" => ["enable istep mode"],
"fspmode" => ["enable istep mode"],
"resume" => ["resume an istep that is at a break point"],
"clear-trace" => ["clear trace buffers before starting"],
"sN" => ["run istep N"],
"sN..M" => ["run isteps N through M"],
"<foo>" => ["run named istep \"foo\""],
"<foo>..<bar>" => ["run named isteps \"foo\" through \"bar\""],
}
);
}
## Increment the sequence number, rolling over at 64
## ---------------------------------------------------------------------------
sub bumpSeqNum()
{
$g_SeqNum++;
$g_SeqNum %= 64;
return $g_SeqNum;
}
## ---------------------------------------------------------------------------
## Dump environment variable specified.
## ---------------------------------------------------------------------------
sub dumpEnvVar( $ )
{
my $envvar = shift;
if ( defined( $ENV{$envvar} ) )
{
::userDisplay "$envvar = $ENV{$envvar}\n";
}
}
##
## Get symbol address from hbotSymsFile
##
sub getSymbol( )
{
my $symbol = shift;
my ($symAddr, $symSize) = ::findSymbolAddress( $symbol ) ;
if ( not defined( $symAddr ) )
{
::userDisplay "Cannot find $symbol.\n"; die;
}
return $symAddr;
}
##
## read in file with csv istep list and store in inList
##
sub get_istep_list()
{
my $istep, my $substep, my $name ;
my @isteplist = ::getIstepList();
foreach( @isteplist )
{
chomp;
( $istep, $substep, $name) = split( ",", $_ );
chomp $name;
## ::userDisplay "$_, $istep, $substep, $name\n" ;
if ( defined($name) && ( $name ne "" ) )
{
$inList[$istep][$substep] = $name;
}
}
}
##
## print the istep list to the screen.
##
sub print_istep_list( )
{
my $hdrflag = 1;
my $col = 0;
## ::userDisplay " IStep Name\n";
##::userDisplay "---------------------------------------------------\n";
for( my $i = 4; $i < MAX_ISTEPS; $i++)
{
for( my $j = 0; $j < MAX_SUBSTEPS; $j++)
{
## print all substeps
if ( defined( $inList[$i][$j] ) )
{
if ( $hdrflag )
{
::userDisplay " ----- IStep $i ----- \n";
$hdrflag = 0;
}
## will truncate after 40 chars, hopefully this will not be an issue
my $ss = sprintf( "%-40s", $inList[$i][$j] );
::userDisplay "$ss" ;
$col ++ ;
if ( $col > 1 )
{
::userDisplay "\n";
$col = 0;
}
}
} ## end for $j
if ( $col > 0 )
{
::userDisplay "\n";
$col = 0;
}
$hdrflag=1;
} ## end for $i
}
##
## Find istep name in inList array.
##
## @param[in] - name
##
## @return - istep #, substep #, found flag = true for success
## false for not found
##
sub find_in_inList( $ )
{
my ( $substepname ) = @_;
for(my $i = 0; $i < MAX_ISTEPS; $i++)
{
for(my $j = 0; $j < MAX_SUBSTEPS; $j++)
{
if ( defined($inList[$i][$j]) && ($inList[$i][$j] eq $substepname ) )
{
return ($i, $j, 1 );
}
}
}
return ( MAX_ISTEPS, MAX_SUBSTEPS, 0 )
}
##
## When HostBoot goes into singlestep mode, it turns on the ready bit in the
## status reg.
##
## @return nonzero if ready bit is on, else 0
##
sub isReadyBitOn()
{
my $result = 0;
my $readybit = 0;
$result = getStatus( );
$readybit = ( ( $result & 0x4000000000000000 ) >> 62 );
if ( $opt_debug ) { ::userDisplay "=== readybit: $readybit\n"; }
if ( $readybit )
{
return 1;
}
return 0;
}
##
## Check if HostBoot has already run and shutdown.
##
## @return nonzero if it has, 0 otherwise
##
sub isShutDown()
{
my $flag = ::read64( $ShutDownFlag );
my $status = ::read64( $ShutDownSts );
if ( $opt_debug )
{
::userDisplay "=== isShutDown : Shutdown Flag = $flag\n";
::userDisplay "=== isShutDown : Shutdown Status = $status\n";
}
if ( $flag )
{
::userDisplay "HostBoot has shut down with status $status.\n";
return 1;
}
return 0;
}
##
## Write to the IstepMode reg in memory. This will not be changed to scom
##
## @param[in] - 64-bit value to write to the IstepModeReg
##
sub writeIstepModeReg( $ )
{
my $data = shift;
if ( $opt_debug )
{ ::userDisplay "=== writeIstepmodeReg ", sprintf("0x%x",$data), "\n"; }
::write64( $IstepModeReg, $data );
}
##
## Read IStepModeReg from memory. This will not be changed to scom.
##
## @return 64-bit value read from IStepModeReg
##
sub readIstepModeReg( )
{
my $data = 0;
$data = ::read64( $IstepModeReg );
if ( $opt_debug )
{ ::userDisplay "=== readIstepmodeReg ", sprintf("0x%x",$data), "\n"; }
return $data;
}
## --------------------------------------------------------------------
## Write command reg
##
## @param[in] - HEX STRING containing the 64-bit command word
##
## @return none
##
## --------------------------------------------------------------------
sub sendCommand( $ )
{
my $data = shift;
if ( $opt_debug )
{ ::userDisplay "=== sendCommand( $data )\n"; }
## convert to binary before sending to writescom
my $bindata = ( hex $data );
## now write the data
::writeScom( MBOX_SCRATCH3, 8, $bindata );
if ( $opt_debug )
{
## sanity check
::executeInstrCycles( 10, NOSHOW );
my $readback = ::readScom( MBOX_SCRATCH3, 8 );
::userDisplay "=== sendCommand readback: $readback\n";
}
}
## --------------------------------------------------------------------
## read status reg
##
## Note - mbox scratchpad regs are only 32 bits, so HostBoot will return
## status in mbox 2 (hi32 bits) and mbox 1 (lo32 bits).
## mbox 0 is reserved for continuous trace.
##
##
##
## @return binary 64-bit value
## --------------------------------------------------------------------
sub getStatus()
{
my $status = 0;
my $statusHi = "";
my $statusLo = "";
$statusHi = ::readScom( MBOX_SCRATCH2, 8 );
if ( $opt_debug ) { ::userDisplay "=== statusHi: $statusHi \n"; }
$statusLo = ::readScom( MBOX_SCRATCH1, 8 );
if ( $opt_debug ) { ::userDisplay "=== statusLo: $statusLo \n"; }
$status = ( ( (hex $statusHi) & 0xffffffff00000000 )
| (( (hex $statusLo) & 0xffffffff00000000 ) >> 32)
);
if ( $opt_debug )
{
::userDisplay "=== getStatus() returned ", (sprintf( "0x%lx", $status ) ), "\n";
}
return $status;
}
##
## keep trying to get status until seqnum syncs up
##
sub getSyncStatus( )
{
# set # of retries
my $count = $hbCount ;
my $result = 0;
my $seqnum = 0;
my $running = 0;
## get response. sendCmd() should have bumped g_SeqNum, so we will sit
## here for a reasonable amount of time waiting for the correct sequence
## number to come back.
while(1)
{
## advance HostBoot code by a certain # of cycles, then check the
## sequence number to see if it has changed. rinse and repeat.
::executeInstrCycles( $hbDefaultCycles, NOSHOW );
## check to see if we need to dump trace - no-op in simics
##::checkContTrace();
$result = getStatus();
$seqnum = ( ( $result & 0x3f00000000000000 ) >> 56 );
$running = ( ( $result & 0x8000000000000000 ) >> 63 );
## @todo great place to add some debug, check running bit BEFORE
## starting the clock (should be off), then run (relatively) small
## number of clocks till the bit turns on.
## If it doesn't go on, command was never received. If so,
## come here to wait for it to go back off again.
## if ( ( $running == 0 )
## && ( $seqnum == $g_SeqNum )
if ( $seqnum == $g_SeqNum )
{
return $result;
}
if ( $count <= 0)
{
::userDisplay "TIMEOUT waiting for seqnum=$g_SeqNum\n";
return -1;
}
$count--;
} ## endwhile
}
##
## Run an istep
##
sub runIStep( $$ )
{
my ( $istep, $substep) = @_;
my $byte0, my $command;
my $cmd;
my $result;
## bump the seqnum
bumpSeqNum() ;
::userDisplay "run $istep.$substep $inList[$istep][$substep]:\n" ;
$byte0 = 0x80 + $g_SeqNum; ## gobit + seqnum
$command = SPLESS_SINGLE_ISTEP_CMD;
$cmd = sprintf( "0x%2.2x%2.2x%2.2x%2.2x00000000", $byte0, $command, $istep, $substep );
sendCommand( $cmd );
$result = getSyncStatus();
## if result is -1 we have a timeout
if ( $result == -1 )
{
::userDisplay "-----------------------------------------------------------------\n";
}
else
{
my $taskStatus = ( ( $result & 0x00ff000000000000 ) >> 48 );
my $stsIStep = ( ( $result & 0x0000ff0000000000 ) >> 40 );
my $stsSubstep = ( ( $result & 0x000000ff00000000 ) >> 32 );
my $istepStatus = ( ( $result & 0x00000000ffffffff ) );
::userDisplay "---------------------------------\n";
if ( $taskStatus != 0 )
{
::userDisplay "Istep $stsIStep.$stsSubstep FAILED to launch, task status is $taskStatus\n" ;
}
else
{
::userDisplay "Istep $stsIStep.$stsSubstep $inList[$istep][$substep] returned Status: ",
sprintf("0x%x",$istepStatus),
"\n" ;
if ( $istepStatus == 0xa )
{
::userDisplay ": not implemented yet.\n";
}
}
::userDisplay "------------------------------------------------------- SeqNum: $g_SeqNum\n";
}
}
##
## run command = "sN"
##
sub sCommand( $ )
{
my ( $scommand ) = @_;
my $i = $scommand;
my $j = 0;
# execute all the substeps in the IStep
for( $j=0; $j<MAX_SUBSTEPS; $j++ )
{
if ( defined( $inList[$i][$j] ) )
{
runIStep( $i, $j );
}
}
}
##
## parse --command [command] option and execute it.
##
sub process_command( $ )
{
my ( $command ) = @_;
my @execlist;
my $istepM, my $substepM, my $foundit, my $istepN, my $substepN;
my $M, my $N, my $scommand;
my @ss_list;
## check to see if we have an 's' command (string starts with 's' and a number)
chomp( $command);
if ( $command =~ m/^s+[0-9].*/ )
{
## run "s" command
if ($opt_debug) { ::userDisplay "=== s command \"$command\" \n"; }
substr( $command, 0, 1, "" );
if ( POSIX::isdigit($command) )
{
# command = "sN"
if ($opt_debug) { ::userDisplay "=== single IStep: ", $command, "\n"; }
sCommand( $command );
}
else
{
# list of substeps = "sM..N"
( $M, $N ) = split( /\.\./, $command );
if ($opt_debug) { ::userDisplay "=== multiple ISteps: ", $M, "-", $N, "\n"; }
for ( my $x=$M; $x<$N+1; $x++ )
{
sCommand( $x );
}
}
}
else
{
## <substep name>, or <substep name>..<substep name>
@ss_list = split( /\.\./, $command );
if ($opt_debug) { ::userDisplay "=== named commands : ", @ss_list, "\n"; }
( $istepM, $substepM, $foundit) = find_in_inList( $ss_list[0] );
$istepN = $istepM;
$substepN = $substepM;
if ( ! $foundit )
{
::userDisplay "Invalid substep ", $ss_list[0], "\n" ;
return -1;
}
if ( $#ss_list > 0 )
{
( $istepN, $substepN, $foundit) = find_in_inList( $ss_list[1] );
if ( ! $foundit )
{
::userDisplay "Invalid substep $ss_list[1] \n" ;
return -1;
}
}
for( my $x=$istepM; $x<$istepN+1; $x++ )
{
for( my $y=$substepM; $y<$substepN+1; $y++ )
{
runIStep( $x, $y );
}
}
}
}
##
## write to mem to set istep or normal mode, check return status
##
## Note that this only happens once at the beginning, when "splessmode"
## or "fsplessmode" is run.
##
sub setMode( $ )
{
my ( $cmd ) = @_;
my $count = 0;
my $expected = 0;
my $readybit = 0;
my $result = 0;
if ( $cmd eq "spless" )
{
writeIstepModeReg( SPLESS_MODE_SIGNATURE );
$expected = 1;
}
elsif ( $cmd eq "fsp" )
{
writeIstepModeReg( FSP_MODE_SIGNATURE );
$expected = 1;
}
else
{
::userDisplay "invalid setMode command: $cmd\n" ;
return -1;
}
if ( $opt_debug )
{
## readback and display
$result = readIstepModeReg( );
::userDisplay "=== IstepModeReg readback: ", sprintf("0x%x", $result), "\n" ;
}
## Loop, advancing clock, and wait for readybit
$count = $hbCount ;
while(1)
{
if ( $opt_debug ) { ::userDisplay "=== executeInstrCycles( $hbDefaultCycles )\n"; }
## advance HostBoot code by a certain # of cycles, then check the
## sequence number to see if it has changed. rinse and repeat.
::executeInstrCycles( $hbDefaultCycles, NOSHOW );
if ( $opt_debug ) { ::userDisplay "=== checkContTrace\n"; }
## check to see if it's time to dump trace - no-op in simics
::checkContTrace();
if ( $opt_debug ) { ::userDisplay "=== isShutDown\n"; }
## check for system crash
if ( isShutDown( ) )
{
::userDisplay "Cannot run HostBoot\n";
return -1;
}
if ( $opt_debug ) { ::userDisplay "=== isReadyBitOn\n"; }
if ( isReadyBitOn() )
{
return 0;
}
if ( $count <= 0 )
{
::userDisplay "TIMEOUT waiting for readybit, status=$result\n" ;
return -1;
}
$count--;
if ( $opt_debug ) { ::userDisplay "=== count = $count\n"; }
}
}
sub resume_istep()
{
my $byte0;
my $command;
my $cmd;
my $result;
bumpSeqNum();
::userDisplay "resume istep\n";
$byte0 = 0x80 + $g_SeqNum; ## gobit + seqnum
$command = SPLESS_RESUME_ISTEP_CMD;
$cmd = sprintf( "0x%2.2x%2.2x000000000000", $byte0, $command );
sendCommand( $cmd );
$result = getSyncStatus();
## if result is -1 we have a timeout
if ( $result == -1 )
{
::userDisplay "-----------------------------------------------------------------\n";
}
else
{
my $taskStatus = ( ( $result & 0x00ff000000000000 ) >> 48 );
::userDisplay "-----------------------------------------------------------------\n";
if ( $taskStatus != 0 )
{
# This probably means istep was not at a breakpoint.
::userDisplay "resume istep FAILED, task status is $taskStatus\n", $taskStatus ;
}
else
{
::userDisplay "resume istep returned success\n" ;
}
::userDisplay "-----------------------------------------------------------------\n";
}
}
sub clear_trace( )
{
my $byte0, my $command;
my $cmd;
my $result;
## bump the seqnum
bumpSeqNum();
$byte0 = 0x80 + $g_SeqNum; ## gobit + seqnum
$command = SPLESS_CLEAR_TRACE_CMD;
$cmd = sprintf( "0x%2.2x%2.2x%2.2x%2.2x00000000", $byte0, $command, 0, 0 );
sendCommand( $cmd );
$result = getSyncStatus();
## if result is -1 we have a timeout
if ( $result == -1 )
{
::userDisplay "-----------------------------------------------------------------\n";
}
else
{
my $taskStatus = ( ( $result & 0x00ff000000000000 ) >> 48 );
my $stsIStep = ( ( $result & 0x0000ff0000000000 ) >> 40 );
my $stsSubstep = ( ( $result & 0x000000ff00000000 ) >> 32 );
my $istepStatus = ( ( $result & 0x00000000ffffffff ) );
::userDisplay "-----------------------------------------------------------------\n";
if ( $taskStatus != 0 )
{
::userDisplay "Clear Trace FAILED, task status is taskStatus\n" ;
}
else
{
::userDisplay "Clear Trace returned Status: $istepStatus\n" ;
}
::userDisplay "-----------------------------------------------------------------\n";
}
}
# A Perl module must end with a true value or else it is considered not to
# have loaded. By convention this value is usually 1 though it can be
# any true value. A module can end with false to indicate failure but
# this is rarely used and it would instead die() (exit with an error).
1;
__END__
|