1 /*******************************************************************************
3 * Module Name: dbmethod - Debug commands for control methods
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2015, 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 #ifdef ACPI_DISASSEMBLER
50 #include <contrib/dev/acpica/include/acdisasm.h>
52 #include <contrib/dev/acpica/include/acparser.h>
53 #include <contrib/dev/acpica/include/acpredef.h>
58 #define _COMPONENT ACPI_CA_DEBUGGER
59 ACPI_MODULE_NAME ("dbmethod")
62 /*******************************************************************************
64 * FUNCTION: AcpiDbSetMethodBreakpoint
66 * PARAMETERS: Location - AML offset of breakpoint
67 * WalkState - Current walk info
68 * Op - Current Op (from parse walk)
72 * DESCRIPTION: Set a breakpoint in a control method at the specified
75 ******************************************************************************/
78 AcpiDbSetMethodBreakpoint (
80 ACPI_WALK_STATE *WalkState,
81 ACPI_PARSE_OBJECT *Op)
89 AcpiOsPrintf ("There is no method currently executing\n");
93 /* Get and verify the breakpoint address */
95 Address = strtoul (Location, NULL, 16);
96 AmlOffset = (UINT32) ACPI_PTR_DIFF (Op->Common.Aml,
97 WalkState->ParserState.AmlStart);
98 if (Address <= AmlOffset)
100 AcpiOsPrintf ("Breakpoint %X is beyond current address %X\n",
104 /* Save breakpoint in current walk */
106 WalkState->UserBreakpoint = Address;
107 AcpiOsPrintf ("Breakpoint set at AML offset %X\n", Address);
111 /*******************************************************************************
113 * FUNCTION: AcpiDbSetMethodCallBreakpoint
115 * PARAMETERS: Op - Current Op (from parse walk)
119 * DESCRIPTION: Set a breakpoint in a control method at the specified
122 ******************************************************************************/
125 AcpiDbSetMethodCallBreakpoint (
126 ACPI_PARSE_OBJECT *Op)
132 AcpiOsPrintf ("There is no method currently executing\n");
136 AcpiGbl_StepToNextCall = TRUE;
140 /*******************************************************************************
142 * FUNCTION: AcpiDbSetMethodData
144 * PARAMETERS: TypeArg - L for local, A for argument
145 * IndexArg - which one
146 * ValueArg - Value to set.
150 * DESCRIPTION: Set a local or argument for the running control method.
151 * NOTE: only object supported is Number.
153 ******************************************************************************/
156 AcpiDbSetMethodData (
164 ACPI_WALK_STATE *WalkState;
165 ACPI_OPERAND_OBJECT *ObjDesc;
167 ACPI_NAMESPACE_NODE *Node;
170 /* Validate TypeArg */
172 AcpiUtStrupr (TypeArg);
178 AcpiOsPrintf ("Invalid SET operand: %s\n", TypeArg);
182 Value = strtoul (ValueArg, NULL, 16);
186 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 = 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 AcpiDbDisplayInternalObject (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 AcpiDbDisplayInternalObject (ObjDesc, WalkState);
278 AcpiUtRemoveReference (ObjDesc);
282 /*******************************************************************************
284 * FUNCTION: AcpiDbDisassembleAml
286 * PARAMETERS: Statements - Number of statements to disassemble
287 * Op - Current Op (from parse walk)
291 * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
292 * of statements specified.
294 ******************************************************************************/
297 AcpiDbDisassembleAml (
299 ACPI_PARSE_OBJECT *Op)
301 UINT32 NumStatements = 8;
306 AcpiOsPrintf ("There is no method currently executing\n");
312 NumStatements = strtoul (Statements, NULL, 0);
315 #ifdef ACPI_DISASSEMBLER
316 AcpiDmDisassemble (NULL, Op, NumStatements);
321 /*******************************************************************************
323 * FUNCTION: AcpiDbDisassembleMethod
325 * PARAMETERS: Name - Name of control method
329 * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
330 * of statements specified.
332 ******************************************************************************/
335 AcpiDbDisassembleMethod (
339 ACPI_PARSE_OBJECT *Op;
340 ACPI_WALK_STATE *WalkState;
341 ACPI_OPERAND_OBJECT *ObjDesc;
342 ACPI_NAMESPACE_NODE *Method;
345 Method = AcpiDbConvertToNode (Name);
348 return (AE_BAD_PARAMETER);
351 if (Method->Type != ACPI_TYPE_METHOD)
353 ACPI_ERROR ((AE_INFO, "%s (%s): Object must be a control method",
354 Name, AcpiUtGetTypeName (Method->Type)));
355 return (AE_BAD_PARAMETER);
358 ObjDesc = Method->Object;
360 Op = AcpiPsCreateScopeOp (ObjDesc->Method.AmlStart);
363 return (AE_NO_MEMORY);
366 /* Create and initialize a new walk state */
368 WalkState = AcpiDsCreateWalkState (0, Op, NULL, NULL);
371 return (AE_NO_MEMORY);
374 Status = AcpiDsInitAmlWalk (WalkState, Op, NULL,
375 ObjDesc->Method.AmlStart,
376 ObjDesc->Method.AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
377 if (ACPI_FAILURE (Status))
382 Status = AcpiUtAllocateOwnerId (&ObjDesc->Method.OwnerId);
383 WalkState->OwnerId = ObjDesc->Method.OwnerId;
385 /* Push start scope on scope stack and make it current */
387 Status = AcpiDsScopeStackPush (Method,
388 Method->Type, WalkState);
389 if (ACPI_FAILURE (Status))
394 /* Parse the entire method AML including deferred operators */
396 WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
397 WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
399 Status = AcpiPsParseAml (WalkState);
401 #ifdef ACPI_DISASSEMBER
402 (void) AcpiDmParseDeferredOps (Op);
404 /* Now we can disassemble the method */
406 AcpiGbl_DbOpt_Verbose = FALSE;
407 AcpiDmDisassemble (NULL, Op, 0);
408 AcpiGbl_DbOpt_Verbose = TRUE;
411 AcpiPsDeleteParseTree (Op);
415 AcpiNsDeleteNamespaceSubtree (Method);
416 AcpiNsDeleteNamespaceByOwner (ObjDesc->Method.OwnerId);
417 AcpiUtReleaseOwnerId (&ObjDesc->Method.OwnerId);
421 #endif /* ACPI_DEBUGGER */