1 /*******************************************************************************
3 * Module Name: dbutils - AML debugger utilities
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.
52 #define _COMPONENT ACPI_CA_DEBUGGER
53 ACPI_MODULE_NAME ("dbutils")
55 /* Local prototypes */
57 #ifdef ACPI_OBSOLETE_FUNCTIONS
59 AcpiDbSecondPassParse (
60 ACPI_PARSE_OBJECT *Root);
67 static char *Converter = "0123456789ABCDEF";
70 /*******************************************************************************
72 * FUNCTION: AcpiDbMatchArgument
74 * PARAMETERS: UserArgument - User command line
75 * Arguments - Array of commands to match against
77 * RETURN: Index into command array or ACPI_TYPE_NOT_FOUND if not found
79 * DESCRIPTION: Search command array for a command match
81 ******************************************************************************/
86 ACPI_DB_ARGUMENT_INFO *Arguments)
91 if (!UserArgument || UserArgument[0] == 0)
93 return (ACPI_TYPE_NOT_FOUND);
96 for (i = 0; Arguments[i].Name; i++)
98 if (strstr (Arguments[i].Name, UserArgument) == Arguments[i].Name)
104 /* Argument not recognized */
106 return (ACPI_TYPE_NOT_FOUND);
110 /*******************************************************************************
112 * FUNCTION: AcpiDbSetOutputDestination
114 * PARAMETERS: OutputFlags - Current flags word
118 * DESCRIPTION: Set the current destination for debugger output. Also sets
119 * the debug output level accordingly.
121 ******************************************************************************/
124 AcpiDbSetOutputDestination (
128 AcpiGbl_DbOutputFlags = (UINT8) OutputFlags;
130 if ((OutputFlags & ACPI_DB_REDIRECTABLE_OUTPUT) && AcpiGbl_DbOutputToFile)
132 AcpiDbgLevel = AcpiGbl_DbDebugLevel;
136 AcpiDbgLevel = AcpiGbl_DbConsoleDebugLevel;
141 /*******************************************************************************
143 * FUNCTION: AcpiDbDumpExternalObject
145 * PARAMETERS: ObjDesc - External ACPI object to dump
146 * Level - Nesting level.
150 * DESCRIPTION: Dump the contents of an ACPI external object
152 ******************************************************************************/
155 AcpiDbDumpExternalObject (
156 ACPI_OBJECT *ObjDesc,
164 AcpiOsPrintf ("[Null Object]\n");
168 for (i = 0; i < Level; i++)
173 switch (ObjDesc->Type)
177 AcpiOsPrintf ("[Null Object] (Type=0)\n");
180 case ACPI_TYPE_INTEGER:
182 AcpiOsPrintf ("[Integer] = %8.8X%8.8X\n",
183 ACPI_FORMAT_UINT64 (ObjDesc->Integer.Value));
186 case ACPI_TYPE_STRING:
188 AcpiOsPrintf ("[String] Length %.2X = ", ObjDesc->String.Length);
189 AcpiUtPrintString (ObjDesc->String.Pointer, ACPI_UINT8_MAX);
193 case ACPI_TYPE_BUFFER:
195 AcpiOsPrintf ("[Buffer] Length %.2X = ", ObjDesc->Buffer.Length);
196 if (ObjDesc->Buffer.Length)
198 if (ObjDesc->Buffer.Length > 16)
202 AcpiUtDebugDumpBuffer (ACPI_CAST_PTR (UINT8, ObjDesc->Buffer.Pointer),
203 ObjDesc->Buffer.Length, DB_BYTE_DISPLAY, _COMPONENT);
211 case ACPI_TYPE_PACKAGE:
213 AcpiOsPrintf ("[Package] Contains %u Elements:\n",
214 ObjDesc->Package.Count);
216 for (i = 0; i < ObjDesc->Package.Count; i++)
218 AcpiDbDumpExternalObject (&ObjDesc->Package.Elements[i], Level+1);
222 case ACPI_TYPE_LOCAL_REFERENCE:
224 AcpiOsPrintf ("[Object Reference] = ");
225 AcpiDbDisplayInternalObject (ObjDesc->Reference.Handle, NULL);
228 case ACPI_TYPE_PROCESSOR:
230 AcpiOsPrintf ("[Processor]\n");
233 case ACPI_TYPE_POWER:
235 AcpiOsPrintf ("[Power Resource]\n");
240 AcpiOsPrintf ("[Unknown Type] %X\n", ObjDesc->Type);
246 /*******************************************************************************
248 * FUNCTION: AcpiDbPrepNamestring
250 * PARAMETERS: Name - String to prepare
254 * DESCRIPTION: Translate all forward slashes and dots to backslashes.
256 ******************************************************************************/
259 AcpiDbPrepNamestring (
270 /* Convert a leading forward slash to a backslash */
277 /* Ignore a leading backslash, this is the root prefix */
279 if (ACPI_IS_ROOT_PREFIX (*Name))
284 /* Convert all slash path separators to dots */
288 if ((*Name == '/') ||
299 /*******************************************************************************
301 * FUNCTION: AcpiDbLocalNsLookup
303 * PARAMETERS: Name - Name to lookup
305 * RETURN: Pointer to a namespace node, null on failure
307 * DESCRIPTION: Lookup a name in the ACPI namespace
309 * Note: Currently begins search from the root. Could be enhanced to use
310 * the current prefix (scope) node as the search beginning point.
312 ******************************************************************************/
314 ACPI_NAMESPACE_NODE *
315 AcpiDbLocalNsLookup (
320 ACPI_NAMESPACE_NODE *Node = NULL;
323 AcpiDbPrepNamestring (Name);
325 /* Build an internal namestring */
327 Status = AcpiNsInternalizeName (Name, &InternalPath);
328 if (ACPI_FAILURE (Status))
330 AcpiOsPrintf ("Invalid namestring: %s\n", Name);
336 * (Uses root node as the search starting point)
338 Status = AcpiNsLookup (NULL, InternalPath, ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
339 ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE, NULL, &Node);
340 if (ACPI_FAILURE (Status))
342 AcpiOsPrintf ("Could not locate name: %s, %s\n",
343 Name, AcpiFormatException (Status));
346 ACPI_FREE (InternalPath);
351 /*******************************************************************************
353 * FUNCTION: AcpiDbUint32ToHexString
355 * PARAMETERS: Value - The value to be converted to string
356 * Buffer - Buffer for result (not less than 11 bytes)
360 * DESCRIPTION: Convert the unsigned 32-bit value to the hexadecimal image
362 * NOTE: It is the caller's responsibility to ensure that the length of buffer
365 ******************************************************************************/
368 AcpiDbUint32ToHexString (
377 strcpy (Buffer, "0");
383 for (i = 7; i >= 0; i--)
385 Buffer[i] = Converter [Value & 0x0F];
391 #ifdef ACPI_OBSOLETE_FUNCTIONS
392 /*******************************************************************************
394 * FUNCTION: AcpiDbSecondPassParse
396 * PARAMETERS: Root - Root of the parse tree
400 * DESCRIPTION: Second pass parse of the ACPI tables. We need to wait until
401 * second pass to parse the control methods
403 ******************************************************************************/
406 AcpiDbSecondPassParse (
407 ACPI_PARSE_OBJECT *Root)
409 ACPI_PARSE_OBJECT *Op = Root;
410 ACPI_PARSE_OBJECT *Method;
411 ACPI_PARSE_OBJECT *SearchOp;
412 ACPI_PARSE_OBJECT *StartOp;
413 ACPI_STATUS Status = AE_OK;
414 UINT32 BaseAmlOffset;
415 ACPI_WALK_STATE *WalkState;
418 ACPI_FUNCTION_ENTRY ();
421 AcpiOsPrintf ("Pass two parse ....\n");
425 if (Op->Common.AmlOpcode == AML_METHOD_OP)
429 /* Create a new walk state for the parse */
431 WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
434 return (AE_NO_MEMORY);
437 /* Init the Walk State */
439 WalkState->ParserState.Aml =
440 WalkState->ParserState.AmlStart = Method->Named.Data;
441 WalkState->ParserState.AmlEnd =
442 WalkState->ParserState.PkgEnd = Method->Named.Data +
443 Method->Named.Length;
444 WalkState->ParserState.StartScope = Op;
446 WalkState->DescendingCallback = AcpiDsLoad1BeginOp;
447 WalkState->AscendingCallback = AcpiDsLoad1EndOp;
449 /* Perform the AML parse */
451 Status = AcpiPsParseAml (WalkState);
453 BaseAmlOffset = (Method->Common.Value.Arg)->Common.AmlOffset + 1;
454 StartOp = (Method->Common.Value.Arg)->Common.Next;
459 SearchOp->Common.AmlOffset += BaseAmlOffset;
460 SearchOp = AcpiPsGetDepthNext (StartOp, SearchOp);
464 if (Op->Common.AmlOpcode == AML_REGION_OP)
466 /* TBD: [Investigate] this isn't quite the right thing to do! */
469 * Method = (ACPI_DEFERRED_OP *) Op;
470 * Status = AcpiPsParseAml (Op, Method->Body, Method->BodyLength);
474 if (ACPI_FAILURE (Status))
479 Op = AcpiPsGetDepthNext (Root, Op);
486 /*******************************************************************************
488 * FUNCTION: AcpiDbDumpBuffer
490 * PARAMETERS: Address - Pointer to the buffer
494 * DESCRIPTION: Print a portion of a buffer
496 ******************************************************************************/
503 AcpiOsPrintf ("\nLocation %X:\n", Address);
505 AcpiDbgLevel |= ACPI_LV_TABLES;
506 AcpiUtDebugDumpBuffer (ACPI_TO_POINTER (Address), 64, DB_BYTE_DISPLAY,
511 #endif /* ACPI_DEBUGGER */