1 /*******************************************************************************
3 * Module Name: dbmethod - Debug commands for control methods
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2014, 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.
44 #include <contrib/dev/acpica/include/acpi.h>
45 #include <contrib/dev/acpica/include/accommon.h>
46 #include <contrib/dev/acpica/include/acdispat.h>
47 #include <contrib/dev/acpica/include/acnamesp.h>
48 #include <contrib/dev/acpica/include/acdebug.h>
49 #include <contrib/dev/acpica/include/acdisasm.h>
50 #include <contrib/dev/acpica/include/acparser.h>
51 #include <contrib/dev/acpica/include/acpredef.h>
56 #define _COMPONENT ACPI_CA_DEBUGGER
57 ACPI_MODULE_NAME ("dbmethod")
60 /*******************************************************************************
62 * FUNCTION: AcpiDbSetMethodBreakpoint
64 * PARAMETERS: Location - AML offset of breakpoint
65 * WalkState - Current walk info
66 * Op - Current Op (from parse walk)
70 * DESCRIPTION: Set a breakpoint in a control method at the specified
73 ******************************************************************************/
76 AcpiDbSetMethodBreakpoint (
78 ACPI_WALK_STATE *WalkState,
79 ACPI_PARSE_OBJECT *Op)
86 AcpiOsPrintf ("There is no method currently executing\n");
90 /* Get and verify the breakpoint address */
92 Address = ACPI_STRTOUL (Location, NULL, 16);
93 if (Address <= Op->Common.AmlOffset)
95 AcpiOsPrintf ("Breakpoint %X is beyond current address %X\n",
96 Address, Op->Common.AmlOffset);
99 /* Save breakpoint in current walk */
101 WalkState->UserBreakpoint = Address;
102 AcpiOsPrintf ("Breakpoint set at AML offset %X\n", Address);
106 /*******************************************************************************
108 * FUNCTION: AcpiDbSetMethodCallBreakpoint
110 * PARAMETERS: Op - Current Op (from parse walk)
114 * DESCRIPTION: Set a breakpoint in a control method at the specified
117 ******************************************************************************/
120 AcpiDbSetMethodCallBreakpoint (
121 ACPI_PARSE_OBJECT *Op)
127 AcpiOsPrintf ("There is no method currently executing\n");
131 AcpiGbl_StepToNextCall = TRUE;
135 /*******************************************************************************
137 * FUNCTION: AcpiDbSetMethodData
139 * PARAMETERS: TypeArg - L for local, A for argument
140 * IndexArg - which one
141 * ValueArg - Value to set.
145 * DESCRIPTION: Set a local or argument for the running control method.
146 * NOTE: only object supported is Number.
148 ******************************************************************************/
151 AcpiDbSetMethodData (
159 ACPI_WALK_STATE *WalkState;
160 ACPI_OPERAND_OBJECT *ObjDesc;
162 ACPI_NAMESPACE_NODE *Node;
165 /* Validate TypeArg */
167 AcpiUtStrupr (TypeArg);
173 AcpiOsPrintf ("Invalid SET operand: %s\n", TypeArg);
177 Value = ACPI_STRTOUL (ValueArg, NULL, 16);
181 Node = AcpiDbConvertToNode (IndexArg);
187 if (Node->Type != ACPI_TYPE_INTEGER)
189 AcpiOsPrintf ("Can only set Integer nodes\n");
192 ObjDesc = Node->Object;
193 ObjDesc->Integer.Value = Value;
197 /* Get the index and value */
199 Index = ACPI_STRTOUL (IndexArg, NULL, 16);
201 WalkState = AcpiDsGetCurrentWalkState (AcpiGbl_CurrentWalkList);
204 AcpiOsPrintf ("There is no method currently executing\n");
208 /* Create and initialize the new object */
210 ObjDesc = AcpiUtCreateIntegerObject ((UINT64) Value);
213 AcpiOsPrintf ("Could not create an internal object\n");
217 /* Store the new object into the target */
223 /* Set a method argument */
225 if (Index > ACPI_METHOD_MAX_ARG)
227 AcpiOsPrintf ("Arg%u - Invalid argument name\n", Index);
231 Status = AcpiDsStoreObjectToLocal (ACPI_REFCLASS_ARG, Index, ObjDesc,
233 if (ACPI_FAILURE (Status))
238 ObjDesc = WalkState->Arguments[Index].Object;
240 AcpiOsPrintf ("Arg%u: ", Index);
241 AcpiDmDisplayInternalObject (ObjDesc, WalkState);
246 /* Set a method local */
248 if (Index > ACPI_METHOD_MAX_LOCAL)
250 AcpiOsPrintf ("Local%u - Invalid local variable name\n", Index);
254 Status = AcpiDsStoreObjectToLocal (ACPI_REFCLASS_LOCAL, Index, ObjDesc,
256 if (ACPI_FAILURE (Status))
261 ObjDesc = WalkState->LocalVariables[Index].Object;
263 AcpiOsPrintf ("Local%u: ", Index);
264 AcpiDmDisplayInternalObject (ObjDesc, WalkState);
273 AcpiUtRemoveReference (ObjDesc);
277 /*******************************************************************************
279 * FUNCTION: AcpiDbDisassembleAml
281 * PARAMETERS: Statements - Number of statements to disassemble
282 * Op - Current Op (from parse walk)
286 * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
287 * of statements specified.
289 ******************************************************************************/
292 AcpiDbDisassembleAml (
294 ACPI_PARSE_OBJECT *Op)
296 UINT32 NumStatements = 8;
301 AcpiOsPrintf ("There is no method currently executing\n");
307 NumStatements = ACPI_STRTOUL (Statements, NULL, 0);
310 #ifdef ACPI_DISASSEMBLER
311 AcpiDmDisassemble (NULL, Op, NumStatements);
316 /*******************************************************************************
318 * FUNCTION: AcpiDbDisassembleMethod
320 * PARAMETERS: Name - Name of control method
324 * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
325 * of statements specified.
327 ******************************************************************************/
330 AcpiDbDisassembleMethod (
334 ACPI_PARSE_OBJECT *Op;
335 ACPI_WALK_STATE *WalkState;
336 ACPI_OPERAND_OBJECT *ObjDesc;
337 ACPI_NAMESPACE_NODE *Method;
340 Method = AcpiDbConvertToNode (Name);
343 return (AE_BAD_PARAMETER);
346 if (Method->Type != ACPI_TYPE_METHOD)
348 ACPI_ERROR ((AE_INFO, "%s (%s): Object must be a control method",
349 Name, AcpiUtGetTypeName (Method->Type)));
350 return (AE_BAD_PARAMETER);
353 ObjDesc = Method->Object;
355 Op = AcpiPsCreateScopeOp ();
358 return (AE_NO_MEMORY);
361 /* Create and initialize a new walk state */
363 WalkState = AcpiDsCreateWalkState (0, Op, NULL, NULL);
366 return (AE_NO_MEMORY);
369 Status = AcpiDsInitAmlWalk (WalkState, Op, NULL,
370 ObjDesc->Method.AmlStart,
371 ObjDesc->Method.AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
372 if (ACPI_FAILURE (Status))
377 Status = AcpiUtAllocateOwnerId (&ObjDesc->Method.OwnerId);
378 WalkState->OwnerId = ObjDesc->Method.OwnerId;
380 /* Push start scope on scope stack and make it current */
382 Status = AcpiDsScopeStackPush (Method,
383 Method->Type, WalkState);
384 if (ACPI_FAILURE (Status))
389 /* Parse the entire method AML including deferred operators */
391 WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
392 WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
394 Status = AcpiPsParseAml (WalkState);
395 (void) AcpiDmParseDeferredOps (Op);
397 /* Now we can disassemble the method */
399 AcpiGbl_DbOpt_verbose = FALSE;
400 #ifdef ACPI_DISASSEMBLER
401 AcpiDmDisassemble (NULL, Op, 0);
403 AcpiGbl_DbOpt_verbose = TRUE;
405 AcpiPsDeleteParseTree (Op);
409 AcpiNsDeleteNamespaceSubtree (Method);
410 AcpiNsDeleteNamespaceByOwner (ObjDesc->Method.OwnerId);
411 AcpiUtReleaseOwnerId (&ObjDesc->Method.OwnerId);
415 #endif /* ACPI_DEBUGGER */