dbmethod.c revision 1.5 1 1.1 jruoho /*******************************************************************************
2 1.1 jruoho *
3 1.1 jruoho * Module Name: dbmethod - Debug commands for control methods
4 1.1 jruoho *
5 1.1 jruoho ******************************************************************************/
6 1.1 jruoho
7 1.1 jruoho /*
8 1.4 christos * Copyright (C) 2000 - 2015, Intel Corp.
9 1.1 jruoho * All rights reserved.
10 1.1 jruoho *
11 1.1 jruoho * Redistribution and use in source and binary forms, with or without
12 1.1 jruoho * modification, are permitted provided that the following conditions
13 1.1 jruoho * are met:
14 1.1 jruoho * 1. Redistributions of source code must retain the above copyright
15 1.1 jruoho * notice, this list of conditions, and the following disclaimer,
16 1.1 jruoho * without modification.
17 1.1 jruoho * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1 jruoho * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1 jruoho * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1 jruoho * including a substantially similar Disclaimer requirement for further
21 1.1 jruoho * binary redistribution.
22 1.1 jruoho * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1 jruoho * of any contributors may be used to endorse or promote products derived
24 1.1 jruoho * from this software without specific prior written permission.
25 1.1 jruoho *
26 1.1 jruoho * Alternatively, this software may be distributed under the terms of the
27 1.1 jruoho * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1 jruoho * Software Foundation.
29 1.1 jruoho *
30 1.1 jruoho * NO WARRANTY
31 1.1 jruoho * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1 jruoho * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1 jruoho * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1 jruoho * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1 jruoho * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1 jruoho * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1 jruoho * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1 jruoho * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1 jruoho * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1 jruoho * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1 jruoho * POSSIBILITY OF SUCH DAMAGES.
42 1.1 jruoho */
43 1.1 jruoho
44 1.1 jruoho #include "acpi.h"
45 1.1 jruoho #include "accommon.h"
46 1.1 jruoho #include "acdispat.h"
47 1.1 jruoho #include "acnamesp.h"
48 1.1 jruoho #include "acdebug.h"
49 1.5 christos #ifdef ACPI_DISASSEMBLER
50 1.1 jruoho #include "acdisasm.h"
51 1.5 christos #endif
52 1.1 jruoho #include "acparser.h"
53 1.2 christos #include "acpredef.h"
54 1.1 jruoho
55 1.1 jruoho
56 1.1 jruoho #ifdef ACPI_DEBUGGER
57 1.1 jruoho
58 1.1 jruoho #define _COMPONENT ACPI_CA_DEBUGGER
59 1.1 jruoho ACPI_MODULE_NAME ("dbmethod")
60 1.1 jruoho
61 1.1 jruoho
62 1.1 jruoho /*******************************************************************************
63 1.1 jruoho *
64 1.1 jruoho * FUNCTION: AcpiDbSetMethodBreakpoint
65 1.1 jruoho *
66 1.1 jruoho * PARAMETERS: Location - AML offset of breakpoint
67 1.1 jruoho * WalkState - Current walk info
68 1.1 jruoho * Op - Current Op (from parse walk)
69 1.1 jruoho *
70 1.1 jruoho * RETURN: None
71 1.1 jruoho *
72 1.1 jruoho * DESCRIPTION: Set a breakpoint in a control method at the specified
73 1.1 jruoho * AML offset
74 1.1 jruoho *
75 1.1 jruoho ******************************************************************************/
76 1.1 jruoho
77 1.1 jruoho void
78 1.1 jruoho AcpiDbSetMethodBreakpoint (
79 1.1 jruoho char *Location,
80 1.1 jruoho ACPI_WALK_STATE *WalkState,
81 1.1 jruoho ACPI_PARSE_OBJECT *Op)
82 1.1 jruoho {
83 1.1 jruoho UINT32 Address;
84 1.5 christos UINT32 AmlOffset;
85 1.1 jruoho
86 1.1 jruoho
87 1.1 jruoho if (!Op)
88 1.1 jruoho {
89 1.1 jruoho AcpiOsPrintf ("There is no method currently executing\n");
90 1.1 jruoho return;
91 1.1 jruoho }
92 1.1 jruoho
93 1.1 jruoho /* Get and verify the breakpoint address */
94 1.1 jruoho
95 1.5 christos Address = strtoul (Location, NULL, 16);
96 1.5 christos AmlOffset = (UINT32) ACPI_PTR_DIFF (Op->Common.Aml,
97 1.5 christos WalkState->ParserState.AmlStart);
98 1.5 christos if (Address <= AmlOffset)
99 1.1 jruoho {
100 1.1 jruoho AcpiOsPrintf ("Breakpoint %X is beyond current address %X\n",
101 1.5 christos Address, AmlOffset);
102 1.1 jruoho }
103 1.1 jruoho
104 1.1 jruoho /* Save breakpoint in current walk */
105 1.1 jruoho
106 1.1 jruoho WalkState->UserBreakpoint = Address;
107 1.1 jruoho AcpiOsPrintf ("Breakpoint set at AML offset %X\n", Address);
108 1.1 jruoho }
109 1.1 jruoho
110 1.1 jruoho
111 1.1 jruoho /*******************************************************************************
112 1.1 jruoho *
113 1.1 jruoho * FUNCTION: AcpiDbSetMethodCallBreakpoint
114 1.1 jruoho *
115 1.1 jruoho * PARAMETERS: Op - Current Op (from parse walk)
116 1.1 jruoho *
117 1.1 jruoho * RETURN: None
118 1.1 jruoho *
119 1.1 jruoho * DESCRIPTION: Set a breakpoint in a control method at the specified
120 1.1 jruoho * AML offset
121 1.1 jruoho *
122 1.1 jruoho ******************************************************************************/
123 1.1 jruoho
124 1.1 jruoho void
125 1.1 jruoho AcpiDbSetMethodCallBreakpoint (
126 1.1 jruoho ACPI_PARSE_OBJECT *Op)
127 1.1 jruoho {
128 1.1 jruoho
129 1.1 jruoho
130 1.1 jruoho if (!Op)
131 1.1 jruoho {
132 1.1 jruoho AcpiOsPrintf ("There is no method currently executing\n");
133 1.1 jruoho return;
134 1.1 jruoho }
135 1.1 jruoho
136 1.1 jruoho AcpiGbl_StepToNextCall = TRUE;
137 1.1 jruoho }
138 1.1 jruoho
139 1.1 jruoho
140 1.1 jruoho /*******************************************************************************
141 1.1 jruoho *
142 1.1 jruoho * FUNCTION: AcpiDbSetMethodData
143 1.1 jruoho *
144 1.1 jruoho * PARAMETERS: TypeArg - L for local, A for argument
145 1.1 jruoho * IndexArg - which one
146 1.1 jruoho * ValueArg - Value to set.
147 1.1 jruoho *
148 1.1 jruoho * RETURN: None
149 1.1 jruoho *
150 1.1 jruoho * DESCRIPTION: Set a local or argument for the running control method.
151 1.1 jruoho * NOTE: only object supported is Number.
152 1.1 jruoho *
153 1.1 jruoho ******************************************************************************/
154 1.1 jruoho
155 1.1 jruoho void
156 1.1 jruoho AcpiDbSetMethodData (
157 1.1 jruoho char *TypeArg,
158 1.1 jruoho char *IndexArg,
159 1.1 jruoho char *ValueArg)
160 1.1 jruoho {
161 1.1 jruoho char Type;
162 1.1 jruoho UINT32 Index;
163 1.1 jruoho UINT32 Value;
164 1.1 jruoho ACPI_WALK_STATE *WalkState;
165 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc;
166 1.1 jruoho ACPI_STATUS Status;
167 1.1 jruoho ACPI_NAMESPACE_NODE *Node;
168 1.1 jruoho
169 1.1 jruoho
170 1.1 jruoho /* Validate TypeArg */
171 1.1 jruoho
172 1.1 jruoho AcpiUtStrupr (TypeArg);
173 1.1 jruoho Type = TypeArg[0];
174 1.1 jruoho if ((Type != 'L') &&
175 1.1 jruoho (Type != 'A') &&
176 1.1 jruoho (Type != 'N'))
177 1.1 jruoho {
178 1.1 jruoho AcpiOsPrintf ("Invalid SET operand: %s\n", TypeArg);
179 1.1 jruoho return;
180 1.1 jruoho }
181 1.1 jruoho
182 1.5 christos Value = strtoul (ValueArg, NULL, 16);
183 1.1 jruoho
184 1.1 jruoho if (Type == 'N')
185 1.1 jruoho {
186 1.1 jruoho Node = AcpiDbConvertToNode (IndexArg);
187 1.3 christos if (!Node)
188 1.3 christos {
189 1.3 christos return;
190 1.3 christos }
191 1.3 christos
192 1.1 jruoho if (Node->Type != ACPI_TYPE_INTEGER)
193 1.1 jruoho {
194 1.1 jruoho AcpiOsPrintf ("Can only set Integer nodes\n");
195 1.1 jruoho return;
196 1.1 jruoho }
197 1.1 jruoho ObjDesc = Node->Object;
198 1.1 jruoho ObjDesc->Integer.Value = Value;
199 1.1 jruoho return;
200 1.1 jruoho }
201 1.1 jruoho
202 1.1 jruoho /* Get the index and value */
203 1.1 jruoho
204 1.5 christos Index = strtoul (IndexArg, NULL, 16);
205 1.1 jruoho
206 1.1 jruoho WalkState = AcpiDsGetCurrentWalkState (AcpiGbl_CurrentWalkList);
207 1.1 jruoho if (!WalkState)
208 1.1 jruoho {
209 1.1 jruoho AcpiOsPrintf ("There is no method currently executing\n");
210 1.1 jruoho return;
211 1.1 jruoho }
212 1.1 jruoho
213 1.1 jruoho /* Create and initialize the new object */
214 1.1 jruoho
215 1.1 jruoho ObjDesc = AcpiUtCreateIntegerObject ((UINT64) Value);
216 1.1 jruoho if (!ObjDesc)
217 1.1 jruoho {
218 1.1 jruoho AcpiOsPrintf ("Could not create an internal object\n");
219 1.1 jruoho return;
220 1.1 jruoho }
221 1.1 jruoho
222 1.1 jruoho /* Store the new object into the target */
223 1.1 jruoho
224 1.1 jruoho switch (Type)
225 1.1 jruoho {
226 1.1 jruoho case 'A':
227 1.1 jruoho
228 1.1 jruoho /* Set a method argument */
229 1.1 jruoho
230 1.1 jruoho if (Index > ACPI_METHOD_MAX_ARG)
231 1.1 jruoho {
232 1.1 jruoho AcpiOsPrintf ("Arg%u - Invalid argument name\n", Index);
233 1.1 jruoho goto Cleanup;
234 1.1 jruoho }
235 1.1 jruoho
236 1.1 jruoho Status = AcpiDsStoreObjectToLocal (ACPI_REFCLASS_ARG, Index, ObjDesc,
237 1.1 jruoho WalkState);
238 1.1 jruoho if (ACPI_FAILURE (Status))
239 1.1 jruoho {
240 1.1 jruoho goto Cleanup;
241 1.1 jruoho }
242 1.1 jruoho
243 1.1 jruoho ObjDesc = WalkState->Arguments[Index].Object;
244 1.1 jruoho
245 1.1 jruoho AcpiOsPrintf ("Arg%u: ", Index);
246 1.5 christos AcpiDbDisplayInternalObject (ObjDesc, WalkState);
247 1.1 jruoho break;
248 1.1 jruoho
249 1.1 jruoho case 'L':
250 1.1 jruoho
251 1.1 jruoho /* Set a method local */
252 1.1 jruoho
253 1.1 jruoho if (Index > ACPI_METHOD_MAX_LOCAL)
254 1.1 jruoho {
255 1.1 jruoho AcpiOsPrintf ("Local%u - Invalid local variable name\n", Index);
256 1.1 jruoho goto Cleanup;
257 1.1 jruoho }
258 1.1 jruoho
259 1.1 jruoho Status = AcpiDsStoreObjectToLocal (ACPI_REFCLASS_LOCAL, Index, ObjDesc,
260 1.1 jruoho WalkState);
261 1.1 jruoho if (ACPI_FAILURE (Status))
262 1.1 jruoho {
263 1.1 jruoho goto Cleanup;
264 1.1 jruoho }
265 1.1 jruoho
266 1.1 jruoho ObjDesc = WalkState->LocalVariables[Index].Object;
267 1.1 jruoho
268 1.1 jruoho AcpiOsPrintf ("Local%u: ", Index);
269 1.5 christos AcpiDbDisplayInternalObject (ObjDesc, WalkState);
270 1.1 jruoho break;
271 1.1 jruoho
272 1.1 jruoho default:
273 1.2 christos
274 1.1 jruoho break;
275 1.1 jruoho }
276 1.1 jruoho
277 1.1 jruoho Cleanup:
278 1.1 jruoho AcpiUtRemoveReference (ObjDesc);
279 1.1 jruoho }
280 1.1 jruoho
281 1.1 jruoho
282 1.1 jruoho /*******************************************************************************
283 1.1 jruoho *
284 1.1 jruoho * FUNCTION: AcpiDbDisassembleAml
285 1.1 jruoho *
286 1.1 jruoho * PARAMETERS: Statements - Number of statements to disassemble
287 1.1 jruoho * Op - Current Op (from parse walk)
288 1.1 jruoho *
289 1.1 jruoho * RETURN: None
290 1.1 jruoho *
291 1.1 jruoho * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
292 1.1 jruoho * of statements specified.
293 1.1 jruoho *
294 1.1 jruoho ******************************************************************************/
295 1.1 jruoho
296 1.1 jruoho void
297 1.1 jruoho AcpiDbDisassembleAml (
298 1.1 jruoho char *Statements,
299 1.1 jruoho ACPI_PARSE_OBJECT *Op)
300 1.1 jruoho {
301 1.1 jruoho UINT32 NumStatements = 8;
302 1.1 jruoho
303 1.1 jruoho
304 1.1 jruoho if (!Op)
305 1.1 jruoho {
306 1.1 jruoho AcpiOsPrintf ("There is no method currently executing\n");
307 1.1 jruoho return;
308 1.1 jruoho }
309 1.1 jruoho
310 1.1 jruoho if (Statements)
311 1.1 jruoho {
312 1.5 christos NumStatements = strtoul (Statements, NULL, 0);
313 1.1 jruoho }
314 1.1 jruoho
315 1.5 christos #ifdef ACPI_DISASSEMBLER
316 1.1 jruoho AcpiDmDisassemble (NULL, Op, NumStatements);
317 1.5 christos #endif
318 1.1 jruoho }
319 1.1 jruoho
320 1.1 jruoho
321 1.1 jruoho /*******************************************************************************
322 1.1 jruoho *
323 1.1 jruoho * FUNCTION: AcpiDbDisassembleMethod
324 1.1 jruoho *
325 1.1 jruoho * PARAMETERS: Name - Name of control method
326 1.1 jruoho *
327 1.1 jruoho * RETURN: None
328 1.1 jruoho *
329 1.1 jruoho * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
330 1.1 jruoho * of statements specified.
331 1.1 jruoho *
332 1.1 jruoho ******************************************************************************/
333 1.1 jruoho
334 1.1 jruoho ACPI_STATUS
335 1.1 jruoho AcpiDbDisassembleMethod (
336 1.1 jruoho char *Name)
337 1.1 jruoho {
338 1.1 jruoho ACPI_STATUS Status;
339 1.1 jruoho ACPI_PARSE_OBJECT *Op;
340 1.1 jruoho ACPI_WALK_STATE *WalkState;
341 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc;
342 1.1 jruoho ACPI_NAMESPACE_NODE *Method;
343 1.1 jruoho
344 1.1 jruoho
345 1.1 jruoho Method = AcpiDbConvertToNode (Name);
346 1.1 jruoho if (!Method)
347 1.1 jruoho {
348 1.1 jruoho return (AE_BAD_PARAMETER);
349 1.1 jruoho }
350 1.1 jruoho
351 1.2 christos if (Method->Type != ACPI_TYPE_METHOD)
352 1.2 christos {
353 1.2 christos ACPI_ERROR ((AE_INFO, "%s (%s): Object must be a control method",
354 1.2 christos Name, AcpiUtGetTypeName (Method->Type)));
355 1.2 christos return (AE_BAD_PARAMETER);
356 1.2 christos }
357 1.2 christos
358 1.1 jruoho ObjDesc = Method->Object;
359 1.1 jruoho
360 1.5 christos Op = AcpiPsCreateScopeOp (ObjDesc->Method.AmlStart);
361 1.1 jruoho if (!Op)
362 1.1 jruoho {
363 1.1 jruoho return (AE_NO_MEMORY);
364 1.1 jruoho }
365 1.1 jruoho
366 1.1 jruoho /* Create and initialize a new walk state */
367 1.1 jruoho
368 1.1 jruoho WalkState = AcpiDsCreateWalkState (0, Op, NULL, NULL);
369 1.1 jruoho if (!WalkState)
370 1.1 jruoho {
371 1.1 jruoho return (AE_NO_MEMORY);
372 1.1 jruoho }
373 1.1 jruoho
374 1.1 jruoho Status = AcpiDsInitAmlWalk (WalkState, Op, NULL,
375 1.2 christos ObjDesc->Method.AmlStart,
376 1.2 christos ObjDesc->Method.AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
377 1.2 christos if (ACPI_FAILURE (Status))
378 1.2 christos {
379 1.2 christos return (Status);
380 1.2 christos }
381 1.2 christos
382 1.2 christos Status = AcpiUtAllocateOwnerId (&ObjDesc->Method.OwnerId);
383 1.2 christos WalkState->OwnerId = ObjDesc->Method.OwnerId;
384 1.2 christos
385 1.2 christos /* Push start scope on scope stack and make it current */
386 1.2 christos
387 1.2 christos Status = AcpiDsScopeStackPush (Method,
388 1.2 christos Method->Type, WalkState);
389 1.1 jruoho if (ACPI_FAILURE (Status))
390 1.1 jruoho {
391 1.1 jruoho return (Status);
392 1.1 jruoho }
393 1.1 jruoho
394 1.2 christos /* Parse the entire method AML including deferred operators */
395 1.1 jruoho
396 1.1 jruoho WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
397 1.1 jruoho WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
398 1.2 christos
399 1.1 jruoho Status = AcpiPsParseAml (WalkState);
400 1.5 christos
401 1.5 christos #ifdef ACPI_DISASSEMBER
402 1.2 christos (void) AcpiDmParseDeferredOps (Op);
403 1.2 christos
404 1.2 christos /* Now we can disassemble the method */
405 1.1 jruoho
406 1.4 christos AcpiGbl_DbOpt_Verbose = FALSE;
407 1.1 jruoho AcpiDmDisassemble (NULL, Op, 0);
408 1.4 christos AcpiGbl_DbOpt_Verbose = TRUE;
409 1.5 christos #endif
410 1.2 christos
411 1.1 jruoho AcpiPsDeleteParseTree (Op);
412 1.2 christos
413 1.2 christos /* Method cleanup */
414 1.2 christos
415 1.2 christos AcpiNsDeleteNamespaceSubtree (Method);
416 1.2 christos AcpiNsDeleteNamespaceByOwner (ObjDesc->Method.OwnerId);
417 1.2 christos AcpiUtReleaseOwnerId (&ObjDesc->Method.OwnerId);
418 1.1 jruoho return (AE_OK);
419 1.1 jruoho }
420 1.1 jruoho
421 1.1 jruoho #endif /* ACPI_DEBUGGER */
422