summaryrefslogtreecommitdiffstats
path: root/src/build/debug/Hostboot/AutoIpl.pm
blob: 6c1227e81b3252cf23641e0845d3b4e7fb125aae (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
#!/usr/bin/perl

use strict;

package Hostboot::AutoIpl;
use Exporter;
our @EXPORT_OK = ('main');

use constant PRINTK_SAMPLING => 50;
use constant NUM_CLOCK_CYCLES => 25000;
use constant MAX_NUM_CONT_TRACE_CTL_STRUCT => 2;
use constant CONT_TRACE_CTL_STRUCT_SIZE => 16;
use constant CONT_TRACE_DISABLE_FLAG_OFFSET => MAX_NUM_CONT_TRACE_CTL_STRUCT * CONT_TRACE_CTL_STRUCT_SIZE;

use File::Temp ('tempfile');

sub main
{
    my ($packName,$args) = @_;
    #userDisplay("args fsp-trace ".$args->{"fsp-trace"}."\n");
    #userDisplay("args with-file-names ".$args->{"with-file-names"}."\n");
    #userDisplay("args num-clk-cycles ".$args->{"num-clk-cycles"}."\n");

    # Ensure environment is in the proper state for running instructions.
    if (!::readyForInstructions())
    {
        ::userDisplay "Cannot execute while unable to run instructions.\n";
        return;
    }

    # retrieve the Information of the Continous Trace Trigger Info structure
    my ($symAddr, $symSize) =
                      ::findSymbolAddress("TRACE::g_cont_trace_trigger_info");
    if (not defined $symAddr)
    {
         ::userDisplay "Cannot find symbol.\n"; die;
    }

    my $disable = 0;
    if (defined $args->{"enable-cont-trace"})
    {
        #my $disable = ::read64($symAddr + CONT_TRACE_DISABLE_FLAG_OFFSET);
        #::userDisplay("Cont Trace Disable Flag read = $disable\n");
        ::write64($symAddr + CONT_TRACE_DISABLE_FLAG_OFFSET, 0);
        #$disable =  ::read64($symAddr + CONT_TRACE_DISABLE_FLAG_OFFSET);
        #::userDisplay("Cont Trace Disable Flag after reset = $disable\n");
        # truncate tracMERG to 0
        system( "cp /dev/null tracMERG" );
        return;
    }
    else
    {
        my $disable = ::read64($symAddr + CONT_TRACE_DISABLE_FLAG_OFFSET);
        #::userDisplay("Cont Trace Disable Flag after reset = $disable\n");
    }

    # set the number of clock cycles
    my $cycles = NUM_CLOCK_CYCLES;
    if (defined $args->{"num-clk-cycles"})
    {
        $cycles = $args->{"num-clk-cycles"};
    }

    # Check if shutdown has been requested
    my $result = ::getShutdownRequestStatus();
    #::userDisplay("shutdown requested: $result\n");

    if ($result)
    {
        ::userDisplay("Shutdown has been reported.\n");
        return;
    }

    # truncate printk.content to 0
    system( "cp /dev/null printk.content" );

    my $loop = 0;
    my $excp = 0;

    while (0 == $result)
    {
        if ( -e 'STOP' )
        {
            return;
        }

        if (::CheckXstopAttn() == 1)
        {
            ::userDisplay("checkstop/attn occur.\n");
            ::FirCheck();
            return;
        }

        $loop++;

        # Display printk buffer's unshown messages
        if (($loop % PRINTK_SAMPLING) == 0)
        {
            system("hb-printk --mute > /dev/null");
            system("diff hb-Printk.output printk.content | sed -e 's/< //g' -e '1d'");
            system("mv hb-Printk.output printk.content");
        }

        # run clock cycles
        ::executeInstrCycles($cycles,1);

        # Display CIA 
        my $pc = ::getCIA();
        ::userDisplay("Loop $loop: $pc");

        # Check for exception
        if ($pc =~ m/.*0x0000000000000E4[04]/)
        {
            $excp++;
            if ($excp == 5)
            {
                ::userDisplay("Trapped in the exception loop.\n");
                return;
            }
        }
        else
        {
            $excp = 0;
        }
            
        if ($disable == 0)
        {
            # collect continuous traces
            system("hb-ContTrace --mute > /dev/null");
            system("cat hb-ContTrace.output >> tracMERG");
        }

        # check if shutdown has been requested
        $result = ::getShutdownRequestStatus();
        #::userDisplay("shutdown requested: $result\n");
    }

    if ($disable == 0)
    {
        # First, collect continuous traces from any triggered buffer
        system("hb-ContTrace --mute > /dev/null");
        system("cat hb-ContTrace.output >> tracMERG");
        # Now, collect the partial continuous traces from untriggered buffer
        system("hb-ContTrace --mute --last > /dev/null");
        system("cat hb-ContTrace.output >> tracMERG");
    }

    #::userDisplay("\n\n Hostboot has shutdown\n\n");

}

sub helpInfo
{
    my %info = (
        name => "AutoIpl",
        intro => ["IPL Hostboot and collect continuous trace."],
        options => {
                    "fsp-trace=<path>" => ["Path to non-default fsp-trace utility."],
                    "with-file-names" => ["Trace statements will include file name of place the",
                                          "trace was defined."],
                    "num-clk-cycles=<number>" => ["Number of clock cycles to before collecting traces."],
                    "enable-cont-trace" => ["Turn on continuous trace"],
                   },
    );
}
OpenPOWER on IntegriCloud