Home | History | Annotate | Line # | Download | only in acpihelp
ahmain.c revision 1.1.1.6
      1 /******************************************************************************
      2  *
      3  * Module Name: ahmain - Main module for the acpi help utility
      4  *
      5  *****************************************************************************/
      6 
      7 /*
      8  * Copyright (C) 2000 - 2016, 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 #include "acpihelp.h"
     45 
     46 
     47 /* Local prototypes */
     48 
     49 static void
     50 AhDisplayUsage (
     51     void);
     52 
     53 #define AH_UTILITY_NAME             "ACPI Help Utility"
     54 #define AH_SUPPORTED_OPTIONS        "adehikmopstuv"
     55 
     56 
     57 /******************************************************************************
     58  *
     59  * FUNCTION:    AhDisplayUsage
     60  *
     61  * DESCRIPTION: Usage message
     62  *
     63  ******************************************************************************/
     64 
     65 static void
     66 AhDisplayUsage (
     67     void)
     68 {
     69 
     70     ACPI_USAGE_HEADER ("acpihelp <options> [Name/Prefix | HexValue]");
     71     ACPI_OPTION ("-h",                      "Display help");
     72     ACPI_OPTION ("-v",                      "Display version information");
     73 
     74     ACPI_USAGE_TEXT ("\nAML (ACPI Machine Language) Names and Encodings:\n");
     75     ACPI_OPTION ("-a [Name/Prefix]",        "Find/Display both ASL operator and AML opcode name(s)");
     76     ACPI_OPTION ("-m [Name/Prefix]",        "Find/Display AML opcode name(s)");
     77 
     78     ACPI_USAGE_TEXT ("\nACPI Values:\n");
     79     ACPI_OPTION ("-e [HexValue]",           "Decode ACPICA exception code");
     80     ACPI_OPTION ("-o [HexValue]",           "Decode hex AML opcode");
     81 
     82     ACPI_USAGE_TEXT ("\nASL (ACPI Source Language) Names and Symbols:\n");
     83     ACPI_OPTION ("-k [Name/Prefix]",        "Find/Display ASL non-operator keyword(s)");
     84     ACPI_OPTION ("-p [Name/Prefix]",        "Find/Display ASL predefined method name(s)");
     85     ACPI_OPTION ("-s [Name/Prefix]",        "Find/Display ASL operator name(s)");
     86 
     87     ACPI_USAGE_TEXT ("\nOther ACPI Names:\n");
     88     ACPI_OPTION ("-i [Name/Prefix]",        "Find/Display ACPI/PNP Hardware ID(s)");
     89     ACPI_OPTION ("-d",                      "Display iASL Preprocessor directives");
     90     ACPI_OPTION ("-t",                      "Display supported ACPI tables");
     91     ACPI_OPTION ("-u",                      "Display ACPI-related UUIDs");
     92 
     93     ACPI_USAGE_TEXT ("\nName/Prefix or HexValue not specified means \"Display All\"\n");
     94     ACPI_USAGE_TEXT ("\nDefault search with valid Name/Prefix and no options:\n");
     95     ACPI_USAGE_TEXT ("    Find ASL/AML operator names - if NamePrefix does not start with underscore\n");
     96     ACPI_USAGE_TEXT ("    Find ASL predefined method names - if NamePrefix starts with underscore\n");
     97 }
     98 
     99 
    100 /******************************************************************************
    101  *
    102  * FUNCTION:    main
    103  *
    104  * DESCRIPTION: C main function for AcpiHelp utility.
    105  *
    106  ******************************************************************************/
    107 
    108 int ACPI_SYSTEM_XFACE
    109 main (
    110     int                     argc,
    111     char                    *argv[])
    112 {
    113     char                    *Name;
    114     UINT32                  DecodeType;
    115     int                     j;
    116 
    117 
    118     AcpiOsInitialize ();
    119     ACPI_DEBUG_INITIALIZE (); /* For debug version only */
    120     printf (ACPI_COMMON_SIGNON (AH_UTILITY_NAME));
    121     DecodeType = AH_DECODE_DEFAULT;
    122 
    123     if (argc < 2)
    124     {
    125         AhDisplayUsage ();
    126         return (0);
    127     }
    128 
    129     /* Command line options */
    130 
    131     while ((j = AcpiGetopt (argc, argv, AH_SUPPORTED_OPTIONS)) != ACPI_OPT_END) switch (j)
    132     {
    133     case 'a':
    134 
    135         DecodeType = AH_DECODE_ASL_AML;
    136         break;
    137 
    138     case 'd':
    139 
    140         DecodeType = AH_DISPLAY_DIRECTIVES;
    141         break;
    142 
    143     case 'e':
    144 
    145         DecodeType = AH_DECODE_EXCEPTION;
    146         break;
    147 
    148     case 'i':
    149 
    150         DecodeType = AH_DISPLAY_DEVICE_IDS;
    151         break;
    152 
    153     case 'k':
    154 
    155         DecodeType = AH_DECODE_ASL_KEYWORD;
    156         break;
    157 
    158     case 'm':
    159 
    160         DecodeType = AH_DECODE_AML;
    161         break;
    162 
    163     case 'o':
    164 
    165         DecodeType = AH_DECODE_AML_OPCODE;
    166         break;
    167 
    168     case 'p':
    169 
    170         DecodeType = AH_DECODE_PREDEFINED_NAME;
    171         break;
    172 
    173     case 's':
    174 
    175         DecodeType = AH_DECODE_ASL;
    176         break;
    177 
    178     case 't':
    179 
    180         DecodeType = AH_DISPLAY_TABLES;
    181         break;
    182 
    183     case 'u':
    184 
    185         DecodeType = AH_DISPLAY_UUIDS;
    186         break;
    187 
    188     case 'v': /* -v: (Version): signon already emitted, just exit */
    189 
    190         return (0);
    191 
    192     case 'h':
    193     default:
    194 
    195         AhDisplayUsage ();
    196         return (-1);
    197     }
    198 
    199     /* Missing (null) name means "display all" */
    200 
    201     Name = argv[AcpiGbl_Optind];
    202 
    203     switch (DecodeType)
    204     {
    205     case AH_DECODE_ASL_AML:
    206 
    207         AhFindAslAndAmlOperators (Name);
    208         break;
    209 
    210     case AH_DECODE_AML:
    211 
    212         AhFindAmlOpcode (Name);
    213         break;
    214 
    215     case AH_DECODE_AML_OPCODE:
    216 
    217         AhDecodeAmlOpcode (Name);
    218         break;
    219 
    220     case AH_DECODE_PREDEFINED_NAME:
    221 
    222         AhFindPredefinedNames (Name);
    223         break;
    224 
    225     case AH_DECODE_ASL:
    226 
    227         AhFindAslOperators (Name);
    228         break;
    229 
    230     case AH_DECODE_ASL_KEYWORD:
    231 
    232         AhFindAslKeywords (Name);
    233         break;
    234 
    235     case AH_DISPLAY_DEVICE_IDS:
    236 
    237         AhDisplayDeviceIds (Name);
    238         break;
    239 
    240     case AH_DECODE_EXCEPTION:
    241 
    242         AhDecodeException (Name);
    243         break;
    244 
    245     case AH_DISPLAY_UUIDS:
    246 
    247         AhDisplayUuids ();
    248         break;
    249 
    250     case AH_DISPLAY_TABLES:
    251 
    252         AhDisplayTables ();
    253         break;
    254 
    255     case AH_DISPLAY_DIRECTIVES:
    256 
    257         AhDisplayDirectives ();
    258         break;
    259 
    260    default:
    261 
    262         if (!Name)
    263         {
    264             AhFindAslOperators (Name);
    265             break;
    266         }
    267 
    268         if (*Name == '_')
    269         {
    270             AhFindPredefinedNames (Name);
    271         }
    272         else
    273         {
    274             AhFindAslAndAmlOperators (Name);
    275         }
    276         break;
    277     }
    278 
    279     return (0);
    280 }
    281