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