blob: 69cf0130ba3716b4cb35d1641a79c4b82a900033 (
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
|
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;
}
# Ensure environment is in the proper state for running instructions.
if (!::readyForInstructions())
{
::userDisplay "Cannot execute while unable to run instructions.\n";
return;
}
# 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;
}
# 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;
}
# 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 < 50))
{
::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;
}
# Display return value.
::userDisplay ::read64($address + CALLFUNC_DEBUG_RETVAL_OFFSET)."\n";
}
sub help
{
::userDisplay "Tool: CallFunc\n";
::userDisplay "\tInteractively execute a function.\n";
::userDisplay "\n Options:\n";
::userDisplay "\tfunction='function name' - Function to execute.\n";
::userDisplay "\targuments=arg0,arg1... - List of arguments to pass.\n";
::userDisplay "\tforce - Run command even if state doesn't not appear ".
"correct.\n";
::userDisplay "\n\tfunc can be used as a short-name for 'function'.\n";
::userDisplay "\targs, parameters, or parms can be used as a short-name ";
::userDisplay "for arguments.\n";
}
|