1 /******************************************************************************
3 * Module Name: ahdecode - Operator/Opcode decoding for acpihelp utility
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 #define ACPI_CREATE_PREDEFINED_TABLE
45 #define ACPI_CREATE_RESOURCE_TABLE
51 #define AH_DISPLAY_EXCEPTION(Status, Name) \
52 printf ("%.4X: %s\n", Status, Name)
54 #define AH_DISPLAY_EXCEPTION_TEXT(Status, Exception) \
55 printf ("%.4X: %-28s (%s)\n", Status, Exception->Name, Exception->Description)
57 #define BUFFER_LENGTH 128
58 #define LINE_BUFFER_LENGTH 512
60 static char Gbl_Buffer[BUFFER_LENGTH];
61 static char Gbl_LineBuffer[LINE_BUFFER_LENGTH];
64 /* Local prototypes */
67 AhDisplayPredefinedName (
72 AhDisplayPredefinedInfo (
76 AhDisplayResourceName (
77 const ACPI_PREDEFINED_INFO *ThisName);
81 const AH_AML_OPCODE *Op);
84 AhDisplayAslOperator (
85 const AH_ASL_OPERATOR *Op);
88 AhDisplayOperatorKeywords (
89 const AH_ASL_OPERATOR *Op);
93 const AH_ASL_KEYWORD *Op);
98 UINT32 CurrentPosition,
104 AhDisplayDirectives (
107 const AH_DIRECTIVE_INFO *Info;
110 printf ("iASL Preprocessor directives:\n\n");
112 for (Info = PreprocessorDirectives; Info->Name; Info++)
114 printf ("%16s : %s\n", Info->Name, Info->Operands);
119 /*******************************************************************************
121 * FUNCTION: AhFindPredefinedNames (entry point for predefined name search)
123 * PARAMETERS: NamePrefix - Name or prefix to find. Must start with
124 * an underscore. NULL means "find all"
128 * DESCRIPTION: Find and display all ACPI predefined names that match the
129 * input name or prefix. Includes the required number of arguments
130 * and the expected return type, if any.
132 ******************************************************************************/
135 AhFindPredefinedNames (
145 Found = AhDisplayPredefinedName (NULL, 0);
149 /* Contruct a local name or name prefix */
151 AhStrupr (NamePrefix);
152 if (*NamePrefix == '_')
158 strncpy (&Name[1], NamePrefix, 7);
160 Length = strlen (Name);
163 printf ("%.8s: Predefined name must be 4 characters maximum\n", Name);
167 Found = AhDisplayPredefinedName (Name, Length);
170 printf ("%s, no matching predefined names\n", Name);
175 /*******************************************************************************
177 * FUNCTION: AhDisplayPredefinedName
179 * PARAMETERS: Name - Name or name prefix
181 * RETURN: TRUE if any names matched, FALSE otherwise
183 * DESCRIPTION: Display information about ACPI predefined names that match
184 * the input name or name prefix.
186 ******************************************************************************/
189 AhDisplayPredefinedName (
193 const AH_PREDEFINED_NAME *Info;
194 BOOLEAN Found = FALSE;
199 /* Find/display all names that match the input name prefix */
201 for (Info = AslPredefinedInfo; Info->Name; Info++)
206 printf ("%s: <%s>\n", Info->Name, Info->Description);
207 printf ("%*s%s\n", 6, " ", Info->Action);
209 AhDisplayPredefinedInfo (Info->Name);
215 for (i = 0; i < Length; i++)
217 if (Info->Name[i] != Name[i])
227 printf ("%s: <%s>\n", Info->Name, Info->Description);
228 printf ("%*s%s\n", 6, " ", Info->Action);
230 AhDisplayPredefinedInfo (Info->Name);
236 printf ("\nFound %d Predefined ACPI Names\n", i);
242 /*******************************************************************************
244 * FUNCTION: AhDisplayPredefinedInfo
246 * PARAMETERS: Name - Exact 4-character ACPI name.
250 * DESCRIPTION: Find the name in the main ACPICA predefined info table and
251 * display the # of arguments and the return value type.
253 * Note: Resource Descriptor field names do not appear in this
254 * table -- thus, nothing will be displayed for them.
256 ******************************************************************************/
259 AhDisplayPredefinedInfo (
262 const ACPI_PREDEFINED_INFO *ThisName;
265 /* NOTE: we check both tables always because there are some dupes */
267 /* Check against the predefine methods first */
269 ThisName = AcpiUtMatchPredefinedMethod (Name);
272 AcpiUtDisplayPredefinedMethod (Gbl_Buffer, ThisName, TRUE);
275 /* Check against the predefined resource descriptor names */
277 ThisName = AcpiUtMatchResourceName (Name);
280 AhDisplayResourceName (ThisName);
285 /*******************************************************************************
287 * FUNCTION: AhDisplayResourceName
289 * PARAMETERS: ThisName - Entry in the predefined method/name table
293 * DESCRIPTION: Display information about a resource descriptor name.
295 ******************************************************************************/
298 AhDisplayResourceName (
299 const ACPI_PREDEFINED_INFO *ThisName)
304 NumTypes = AcpiUtGetResourceBitWidth (Gbl_Buffer,
305 ThisName->Info.ArgumentList);
307 printf (" %4.4s resource descriptor field is %s bits wide%s\n",
310 (NumTypes > 1) ? " (depending on descriptor type)" : "");
314 /*******************************************************************************
316 * FUNCTION: AhFindAmlOpcode (entry point for AML opcode name search)
318 * PARAMETERS: Name - Name or prefix for an AML opcode.
319 * NULL means "find all"
323 * DESCRIPTION: Find all AML opcodes that match the input Name or name
326 ******************************************************************************/
332 const AH_AML_OPCODE *Op;
333 BOOLEAN Found = FALSE;
338 /* Find/display all opcode names that match the input name prefix */
340 for (Op = AmlOpcodeInfo; Op->OpcodeString; Op++)
342 if (!Op->OpcodeName) /* Unused opcodes */
349 AhDisplayAmlOpcode (Op);
354 /* Upper case the opcode name before substring compare */
356 strcpy (Gbl_Buffer, Op->OpcodeName);
357 AhStrupr (Gbl_Buffer);
359 if (strstr (Gbl_Buffer, Name) == Gbl_Buffer)
361 AhDisplayAmlOpcode (Op);
368 printf ("%s, no matching AML operators\n", Name);
373 /*******************************************************************************
375 * FUNCTION: AhDecodeAmlOpcode (entry point for AML opcode search)
377 * PARAMETERS: OpcodeString - String version of AML opcode
381 * DESCRIPTION: Display information about the input AML opcode
383 ******************************************************************************/
389 const AH_AML_OPCODE *Op;
396 AhFindAmlOpcode (NULL);
400 Opcode = strtoul (OpcodeString, NULL, 16);
401 if (Opcode > ACPI_UINT16_MAX)
403 printf ("Invalid opcode (more than 16 bits)\n");
407 /* Only valid opcode extension is 0x5B */
409 Prefix = (Opcode & 0x0000FF00) >> 8;
410 if (Prefix && (Prefix != 0x5B))
412 printf ("Invalid opcode (invalid extension prefix 0x%X)\n",
417 /* Find/Display the opcode. May fall within an opcode range */
419 for (Op = AmlOpcodeInfo; Op->OpcodeString; Op++)
421 if ((Opcode >= Op->OpcodeRangeStart) &&
422 (Opcode <= Op->OpcodeRangeEnd))
424 AhDisplayAmlOpcode (Op);
430 /*******************************************************************************
432 * FUNCTION: AhDisplayAmlOpcode
434 * PARAMETERS: Op - An opcode info struct
438 * DESCRIPTION: Display the contents of an AML opcode information struct
440 ******************************************************************************/
444 const AH_AML_OPCODE *Op)
449 printf ("%18s: Opcode=%-9s\n", "Reserved opcode", Op->OpcodeString);
453 /* Opcode name and value(s) */
455 printf ("%18s: Opcode=%-9s Type (%s)",
456 Op->OpcodeName, Op->OpcodeString, Op->Type);
458 /* Optional fixed/static arguments */
460 if (Op->FixedArguments)
462 printf (" FixedArgs (");
463 AhPrintOneField (37, 36 + 7 + strlen (Op->Type) + 12,
464 AH_MAX_AML_LINE_LENGTH, Op->FixedArguments);
468 /* Optional variable-length argument list */
470 if (Op->VariableArguments)
472 if (Op->FixedArguments)
474 printf ("\n%*s", 36, " ");
476 printf (" VariableArgs (");
477 AhPrintOneField (37, 15, AH_MAX_AML_LINE_LENGTH, Op->VariableArguments);
482 /* Grammar specification */
486 AhPrintOneField (37, 0, AH_MAX_AML_LINE_LENGTH, Op->Grammar);
492 /*******************************************************************************
494 * FUNCTION: AhFindAslKeywords (entry point for ASL keyword search)
496 * PARAMETERS: Name - Name or prefix for an ASL keyword.
497 * NULL means "find all"
501 * DESCRIPTION: Find all ASL keywords that match the input Name or name
504 ******************************************************************************/
510 const AH_ASL_KEYWORD *Keyword;
511 BOOLEAN Found = FALSE;
516 for (Keyword = AslKeywordInfo; Keyword->Name; Keyword++)
520 AhDisplayAslKeyword (Keyword);
525 /* Upper case the operator name before substring compare */
527 strcpy (Gbl_Buffer, Keyword->Name);
528 AhStrupr (Gbl_Buffer);
530 if (strstr (Gbl_Buffer, Name) == Gbl_Buffer)
532 AhDisplayAslKeyword (Keyword);
539 printf ("%s, no matching ASL keywords\n", Name);
544 /*******************************************************************************
546 * FUNCTION: AhDisplayAslKeyword
548 * PARAMETERS: Op - Pointer to ASL keyword with syntax info
552 * DESCRIPTION: Format and display syntax info for an ASL keyword. Splits
553 * long lines appropriately for reading.
555 ******************************************************************************/
558 AhDisplayAslKeyword (
559 const AH_ASL_KEYWORD *Op)
562 /* ASL keyword name and description */
564 printf ("%22s: %s\n", Op->Name, Op->Description);
565 if (!Op->KeywordList)
570 /* List of actual keywords */
572 AhPrintOneField (24, 0, AH_MAX_ASL_LINE_LENGTH, Op->KeywordList);
577 /*******************************************************************************
579 * FUNCTION: AhFindAslAndAmlOperators
581 * PARAMETERS: Name - Name or prefix for an ASL operator.
582 * NULL means "find all"
586 * DESCRIPTION: Find all ASL operators that match the input Name or name
587 * prefix. Also displays the AML information if only one entry
590 ******************************************************************************/
593 AhFindAslAndAmlOperators (
599 MatchCount = AhFindAslOperators (Name);
602 AhFindAmlOpcode (Name);
607 /*******************************************************************************
609 * FUNCTION: AhFindAslOperators (entry point for ASL operator search)
611 * PARAMETERS: Name - Name or prefix for an ASL operator.
612 * NULL means "find all"
614 * RETURN: Number of operators that matched the name prefix.
616 * DESCRIPTION: Find all ASL operators that match the input Name or name
619 ******************************************************************************/
625 const AH_ASL_OPERATOR *Operator;
626 BOOLEAN MatchCount = 0;
631 /* Find/display all names that match the input name prefix */
633 for (Operator = AslOperatorInfo; Operator->Name; Operator++)
637 AhDisplayAslOperator (Operator);
642 /* Upper case the operator name before substring compare */
644 strcpy (Gbl_Buffer, Operator->Name);
645 AhStrupr (Gbl_Buffer);
647 if (strstr (Gbl_Buffer, Name) == Gbl_Buffer)
649 AhDisplayAslOperator (Operator);
656 printf ("%s, no matching ASL operators\n", Name);
663 /*******************************************************************************
665 * FUNCTION: AhDisplayAslOperator
667 * PARAMETERS: Op - Pointer to ASL operator with syntax info
671 * DESCRIPTION: Format and display syntax info for an ASL operator. Splits
672 * long lines appropriately for reading.
674 ******************************************************************************/
677 AhDisplayAslOperator (
678 const AH_ASL_OPERATOR *Op)
681 /* ASL operator name and description */
683 printf ("%16s: %s\n", Op->Name, Op->Description);
689 /* Syntax for the operator */
691 AhPrintOneField (18, 0, AH_MAX_ASL_LINE_LENGTH, Op->Syntax);
694 AhDisplayOperatorKeywords (Op);
699 /*******************************************************************************
701 * FUNCTION: AhDisplayOperatorKeywords
703 * PARAMETERS: Op - Pointer to ASL keyword with syntax info
707 * DESCRIPTION: Display any/all keywords that are associated with the ASL
710 ******************************************************************************/
713 AhDisplayOperatorKeywords (
714 const AH_ASL_OPERATOR *Op)
717 char *Separators = "(){}, ";
718 BOOLEAN FirstKeyword = TRUE;
721 if (!Op || !Op->Syntax)
727 * Find all parameters that have the word "keyword" within, and then
728 * display the info about that keyword
730 strcpy (Gbl_LineBuffer, Op->Syntax);
731 Token = strtok (Gbl_LineBuffer, Separators);
734 if (strstr (Token, "Keyword"))
739 FirstKeyword = FALSE;
742 /* Found a keyword, display keyword information */
744 AhFindAslKeywords (Token);
747 Token = strtok (NULL, Separators);
752 /*******************************************************************************
754 * FUNCTION: AhPrintOneField
756 * PARAMETERS: Indent - Indent length for new line(s)
757 * CurrentPosition - Position on current line
758 * MaxPosition - Max allowed line length
759 * Field - Data to output
761 * RETURN: Line position after field is written
763 * DESCRIPTION: Split long lines appropriately for ease of reading.
765 ******************************************************************************/
770 UINT32 CurrentPosition,
782 Position = CurrentPosition;
786 printf ("%*s", (int) Indent, " ");
790 Last = This + strlen (This);
791 while ((Next = strpbrk (This, " ")))
793 TokenLength = Next - This;
794 Position += TokenLength;
796 /* Split long lines */
798 if (Position > MaxPosition)
800 printf ("\n%*s", (int) Indent, " ");
801 Position = TokenLength;
804 printf ("%.*s ", (int) TokenLength, This);
808 /* Handle last token on the input line */
810 TokenLength = Last - This;
813 Position += TokenLength;
814 if (Position > MaxPosition)
816 printf ("\n%*s", (int) Indent, " ");
823 /*******************************************************************************
825 * FUNCTION: AhDisplayDeviceIds
827 * PARAMETERS: Name - Device Hardware ID string.
828 * NULL means "find all"
832 * DESCRIPTION: Display PNP* and ACPI* device IDs.
834 ******************************************************************************/
840 const AH_DEVICE_ID *Info;
844 BOOLEAN Found = FALSE;
847 /* Null input name indicates "display all" */
851 printf ("ACPI and PNP Device/Hardware IDs:\n\n");
852 for (Info = AslDeviceIds; Info->Name; Info++)
854 printf ("%8s %s\n", Info->Name, Info->Description);
860 Length = strlen (Name);
863 printf ("%.8s: Hardware ID must be 8 characters maximum\n", Name);
867 /* Find/display all names that match the input name prefix */
870 for (Info = AslDeviceIds; Info->Name; Info++)
873 for (i = 0; i < Length; i++)
875 if (Info->Name[i] != Name[i])
885 printf ("%8s %s\n", Info->Name, Info->Description);
891 printf ("%s, Hardware ID not found\n", Name);
896 /*******************************************************************************
898 * FUNCTION: AhDisplayUuids
904 * DESCRIPTION: Display all known UUIDs.
906 ******************************************************************************/
915 printf ("ACPI-related UUIDs/GUIDs:\n");
917 /* Display entire table of known ACPI-related UUIDs/GUIDs */
919 for (Info = AcpiUuids; Info->Description; Info++)
921 if (!Info->String) /* Null UUID string means group description */
923 printf ("\n%36s\n", Info->Description);
927 printf ("%32s : %s\n", Info->Description, Info->String);
931 /* Help info on how UUIDs/GUIDs strings are encoded */
933 printf ("\n\nByte encoding of UUID/GUID strings"
934 " into ACPI Buffer objects (use ToUUID from ASL):\n\n");
936 printf ("%32s : %s\n", "Input UUID/GUID String format",
937 "aabbccdd-eeff-gghh-iijj-kkllmmnnoopp");
939 printf ("%32s : %s\n", "Expected output ACPI buffer",
940 "dd,cc,bb,aa, ff,ee, hh,gg, ii,jj, kk,ll,mm,nn,oo,pp");
944 /*******************************************************************************
946 * FUNCTION: AhDisplayTables
952 * DESCRIPTION: Display all known ACPI tables
954 ******************************************************************************/
960 const AH_TABLE *Info;
964 printf ("Known ACPI tables:\n");
966 for (Info = AcpiSupportedTables; Info->Signature; Info++)
968 printf ("%8s : %s\n", Info->Signature, Info->Description);
972 printf ("\nTotal %u ACPI tables\n\n", i);
976 /*******************************************************************************
978 * FUNCTION: AhDecodeException
980 * PARAMETERS: HexString - ACPI status string from command line, in
981 * hex. If null, display all exceptions.
985 * DESCRIPTION: Decode and display an ACPI_STATUS exception code.
987 ******************************************************************************/
993 const ACPI_EXCEPTION_INFO *ExceptionInfo;
999 * A null input string means to decode and display all known
1004 printf ("All defined ACPICA exception codes:\n\n");
1005 AH_DISPLAY_EXCEPTION (0, "AE_OK (No error occurred)");
1007 /* Display codes in each block of exception types */
1009 for (i = 1; (i & AE_CODE_MASK) <= AE_CODE_MAX; i += 0x1000)
1014 ExceptionInfo = AcpiUtValidateException ((ACPI_STATUS) Status);
1017 AH_DISPLAY_EXCEPTION_TEXT (Status, ExceptionInfo);
1021 } while (ExceptionInfo);
1026 /* Decode a single user-supplied exception code */
1028 Status = strtoul (HexString, NULL, 16);
1031 printf ("%s: Invalid hexadecimal exception code value\n", HexString);
1035 if (Status > ACPI_UINT16_MAX)
1037 AH_DISPLAY_EXCEPTION (Status, "Invalid exception code (more than 16 bits)");
1041 ExceptionInfo = AcpiUtValidateException ((ACPI_STATUS) Status);
1044 AH_DISPLAY_EXCEPTION (Status, "Unknown exception code");
1048 AH_DISPLAY_EXCEPTION_TEXT (Status, ExceptionInfo);