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