1 /*******************************************************************************
3 * Module Name: dbmethod - Debug commands for control methods
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2011, 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.
45 #include <contrib/dev/acpica/include/acpi.h>
46 #include <contrib/dev/acpica/include/accommon.h>
47 #include <contrib/dev/acpica/include/acdispat.h>
48 #include <contrib/dev/acpica/include/acnamesp.h>
49 #include <contrib/dev/acpica/include/acdebug.h>
50 #include <contrib/dev/acpica/include/acdisasm.h>
51 #include <contrib/dev/acpica/include/acparser.h>
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 #ifdef ACPI_DISASSEMBLER
315 AcpiDmDisassemble (NULL, Op, NumStatements);
320 /*******************************************************************************
322 * FUNCTION: AcpiDbDisassembleMethod
324 * PARAMETERS: Name - Name of control method
328 * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
329 * of statements specified.
331 ******************************************************************************/
334 AcpiDbDisassembleMethod (
338 ACPI_PARSE_OBJECT *Op;
339 ACPI_WALK_STATE *WalkState;
340 ACPI_OPERAND_OBJECT *ObjDesc;
341 ACPI_NAMESPACE_NODE *Method;
344 Method = AcpiDbConvertToNode (Name);
347 return (AE_BAD_PARAMETER);
350 ObjDesc = Method->Object;
352 Op = AcpiPsCreateScopeOp ();
355 return (AE_NO_MEMORY);
358 /* Create and initialize a new walk state */
360 WalkState = AcpiDsCreateWalkState (0, Op, NULL, NULL);
363 return (AE_NO_MEMORY);
366 Status = AcpiDsInitAmlWalk (WalkState, Op, NULL,
367 ObjDesc->Method.AmlStart,
368 ObjDesc->Method.AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
369 if (ACPI_FAILURE (Status))
376 WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
377 WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
378 Status = AcpiPsParseAml (WalkState);
380 #ifdef ACPI_DISASSEMBLER
381 AcpiDmDisassemble (NULL, Op, 0);
383 AcpiPsDeleteParseTree (Op);
388 /*******************************************************************************
390 * FUNCTION: AcpiDbWalkForExecute
392 * PARAMETERS: Callback from WalkNamespace
396 * DESCRIPTION: Batch execution module. Currently only executes predefined
399 ******************************************************************************/
402 AcpiDbWalkForExecute (
403 ACPI_HANDLE ObjHandle,
408 ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
409 ACPI_EXECUTE_WALK *Info = (ACPI_EXECUTE_WALK *) Context;
410 ACPI_BUFFER ReturnObj;
414 ACPI_DEVICE_INFO *ObjInfo;
415 ACPI_OBJECT_LIST ParamObjects;
416 ACPI_OBJECT Params[ACPI_METHOD_NUM_ARGS];
417 const ACPI_PREDEFINED_INFO *Predefined;
420 Predefined = AcpiNsCheckForPredefinedName (Node);
426 if (Node->Type == ACPI_TYPE_LOCAL_SCOPE)
431 Pathname = AcpiNsGetExternalPathname (Node);
437 /* Get the object info for number of method parameters */
439 Status = AcpiGetObjectInfo (ObjHandle, &ObjInfo);
440 if (ACPI_FAILURE (Status))
445 ParamObjects.Pointer = NULL;
446 ParamObjects.Count = 0;
448 if (ObjInfo->Type == ACPI_TYPE_METHOD)
450 /* Setup default parameters */
452 for (i = 0; i < ObjInfo->ParamCount; i++)
454 Params[i].Type = ACPI_TYPE_INTEGER;
455 Params[i].Integer.Value = 1;
458 ParamObjects.Pointer = Params;
459 ParamObjects.Count = ObjInfo->ParamCount;
463 ReturnObj.Pointer = NULL;
464 ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
466 /* Do the actual method execution */
468 AcpiGbl_MethodExecuting = TRUE;
470 Status = AcpiEvaluateObject (Node, NULL, &ParamObjects, &ReturnObj);
472 AcpiOsPrintf ("%-32s returned %s\n", Pathname, AcpiFormatException (Status));
473 AcpiGbl_MethodExecuting = FALSE;
474 ACPI_FREE (Pathname);
476 /* Ignore status from method execution */
480 /* Update count, check if we have executed enough methods */
483 if (Info->Count >= Info->MaxCount)
485 Status = AE_CTRL_TERMINATE;
492 /*******************************************************************************
494 * FUNCTION: AcpiDbBatchExecute
496 * PARAMETERS: CountArg - Max number of methods to execute
500 * DESCRIPTION: Namespace batch execution. Execute predefined names in the
501 * namespace, up to the max count, if specified.
503 ******************************************************************************/
509 ACPI_EXECUTE_WALK Info;
513 Info.MaxCount = ACPI_UINT32_MAX;
517 Info.MaxCount = ACPI_STRTOUL (CountArg, NULL, 0);
521 /* Search all nodes in namespace */
523 (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
524 AcpiDbWalkForExecute, NULL, (void *) &Info, NULL);
526 AcpiOsPrintf ("Executed %u predefined names in the namespace\n", Info.Count);
529 #endif /* ACPI_DEBUGGER */