ahaml.c revision 1.1.1.1.8.2 1 1.1.1.1.8.2 bouyer /******************************************************************************
2 1.1.1.1.8.2 bouyer *
3 1.1.1.1.8.2 bouyer * Module Name: ahaml - AML opcode decoding for acpihelp utility
4 1.1.1.1.8.2 bouyer *
5 1.1.1.1.8.2 bouyer *****************************************************************************/
6 1.1.1.1.8.2 bouyer
7 1.1.1.1.8.2 bouyer /*
8 1.1.1.1.8.2 bouyer * Copyright (C) 2000 - 2017, Intel Corp.
9 1.1.1.1.8.2 bouyer * All rights reserved.
10 1.1.1.1.8.2 bouyer *
11 1.1.1.1.8.2 bouyer * Redistribution and use in source and binary forms, with or without
12 1.1.1.1.8.2 bouyer * modification, are permitted provided that the following conditions
13 1.1.1.1.8.2 bouyer * are met:
14 1.1.1.1.8.2 bouyer * 1. Redistributions of source code must retain the above copyright
15 1.1.1.1.8.2 bouyer * notice, this list of conditions, and the following disclaimer,
16 1.1.1.1.8.2 bouyer * without modification.
17 1.1.1.1.8.2 bouyer * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1.1.1.8.2 bouyer * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1.1.1.8.2 bouyer * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1.1.1.8.2 bouyer * including a substantially similar Disclaimer requirement for further
21 1.1.1.1.8.2 bouyer * binary redistribution.
22 1.1.1.1.8.2 bouyer * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1.1.1.8.2 bouyer * of any contributors may be used to endorse or promote products derived
24 1.1.1.1.8.2 bouyer * from this software without specific prior written permission.
25 1.1.1.1.8.2 bouyer *
26 1.1.1.1.8.2 bouyer * Alternatively, this software may be distributed under the terms of the
27 1.1.1.1.8.2 bouyer * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1.1.1.8.2 bouyer * Software Foundation.
29 1.1.1.1.8.2 bouyer *
30 1.1.1.1.8.2 bouyer * NO WARRANTY
31 1.1.1.1.8.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1.1.1.8.2 bouyer * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1.1.1.8.2 bouyer * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1.1.1.8.2 bouyer * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1.1.1.8.2 bouyer * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1.1.1.8.2 bouyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1.1.1.8.2 bouyer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1.1.1.8.2 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1.1.1.8.2 bouyer * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1.1.1.8.2 bouyer * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1.1.1.8.2 bouyer * POSSIBILITY OF SUCH DAMAGES.
42 1.1.1.1.8.2 bouyer */
43 1.1.1.1.8.2 bouyer
44 1.1.1.1.8.2 bouyer #include "acpihelp.h"
45 1.1.1.1.8.2 bouyer
46 1.1.1.1.8.2 bouyer
47 1.1.1.1.8.2 bouyer /* Local prototypes */
48 1.1.1.1.8.2 bouyer
49 1.1.1.1.8.2 bouyer static void
50 1.1.1.1.8.2 bouyer AhDisplayAmlOpcode (
51 1.1.1.1.8.2 bouyer const AH_AML_OPCODE *Op);
52 1.1.1.1.8.2 bouyer
53 1.1.1.1.8.2 bouyer static void
54 1.1.1.1.8.2 bouyer AhDisplayAmlType (
55 1.1.1.1.8.2 bouyer const AH_AML_TYPE *Op);
56 1.1.1.1.8.2 bouyer
57 1.1.1.1.8.2 bouyer
58 1.1.1.1.8.2 bouyer /*******************************************************************************
59 1.1.1.1.8.2 bouyer *
60 1.1.1.1.8.2 bouyer * FUNCTION: AhFindAmlOpcode (entry point for AML opcode name search)
61 1.1.1.1.8.2 bouyer *
62 1.1.1.1.8.2 bouyer * PARAMETERS: Name - Name or prefix for an AML opcode.
63 1.1.1.1.8.2 bouyer * NULL means "find all"
64 1.1.1.1.8.2 bouyer *
65 1.1.1.1.8.2 bouyer * RETURN: None
66 1.1.1.1.8.2 bouyer *
67 1.1.1.1.8.2 bouyer * DESCRIPTION: Find all AML opcodes that match the input Name or name
68 1.1.1.1.8.2 bouyer * prefix.
69 1.1.1.1.8.2 bouyer *
70 1.1.1.1.8.2 bouyer ******************************************************************************/
71 1.1.1.1.8.2 bouyer
72 1.1.1.1.8.2 bouyer void
73 1.1.1.1.8.2 bouyer AhFindAmlOpcode (
74 1.1.1.1.8.2 bouyer char *Name)
75 1.1.1.1.8.2 bouyer {
76 1.1.1.1.8.2 bouyer const AH_AML_OPCODE *Op;
77 1.1.1.1.8.2 bouyer BOOLEAN Found = FALSE;
78 1.1.1.1.8.2 bouyer
79 1.1.1.1.8.2 bouyer
80 1.1.1.1.8.2 bouyer AcpiUtStrupr (Name);
81 1.1.1.1.8.2 bouyer
82 1.1.1.1.8.2 bouyer /* Find/display all opcode names that match the input name prefix */
83 1.1.1.1.8.2 bouyer
84 1.1.1.1.8.2 bouyer for (Op = Gbl_AmlOpcodeInfo; Op->OpcodeString; Op++)
85 1.1.1.1.8.2 bouyer {
86 1.1.1.1.8.2 bouyer if (!Op->OpcodeName) /* Unused opcodes */
87 1.1.1.1.8.2 bouyer {
88 1.1.1.1.8.2 bouyer continue;
89 1.1.1.1.8.2 bouyer }
90 1.1.1.1.8.2 bouyer
91 1.1.1.1.8.2 bouyer if (!Name || (Name[0] == '*'))
92 1.1.1.1.8.2 bouyer {
93 1.1.1.1.8.2 bouyer AhDisplayAmlOpcode (Op);
94 1.1.1.1.8.2 bouyer Found = TRUE;
95 1.1.1.1.8.2 bouyer continue;
96 1.1.1.1.8.2 bouyer }
97 1.1.1.1.8.2 bouyer
98 1.1.1.1.8.2 bouyer /* Upper case the opcode name before substring compare */
99 1.1.1.1.8.2 bouyer
100 1.1.1.1.8.2 bouyer strcpy (Gbl_Buffer, Op->OpcodeName);
101 1.1.1.1.8.2 bouyer AcpiUtStrupr (Gbl_Buffer);
102 1.1.1.1.8.2 bouyer
103 1.1.1.1.8.2 bouyer if (strstr (Gbl_Buffer, Name) == Gbl_Buffer)
104 1.1.1.1.8.2 bouyer {
105 1.1.1.1.8.2 bouyer AhDisplayAmlOpcode (Op);
106 1.1.1.1.8.2 bouyer Found = TRUE;
107 1.1.1.1.8.2 bouyer }
108 1.1.1.1.8.2 bouyer }
109 1.1.1.1.8.2 bouyer
110 1.1.1.1.8.2 bouyer if (!Found)
111 1.1.1.1.8.2 bouyer {
112 1.1.1.1.8.2 bouyer printf ("%s, no matching AML operators\n", Name);
113 1.1.1.1.8.2 bouyer }
114 1.1.1.1.8.2 bouyer }
115 1.1.1.1.8.2 bouyer
116 1.1.1.1.8.2 bouyer
117 1.1.1.1.8.2 bouyer /*******************************************************************************
118 1.1.1.1.8.2 bouyer *
119 1.1.1.1.8.2 bouyer * FUNCTION: AhDecodeAmlOpcode (entry point for AML opcode search)
120 1.1.1.1.8.2 bouyer *
121 1.1.1.1.8.2 bouyer * PARAMETERS: OpcodeString - String version of AML opcode
122 1.1.1.1.8.2 bouyer *
123 1.1.1.1.8.2 bouyer * RETURN: None
124 1.1.1.1.8.2 bouyer *
125 1.1.1.1.8.2 bouyer * DESCRIPTION: Display information about the input AML opcode
126 1.1.1.1.8.2 bouyer *
127 1.1.1.1.8.2 bouyer ******************************************************************************/
128 1.1.1.1.8.2 bouyer
129 1.1.1.1.8.2 bouyer void
130 1.1.1.1.8.2 bouyer AhDecodeAmlOpcode (
131 1.1.1.1.8.2 bouyer char *OpcodeString)
132 1.1.1.1.8.2 bouyer {
133 1.1.1.1.8.2 bouyer const AH_AML_OPCODE *Op;
134 1.1.1.1.8.2 bouyer UINT32 Opcode;
135 1.1.1.1.8.2 bouyer UINT8 Prefix;
136 1.1.1.1.8.2 bouyer
137 1.1.1.1.8.2 bouyer
138 1.1.1.1.8.2 bouyer if (!OpcodeString)
139 1.1.1.1.8.2 bouyer {
140 1.1.1.1.8.2 bouyer AhFindAmlOpcode (NULL);
141 1.1.1.1.8.2 bouyer return;
142 1.1.1.1.8.2 bouyer }
143 1.1.1.1.8.2 bouyer
144 1.1.1.1.8.2 bouyer Opcode = strtoul (OpcodeString, NULL, 16);
145 1.1.1.1.8.2 bouyer if (Opcode > ACPI_UINT16_MAX)
146 1.1.1.1.8.2 bouyer {
147 1.1.1.1.8.2 bouyer printf ("Invalid opcode (more than 16 bits)\n");
148 1.1.1.1.8.2 bouyer return;
149 1.1.1.1.8.2 bouyer }
150 1.1.1.1.8.2 bouyer
151 1.1.1.1.8.2 bouyer /* Only valid opcode extension is 0x5B */
152 1.1.1.1.8.2 bouyer
153 1.1.1.1.8.2 bouyer Prefix = (Opcode & 0x0000FF00) >> 8;
154 1.1.1.1.8.2 bouyer if (Prefix && (Prefix != 0x5B))
155 1.1.1.1.8.2 bouyer {
156 1.1.1.1.8.2 bouyer printf ("Invalid opcode (invalid extension prefix 0x%X)\n",
157 1.1.1.1.8.2 bouyer Prefix);
158 1.1.1.1.8.2 bouyer return;
159 1.1.1.1.8.2 bouyer }
160 1.1.1.1.8.2 bouyer
161 1.1.1.1.8.2 bouyer /* Find/Display the opcode. May fall within an opcode range */
162 1.1.1.1.8.2 bouyer
163 1.1.1.1.8.2 bouyer for (Op = Gbl_AmlOpcodeInfo; Op->OpcodeString; Op++)
164 1.1.1.1.8.2 bouyer {
165 1.1.1.1.8.2 bouyer if ((Opcode >= Op->OpcodeRangeStart) &&
166 1.1.1.1.8.2 bouyer (Opcode <= Op->OpcodeRangeEnd))
167 1.1.1.1.8.2 bouyer {
168 1.1.1.1.8.2 bouyer AhDisplayAmlOpcode (Op);
169 1.1.1.1.8.2 bouyer }
170 1.1.1.1.8.2 bouyer }
171 1.1.1.1.8.2 bouyer }
172 1.1.1.1.8.2 bouyer
173 1.1.1.1.8.2 bouyer
174 1.1.1.1.8.2 bouyer /*******************************************************************************
175 1.1.1.1.8.2 bouyer *
176 1.1.1.1.8.2 bouyer * FUNCTION: AhDisplayAmlOpcode
177 1.1.1.1.8.2 bouyer *
178 1.1.1.1.8.2 bouyer * PARAMETERS: Op - An opcode info struct
179 1.1.1.1.8.2 bouyer *
180 1.1.1.1.8.2 bouyer * RETURN: None
181 1.1.1.1.8.2 bouyer *
182 1.1.1.1.8.2 bouyer * DESCRIPTION: Display the contents of an AML opcode information struct
183 1.1.1.1.8.2 bouyer *
184 1.1.1.1.8.2 bouyer ******************************************************************************/
185 1.1.1.1.8.2 bouyer
186 1.1.1.1.8.2 bouyer static void
187 1.1.1.1.8.2 bouyer AhDisplayAmlOpcode (
188 1.1.1.1.8.2 bouyer const AH_AML_OPCODE *Op)
189 1.1.1.1.8.2 bouyer {
190 1.1.1.1.8.2 bouyer
191 1.1.1.1.8.2 bouyer if (!Op->OpcodeName)
192 1.1.1.1.8.2 bouyer {
193 1.1.1.1.8.2 bouyer printf ("%18s: Opcode=%-9s\n", "Reserved opcode", Op->OpcodeString);
194 1.1.1.1.8.2 bouyer return;
195 1.1.1.1.8.2 bouyer }
196 1.1.1.1.8.2 bouyer
197 1.1.1.1.8.2 bouyer /* Opcode name and value(s) */
198 1.1.1.1.8.2 bouyer
199 1.1.1.1.8.2 bouyer printf ("%18s: Opcode=%-9s Type (%s)",
200 1.1.1.1.8.2 bouyer Op->OpcodeName, Op->OpcodeString, Op->Type);
201 1.1.1.1.8.2 bouyer
202 1.1.1.1.8.2 bouyer /* Optional fixed/static arguments */
203 1.1.1.1.8.2 bouyer
204 1.1.1.1.8.2 bouyer if (Op->FixedArguments)
205 1.1.1.1.8.2 bouyer {
206 1.1.1.1.8.2 bouyer printf (" FixedArgs (");
207 1.1.1.1.8.2 bouyer AhPrintOneField (37, 36 + 7 + strlen (Op->Type) + 12,
208 1.1.1.1.8.2 bouyer AH_MAX_AML_LINE_LENGTH, Op->FixedArguments);
209 1.1.1.1.8.2 bouyer printf (")");
210 1.1.1.1.8.2 bouyer }
211 1.1.1.1.8.2 bouyer
212 1.1.1.1.8.2 bouyer /* Optional variable-length argument list */
213 1.1.1.1.8.2 bouyer
214 1.1.1.1.8.2 bouyer if (Op->VariableArguments)
215 1.1.1.1.8.2 bouyer {
216 1.1.1.1.8.2 bouyer if (Op->FixedArguments)
217 1.1.1.1.8.2 bouyer {
218 1.1.1.1.8.2 bouyer printf ("\n%*s", 36, " ");
219 1.1.1.1.8.2 bouyer }
220 1.1.1.1.8.2 bouyer printf (" VariableArgs (");
221 1.1.1.1.8.2 bouyer AhPrintOneField (37, 15, AH_MAX_AML_LINE_LENGTH, Op->VariableArguments);
222 1.1.1.1.8.2 bouyer printf (")");
223 1.1.1.1.8.2 bouyer }
224 1.1.1.1.8.2 bouyer printf ("\n");
225 1.1.1.1.8.2 bouyer
226 1.1.1.1.8.2 bouyer /* Grammar specification */
227 1.1.1.1.8.2 bouyer
228 1.1.1.1.8.2 bouyer if (Op->Grammar)
229 1.1.1.1.8.2 bouyer {
230 1.1.1.1.8.2 bouyer AhPrintOneField (37, 0, AH_MAX_AML_LINE_LENGTH, Op->Grammar);
231 1.1.1.1.8.2 bouyer printf ("\n");
232 1.1.1.1.8.2 bouyer }
233 1.1.1.1.8.2 bouyer }
234 1.1.1.1.8.2 bouyer
235 1.1.1.1.8.2 bouyer
236 1.1.1.1.8.2 bouyer /*******************************************************************************
237 1.1.1.1.8.2 bouyer *
238 1.1.1.1.8.2 bouyer * FUNCTION: AhFindAmlTypes (entry point for AML grammar keyword search)
239 1.1.1.1.8.2 bouyer *
240 1.1.1.1.8.2 bouyer * PARAMETERS: Name - Name or prefix for an AML grammar element.
241 1.1.1.1.8.2 bouyer * NULL means "find all"
242 1.1.1.1.8.2 bouyer *
243 1.1.1.1.8.2 bouyer * RETURN: None
244 1.1.1.1.8.2 bouyer *
245 1.1.1.1.8.2 bouyer * DESCRIPTION: Find all AML grammar keywords that match the input Name or name
246 1.1.1.1.8.2 bouyer * prefix.
247 1.1.1.1.8.2 bouyer *
248 1.1.1.1.8.2 bouyer ******************************************************************************/
249 1.1.1.1.8.2 bouyer
250 1.1.1.1.8.2 bouyer void
251 1.1.1.1.8.2 bouyer AhFindAmlTypes (
252 1.1.1.1.8.2 bouyer char *Name)
253 1.1.1.1.8.2 bouyer {
254 1.1.1.1.8.2 bouyer const AH_AML_TYPE *Keyword;
255 1.1.1.1.8.2 bouyer BOOLEAN Found = FALSE;
256 1.1.1.1.8.2 bouyer
257 1.1.1.1.8.2 bouyer
258 1.1.1.1.8.2 bouyer AcpiUtStrupr (Name);
259 1.1.1.1.8.2 bouyer
260 1.1.1.1.8.2 bouyer for (Keyword = Gbl_AmlTypesInfo; Keyword->Name; Keyword++)
261 1.1.1.1.8.2 bouyer {
262 1.1.1.1.8.2 bouyer if (!Name)
263 1.1.1.1.8.2 bouyer {
264 1.1.1.1.8.2 bouyer printf (" %s\n", Keyword->Name);
265 1.1.1.1.8.2 bouyer Found = TRUE;
266 1.1.1.1.8.2 bouyer continue;
267 1.1.1.1.8.2 bouyer }
268 1.1.1.1.8.2 bouyer
269 1.1.1.1.8.2 bouyer if (*Name == '*')
270 1.1.1.1.8.2 bouyer {
271 1.1.1.1.8.2 bouyer AhDisplayAmlType (Keyword);
272 1.1.1.1.8.2 bouyer Found = TRUE;
273 1.1.1.1.8.2 bouyer continue;
274 1.1.1.1.8.2 bouyer }
275 1.1.1.1.8.2 bouyer
276 1.1.1.1.8.2 bouyer /* Upper case the operator name before substring compare */
277 1.1.1.1.8.2 bouyer
278 1.1.1.1.8.2 bouyer strcpy (Gbl_Buffer, Keyword->Name);
279 1.1.1.1.8.2 bouyer AcpiUtStrupr (Gbl_Buffer);
280 1.1.1.1.8.2 bouyer
281 1.1.1.1.8.2 bouyer if (strstr (Gbl_Buffer, Name) == Gbl_Buffer)
282 1.1.1.1.8.2 bouyer {
283 1.1.1.1.8.2 bouyer AhDisplayAmlType (Keyword);
284 1.1.1.1.8.2 bouyer Found = TRUE;
285 1.1.1.1.8.2 bouyer }
286 1.1.1.1.8.2 bouyer }
287 1.1.1.1.8.2 bouyer
288 1.1.1.1.8.2 bouyer if (!Found)
289 1.1.1.1.8.2 bouyer {
290 1.1.1.1.8.2 bouyer printf ("%s, no matching AML grammar type\n", Name);
291 1.1.1.1.8.2 bouyer }
292 1.1.1.1.8.2 bouyer }
293 1.1.1.1.8.2 bouyer
294 1.1.1.1.8.2 bouyer
295 1.1.1.1.8.2 bouyer /*******************************************************************************
296 1.1.1.1.8.2 bouyer *
297 1.1.1.1.8.2 bouyer * FUNCTION: AhDisplayAmlType
298 1.1.1.1.8.2 bouyer *
299 1.1.1.1.8.2 bouyer * PARAMETERS: Op - Pointer to AML grammar info
300 1.1.1.1.8.2 bouyer *
301 1.1.1.1.8.2 bouyer * RETURN: None
302 1.1.1.1.8.2 bouyer *
303 1.1.1.1.8.2 bouyer * DESCRIPTION: Format and display info for an AML grammar element.
304 1.1.1.1.8.2 bouyer *
305 1.1.1.1.8.2 bouyer ******************************************************************************/
306 1.1.1.1.8.2 bouyer
307 1.1.1.1.8.2 bouyer static void
308 1.1.1.1.8.2 bouyer AhDisplayAmlType (
309 1.1.1.1.8.2 bouyer const AH_AML_TYPE *Op)
310 1.1.1.1.8.2 bouyer {
311 1.1.1.1.8.2 bouyer char *Description;
312 1.1.1.1.8.2 bouyer
313 1.1.1.1.8.2 bouyer
314 1.1.1.1.8.2 bouyer Description = Op->Description;
315 1.1.1.1.8.2 bouyer printf ("%4s", " "); /* Primary indent */
316 1.1.1.1.8.2 bouyer
317 1.1.1.1.8.2 bouyer /* Emit the entire description string */
318 1.1.1.1.8.2 bouyer
319 1.1.1.1.8.2 bouyer while (*Description)
320 1.1.1.1.8.2 bouyer {
321 1.1.1.1.8.2 bouyer /* Description can be multiple lines, must indent each */
322 1.1.1.1.8.2 bouyer
323 1.1.1.1.8.2 bouyer while (*Description != '\n')
324 1.1.1.1.8.2 bouyer {
325 1.1.1.1.8.2 bouyer printf ("%c", *Description);
326 1.1.1.1.8.2 bouyer Description++;
327 1.1.1.1.8.2 bouyer }
328 1.1.1.1.8.2 bouyer
329 1.1.1.1.8.2 bouyer printf ("\n");
330 1.1.1.1.8.2 bouyer Description++;
331 1.1.1.1.8.2 bouyer
332 1.1.1.1.8.2 bouyer /* Do indent */
333 1.1.1.1.8.2 bouyer
334 1.1.1.1.8.2 bouyer if (*Description)
335 1.1.1.1.8.2 bouyer {
336 1.1.1.1.8.2 bouyer printf ("%8s", " "); /* Secondary indent */
337 1.1.1.1.8.2 bouyer
338 1.1.1.1.8.2 bouyer /* Index extra for a comment */
339 1.1.1.1.8.2 bouyer
340 1.1.1.1.8.2 bouyer if ((Description[0] == '/') &&
341 1.1.1.1.8.2 bouyer (Description[1] == '/'))
342 1.1.1.1.8.2 bouyer {
343 1.1.1.1.8.2 bouyer printf ("%4s", " ");
344 1.1.1.1.8.2 bouyer }
345 1.1.1.1.8.2 bouyer }
346 1.1.1.1.8.2 bouyer }
347 1.1.1.1.8.2 bouyer
348 1.1.1.1.8.2 bouyer printf ("\n");
349 1.1.1.1.8.2 bouyer }
350