1 /*******************************************************************************
3 * Module Name: dbmethod - Debug commands for control methods
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2013, 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>
52 #include <contrib/dev/acpica/include/acpredef.h>
57 #define _COMPONENT ACPI_CA_DEBUGGER
58 ACPI_MODULE_NAME ("dbmethod")
61 /* Local prototypes */
64 AcpiDbWalkForExecute (
65 ACPI_HANDLE ObjHandle,
71 /*******************************************************************************
73 * FUNCTION: AcpiDbSetMethodBreakpoint
75 * PARAMETERS: Location - AML offset of breakpoint
76 * WalkState - Current walk info
77 * Op - Current Op (from parse walk)
81 * DESCRIPTION: Set a breakpoint in a control method at the specified
84 ******************************************************************************/
87 AcpiDbSetMethodBreakpoint (
89 ACPI_WALK_STATE *WalkState,
90 ACPI_PARSE_OBJECT *Op)
97 AcpiOsPrintf ("There is no method currently executing\n");
101 /* Get and verify the breakpoint address */
103 Address = ACPI_STRTOUL (Location, NULL, 16);
104 if (Address <= Op->Common.AmlOffset)
106 AcpiOsPrintf ("Breakpoint %X is beyond current address %X\n",
107 Address, Op->Common.AmlOffset);
110 /* Save breakpoint in current walk */
112 WalkState->UserBreakpoint = Address;
113 AcpiOsPrintf ("Breakpoint set at AML offset %X\n", Address);
117 /*******************************************************************************
119 * FUNCTION: AcpiDbSetMethodCallBreakpoint
121 * PARAMETERS: Op - Current Op (from parse walk)
125 * DESCRIPTION: Set a breakpoint in a control method at the specified
128 ******************************************************************************/
131 AcpiDbSetMethodCallBreakpoint (
132 ACPI_PARSE_OBJECT *Op)
138 AcpiOsPrintf ("There is no method currently executing\n");
142 AcpiGbl_StepToNextCall = TRUE;
146 /*******************************************************************************
148 * FUNCTION: AcpiDbSetMethodData
150 * PARAMETERS: TypeArg - L for local, A for argument
151 * IndexArg - which one
152 * ValueArg - Value to set.
156 * DESCRIPTION: Set a local or argument for the running control method.
157 * NOTE: only object supported is Number.
159 ******************************************************************************/
162 AcpiDbSetMethodData (
170 ACPI_WALK_STATE *WalkState;
171 ACPI_OPERAND_OBJECT *ObjDesc;
173 ACPI_NAMESPACE_NODE *Node;
176 /* Validate TypeArg */
178 AcpiUtStrupr (TypeArg);
184 AcpiOsPrintf ("Invalid SET operand: %s\n", TypeArg);
188 Value = ACPI_STRTOUL (ValueArg, NULL, 16);
192 Node = AcpiDbConvertToNode (IndexArg);
193 if (Node->Type != ACPI_TYPE_INTEGER)
195 AcpiOsPrintf ("Can only set Integer nodes\n");
198 ObjDesc = Node->Object;
199 ObjDesc->Integer.Value = Value;
203 /* Get the index and value */
205 Index = ACPI_STRTOUL (IndexArg, NULL, 16);
207 WalkState = AcpiDsGetCurrentWalkState (AcpiGbl_CurrentWalkList);
210 AcpiOsPrintf ("There is no method currently executing\n");
214 /* Create and initialize the new object */
216 ObjDesc = AcpiUtCreateIntegerObject ((UINT64) Value);
219 AcpiOsPrintf ("Could not create an internal object\n");
223 /* Store the new object into the target */
229 /* Set a method argument */
231 if (Index > ACPI_METHOD_MAX_ARG)
233 AcpiOsPrintf ("Arg%u - Invalid argument name\n", Index);
237 Status = AcpiDsStoreObjectToLocal (ACPI_REFCLASS_ARG, Index, ObjDesc,
239 if (ACPI_FAILURE (Status))
244 ObjDesc = WalkState->Arguments[Index].Object;
246 AcpiOsPrintf ("Arg%u: ", Index);
247 AcpiDmDisplayInternalObject (ObjDesc, WalkState);
252 /* Set a method local */
254 if (Index > ACPI_METHOD_MAX_LOCAL)
256 AcpiOsPrintf ("Local%u - Invalid local variable name\n", Index);
260 Status = AcpiDsStoreObjectToLocal (ACPI_REFCLASS_LOCAL, Index, ObjDesc,
262 if (ACPI_FAILURE (Status))
267 ObjDesc = WalkState->LocalVariables[Index].Object;
269 AcpiOsPrintf ("Local%u: ", Index);
270 AcpiDmDisplayInternalObject (ObjDesc, WalkState);
279 AcpiUtRemoveReference (ObjDesc);
283 /*******************************************************************************
285 * FUNCTION: AcpiDbDisassembleAml
287 * PARAMETERS: Statements - Number of statements to disassemble
288 * Op - Current Op (from parse walk)
292 * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
293 * of statements specified.
295 ******************************************************************************/
298 AcpiDbDisassembleAml (
300 ACPI_PARSE_OBJECT *Op)
302 UINT32 NumStatements = 8;
307 AcpiOsPrintf ("There is no method currently executing\n");
313 NumStatements = ACPI_STRTOUL (Statements, NULL, 0);
316 #ifdef ACPI_DISASSEMBLER
317 AcpiDmDisassemble (NULL, Op, NumStatements);
322 /*******************************************************************************
324 * FUNCTION: AcpiDbDisassembleMethod
326 * PARAMETERS: Name - Name of control method
330 * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
331 * of statements specified.
333 ******************************************************************************/
336 AcpiDbDisassembleMethod (
340 ACPI_PARSE_OBJECT *Op;
341 ACPI_WALK_STATE *WalkState;
342 ACPI_OPERAND_OBJECT *ObjDesc;
343 ACPI_NAMESPACE_NODE *Method;
346 Method = AcpiDbConvertToNode (Name);
349 return (AE_BAD_PARAMETER);
352 if (Method->Type != ACPI_TYPE_METHOD)
354 ACPI_ERROR ((AE_INFO, "%s (%s): Object must be a control method",
355 Name, AcpiUtGetTypeName (Method->Type)));
356 return (AE_BAD_PARAMETER);
359 ObjDesc = Method->Object;
361 Op = AcpiPsCreateScopeOp ();
364 return (AE_NO_MEMORY);
367 /* Create and initialize a new walk state */
369 WalkState = AcpiDsCreateWalkState (0, Op, NULL, NULL);
372 return (AE_NO_MEMORY);
375 Status = AcpiDsInitAmlWalk (WalkState, Op, NULL,
376 ObjDesc->Method.AmlStart,
377 ObjDesc->Method.AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
378 if (ACPI_FAILURE (Status))
383 Status = AcpiUtAllocateOwnerId (&ObjDesc->Method.OwnerId);
384 WalkState->OwnerId = ObjDesc->Method.OwnerId;
386 /* Push start scope on scope stack and make it current */
388 Status = AcpiDsScopeStackPush (Method,
389 Method->Type, WalkState);
390 if (ACPI_FAILURE (Status))
395 /* Parse the entire method AML including deferred operators */
397 WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
398 WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
400 Status = AcpiPsParseAml (WalkState);
401 (void) AcpiDmParseDeferredOps (Op);
403 /* Now we can disassemble the method */
405 AcpiGbl_DbOpt_verbose = FALSE;
406 #ifdef ACPI_DISASSEMBLER
407 AcpiDmDisassemble (NULL, Op, 0);
409 AcpiGbl_DbOpt_verbose = TRUE;
411 AcpiPsDeleteParseTree (Op);
415 AcpiNsDeleteNamespaceSubtree (Method);
416 AcpiNsDeleteNamespaceByOwner (ObjDesc->Method.OwnerId);
417 AcpiUtReleaseOwnerId (&ObjDesc->Method.OwnerId);
422 /*******************************************************************************
424 * FUNCTION: AcpiDbWalkForExecute
426 * PARAMETERS: Callback from WalkNamespace
430 * DESCRIPTION: Batch execution module. Currently only executes predefined
433 ******************************************************************************/
436 AcpiDbWalkForExecute (
437 ACPI_HANDLE ObjHandle,
442 ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
443 ACPI_DB_EXECUTE_WALK *Info = (ACPI_DB_EXECUTE_WALK *) Context;
445 const ACPI_PREDEFINED_INFO *Predefined;
446 ACPI_DEVICE_INFO *ObjInfo;
447 ACPI_OBJECT_LIST ParamObjects;
448 ACPI_OBJECT Params[ACPI_METHOD_NUM_ARGS];
449 ACPI_OBJECT *ThisParam;
450 ACPI_BUFFER ReturnObj;
458 /* The name must be a predefined ACPI name */
460 Predefined = AcpiUtMatchPredefinedMethod (Node->Name.Ascii);
466 if (Node->Type == ACPI_TYPE_LOCAL_SCOPE)
471 Pathname = AcpiNsGetExternalPathname (Node);
477 /* Get the object info for number of method parameters */
479 Status = AcpiGetObjectInfo (ObjHandle, &ObjInfo);
480 if (ACPI_FAILURE (Status))
485 ParamObjects.Count = 0;
486 ParamObjects.Pointer = NULL;
488 if (ObjInfo->Type == ACPI_TYPE_METHOD)
490 /* Setup default parameters (with proper types) */
492 ArgTypeList = Predefined->Info.ArgumentList;
493 ArgCount = METHOD_GET_ARG_COUNT (ArgTypeList);
496 * Setup the ACPI-required number of arguments, regardless of what
497 * the actual method defines. If there is a difference, then the
498 * method is wrong and a warning will be issued during execution.
501 for (i = 0; i < ArgCount; i++)
503 ArgType = METHOD_GET_NEXT_TYPE (ArgTypeList);
504 ThisParam->Type = ArgType;
508 case ACPI_TYPE_INTEGER:
510 ThisParam->Integer.Value = 1;
513 case ACPI_TYPE_STRING:
515 ThisParam->String.Pointer = "This is the default argument string";
516 ThisParam->String.Length = ACPI_STRLEN (ThisParam->String.Pointer);
519 case ACPI_TYPE_BUFFER:
521 ThisParam->Buffer.Pointer = (UINT8 *) Params; /* just a garbage buffer */
522 ThisParam->Buffer.Length = 48;
525 case ACPI_TYPE_PACKAGE:
527 ThisParam->Package.Elements = NULL;
528 ThisParam->Package.Count = 0;
533 AcpiOsPrintf ("%s: Unsupported argument type: %u\n",
541 ParamObjects.Count = ArgCount;
542 ParamObjects.Pointer = Params;
546 ReturnObj.Pointer = NULL;
547 ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
549 /* Do the actual method execution */
551 AcpiGbl_MethodExecuting = TRUE;
553 Status = AcpiEvaluateObject (Node, NULL, &ParamObjects, &ReturnObj);
555 AcpiOsPrintf ("%-32s returned %s\n", Pathname, AcpiFormatException (Status));
556 AcpiGbl_MethodExecuting = FALSE;
557 ACPI_FREE (Pathname);
559 /* Ignore status from method execution */
563 /* Update count, check if we have executed enough methods */
566 if (Info->Count >= Info->MaxCount)
568 Status = AE_CTRL_TERMINATE;
575 /*******************************************************************************
577 * FUNCTION: AcpiDbBatchExecute
579 * PARAMETERS: CountArg - Max number of methods to execute
583 * DESCRIPTION: Namespace batch execution. Execute predefined names in the
584 * namespace, up to the max count, if specified.
586 ******************************************************************************/
592 ACPI_DB_EXECUTE_WALK Info;
596 Info.MaxCount = ACPI_UINT32_MAX;
600 Info.MaxCount = ACPI_STRTOUL (CountArg, NULL, 0);
604 /* Search all nodes in namespace */
606 (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
607 AcpiDbWalkForExecute, NULL, (void *) &Info, NULL);
609 AcpiOsPrintf ("Evaluated %u predefined names in the namespace\n", Info.Count);
612 #endif /* ACPI_DEBUGGER */