summaryrefslogtreecommitdiffstats
path: root/src/build/debug/Hostboot/CallFunc.pm
blob: 403be45e9cf40e522208fce3a94fdf5d66847db9 (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
#  IBM_PROLOG_BEGIN_TAG
#  This is an automatically generated prolog.
#
#  $Source: src/build/debug/Hostboot/CallFunc.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
use strict;

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

use constant CALLFUNC_DEBUG_READY_OFFSET => 0;
use constant CALLFUNC_DEBUG_RUNNING_OFFSET => CALLFUNC_DEBUG_READY_OFFSET + 1;
use constant CALLFUNC_DEBUG_COMPLETE_OFFSET => CALLFUNC_DEBUG_READY_OFFSET + 2;
use constant CALLFUNC_DEBUG_ENTRY_OFFSET => CALLFUNC_DEBUG_READY_OFFSET + 8;
use constant CALLFUNC_DEBUG_RETVAL_OFFSET => CALLFUNC_DEBUG_ENTRY_OFFSET + 8;
use constant CALLFUNC_DEBUG_PARMS_OFFSET => CALLFUNC_DEBUG_RETVAL_OFFSET + 8;
use constant CALLFUNC_DEBUG_PARMS => 8;
sub main
{
    my ($packName,$args) = @_;

    # Parse 'debug' option.
    my $debug = 0;
    if (defined $args->{"debug"})
    {
        $debug = 1;
    }

    # Parse function name from options.
    my $function = "";
    if (defined $args->{"function"})
    {
        $function = $args->{"function"};
    }
    elsif (defined $args->{"func"})
    {
        $function = $args->{"func"};
    }
    else
    {
        ::userDisplay "Must give a function to execute.\n";
        return;
    }

    # Parse function arguments from options.
    my @parms = ();
    my $parms_string = "";
    if (defined $args->{"arguments"})
    {
        $parms_string = $args->{"arguments"}
    }
    elsif (defined $args->{"args"})
    {
        $parms_string = $args->{"args"};
    }
    elsif (defined $args->{"parameters"})
    {
        $parms_string = $args->{"parameters"};
    }
    elsif (defined $args->{"parms"})
    {
        $parms_string = $args->{"parms"};
    }
    @parms = map eval, split /,/, $parms_string;

    # Parse 'force' argument.
    my $force = 0;
    if (defined $args->{"force"})
    {
        $force = 1;
    }

    my $error = execFunc( $function, $debug, $force, @parms );
    if( $error )
    {
       return;
    }
}

sub execFunc
{
    my $function = shift;
    my $debug = shift;
    my $force = shift;
    my $parms_arg = shift;
    my @parms = @{$parms_arg};

    if( $debug )
    {
        ::userDisplay("function = $function.\n");
        my $tmparg;
        foreach $tmparg (@parms)
        {
            ::userDisplay("arg = $tmparg.\n");
        }
    }

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

    # Find symbol's TOC address.
    my $toc = ::findSymbolTOCAddress($function);
    if ($debug)
    {
        ::userDisplay("Symbol $function TOC at $toc.\n");
    }

    # Find interactive debug structure in the kernel.
    my $address = (::findSymbolAddress("CpuManager::cv_interactive_debug"))[0];

    if ((not defined $toc) || (not defined $address))
    {
        ::userDisplay "Cannot find symbol to execute $function.\n";
        return 1;
    }

    # Verify kernel isn't busy with an outstanding request.
    if ((0 != ::read16 ($address + CALLFUNC_DEBUG_READY_OFFSET)) &&
        (0 == $force))
    {
        ::userDisplay "Another command is still pending.\n";
        return 1;
    }

    # Write entry point (function TOC) and parameters into debug structure.
    ::write64(($address + CALLFUNC_DEBUG_ENTRY_OFFSET), $toc);
    while(($#parms + 1) != CALLFUNC_DEBUG_PARMS)
    {
        push @parms, 0x0;
    }
    my $i = 0;
    while ($i != CALLFUNC_DEBUG_PARMS)
    {
        if ($debug)
        {
            ::userDisplay "Param $i = ".$parms[$i]."\n";
        }
        ::write64(($address + CALLFUNC_DEBUG_PARMS_OFFSET + 8*$i), $parms[$i]);
        $i = $i + 1;
    }

    # Set ready state.
    ::write32(($address + CALLFUNC_DEBUG_READY_OFFSET), 0x01000000);

    # Clock forward until kernel marks 'complete' state.
    my $i = 0;
    while((0 != ::read16($address + CALLFUNC_DEBUG_READY_OFFSET)) &&
          (0 == ::read8($address + CALLFUNC_DEBUG_COMPLETE_OFFSET)) &&
          ($i < 100))
    {
        ::executeInstrCycles(100000);
        $i = $i + 1;
        if ($debug)
        {
            ::userDisplay("Loop $i.\n");
        }
    }

    # Verify successful execution ('complete' state set).
    if (0 == ::read8($address + CALLFUNC_DEBUG_COMPLETE_OFFSET))
    {
        ::userDisplay "Command failed to complete.\n";
        return 1;
    }
    
    if( $debug )
    {
        # Display return value.
        ::userDisplay ::read64($address + CALLFUNC_DEBUG_RETVAL_OFFSET)."\n";
    }
}

sub helpInfo
{
    my %info = (
        name => "CallFunc",
        intro => ["Interactively execute a function."],
        options => {
                    "function='function name'" => ["Function to execute."],
                    "arguments=arg0,arg1..." =>["List of arguments to pass function."],
                    "force" => ["Run command even if state does not appear correct."],
                   },
        notes => ["func can be used as a short-name for 'function'.",
                  "args, parameters, or parms can be used as a short-name for arguments."]
    );
}

OpenPOWER on IntegriCloud