1 /*******************************************************************************
3 * Module Name: dbutils - AML debugger utilities
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/acnamesp.h>
48 #include <contrib/dev/acpica/include/acdebug.h>
49 #include <contrib/dev/acpica/include/acdisasm.h>
54 #define _COMPONENT ACPI_CA_DEBUGGER
55 ACPI_MODULE_NAME ("dbutils")
57 /* Local prototypes */
59 #ifdef ACPI_OBSOLETE_FUNCTIONS
61 AcpiDbSecondPassParse (
62 ACPI_PARSE_OBJECT *Root);
69 static char *Converter = "0123456789ABCDEF";
72 /*******************************************************************************
74 * FUNCTION: AcpiDbMatchArgument
76 * PARAMETERS: UserArgument - User command line
77 * Arguments - Array of commands to match against
79 * RETURN: Index into command array or ACPI_TYPE_NOT_FOUND if not found
81 * DESCRIPTION: Search command array for a command match
83 ******************************************************************************/
88 ARGUMENT_INFO *Arguments)
93 if (!UserArgument || UserArgument[0] == 0)
95 return (ACPI_TYPE_NOT_FOUND);
98 for (i = 0; Arguments[i].Name; i++)
100 if (ACPI_STRSTR (Arguments[i].Name, UserArgument) == Arguments[i].Name)
106 /* Argument not recognized */
108 return (ACPI_TYPE_NOT_FOUND);
112 /*******************************************************************************
114 * FUNCTION: AcpiDbSetOutputDestination
116 * PARAMETERS: OutputFlags - Current flags word
120 * DESCRIPTION: Set the current destination for debugger output. Also sets
121 * the debug output level accordingly.
123 ******************************************************************************/
126 AcpiDbSetOutputDestination (
130 AcpiGbl_DbOutputFlags = (UINT8) OutputFlags;
132 if ((OutputFlags & ACPI_DB_REDIRECTABLE_OUTPUT) && AcpiGbl_DbOutputToFile)
134 AcpiDbgLevel = AcpiGbl_DbDebugLevel;
138 AcpiDbgLevel = AcpiGbl_DbConsoleDebugLevel;
143 /*******************************************************************************
145 * FUNCTION: AcpiDbDumpExternalObject
147 * PARAMETERS: ObjDesc - External ACPI object to dump
148 * Level - Nesting level.
152 * DESCRIPTION: Dump the contents of an ACPI external object
154 ******************************************************************************/
157 AcpiDbDumpExternalObject (
158 ACPI_OBJECT *ObjDesc,
166 AcpiOsPrintf ("[Null Object]\n");
170 for (i = 0; i < Level; i++)
175 switch (ObjDesc->Type)
179 AcpiOsPrintf ("[Null Object] (Type=0)\n");
183 case ACPI_TYPE_INTEGER:
185 AcpiOsPrintf ("[Integer] = %8.8X%8.8X\n",
186 ACPI_FORMAT_UINT64 (ObjDesc->Integer.Value));
190 case ACPI_TYPE_STRING:
192 AcpiOsPrintf ("[String] Length %.2X = ", ObjDesc->String.Length);
193 for (i = 0; i < ObjDesc->String.Length; i++)
195 AcpiOsPrintf ("%c", ObjDesc->String.Pointer[i]);
201 case ACPI_TYPE_BUFFER:
203 AcpiOsPrintf ("[Buffer] Length %.2X = ", ObjDesc->Buffer.Length);
204 if (ObjDesc->Buffer.Length)
206 if (ObjDesc->Buffer.Length > 16)
210 AcpiUtDumpBuffer (ACPI_CAST_PTR (UINT8, ObjDesc->Buffer.Pointer),
211 ObjDesc->Buffer.Length, DB_DWORD_DISPLAY, _COMPONENT);
220 case ACPI_TYPE_PACKAGE:
222 AcpiOsPrintf ("[Package] Contains %u Elements:\n",
223 ObjDesc->Package.Count);
225 for (i = 0; i < ObjDesc->Package.Count; i++)
227 AcpiDbDumpExternalObject (&ObjDesc->Package.Elements[i], Level+1);
232 case ACPI_TYPE_LOCAL_REFERENCE:
234 AcpiOsPrintf ("[Object Reference] = ");
235 AcpiDmDisplayInternalObject (ObjDesc->Reference.Handle, NULL);
239 case ACPI_TYPE_PROCESSOR:
241 AcpiOsPrintf ("[Processor]\n");
245 case ACPI_TYPE_POWER:
247 AcpiOsPrintf ("[Power Resource]\n");
253 AcpiOsPrintf ("[Unknown Type] %X\n", ObjDesc->Type);
259 /*******************************************************************************
261 * FUNCTION: AcpiDbPrepNamestring
263 * PARAMETERS: Name - String to prepare
267 * DESCRIPTION: Translate all forward slashes and dots to backslashes.
269 ******************************************************************************/
272 AcpiDbPrepNamestring (
283 /* Convert a leading forward slash to a backslash */
290 /* Ignore a leading backslash, this is the root prefix */
297 /* Convert all slash path separators to dots */
301 if ((*Name == '/') ||
312 /*******************************************************************************
314 * FUNCTION: AcpiDbLocalNsLookup
316 * PARAMETERS: Name - Name to lookup
318 * RETURN: Pointer to a namespace node, null on failure
320 * DESCRIPTION: Lookup a name in the ACPI namespace
322 * Note: Currently begins search from the root. Could be enhanced to use
323 * the current prefix (scope) node as the search beginning point.
325 ******************************************************************************/
327 ACPI_NAMESPACE_NODE *
328 AcpiDbLocalNsLookup (
333 ACPI_NAMESPACE_NODE *Node = NULL;
336 AcpiDbPrepNamestring (Name);
338 /* Build an internal namestring */
340 Status = AcpiNsInternalizeName (Name, &InternalPath);
341 if (ACPI_FAILURE (Status))
343 AcpiOsPrintf ("Invalid namestring: %s\n", Name);
349 * (Uses root node as the search starting point)
351 Status = AcpiNsLookup (NULL, InternalPath, ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
352 ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE, NULL, &Node);
353 if (ACPI_FAILURE (Status))
355 AcpiOsPrintf ("Could not locate name: %s, %s\n",
356 Name, AcpiFormatException (Status));
359 ACPI_FREE (InternalPath);
364 /*******************************************************************************
366 * FUNCTION: AcpiDbUInt32ToHexString
368 * PARAMETERS: Value - The value to be converted to string
369 * Buffer - Buffer for result (not less than 11 bytes)
373 * DESCRIPTION: Convert the unsigned 32-bit value to the hexadecimal image
375 * NOTE: It is the caller's responsibility to ensure that the length of buffer
378 ******************************************************************************/
381 AcpiDbUInt32ToHexString (
390 ACPI_STRCPY (Buffer, "0");
396 for (i = 7; i >= 0; i--)
398 Buffer[i] = Converter [Value & 0x0F];
404 #ifdef ACPI_OBSOLETE_FUNCTIONS
405 /*******************************************************************************
407 * FUNCTION: AcpiDbSecondPassParse
409 * PARAMETERS: Root - Root of the parse tree
413 * DESCRIPTION: Second pass parse of the ACPI tables. We need to wait until
414 * second pass to parse the control methods
416 ******************************************************************************/
419 AcpiDbSecondPassParse (
420 ACPI_PARSE_OBJECT *Root)
422 ACPI_PARSE_OBJECT *Op = Root;
423 ACPI_PARSE_OBJECT *Method;
424 ACPI_PARSE_OBJECT *SearchOp;
425 ACPI_PARSE_OBJECT *StartOp;
426 ACPI_STATUS Status = AE_OK;
427 UINT32 BaseAmlOffset;
428 ACPI_WALK_STATE *WalkState;
431 ACPI_FUNCTION_ENTRY ();
434 AcpiOsPrintf ("Pass two parse ....\n");
438 if (Op->Common.AmlOpcode == AML_METHOD_OP)
442 /* Create a new walk state for the parse */
444 WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
447 return (AE_NO_MEMORY);
450 /* Init the Walk State */
452 WalkState->ParserState.Aml =
453 WalkState->ParserState.AmlStart = Method->Named.Data;
454 WalkState->ParserState.AmlEnd =
455 WalkState->ParserState.PkgEnd = Method->Named.Data +
456 Method->Named.Length;
457 WalkState->ParserState.StartScope = Op;
459 WalkState->DescendingCallback = AcpiDsLoad1BeginOp;
460 WalkState->AscendingCallback = AcpiDsLoad1EndOp;
462 /* Perform the AML parse */
464 Status = AcpiPsParseAml (WalkState);
466 BaseAmlOffset = (Method->Common.Value.Arg)->Common.AmlOffset + 1;
467 StartOp = (Method->Common.Value.Arg)->Common.Next;
472 SearchOp->Common.AmlOffset += BaseAmlOffset;
473 SearchOp = AcpiPsGetDepthNext (StartOp, SearchOp);
477 if (Op->Common.AmlOpcode == AML_REGION_OP)
479 /* TBD: [Investigate] this isn't quite the right thing to do! */
482 * Method = (ACPI_DEFERRED_OP *) Op;
483 * Status = AcpiPsParseAml (Op, Method->Body, Method->BodyLength);
487 if (ACPI_FAILURE (Status))
492 Op = AcpiPsGetDepthNext (Root, Op);
499 /*******************************************************************************
501 * FUNCTION: AcpiDbDumpBuffer
503 * PARAMETERS: Address - Pointer to the buffer
507 * DESCRIPTION: Print a portion of a buffer
509 ******************************************************************************/
516 AcpiOsPrintf ("\nLocation %X:\n", Address);
518 AcpiDbgLevel |= ACPI_LV_TABLES;
519 AcpiUtDumpBuffer (ACPI_TO_POINTER (Address), 64, DB_BYTE_DISPLAY,
524 #endif /* ACPI_DEBUGGER */