1 /******************************************************************************
3 * Module Name: ahdecode - Operator/Opcode decoding for acpihelp utility
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2015, Intel Corp.
12 * All rights reserved.
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
72 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************/
116 #define ACPI_CREATE_PREDEFINED_TABLE
117 #define ACPI_CREATE_RESOURCE_TABLE
119 #include "acpihelp.h"
120 #include "acpredef.h"
123 #define AH_DISPLAY_EXCEPTION(Status, Name) \
124 printf ("%.4X: %s\n", Status, Name)
126 #define AH_DISPLAY_EXCEPTION_TEXT(Status, Exception) \
127 printf ("%.4X: %-28s (%s)\n", Status, Exception->Name, Exception->Description)
129 #define BUFFER_LENGTH 128
130 #define LINE_BUFFER_LENGTH 512
132 static char Gbl_Buffer[BUFFER_LENGTH];
133 static char Gbl_LineBuffer[LINE_BUFFER_LENGTH];
136 /* Local prototypes */
139 AhDisplayPredefinedName (
144 AhDisplayPredefinedInfo (
148 AhDisplayResourceName (
149 const ACPI_PREDEFINED_INFO *ThisName);
153 const AH_AML_OPCODE *Op);
156 AhDisplayAslOperator (
157 const AH_ASL_OPERATOR *Op);
160 AhDisplayOperatorKeywords (
161 const AH_ASL_OPERATOR *Op);
164 AhDisplayAslKeyword (
165 const AH_ASL_KEYWORD *Op);
170 UINT32 CurrentPosition,
176 AhDisplayDirectives (
179 const AH_DIRECTIVE_INFO *Info;
182 printf ("iASL Preprocessor directives:\n\n");
184 for (Info = PreprocessorDirectives; Info->Name; Info++)
186 printf ("%16s : %s\n", Info->Name, Info->Operands);
191 /*******************************************************************************
193 * FUNCTION: AhFindPredefinedNames (entry point for predefined name search)
195 * PARAMETERS: NamePrefix - Name or prefix to find. Must start with
196 * an underscore. NULL means "find all"
200 * DESCRIPTION: Find and display all ACPI predefined names that match the
201 * input name or prefix. Includes the required number of arguments
202 * and the expected return type, if any.
204 ******************************************************************************/
207 AhFindPredefinedNames (
217 Found = AhDisplayPredefinedName (NULL, 0);
221 /* Contruct a local name or name prefix */
223 AhStrupr (NamePrefix);
224 if (*NamePrefix == '_')
230 strncpy (&Name[1], NamePrefix, 7);
232 Length = strlen (Name);
235 printf ("%.8s: Predefined name must be 4 characters maximum\n", Name);
239 Found = AhDisplayPredefinedName (Name, Length);
242 printf ("%s, no matching predefined names\n", Name);
247 /*******************************************************************************
249 * FUNCTION: AhDisplayPredefinedName
251 * PARAMETERS: Name - Name or name prefix
253 * RETURN: TRUE if any names matched, FALSE otherwise
255 * DESCRIPTION: Display information about ACPI predefined names that match
256 * the input name or name prefix.
258 ******************************************************************************/
261 AhDisplayPredefinedName (
265 const AH_PREDEFINED_NAME *Info;
266 BOOLEAN Found = FALSE;
271 /* Find/display all names that match the input name prefix */
273 for (Info = AslPredefinedInfo; Info->Name; Info++)
278 printf ("%s: <%s>\n", Info->Name, Info->Description);
279 printf ("%*s%s\n", 6, " ", Info->Action);
281 AhDisplayPredefinedInfo (Info->Name);
287 for (i = 0; i < Length; i++)
289 if (Info->Name[i] != Name[i])
299 printf ("%s: <%s>\n", Info->Name, Info->Description);
300 printf ("%*s%s\n", 6, " ", Info->Action);
302 AhDisplayPredefinedInfo (Info->Name);
308 printf ("\nFound %d Predefined ACPI Names\n", i);
314 /*******************************************************************************
316 * FUNCTION: AhDisplayPredefinedInfo
318 * PARAMETERS: Name - Exact 4-character ACPI name.
322 * DESCRIPTION: Find the name in the main ACPICA predefined info table and
323 * display the # of arguments and the return value type.
325 * Note: Resource Descriptor field names do not appear in this
326 * table -- thus, nothing will be displayed for them.
328 ******************************************************************************/
331 AhDisplayPredefinedInfo (
334 const ACPI_PREDEFINED_INFO *ThisName;
337 /* NOTE: we check both tables always because there are some dupes */
339 /* Check against the predefine methods first */
341 ThisName = AcpiUtMatchPredefinedMethod (Name);
344 AcpiUtDisplayPredefinedMethod (Gbl_Buffer, ThisName, TRUE);
347 /* Check against the predefined resource descriptor names */
349 ThisName = AcpiUtMatchResourceName (Name);
352 AhDisplayResourceName (ThisName);
357 /*******************************************************************************
359 * FUNCTION: AhDisplayResourceName
361 * PARAMETERS: ThisName - Entry in the predefined method/name table
365 * DESCRIPTION: Display information about a resource descriptor name.
367 ******************************************************************************/
370 AhDisplayResourceName (
371 const ACPI_PREDEFINED_INFO *ThisName)
376 NumTypes = AcpiUtGetResourceBitWidth (Gbl_Buffer,
377 ThisName->Info.ArgumentList);
379 printf (" %4.4s resource descriptor field is %s bits wide%s\n",
382 (NumTypes > 1) ? " (depending on descriptor type)" : "");
386 /*******************************************************************************
388 * FUNCTION: AhFindAmlOpcode (entry point for AML opcode name search)
390 * PARAMETERS: Name - Name or prefix for an AML opcode.
391 * NULL means "find all"
395 * DESCRIPTION: Find all AML opcodes that match the input Name or name
398 ******************************************************************************/
404 const AH_AML_OPCODE *Op;
405 BOOLEAN Found = FALSE;
410 /* Find/display all opcode names that match the input name prefix */
412 for (Op = AmlOpcodeInfo; Op->OpcodeString; Op++)
414 if (!Op->OpcodeName) /* Unused opcodes */
421 AhDisplayAmlOpcode (Op);
426 /* Upper case the opcode name before substring compare */
428 strcpy (Gbl_Buffer, Op->OpcodeName);
429 AhStrupr (Gbl_Buffer);
431 if (strstr (Gbl_Buffer, Name) == Gbl_Buffer)
433 AhDisplayAmlOpcode (Op);
440 printf ("%s, no matching AML operators\n", Name);
445 /*******************************************************************************
447 * FUNCTION: AhDecodeAmlOpcode (entry point for AML opcode search)
449 * PARAMETERS: OpcodeString - String version of AML opcode
453 * DESCRIPTION: Display information about the input AML opcode
455 ******************************************************************************/
461 const AH_AML_OPCODE *Op;
468 AhFindAmlOpcode (NULL);
472 Opcode = ACPI_STRTOUL (OpcodeString, NULL, 16);
473 if (Opcode > ACPI_UINT16_MAX)
475 printf ("Invalid opcode (more than 16 bits)\n");
479 /* Only valid opcode extension is 0x5B */
481 Prefix = (Opcode & 0x0000FF00) >> 8;
482 if (Prefix && (Prefix != 0x5B))
484 printf ("Invalid opcode (invalid extension prefix 0x%X)\n",
489 /* Find/Display the opcode. May fall within an opcode range */
491 for (Op = AmlOpcodeInfo; Op->OpcodeString; Op++)
493 if ((Opcode >= Op->OpcodeRangeStart) &&
494 (Opcode <= Op->OpcodeRangeEnd))
496 AhDisplayAmlOpcode (Op);
502 /*******************************************************************************
504 * FUNCTION: AhDisplayAmlOpcode
506 * PARAMETERS: Op - An opcode info struct
510 * DESCRIPTION: Display the contents of an AML opcode information struct
512 ******************************************************************************/
516 const AH_AML_OPCODE *Op)
521 printf ("%18s: Opcode=%-9s\n", "Reserved opcode", Op->OpcodeString);
525 /* Opcode name and value(s) */
527 printf ("%18s: Opcode=%-9s Type (%s)",
528 Op->OpcodeName, Op->OpcodeString, Op->Type);
530 /* Optional fixed/static arguments */
532 if (Op->FixedArguments)
534 printf (" FixedArgs (");
535 AhPrintOneField (37, 36 + 7 + strlen (Op->Type) + 12,
536 AH_MAX_AML_LINE_LENGTH, Op->FixedArguments);
540 /* Optional variable-length argument list */
542 if (Op->VariableArguments)
544 if (Op->FixedArguments)
546 printf ("\n%*s", 36, " ");
548 printf (" VariableArgs (");
549 AhPrintOneField (37, 15, AH_MAX_AML_LINE_LENGTH, Op->VariableArguments);
554 /* Grammar specification */
558 AhPrintOneField (37, 0, AH_MAX_AML_LINE_LENGTH, Op->Grammar);
564 /*******************************************************************************
566 * FUNCTION: AhFindAslKeywords (entry point for ASL keyword search)
568 * PARAMETERS: Name - Name or prefix for an ASL keyword.
569 * NULL means "find all"
573 * DESCRIPTION: Find all ASL keywords that match the input Name or name
576 ******************************************************************************/
582 const AH_ASL_KEYWORD *Keyword;
583 BOOLEAN Found = FALSE;
588 for (Keyword = AslKeywordInfo; Keyword->Name; Keyword++)
592 AhDisplayAslKeyword (Keyword);
597 /* Upper case the operator name before substring compare */
599 strcpy (Gbl_Buffer, Keyword->Name);
600 AhStrupr (Gbl_Buffer);
602 if (strstr (Gbl_Buffer, Name) == Gbl_Buffer)
604 AhDisplayAslKeyword (Keyword);
611 printf ("%s, no matching ASL keywords\n", Name);
616 /*******************************************************************************
618 * FUNCTION: AhDisplayAslKeyword
620 * PARAMETERS: Op - Pointer to ASL keyword with syntax info
624 * DESCRIPTION: Format and display syntax info for an ASL keyword. Splits
625 * long lines appropriately for reading.
627 ******************************************************************************/
630 AhDisplayAslKeyword (
631 const AH_ASL_KEYWORD *Op)
634 /* ASL keyword name and description */
636 printf ("%22s: %s\n", Op->Name, Op->Description);
637 if (!Op->KeywordList)
642 /* List of actual keywords */
644 AhPrintOneField (24, 0, AH_MAX_ASL_LINE_LENGTH, Op->KeywordList);
649 /*******************************************************************************
651 * FUNCTION: AhFindAslAndAmlOperators
653 * PARAMETERS: Name - Name or prefix for an ASL operator.
654 * NULL means "find all"
658 * DESCRIPTION: Find all ASL operators that match the input Name or name
659 * prefix. Also displays the AML information if only one entry
662 ******************************************************************************/
665 AhFindAslAndAmlOperators (
671 MatchCount = AhFindAslOperators (Name);
674 AhFindAmlOpcode (Name);
679 /*******************************************************************************
681 * FUNCTION: AhFindAslOperators (entry point for ASL operator search)
683 * PARAMETERS: Name - Name or prefix for an ASL operator.
684 * NULL means "find all"
686 * RETURN: Number of operators that matched the name prefix.
688 * DESCRIPTION: Find all ASL operators that match the input Name or name
691 ******************************************************************************/
697 const AH_ASL_OPERATOR *Operator;
698 BOOLEAN MatchCount = 0;
703 /* Find/display all names that match the input name prefix */
705 for (Operator = AslOperatorInfo; Operator->Name; Operator++)
709 AhDisplayAslOperator (Operator);
714 /* Upper case the operator name before substring compare */
716 strcpy (Gbl_Buffer, Operator->Name);
717 AhStrupr (Gbl_Buffer);
719 if (strstr (Gbl_Buffer, Name) == Gbl_Buffer)
721 AhDisplayAslOperator (Operator);
728 printf ("%s, no matching ASL operators\n", Name);
735 /*******************************************************************************
737 * FUNCTION: AhDisplayAslOperator
739 * PARAMETERS: Op - Pointer to ASL operator with syntax info
743 * DESCRIPTION: Format and display syntax info for an ASL operator. Splits
744 * long lines appropriately for reading.
746 ******************************************************************************/
749 AhDisplayAslOperator (
750 const AH_ASL_OPERATOR *Op)
753 /* ASL operator name and description */
755 printf ("%16s: %s\n", Op->Name, Op->Description);
761 /* Syntax for the operator */
763 AhPrintOneField (18, 0, AH_MAX_ASL_LINE_LENGTH, Op->Syntax);
766 AhDisplayOperatorKeywords (Op);
771 /*******************************************************************************
773 * FUNCTION: AhDisplayOperatorKeywords
775 * PARAMETERS: Op - Pointer to ASL keyword with syntax info
779 * DESCRIPTION: Display any/all keywords that are associated with the ASL
782 ******************************************************************************/
785 AhDisplayOperatorKeywords (
786 const AH_ASL_OPERATOR *Op)
789 char *Separators = "(){}, ";
790 BOOLEAN FirstKeyword = TRUE;
793 if (!Op || !Op->Syntax)
799 * Find all parameters that have the word "keyword" within, and then
800 * display the info about that keyword
802 strcpy (Gbl_LineBuffer, Op->Syntax);
803 Token = strtok (Gbl_LineBuffer, Separators);
806 if (strstr (Token, "Keyword"))
811 FirstKeyword = FALSE;
814 /* Found a keyword, display keyword information */
816 AhFindAslKeywords (Token);
819 Token = strtok (NULL, Separators);
824 /*******************************************************************************
826 * FUNCTION: AhPrintOneField
828 * PARAMETERS: Indent - Indent length for new line(s)
829 * CurrentPosition - Position on current line
830 * MaxPosition - Max allowed line length
831 * Field - Data to output
833 * RETURN: Line position after field is written
835 * DESCRIPTION: Split long lines appropriately for ease of reading.
837 ******************************************************************************/
842 UINT32 CurrentPosition,
854 Position = CurrentPosition;
858 printf ("%*s", (int) Indent, " ");
862 Last = This + strlen (This);
863 while ((Next = strpbrk (This, " ")))
865 TokenLength = Next - This;
866 Position += TokenLength;
868 /* Split long lines */
870 if (Position > MaxPosition)
872 printf ("\n%*s", (int) Indent, " ");
873 Position = TokenLength;
876 printf ("%.*s ", (int) TokenLength, This);
880 /* Handle last token on the input line */
882 TokenLength = Last - This;
885 Position += TokenLength;
886 if (Position > MaxPosition)
888 printf ("\n%*s", (int) Indent, " ");
895 /*******************************************************************************
897 * FUNCTION: AhDisplayDeviceIds
899 * PARAMETERS: Name - Device Hardware ID string.
900 * NULL means "find all"
904 * DESCRIPTION: Display PNP* and ACPI* device IDs.
906 ******************************************************************************/
912 const AH_DEVICE_ID *Info;
916 BOOLEAN Found = FALSE;
919 /* Null input name indicates "display all" */
923 printf ("ACPI and PNP Device/Hardware IDs:\n\n");
924 for (Info = AslDeviceIds; Info->Name; Info++)
926 printf ("%8s %s\n", Info->Name, Info->Description);
932 Length = strlen (Name);
935 printf ("%.8s: Hardware ID must be 8 characters maximum\n", Name);
939 /* Find/display all names that match the input name prefix */
942 for (Info = AslDeviceIds; Info->Name; Info++)
945 for (i = 0; i < Length; i++)
947 if (Info->Name[i] != Name[i])
957 printf ("%8s %s\n", Info->Name, Info->Description);
963 printf ("%s, Hardware ID not found\n", Name);
968 /*******************************************************************************
970 * FUNCTION: AhDisplayUuids
976 * DESCRIPTION: Display all known UUIDs.
978 ******************************************************************************/
987 printf ("ACPI-related UUIDs:\n\n");
989 for (Info = AcpiUuids; Info->Description; Info++)
991 printf ("%32s : %s\n", Info->Description, Info->String);
996 /*******************************************************************************
998 * FUNCTION: AhDisplayTables
1004 * DESCRIPTION: Display all known ACPI tables
1006 ******************************************************************************/
1012 const AH_TABLE *Info;
1016 printf ("Known ACPI tables:\n");
1018 for (Info = AcpiSupportedTables; Info->Signature; Info++)
1020 printf ("%8s : %s\n", Info->Signature, Info->Description);
1024 printf ("\nTotal %u ACPI tables\n\n", i);
1028 /*******************************************************************************
1030 * FUNCTION: AhDecodeException
1032 * PARAMETERS: HexString - ACPI status string from command line, in
1033 * hex. If null, display all exceptions.
1037 * DESCRIPTION: Decode and display an ACPI_STATUS exception code.
1039 ******************************************************************************/
1045 const ACPI_EXCEPTION_INFO *ExceptionInfo;
1051 * A null input string means to decode and display all known
1056 printf ("All defined ACPICA exception codes:\n\n");
1057 AH_DISPLAY_EXCEPTION (0, "AE_OK (No error occurred)");
1059 /* Display codes in each block of exception types */
1061 for (i = 1; (i & AE_CODE_MASK) <= AE_CODE_MAX; i += 0x1000)
1066 ExceptionInfo = AcpiUtValidateException ((ACPI_STATUS) Status);
1069 AH_DISPLAY_EXCEPTION_TEXT (Status, ExceptionInfo);
1073 } while (ExceptionInfo);
1078 /* Decode a single user-supplied exception code */
1080 Status = ACPI_STRTOUL (HexString, NULL, 16);
1083 printf ("%s: Invalid hexadecimal exception code value\n", HexString);
1087 if (Status > ACPI_UINT16_MAX)
1089 AH_DISPLAY_EXCEPTION (Status, "Invalid exception code (more than 16 bits)");
1093 ExceptionInfo = AcpiUtValidateException ((ACPI_STATUS) Status);
1096 AH_DISPLAY_EXCEPTION (Status, "Unknown exception code");
1100 AH_DISPLAY_EXCEPTION_TEXT (Status, ExceptionInfo);