1 /*******************************************************************************
3 * Module Name: dbmethod - Debug commands for control methods
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2012, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
56 #define _COMPONENT ACPI_CA_DEBUGGER
57 ACPI_MODULE_NAME ("dbmethod")
60 /* Local prototypes */
63 AcpiDbWalkForExecute (
64 ACPI_HANDLE ObjHandle,
70 /*******************************************************************************
72 * FUNCTION: AcpiDbSetMethodBreakpoint
74 * PARAMETERS: Location - AML offset of breakpoint
75 * WalkState - Current walk info
76 * Op - Current Op (from parse walk)
80 * DESCRIPTION: Set a breakpoint in a control method at the specified
83 ******************************************************************************/
86 AcpiDbSetMethodBreakpoint (
88 ACPI_WALK_STATE *WalkState,
89 ACPI_PARSE_OBJECT *Op)
96 AcpiOsPrintf ("There is no method currently executing\n");
100 /* Get and verify the breakpoint address */
102 Address = ACPI_STRTOUL (Location, NULL, 16);
103 if (Address <= Op->Common.AmlOffset)
105 AcpiOsPrintf ("Breakpoint %X is beyond current address %X\n",
106 Address, Op->Common.AmlOffset);
109 /* Save breakpoint in current walk */
111 WalkState->UserBreakpoint = Address;
112 AcpiOsPrintf ("Breakpoint set at AML offset %X\n", Address);
116 /*******************************************************************************
118 * FUNCTION: AcpiDbSetMethodCallBreakpoint
120 * PARAMETERS: Op - Current Op (from parse walk)
124 * DESCRIPTION: Set a breakpoint in a control method at the specified
127 ******************************************************************************/
130 AcpiDbSetMethodCallBreakpoint (
131 ACPI_PARSE_OBJECT *Op)
137 AcpiOsPrintf ("There is no method currently executing\n");
141 AcpiGbl_StepToNextCall = TRUE;
145 /*******************************************************************************
147 * FUNCTION: AcpiDbSetMethodData
149 * PARAMETERS: TypeArg - L for local, A for argument
150 * IndexArg - which one
151 * ValueArg - Value to set.
155 * DESCRIPTION: Set a local or argument for the running control method.
156 * NOTE: only object supported is Number.
158 ******************************************************************************/
161 AcpiDbSetMethodData (
169 ACPI_WALK_STATE *WalkState;
170 ACPI_OPERAND_OBJECT *ObjDesc;
172 ACPI_NAMESPACE_NODE *Node;
175 /* Validate TypeArg */
177 AcpiUtStrupr (TypeArg);
183 AcpiOsPrintf ("Invalid SET operand: %s\n", TypeArg);
187 Value = ACPI_STRTOUL (ValueArg, NULL, 16);
191 Node = AcpiDbConvertToNode (IndexArg);
192 if (Node->Type != ACPI_TYPE_INTEGER)
194 AcpiOsPrintf ("Can only set Integer nodes\n");
197 ObjDesc = Node->Object;
198 ObjDesc->Integer.Value = Value;
202 /* Get the index and value */
204 Index = ACPI_STRTOUL (IndexArg, NULL, 16);
206 WalkState = AcpiDsGetCurrentWalkState (AcpiGbl_CurrentWalkList);
209 AcpiOsPrintf ("There is no method currently executing\n");
213 /* Create and initialize the new object */
215 ObjDesc = AcpiUtCreateIntegerObject ((UINT64) Value);
218 AcpiOsPrintf ("Could not create an internal object\n");
222 /* Store the new object into the target */
228 /* Set a method argument */
230 if (Index > ACPI_METHOD_MAX_ARG)
232 AcpiOsPrintf ("Arg%u - Invalid argument name\n", Index);
236 Status = AcpiDsStoreObjectToLocal (ACPI_REFCLASS_ARG, Index, ObjDesc,
238 if (ACPI_FAILURE (Status))
243 ObjDesc = WalkState->Arguments[Index].Object;
245 AcpiOsPrintf ("Arg%u: ", Index);
246 AcpiDmDisplayInternalObject (ObjDesc, WalkState);
251 /* Set a method local */
253 if (Index > ACPI_METHOD_MAX_LOCAL)
255 AcpiOsPrintf ("Local%u - Invalid local variable name\n", Index);
259 Status = AcpiDsStoreObjectToLocal (ACPI_REFCLASS_LOCAL, Index, ObjDesc,
261 if (ACPI_FAILURE (Status))
266 ObjDesc = WalkState->LocalVariables[Index].Object;
268 AcpiOsPrintf ("Local%u: ", Index);
269 AcpiDmDisplayInternalObject (ObjDesc, WalkState);
277 AcpiUtRemoveReference (ObjDesc);
281 /*******************************************************************************
283 * FUNCTION: AcpiDbDisassembleAml
285 * PARAMETERS: Statements - Number of statements to disassemble
286 * Op - Current Op (from parse walk)
290 * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
291 * of statements specified.
293 ******************************************************************************/
296 AcpiDbDisassembleAml (
298 ACPI_PARSE_OBJECT *Op)
300 UINT32 NumStatements = 8;
305 AcpiOsPrintf ("There is no method currently executing\n");
311 NumStatements = ACPI_STRTOUL (Statements, NULL, 0);
314 AcpiDmDisassemble (NULL, Op, NumStatements);
318 /*******************************************************************************
320 * FUNCTION: AcpiDbDisassembleMethod
322 * PARAMETERS: Name - Name of control method
326 * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
327 * of statements specified.
329 ******************************************************************************/
332 AcpiDbDisassembleMethod (
336 ACPI_PARSE_OBJECT *Op;
337 ACPI_WALK_STATE *WalkState;
338 ACPI_OPERAND_OBJECT *ObjDesc;
339 ACPI_NAMESPACE_NODE *Method;
342 Method = AcpiDbConvertToNode (Name);
345 return (AE_BAD_PARAMETER);
348 if (Method->Type != ACPI_TYPE_METHOD)
350 ACPI_ERROR ((AE_INFO, "%s (%s): Object must be a control method",
351 Name, AcpiUtGetTypeName (Method->Type)));
352 return (AE_BAD_PARAMETER);
355 ObjDesc = Method->Object;
357 Op = AcpiPsCreateScopeOp ();
360 return (AE_NO_MEMORY);
363 /* Create and initialize a new walk state */
365 WalkState = AcpiDsCreateWalkState (0, Op, NULL, NULL);
368 return (AE_NO_MEMORY);
371 Status = AcpiDsInitAmlWalk (WalkState, Op, NULL,
372 ObjDesc->Method.AmlStart,
373 ObjDesc->Method.AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
374 if (ACPI_FAILURE (Status))
379 Status = AcpiUtAllocateOwnerId (&ObjDesc->Method.OwnerId);
380 WalkState->OwnerId = ObjDesc->Method.OwnerId;
382 /* Push start scope on scope stack and make it current */
384 Status = AcpiDsScopeStackPush (Method,
385 Method->Type, WalkState);
386 if (ACPI_FAILURE (Status))
391 /* Parse the entire method AML including deferred operators */
393 WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
394 WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
396 Status = AcpiPsParseAml (WalkState);
397 AcpiDmParseDeferredOps (Op);
399 /* Now we can disassemble the method */
401 AcpiGbl_DbOpt_verbose = TRUE;
402 AcpiGbl_DbOpt_verbose = FALSE;
403 AcpiDmDisassemble (NULL, Op, 0);
404 AcpiGbl_DbOpt_verbose = TRUE;
406 AcpiPsDeleteParseTree (Op);
410 AcpiNsDeleteNamespaceSubtree (Method);
411 AcpiNsDeleteNamespaceByOwner (ObjDesc->Method.OwnerId);
412 AcpiUtReleaseOwnerId (&ObjDesc->Method.OwnerId);
417 /*******************************************************************************
419 * FUNCTION: AcpiDbWalkForExecute
421 * PARAMETERS: Callback from WalkNamespace
425 * DESCRIPTION: Batch execution module. Currently only executes predefined
428 ******************************************************************************/
431 AcpiDbWalkForExecute (
432 ACPI_HANDLE ObjHandle,
437 ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
438 ACPI_DB_EXECUTE_WALK *Info = (ACPI_DB_EXECUTE_WALK *) Context;
439 ACPI_BUFFER ReturnObj;
443 ACPI_DEVICE_INFO *ObjInfo;
444 ACPI_OBJECT_LIST ParamObjects;
445 ACPI_OBJECT Params[ACPI_METHOD_NUM_ARGS];
446 const ACPI_PREDEFINED_INFO *Predefined;
449 Predefined = AcpiNsCheckForPredefinedName (Node);
455 if (Node->Type == ACPI_TYPE_LOCAL_SCOPE)
460 Pathname = AcpiNsGetExternalPathname (Node);
466 /* Get the object info for number of method parameters */
468 Status = AcpiGetObjectInfo (ObjHandle, &ObjInfo);
469 if (ACPI_FAILURE (Status))
474 ParamObjects.Pointer = NULL;
475 ParamObjects.Count = 0;
477 if (ObjInfo->Type == ACPI_TYPE_METHOD)
479 /* Setup default parameters */
481 for (i = 0; i < ObjInfo->ParamCount; i++)
483 Params[i].Type = ACPI_TYPE_INTEGER;
484 Params[i].Integer.Value = 1;
487 ParamObjects.Pointer = Params;
488 ParamObjects.Count = ObjInfo->ParamCount;
492 ReturnObj.Pointer = NULL;
493 ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
495 /* Do the actual method execution */
497 AcpiGbl_MethodExecuting = TRUE;
499 Status = AcpiEvaluateObject (Node, NULL, &ParamObjects, &ReturnObj);
501 AcpiOsPrintf ("%-32s returned %s\n", Pathname, AcpiFormatException (Status));
502 AcpiGbl_MethodExecuting = FALSE;
503 ACPI_FREE (Pathname);
505 /* Ignore status from method execution */
509 /* Update count, check if we have executed enough methods */
512 if (Info->Count >= Info->MaxCount)
514 Status = AE_CTRL_TERMINATE;
521 /*******************************************************************************
523 * FUNCTION: AcpiDbBatchExecute
525 * PARAMETERS: CountArg - Max number of methods to execute
529 * DESCRIPTION: Namespace batch execution. Execute predefined names in the
530 * namespace, up to the max count, if specified.
532 ******************************************************************************/
538 ACPI_DB_EXECUTE_WALK Info;
542 Info.MaxCount = ACPI_UINT32_MAX;
546 Info.MaxCount = ACPI_STRTOUL (CountArg, NULL, 0);
550 /* Search all nodes in namespace */
552 (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
553 AcpiDbWalkForExecute, NULL, (void *) &Info, NULL);
555 AcpiOsPrintf ("Evaluated %u predefined names in the namespace\n", Info.Count);
558 #endif /* ACPI_DEBUGGER */