Home | History | Annotate | Line # | Download | only in acpihelp
ahdecode.c revision 1.1.1.3
      1 /******************************************************************************
      2  *
      3  * Module Name: ahdecode - Operator/Opcode decoding for acpihelp utility
      4  *
      5  *****************************************************************************/
      6 
      7 /*
      8  * Copyright (C) 2000 - 2014, Intel Corp.
      9  * All rights reserved.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     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.
     25  *
     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.
     29  *
     30  * NO WARRANTY
     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.
     42  */
     43 
     44 #define ACPI_CREATE_PREDEFINED_TABLE
     45 #define ACPI_CREATE_RESOURCE_TABLE
     46 
     47 #include "acpihelp.h"
     48 #include "acpredef.h"
     49 
     50 
     51 #define AH_DISPLAY_EXCEPTION(Status, Name) \
     52     printf ("%.4X: %s\n", Status, Name)
     53 
     54 #define AH_DISPLAY_EXCEPTION_TEXT(Status, Exception) \
     55     printf ("%.4X: %-28s (%s)\n", Status, Exception->Name, Exception->Description)
     56 
     57 #define BUFFER_LENGTH           128
     58 #define LINE_BUFFER_LENGTH      512
     59 
     60 static char         Gbl_Buffer[BUFFER_LENGTH];
     61 static char         Gbl_LineBuffer[LINE_BUFFER_LENGTH];
     62 
     63 /* Local prototypes */
     64 
     65 static BOOLEAN
     66 AhDisplayPredefinedName (
     67     char                    *Name,
     68     UINT32                  Length);
     69 
     70 static void
     71 AhDisplayPredefinedInfo (
     72     char                    *Name);
     73 
     74 static void
     75 AhDisplayResourceName (
     76     const ACPI_PREDEFINED_INFO  *ThisName);
     77 
     78 static void
     79 AhDisplayAmlOpcode (
     80     const AH_AML_OPCODE     *Op);
     81 
     82 static void
     83 AhDisplayAslOperator (
     84     const AH_ASL_OPERATOR   *Op);
     85 
     86 static void
     87 AhDisplayOperatorKeywords (
     88     const AH_ASL_OPERATOR   *Op);
     89 
     90 static void
     91 AhDisplayAslKeyword (
     92     const AH_ASL_KEYWORD    *Op);
     93 
     94 static void
     95 AhPrintOneField (
     96     UINT32                  Indent,
     97     UINT32                  CurrentPosition,
     98     UINT32                  MaxPosition,
     99     const char              *Field);
    100 
    101 
    102 /*******************************************************************************
    103  *
    104  * FUNCTION:    AhFindPredefinedNames (entry point for predefined name search)
    105  *
    106  * PARAMETERS:  NamePrefix          - Name or prefix to find. Must start with
    107  *                                    an underscore. NULL means "find all"
    108  *
    109  * RETURN:      None
    110  *
    111  * DESCRIPTION: Find and display all ACPI predefined names that match the
    112  *              input name or prefix. Includes the required number of arguments
    113  *              and the expected return type, if any.
    114  *
    115  ******************************************************************************/
    116 
    117 void
    118 AhFindPredefinedNames (
    119     char                    *NamePrefix)
    120 {
    121     UINT32                  Length;
    122     BOOLEAN                 Found;
    123     char                    Name[9];
    124 
    125 
    126     if (!NamePrefix)
    127     {
    128         Found = AhDisplayPredefinedName (Name, 0);
    129         return;
    130     }
    131 
    132     /* Contruct a local name or name prefix */
    133 
    134     AhStrupr (NamePrefix);
    135     if (*NamePrefix == '_')
    136     {
    137         NamePrefix++;
    138     }
    139 
    140     Name[0] = '_';
    141     strncpy (&Name[1], NamePrefix, 7);
    142 
    143     Length = strlen (Name);
    144     if (Length > 4)
    145     {
    146         printf ("%.8s: Predefined name must be 4 characters maximum\n", Name);
    147         return;
    148     }
    149 
    150     Found = AhDisplayPredefinedName (Name, Length);
    151     if (!Found)
    152     {
    153         printf ("%s, no matching predefined names\n", Name);
    154     }
    155 }
    156 
    157 
    158 /*******************************************************************************
    159  *
    160  * FUNCTION:    AhDisplayPredefinedName
    161  *
    162  * PARAMETERS:  Name                - Name or name prefix
    163  *
    164  * RETURN:      TRUE if any names matched, FALSE otherwise
    165  *
    166  * DESCRIPTION: Display information about ACPI predefined names that match
    167  *              the input name or name prefix.
    168  *
    169  ******************************************************************************/
    170 
    171 static BOOLEAN
    172 AhDisplayPredefinedName (
    173     char                    *Name,
    174     UINT32                  Length)
    175 {
    176     const AH_PREDEFINED_NAME    *Info;
    177     BOOLEAN                     Found = FALSE;
    178     BOOLEAN                     Matched;
    179     UINT32                      i;
    180 
    181 
    182     /* Find/display all names that match the input name prefix */
    183 
    184     for (Info = AslPredefinedInfo; Info->Name; Info++)
    185     {
    186         if (!Name)
    187         {
    188             Found = TRUE;
    189             printf ("%s: <%s>\n", Info->Name, Info->Description);
    190             printf ("%*s%s\n", 6, " ", Info->Action);
    191 
    192             AhDisplayPredefinedInfo (Info->Name);
    193             continue;
    194         }
    195 
    196         Matched = TRUE;
    197         for (i = 0; i < Length; i++)
    198         {
    199             if (Info->Name[i] != Name[i])
    200             {
    201                 Matched = FALSE;
    202                 break;
    203             }
    204         }
    205 
    206         if (Matched)
    207         {
    208             Found = TRUE;
    209             printf ("%s: <%s>\n", Info->Name, Info->Description);
    210             printf ("%*s%s\n", 6, " ", Info->Action);
    211 
    212             AhDisplayPredefinedInfo (Info->Name);
    213         }
    214     }
    215 
    216     return (Found);
    217 }
    218 
    219 
    220 /*******************************************************************************
    221  *
    222  * FUNCTION:    AhDisplayPredefinedInfo
    223  *
    224  * PARAMETERS:  Name                - Exact 4-character ACPI name.
    225  *
    226  * RETURN:      None
    227  *
    228  * DESCRIPTION: Find the name in the main ACPICA predefined info table and
    229  *              display the # of arguments and the return value type.
    230  *
    231  *              Note: Resource Descriptor field names do not appear in this
    232  *              table -- thus, nothing will be displayed for them.
    233  *
    234  ******************************************************************************/
    235 
    236 static void
    237 AhDisplayPredefinedInfo (
    238     char                        *Name)
    239 {
    240     const ACPI_PREDEFINED_INFO  *ThisName;
    241 
    242 
    243     /* NOTE: we check both tables always because there are some dupes */
    244 
    245     /* Check against the predefine methods first */
    246 
    247     ThisName = AcpiUtMatchPredefinedMethod (Name);
    248     if (ThisName)
    249     {
    250         AcpiUtDisplayPredefinedMethod (Gbl_Buffer, ThisName, TRUE);
    251     }
    252 
    253     /* Check against the predefined resource descriptor names */
    254 
    255     ThisName = AcpiUtMatchResourceName (Name);
    256     if (ThisName)
    257     {
    258         AhDisplayResourceName (ThisName);
    259     }
    260 }
    261 
    262 
    263 /*******************************************************************************
    264  *
    265  * FUNCTION:    AhDisplayResourceName
    266  *
    267  * PARAMETERS:  ThisName            - Entry in the predefined method/name table
    268  *
    269  * RETURN:      None
    270  *
    271  * DESCRIPTION: Display information about a resource descriptor name.
    272  *
    273  ******************************************************************************/
    274 
    275 static void
    276 AhDisplayResourceName (
    277     const ACPI_PREDEFINED_INFO  *ThisName)
    278 {
    279     UINT32                      NumTypes;
    280 
    281 
    282     NumTypes = AcpiUtGetResourceBitWidth (Gbl_Buffer,
    283         ThisName->Info.ArgumentList);
    284 
    285     printf ("      %4.4s resource descriptor field is %s bits wide%s\n",
    286         ThisName->Info.Name,
    287         Gbl_Buffer,
    288         (NumTypes > 1) ? " (depending on descriptor type)" : "");
    289 }
    290 
    291 
    292 /*******************************************************************************
    293  *
    294  * FUNCTION:    AhFindAmlOpcode (entry point for AML opcode name search)
    295  *
    296  * PARAMETERS:  Name                - Name or prefix for an AML opcode.
    297  *                                    NULL means "find all"
    298  *
    299  * RETURN:      None
    300  *
    301  * DESCRIPTION: Find all AML opcodes that match the input Name or name
    302  *              prefix.
    303  *
    304  ******************************************************************************/
    305 
    306 void
    307 AhFindAmlOpcode (
    308     char                    *Name)
    309 {
    310     const AH_AML_OPCODE     *Op;
    311     BOOLEAN                 Found = FALSE;
    312 
    313 
    314     AhStrupr (Name);
    315 
    316     /* Find/display all opcode names that match the input name prefix */
    317 
    318     for (Op = AmlOpcodeInfo; Op->OpcodeString; Op++)
    319     {
    320         if (!Op->OpcodeName) /* Unused opcodes */
    321         {
    322             continue;
    323         }
    324 
    325         if (!Name)
    326         {
    327             AhDisplayAmlOpcode (Op);
    328             Found = TRUE;
    329             continue;
    330         }
    331 
    332         /* Upper case the opcode name before substring compare */
    333 
    334         strcpy (Gbl_Buffer, Op->OpcodeName);
    335         AhStrupr (Gbl_Buffer);
    336 
    337         if (strstr (Gbl_Buffer, Name) == Gbl_Buffer)
    338         {
    339             AhDisplayAmlOpcode (Op);
    340             Found = TRUE;
    341         }
    342     }
    343 
    344     if (!Found)
    345     {
    346         printf ("%s, no matching AML operators\n", Name);
    347     }
    348 }
    349 
    350 
    351 /*******************************************************************************
    352  *
    353  * FUNCTION:    AhDecodeAmlOpcode (entry point for AML opcode search)
    354  *
    355  * PARAMETERS:  OpcodeString        - String version of AML opcode
    356  *
    357  * RETURN:      None
    358  *
    359  * DESCRIPTION: Display information about the input AML opcode
    360  *
    361  ******************************************************************************/
    362 
    363 void
    364 AhDecodeAmlOpcode (
    365     char                    *OpcodeString)
    366 {
    367     const AH_AML_OPCODE     *Op;
    368     UINT32                  Opcode;
    369     UINT8                   Prefix;
    370 
    371 
    372     if (!OpcodeString)
    373     {
    374         AhFindAmlOpcode (NULL);
    375         return;
    376     }
    377 
    378     Opcode = ACPI_STRTOUL (OpcodeString, NULL, 16);
    379     if (Opcode > ACPI_UINT16_MAX)
    380     {
    381         printf ("Invalid opcode (more than 16 bits)\n");
    382         return;
    383     }
    384 
    385     /* Only valid opcode extension is 0x5B */
    386 
    387     Prefix = (Opcode & 0x0000FF00) >> 8;
    388     if (Prefix && (Prefix != 0x5B))
    389     {
    390         printf ("Invalid opcode (invalid extension prefix 0x%X)\n",
    391             Prefix);
    392         return;
    393     }
    394 
    395     /* Find/Display the opcode. May fall within an opcode range */
    396 
    397     for (Op = AmlOpcodeInfo; Op->OpcodeString; Op++)
    398     {
    399         if ((Opcode >= Op->OpcodeRangeStart) &&
    400             (Opcode <= Op->OpcodeRangeEnd))
    401         {
    402             AhDisplayAmlOpcode (Op);
    403         }
    404     }
    405 }
    406 
    407 
    408 /*******************************************************************************
    409  *
    410  * FUNCTION:    AhDisplayAmlOpcode
    411  *
    412  * PARAMETERS:  Op                  - An opcode info struct
    413  *
    414  * RETURN:      None
    415  *
    416  * DESCRIPTION: Display the contents of an AML opcode information struct
    417  *
    418  ******************************************************************************/
    419 
    420 static void
    421 AhDisplayAmlOpcode (
    422     const AH_AML_OPCODE     *Op)
    423 {
    424 
    425     if (!Op->OpcodeName)
    426     {
    427         printf ("%18s: Opcode=%-9s\n", "Reserved opcode", Op->OpcodeString);
    428         return;
    429     }
    430 
    431     /* Opcode name and value(s) */
    432 
    433     printf ("%18s: Opcode=%-9s Type (%s)",
    434         Op->OpcodeName, Op->OpcodeString, Op->Type);
    435 
    436     /* Optional fixed/static arguments */
    437 
    438     if (Op->FixedArguments)
    439     {
    440         printf (" FixedArgs (");
    441         AhPrintOneField (37, 36 + 7 + strlen (Op->Type) + 12,
    442             AH_MAX_AML_LINE_LENGTH, Op->FixedArguments);
    443         printf (")");
    444     }
    445 
    446     /* Optional variable-length argument list */
    447 
    448     if (Op->VariableArguments)
    449     {
    450         if (Op->FixedArguments)
    451         {
    452             printf ("\n%*s", 36, " ");
    453         }
    454         printf (" VariableArgs (");
    455         AhPrintOneField (37, 15, AH_MAX_AML_LINE_LENGTH, Op->VariableArguments);
    456         printf (")");
    457     }
    458     printf ("\n");
    459 
    460     /* Grammar specification */
    461 
    462     if (Op->Grammar)
    463     {
    464         AhPrintOneField (37, 0, AH_MAX_AML_LINE_LENGTH, Op->Grammar);
    465         printf ("\n");
    466     }
    467 }
    468 
    469 
    470 /*******************************************************************************
    471  *
    472  * FUNCTION:    AhFindAslKeywords (entry point for ASL keyword search)
    473  *
    474  * PARAMETERS:  Name                - Name or prefix for an ASL keyword.
    475  *                                    NULL means "find all"
    476  *
    477  * RETURN:      None
    478  *
    479  * DESCRIPTION: Find all ASL keywords that match the input Name or name
    480  *              prefix.
    481  *
    482  ******************************************************************************/
    483 
    484 void
    485 AhFindAslKeywords (
    486     char                    *Name)
    487 {
    488     const AH_ASL_KEYWORD    *Keyword;
    489     BOOLEAN                 Found = FALSE;
    490 
    491 
    492     AhStrupr (Name);
    493 
    494     for (Keyword = AslKeywordInfo; Keyword->Name; Keyword++)
    495     {
    496         if (!Name)
    497         {
    498             AhDisplayAslKeyword (Keyword);
    499             Found = TRUE;
    500             continue;
    501         }
    502 
    503         /* Upper case the operator name before substring compare */
    504 
    505         strcpy (Gbl_Buffer, Keyword->Name);
    506         AhStrupr (Gbl_Buffer);
    507 
    508         if (strstr (Gbl_Buffer, Name) == Gbl_Buffer)
    509         {
    510             AhDisplayAslKeyword (Keyword);
    511             Found = TRUE;
    512         }
    513     }
    514 
    515     if (!Found)
    516     {
    517         printf ("%s, no matching ASL keywords\n", Name);
    518     }
    519 }
    520 
    521 
    522 /*******************************************************************************
    523  *
    524  * FUNCTION:    AhDisplayAslKeyword
    525  *
    526  * PARAMETERS:  Op                  - Pointer to ASL keyword with syntax info
    527  *
    528  * RETURN:      None
    529  *
    530  * DESCRIPTION: Format and display syntax info for an ASL keyword. Splits
    531  *              long lines appropriately for reading.
    532  *
    533  ******************************************************************************/
    534 
    535 static void
    536 AhDisplayAslKeyword (
    537     const AH_ASL_KEYWORD    *Op)
    538 {
    539 
    540     /* ASL keyword name and description */
    541 
    542     printf ("%22s: %s\n", Op->Name, Op->Description);
    543     if (!Op->KeywordList)
    544     {
    545         return;
    546     }
    547 
    548     /* List of actual keywords */
    549 
    550     AhPrintOneField (24, 0, AH_MAX_ASL_LINE_LENGTH, Op->KeywordList);
    551     printf ("\n");
    552 }
    553 
    554 
    555 /*******************************************************************************
    556  *
    557  * FUNCTION:    AhFindAslAndAmlOperators
    558  *
    559  * PARAMETERS:  Name                - Name or prefix for an ASL operator.
    560  *                                    NULL means "find all"
    561  *
    562  * RETURN:      None
    563  *
    564  * DESCRIPTION: Find all ASL operators that match the input Name or name
    565  *              prefix. Also displays the AML information if only one entry
    566  *              matches.
    567  *
    568  ******************************************************************************/
    569 
    570 void
    571 AhFindAslAndAmlOperators (
    572     char                    *Name)
    573 {
    574     UINT32                  MatchCount;
    575 
    576 
    577     MatchCount = AhFindAslOperators (Name);
    578     if (MatchCount == 1)
    579     {
    580         AhFindAmlOpcode (Name);
    581     }
    582 }
    583 
    584 
    585 /*******************************************************************************
    586  *
    587  * FUNCTION:    AhFindAslOperators (entry point for ASL operator search)
    588  *
    589  * PARAMETERS:  Name                - Name or prefix for an ASL operator.
    590  *                                    NULL means "find all"
    591  *
    592  * RETURN:      Number of operators that matched the name prefix.
    593  *
    594  * DESCRIPTION: Find all ASL operators that match the input Name or name
    595  *              prefix.
    596  *
    597  ******************************************************************************/
    598 
    599 UINT32
    600 AhFindAslOperators (
    601     char                    *Name)
    602 {
    603     const AH_ASL_OPERATOR   *Operator;
    604     BOOLEAN                 MatchCount = 0;
    605 
    606 
    607     AhStrupr (Name);
    608 
    609     /* Find/display all names that match the input name prefix */
    610 
    611     for (Operator = AslOperatorInfo; Operator->Name; Operator++)
    612     {
    613         if (!Name)
    614         {
    615             AhDisplayAslOperator (Operator);
    616             MatchCount++;
    617             continue;
    618         }
    619 
    620         /* Upper case the operator name before substring compare */
    621 
    622         strcpy (Gbl_Buffer, Operator->Name);
    623         AhStrupr (Gbl_Buffer);
    624 
    625         if (strstr (Gbl_Buffer, Name) == Gbl_Buffer)
    626         {
    627             AhDisplayAslOperator (Operator);
    628             MatchCount++;
    629         }
    630     }
    631 
    632     if (!MatchCount)
    633     {
    634         printf ("%s, no matching ASL operators\n", Name);
    635     }
    636 
    637     return (MatchCount);
    638 }
    639 
    640 
    641 /*******************************************************************************
    642  *
    643  * FUNCTION:    AhDisplayAslOperator
    644  *
    645  * PARAMETERS:  Op                  - Pointer to ASL operator with syntax info
    646  *
    647  * RETURN:      None
    648  *
    649  * DESCRIPTION: Format and display syntax info for an ASL operator. Splits
    650  *              long lines appropriately for reading.
    651  *
    652  ******************************************************************************/
    653 
    654 static void
    655 AhDisplayAslOperator (
    656     const AH_ASL_OPERATOR   *Op)
    657 {
    658 
    659     /* ASL operator name and description */
    660 
    661     printf ("%16s: %s\n", Op->Name, Op->Description);
    662     if (!Op->Syntax)
    663     {
    664         return;
    665     }
    666 
    667     /* Syntax for the operator */
    668 
    669     AhPrintOneField (18, 0, AH_MAX_ASL_LINE_LENGTH, Op->Syntax);
    670     printf ("\n");
    671 
    672     AhDisplayOperatorKeywords (Op);
    673     printf ("\n");
    674 }
    675 
    676 
    677 /*******************************************************************************
    678  *
    679  * FUNCTION:    AhDisplayOperatorKeywords
    680  *
    681  * PARAMETERS:  Op                  - Pointer to ASL keyword with syntax info
    682  *
    683  * RETURN:      None
    684  *
    685  * DESCRIPTION: Display any/all keywords that are associated with the ASL
    686  *              operator.
    687  *
    688  ******************************************************************************/
    689 
    690 static void
    691 AhDisplayOperatorKeywords (
    692     const AH_ASL_OPERATOR   *Op)
    693 {
    694     char                    *Token;
    695     char                    *Separators = "(){}, ";
    696     BOOLEAN                 FirstKeyword = TRUE;
    697 
    698 
    699     if (!Op || !Op->Syntax)
    700     {
    701         return;
    702     }
    703 
    704     /*
    705      * Find all parameters that have the word "keyword" within, and then
    706      * display the info about that keyword
    707      */
    708     strcpy (Gbl_LineBuffer, Op->Syntax);
    709     Token = strtok (Gbl_LineBuffer, Separators);
    710     while (Token)
    711     {
    712         if (strstr (Token, "Keyword"))
    713         {
    714             if (FirstKeyword)
    715             {
    716                 printf ("\n");
    717                 FirstKeyword = FALSE;
    718             }
    719 
    720             /* Found a keyword, display keyword information */
    721 
    722             AhFindAslKeywords (Token);
    723         }
    724 
    725         Token = strtok (NULL, Separators);
    726     }
    727 }
    728 
    729 
    730 /*******************************************************************************
    731  *
    732  * FUNCTION:    AhPrintOneField
    733  *
    734  * PARAMETERS:  Indent              - Indent length for new line(s)
    735  *              CurrentPosition     - Position on current line
    736  *              MaxPosition         - Max allowed line length
    737  *              Field               - Data to output
    738  *
    739  * RETURN:      Line position after field is written
    740  *
    741  * DESCRIPTION: Split long lines appropriately for ease of reading.
    742  *
    743  ******************************************************************************/
    744 
    745 static void
    746 AhPrintOneField (
    747     UINT32                  Indent,
    748     UINT32                  CurrentPosition,
    749     UINT32                  MaxPosition,
    750     const char              *Field)
    751 {
    752     UINT32                  Position;
    753     UINT32                  TokenLength;
    754     const char              *This;
    755     const char              *Next;
    756     const char              *Last;
    757 
    758 
    759     This = Field;
    760     Position = CurrentPosition;
    761 
    762     if (Position == 0)
    763     {
    764         printf ("%*s", (int) Indent, " ");
    765         Position = Indent;
    766     }
    767 
    768     Last = This + strlen (This);
    769     while ((Next = strpbrk (This, " ")))
    770     {
    771         TokenLength = Next - This;
    772         Position += TokenLength;
    773 
    774         /* Split long lines */
    775 
    776         if (Position > MaxPosition)
    777         {
    778             printf ("\n%*s", (int) Indent, " ");
    779             Position = TokenLength;
    780         }
    781 
    782         printf ("%.*s ", (int) TokenLength, This);
    783         This = Next + 1;
    784     }
    785 
    786     /* Handle last token on the input line */
    787 
    788     TokenLength = Last - This;
    789     if (TokenLength > 0)
    790     {
    791         Position += TokenLength;
    792         if (Position > MaxPosition)
    793         {
    794             printf ("\n%*s", (int) Indent, " ");
    795         }
    796         printf ("%s", This);
    797     }
    798 }
    799 
    800 
    801 /*******************************************************************************
    802  *
    803  * FUNCTION:    AhDisplayDeviceIds
    804  *
    805  * PARAMETERS:  Name                - Device Hardware ID string.
    806  *                                    NULL means "find all"
    807  *
    808  * RETURN:      None
    809  *
    810  * DESCRIPTION: Display PNP* and ACPI* device IDs.
    811  *
    812  ******************************************************************************/
    813 
    814 void
    815 AhDisplayDeviceIds (
    816     char                    *Name)
    817 {
    818     const AH_DEVICE_ID      *Info;
    819     UINT32                  Length;
    820     BOOLEAN                 Matched;
    821     UINT32                  i;
    822     BOOLEAN                 Found = FALSE;
    823 
    824 
    825     /* Null input name indicates "display all" */
    826 
    827     if (!Name)
    828     {
    829         printf ("ACPI and PNP Device/Hardware IDs:\n\n");
    830         for (Info = AslDeviceIds; Info->Name; Info++)
    831         {
    832             printf ("%8s   %s\n", Info->Name, Info->Description);
    833         }
    834 
    835         return;
    836     }
    837 
    838     Length = strlen (Name);
    839     if (Length > 8)
    840     {
    841         printf ("%.8s: Hardware ID must be 8 characters maximum\n", Name);
    842         return;
    843     }
    844 
    845     /* Find/display all names that match the input name prefix */
    846 
    847     AhStrupr (Name);
    848     for (Info = AslDeviceIds; Info->Name; Info++)
    849     {
    850         Matched = TRUE;
    851         for (i = 0; i < Length; i++)
    852         {
    853             if (Info->Name[i] != Name[i])
    854             {
    855                 Matched = FALSE;
    856                 break;
    857             }
    858         }
    859 
    860         if (Matched)
    861         {
    862             Found = TRUE;
    863             printf ("%8s   %s\n", Info->Name, Info->Description);
    864         }
    865     }
    866 
    867     if (!Found)
    868     {
    869         printf ("%s, Hardware ID not found\n", Name);
    870     }
    871 }
    872 
    873 
    874 /*******************************************************************************
    875  *
    876  * FUNCTION:    AhDisplayUuids
    877  *
    878  * PARAMETERS:  None
    879  *
    880  * RETURN:      None
    881  *
    882  * DESCRIPTION: Display all known UUIDs.
    883  *
    884  ******************************************************************************/
    885 
    886 void
    887 AhDisplayUuids (
    888     void)
    889 {
    890     const AH_UUID           *Info;
    891 
    892 
    893     printf ("ACPI-related UUIDs:\n\n");
    894 
    895     for (Info = AcpiUuids; Info->Description; Info++)
    896     {
    897         printf ("%32s : %s\n", Info->Description, Info->String);
    898     }
    899 }
    900 
    901 
    902 /*******************************************************************************
    903  *
    904  * FUNCTION:    AhDecodeException
    905  *
    906  * PARAMETERS:  HexString           - ACPI status string from command line, in
    907  *                                    hex. If null, display all exceptions.
    908  *
    909  * RETURN:      None
    910  *
    911  * DESCRIPTION: Decode and display an ACPI_STATUS exception code.
    912  *
    913  ******************************************************************************/
    914 
    915 void
    916 AhDecodeException (
    917     char                    *HexString)
    918 {
    919     const ACPI_EXCEPTION_INFO   *ExceptionInfo;
    920     UINT32                      Status;
    921     UINT32                      i;
    922 
    923 
    924     /*
    925      * A null input string means to decode and display all known
    926      * exception codes.
    927      */
    928     if (!HexString)
    929     {
    930         printf ("All defined ACPICA exception codes:\n\n");
    931         AH_DISPLAY_EXCEPTION (0, "AE_OK                        (No error occurred)");
    932 
    933         /* Display codes in each block of exception types */
    934 
    935         for (i = 1; (i & AE_CODE_MASK) <= AE_CODE_MAX; i += 0x1000)
    936         {
    937             Status = i;
    938             do
    939             {
    940                 ExceptionInfo = AcpiUtValidateException ((ACPI_STATUS) Status);
    941                 if (ExceptionInfo)
    942                 {
    943                     AH_DISPLAY_EXCEPTION_TEXT (Status, ExceptionInfo);
    944                 }
    945                 Status++;
    946 
    947             } while (ExceptionInfo);
    948         }
    949         return;
    950     }
    951 
    952     /* Decode a single user-supplied exception code */
    953 
    954     Status = ACPI_STRTOUL (HexString, NULL, 16);
    955     if (!Status)
    956     {
    957         printf ("%s: Invalid hexadecimal exception code value\n", HexString);
    958         return;
    959     }
    960 
    961     if (Status > ACPI_UINT16_MAX)
    962     {
    963         AH_DISPLAY_EXCEPTION (Status, "Invalid exception code (more than 16 bits)");
    964         return;
    965     }
    966 
    967     ExceptionInfo = AcpiUtValidateException ((ACPI_STATUS) Status);
    968     if (!ExceptionInfo)
    969     {
    970         AH_DISPLAY_EXCEPTION (Status, "Unknown exception code");
    971         return;
    972     }
    973 
    974     AH_DISPLAY_EXCEPTION_TEXT (Status, ExceptionInfo);
    975 }
    976