psloop.c revision 1.1.1.20 1 1.1 jruoho /******************************************************************************
2 1.1 jruoho *
3 1.1 jruoho * Module Name: psloop - Main AML parse loop
4 1.1 jruoho *
5 1.1 jruoho *****************************************************************************/
6 1.1 jruoho
7 1.1.1.19 christos /******************************************************************************
8 1.1.1.19 christos *
9 1.1.1.19 christos * 1. Copyright Notice
10 1.1.1.19 christos *
11 1.1.1.20 christos * Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.
12 1.1 jruoho * All rights reserved.
13 1.1 jruoho *
14 1.1.1.19 christos * 2. License
15 1.1.1.19 christos *
16 1.1.1.19 christos * 2.1. This is your license from Intel Corp. under its intellectual property
17 1.1.1.19 christos * rights. You may have additional license terms from the party that provided
18 1.1.1.19 christos * you this software, covering your right to use that party's intellectual
19 1.1.1.19 christos * property rights.
20 1.1.1.19 christos *
21 1.1.1.19 christos * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 1.1.1.19 christos * copy of the source code appearing in this file ("Covered Code") an
23 1.1.1.19 christos * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 1.1.1.19 christos * base code distributed originally by Intel ("Original Intel Code") to copy,
25 1.1.1.19 christos * make derivatives, distribute, use and display any portion of the Covered
26 1.1.1.19 christos * Code in any form, with the right to sublicense such rights; and
27 1.1.1.19 christos *
28 1.1.1.19 christos * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 1.1.1.19 christos * license (with the right to sublicense), under only those claims of Intel
30 1.1.1.19 christos * patents that are infringed by the Original Intel Code, to make, use, sell,
31 1.1.1.19 christos * offer to sell, and import the Covered Code and derivative works thereof
32 1.1.1.19 christos * solely to the minimum extent necessary to exercise the above copyright
33 1.1.1.19 christos * license, and in no event shall the patent license extend to any additions
34 1.1.1.19 christos * to or modifications of the Original Intel Code. No other license or right
35 1.1.1.19 christos * is granted directly or by implication, estoppel or otherwise;
36 1.1.1.19 christos *
37 1.1.1.19 christos * The above copyright and patent license is granted only if the following
38 1.1.1.19 christos * conditions are met:
39 1.1.1.19 christos *
40 1.1.1.19 christos * 3. Conditions
41 1.1.1.19 christos *
42 1.1.1.19 christos * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 1.1.1.19 christos * Redistribution of source code of any substantial portion of the Covered
44 1.1.1.19 christos * Code or modification with rights to further distribute source must include
45 1.1.1.19 christos * the above Copyright Notice, the above License, this list of Conditions,
46 1.1.1.19 christos * and the following Disclaimer and Export Compliance provision. In addition,
47 1.1.1.19 christos * Licensee must cause all Covered Code to which Licensee contributes to
48 1.1.1.19 christos * contain a file documenting the changes Licensee made to create that Covered
49 1.1.1.19 christos * Code and the date of any change. Licensee must include in that file the
50 1.1.1.19 christos * documentation of any changes made by any predecessor Licensee. Licensee
51 1.1.1.19 christos * must include a prominent statement that the modification is derived,
52 1.1.1.19 christos * directly or indirectly, from Original Intel Code.
53 1.1.1.19 christos *
54 1.1.1.19 christos * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 1.1.1.19 christos * Redistribution of source code of any substantial portion of the Covered
56 1.1.1.19 christos * Code or modification without rights to further distribute source must
57 1.1.1.19 christos * include the following Disclaimer and Export Compliance provision in the
58 1.1.1.19 christos * documentation and/or other materials provided with distribution. In
59 1.1.1.19 christos * addition, Licensee may not authorize further sublicense of source of any
60 1.1.1.19 christos * portion of the Covered Code, and must include terms to the effect that the
61 1.1.1.19 christos * license from Licensee to its licensee is limited to the intellectual
62 1.1.1.19 christos * property embodied in the software Licensee provides to its licensee, and
63 1.1.1.19 christos * not to intellectual property embodied in modifications its licensee may
64 1.1.1.19 christos * make.
65 1.1.1.19 christos *
66 1.1.1.19 christos * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 1.1.1.19 christos * substantial portion of the Covered Code or modification must reproduce the
68 1.1.1.19 christos * above Copyright Notice, and the following Disclaimer and Export Compliance
69 1.1.1.19 christos * provision in the documentation and/or other materials provided with the
70 1.1.1.19 christos * distribution.
71 1.1.1.19 christos *
72 1.1.1.19 christos * 3.4. Intel retains all right, title, and interest in and to the Original
73 1.1.1.19 christos * Intel Code.
74 1.1.1.19 christos *
75 1.1.1.19 christos * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 1.1.1.19 christos * Intel shall be used in advertising or otherwise to promote the sale, use or
77 1.1.1.19 christos * other dealings in products derived from or relating to the Covered Code
78 1.1.1.19 christos * without prior written authorization from Intel.
79 1.1.1.19 christos *
80 1.1.1.19 christos * 4. Disclaimer and Export Compliance
81 1.1.1.19 christos *
82 1.1.1.19 christos * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 1.1.1.19 christos * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 1.1.1.19 christos * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 1.1.1.19 christos * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 1.1.1.19 christos * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 1.1.1.19 christos * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88 1.1.1.19 christos * PARTICULAR PURPOSE.
89 1.1.1.19 christos *
90 1.1.1.19 christos * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 1.1.1.19 christos * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 1.1.1.19 christos * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 1.1.1.19 christos * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 1.1.1.19 christos * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 1.1.1.19 christos * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 1.1.1.19 christos * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97 1.1.1.19 christos * LIMITED REMEDY.
98 1.1.1.19 christos *
99 1.1.1.19 christos * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 1.1.1.19 christos * software or system incorporating such software without first obtaining any
101 1.1.1.19 christos * required license or other approval from the U. S. Department of Commerce or
102 1.1.1.19 christos * any other agency or department of the United States Government. In the
103 1.1.1.19 christos * event Licensee exports any such software from the United States or
104 1.1.1.19 christos * re-exports any such software from a foreign destination, Licensee shall
105 1.1.1.19 christos * ensure that the distribution and export/re-export of the software is in
106 1.1.1.19 christos * compliance with all laws, regulations, orders, or other restrictions of the
107 1.1.1.19 christos * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 1.1.1.19 christos * any of its subsidiaries will export/re-export any technical data, process,
109 1.1.1.19 christos * software, or service, directly or indirectly, to any country for which the
110 1.1.1.19 christos * United States government or any agency thereof requires an export license,
111 1.1.1.19 christos * other governmental approval, or letter of assurance, without first obtaining
112 1.1.1.19 christos * such license, approval or letter.
113 1.1.1.19 christos *
114 1.1.1.19 christos *****************************************************************************
115 1.1.1.19 christos *
116 1.1.1.19 christos * Alternatively, you may choose to be licensed under the terms of the
117 1.1.1.19 christos * following license:
118 1.1.1.19 christos *
119 1.1.1.2 jruoho * Redistribution and use in source and binary forms, with or without
120 1.1.1.2 jruoho * modification, are permitted provided that the following conditions
121 1.1.1.2 jruoho * are met:
122 1.1.1.2 jruoho * 1. Redistributions of source code must retain the above copyright
123 1.1.1.2 jruoho * notice, this list of conditions, and the following disclaimer,
124 1.1.1.2 jruoho * without modification.
125 1.1.1.2 jruoho * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 1.1.1.2 jruoho * substantially similar to the "NO WARRANTY" disclaimer below
127 1.1.1.2 jruoho * ("Disclaimer") and any redistribution must be conditioned upon
128 1.1.1.2 jruoho * including a substantially similar Disclaimer requirement for further
129 1.1.1.2 jruoho * binary redistribution.
130 1.1.1.2 jruoho * 3. Neither the names of the above-listed copyright holders nor the names
131 1.1.1.2 jruoho * of any contributors may be used to endorse or promote products derived
132 1.1.1.2 jruoho * from this software without specific prior written permission.
133 1.1.1.2 jruoho *
134 1.1.1.2 jruoho * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 1.1.1.2 jruoho * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 1.1.1.16 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 1.1.1.2 jruoho * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 1.1.1.19 christos * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 1.1.1.19 christos * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 1.1.1.19 christos * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 1.1.1.19 christos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 1.1.1.19 christos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 1.1.1.19 christos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 1.1.1.19 christos * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145 1.1.1.19 christos *
146 1.1.1.19 christos * Alternatively, you may choose to be licensed under the terms of the
147 1.1.1.19 christos * GNU General Public License ("GPL") version 2 as published by the Free
148 1.1.1.19 christos * Software Foundation.
149 1.1.1.19 christos *
150 1.1.1.19 christos *****************************************************************************/
151 1.1 jruoho
152 1.1 jruoho /*
153 1.1 jruoho * Parse the AML and build an operation tree as most interpreters, (such as
154 1.1 jruoho * Perl) do. Parsing is done by hand rather than with a YACC generated parser
155 1.1 jruoho * to tightly constrain stack and dynamic memory usage. Parsing is kept
156 1.1 jruoho * flexible and the code fairly compact by parsing based on a list of AML
157 1.1 jruoho * opcode templates in AmlOpInfo[].
158 1.1 jruoho */
159 1.1 jruoho
160 1.1 jruoho #include "acpi.h"
161 1.1 jruoho #include "accommon.h"
162 1.1.1.6 christos #include "acinterp.h"
163 1.1 jruoho #include "acparser.h"
164 1.1 jruoho #include "acdispat.h"
165 1.1 jruoho #include "amlcode.h"
166 1.1.1.9 christos #include "acconvert.h"
167 1.1.1.12 christos #include "acnamesp.h"
168 1.1 jruoho
169 1.1 jruoho #define _COMPONENT ACPI_PARSER
170 1.1 jruoho ACPI_MODULE_NAME ("psloop")
171 1.1 jruoho
172 1.1 jruoho
173 1.1 jruoho /* Local prototypes */
174 1.1 jruoho
175 1.1 jruoho static ACPI_STATUS
176 1.1 jruoho AcpiPsGetArguments (
177 1.1 jruoho ACPI_WALK_STATE *WalkState,
178 1.1 jruoho UINT8 *AmlOpStart,
179 1.1 jruoho ACPI_PARSE_OBJECT *Op);
180 1.1 jruoho
181 1.1 jruoho
182 1.1 jruoho /*******************************************************************************
183 1.1 jruoho *
184 1.1 jruoho * FUNCTION: AcpiPsGetArguments
185 1.1 jruoho *
186 1.1 jruoho * PARAMETERS: WalkState - Current state
187 1.1 jruoho * AmlOpStart - Op start in AML
188 1.1 jruoho * Op - Current Op
189 1.1 jruoho *
190 1.1 jruoho * RETURN: Status
191 1.1 jruoho *
192 1.1 jruoho * DESCRIPTION: Get arguments for passed Op.
193 1.1 jruoho *
194 1.1 jruoho ******************************************************************************/
195 1.1 jruoho
196 1.1 jruoho static ACPI_STATUS
197 1.1 jruoho AcpiPsGetArguments (
198 1.1 jruoho ACPI_WALK_STATE *WalkState,
199 1.1 jruoho UINT8 *AmlOpStart,
200 1.1 jruoho ACPI_PARSE_OBJECT *Op)
201 1.1 jruoho {
202 1.1 jruoho ACPI_STATUS Status = AE_OK;
203 1.1 jruoho ACPI_PARSE_OBJECT *Arg = NULL;
204 1.1 jruoho
205 1.1 jruoho
206 1.1 jruoho ACPI_FUNCTION_TRACE_PTR (PsGetArguments, WalkState);
207 1.1 jruoho
208 1.1 jruoho
209 1.1.1.8 christos ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
210 1.1.1.8 christos "Get arguments for opcode [%s]\n", Op->Common.AmlOpName));
211 1.1.1.8 christos
212 1.1 jruoho switch (Op->Common.AmlOpcode)
213 1.1 jruoho {
214 1.1 jruoho case AML_BYTE_OP: /* AML_BYTEDATA_ARG */
215 1.1 jruoho case AML_WORD_OP: /* AML_WORDDATA_ARG */
216 1.1 jruoho case AML_DWORD_OP: /* AML_DWORDATA_ARG */
217 1.1 jruoho case AML_QWORD_OP: /* AML_QWORDATA_ARG */
218 1.1 jruoho case AML_STRING_OP: /* AML_ASCIICHARLIST_ARG */
219 1.1 jruoho
220 1.1 jruoho /* Fill in constant or string argument directly */
221 1.1 jruoho
222 1.1 jruoho AcpiPsGetNextSimpleArg (&(WalkState->ParserState),
223 1.1 jruoho GET_CURRENT_ARG_TYPE (WalkState->ArgTypes), Op);
224 1.1 jruoho break;
225 1.1 jruoho
226 1.1 jruoho case AML_INT_NAMEPATH_OP: /* AML_NAMESTRING_ARG */
227 1.1 jruoho
228 1.1.1.7 christos Status = AcpiPsGetNextNamepath (WalkState,
229 1.1.1.7 christos &(WalkState->ParserState), Op, ACPI_POSSIBLE_METHOD_CALL);
230 1.1 jruoho if (ACPI_FAILURE (Status))
231 1.1 jruoho {
232 1.1 jruoho return_ACPI_STATUS (Status);
233 1.1 jruoho }
234 1.1 jruoho
235 1.1 jruoho WalkState->ArgTypes = 0;
236 1.1 jruoho break;
237 1.1 jruoho
238 1.1 jruoho default:
239 1.1 jruoho /*
240 1.1 jruoho * Op is not a constant or string, append each argument to the Op
241 1.1 jruoho */
242 1.1.1.7 christos while (GET_CURRENT_ARG_TYPE (WalkState->ArgTypes) &&
243 1.1.1.7 christos !WalkState->ArgCount)
244 1.1 jruoho {
245 1.1.1.6 christos WalkState->Aml = WalkState->ParserState.Aml;
246 1.1 jruoho
247 1.1.1.9 christos switch (Op->Common.AmlOpcode)
248 1.1.1.9 christos {
249 1.1.1.9 christos case AML_METHOD_OP:
250 1.1.1.9 christos case AML_BUFFER_OP:
251 1.1.1.9 christos case AML_PACKAGE_OP:
252 1.1.1.9 christos case AML_VARIABLE_PACKAGE_OP:
253 1.1.1.9 christos case AML_WHILE_OP:
254 1.1.1.9 christos
255 1.1.1.9 christos break;
256 1.1.1.9 christos
257 1.1.1.9 christos default:
258 1.1.1.9 christos
259 1.1.1.9 christos ASL_CV_CAPTURE_COMMENTS (WalkState);
260 1.1.1.9 christos break;
261 1.1.1.9 christos }
262 1.1.1.9 christos
263 1.1 jruoho Status = AcpiPsGetNextArg (WalkState, &(WalkState->ParserState),
264 1.1.1.7 christos GET_CURRENT_ARG_TYPE (WalkState->ArgTypes), &Arg);
265 1.1 jruoho if (ACPI_FAILURE (Status))
266 1.1 jruoho {
267 1.1 jruoho return_ACPI_STATUS (Status);
268 1.1 jruoho }
269 1.1 jruoho
270 1.1 jruoho if (Arg)
271 1.1 jruoho {
272 1.1 jruoho AcpiPsAppendArg (Op, Arg);
273 1.1 jruoho }
274 1.1 jruoho
275 1.1 jruoho INCREMENT_ARG_LIST (WalkState->ArgTypes);
276 1.1 jruoho }
277 1.1 jruoho
278 1.1.1.10 christos ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
279 1.1.1.11 christos "Final argument count: %8.8X pass %u\n",
280 1.1.1.10 christos WalkState->ArgCount, WalkState->PassNumber));
281 1.1 jruoho
282 1.1 jruoho /* Special processing for certain opcodes */
283 1.1 jruoho
284 1.1 jruoho switch (Op->Common.AmlOpcode)
285 1.1 jruoho {
286 1.1 jruoho case AML_METHOD_OP:
287 1.1 jruoho /*
288 1.1 jruoho * Skip parsing of control method because we don't have enough
289 1.1 jruoho * info in the first pass to parse it correctly.
290 1.1 jruoho *
291 1.1 jruoho * Save the length and address of the body
292 1.1 jruoho */
293 1.1 jruoho Op->Named.Data = WalkState->ParserState.Aml;
294 1.1 jruoho Op->Named.Length = (UINT32)
295 1.1 jruoho (WalkState->ParserState.PkgEnd - WalkState->ParserState.Aml);
296 1.1 jruoho
297 1.1 jruoho /* Skip body of method */
298 1.1 jruoho
299 1.1 jruoho WalkState->ParserState.Aml = WalkState->ParserState.PkgEnd;
300 1.1 jruoho WalkState->ArgCount = 0;
301 1.1 jruoho break;
302 1.1 jruoho
303 1.1 jruoho case AML_BUFFER_OP:
304 1.1 jruoho case AML_PACKAGE_OP:
305 1.1.1.9 christos case AML_VARIABLE_PACKAGE_OP:
306 1.1 jruoho
307 1.1 jruoho if ((Op->Common.Parent) &&
308 1.1 jruoho (Op->Common.Parent->Common.AmlOpcode == AML_NAME_OP) &&
309 1.1 jruoho (WalkState->PassNumber <= ACPI_IMODE_LOAD_PASS2))
310 1.1 jruoho {
311 1.1.1.10 christos ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
312 1.1.1.10 christos "Setup Package/Buffer: Pass %u, AML Ptr: %p\n",
313 1.1.1.10 christos WalkState->PassNumber, AmlOpStart));
314 1.1.1.10 christos
315 1.1 jruoho /*
316 1.1 jruoho * Skip parsing of Buffers and Packages because we don't have
317 1.1 jruoho * enough info in the first pass to parse them correctly.
318 1.1 jruoho */
319 1.1 jruoho Op->Named.Data = AmlOpStart;
320 1.1 jruoho Op->Named.Length = (UINT32)
321 1.1 jruoho (WalkState->ParserState.PkgEnd - AmlOpStart);
322 1.1 jruoho
323 1.1 jruoho /* Skip body */
324 1.1 jruoho
325 1.1 jruoho WalkState->ParserState.Aml = WalkState->ParserState.PkgEnd;
326 1.1 jruoho WalkState->ArgCount = 0;
327 1.1 jruoho }
328 1.1 jruoho break;
329 1.1 jruoho
330 1.1 jruoho case AML_WHILE_OP:
331 1.1 jruoho
332 1.1 jruoho if (WalkState->ControlState)
333 1.1 jruoho {
334 1.1 jruoho WalkState->ControlState->Control.PackageEnd =
335 1.1 jruoho WalkState->ParserState.PkgEnd;
336 1.1 jruoho }
337 1.1 jruoho break;
338 1.1 jruoho
339 1.1 jruoho default:
340 1.1 jruoho
341 1.1 jruoho /* No action for all other opcodes */
342 1.1.1.3 christos
343 1.1 jruoho break;
344 1.1 jruoho }
345 1.1 jruoho
346 1.1 jruoho break;
347 1.1 jruoho }
348 1.1 jruoho
349 1.1 jruoho return_ACPI_STATUS (AE_OK);
350 1.1 jruoho }
351 1.1 jruoho
352 1.1 jruoho
353 1.1 jruoho /*******************************************************************************
354 1.1 jruoho *
355 1.1 jruoho * FUNCTION: AcpiPsParseLoop
356 1.1 jruoho *
357 1.1 jruoho * PARAMETERS: WalkState - Current state
358 1.1 jruoho *
359 1.1 jruoho * RETURN: Status
360 1.1 jruoho *
361 1.1 jruoho * DESCRIPTION: Parse AML (pointed to by the current parser state) and return
362 1.1 jruoho * a tree of ops.
363 1.1 jruoho *
364 1.1 jruoho ******************************************************************************/
365 1.1 jruoho
366 1.1 jruoho ACPI_STATUS
367 1.1 jruoho AcpiPsParseLoop (
368 1.1 jruoho ACPI_WALK_STATE *WalkState)
369 1.1 jruoho {
370 1.1 jruoho ACPI_STATUS Status = AE_OK;
371 1.1 jruoho ACPI_PARSE_OBJECT *Op = NULL; /* current op */
372 1.1 jruoho ACPI_PARSE_STATE *ParserState;
373 1.1 jruoho UINT8 *AmlOpStart = NULL;
374 1.1.1.13 christos UINT8 OpcodeLength;
375 1.1 jruoho
376 1.1 jruoho
377 1.1 jruoho ACPI_FUNCTION_TRACE_PTR (PsParseLoop, WalkState);
378 1.1 jruoho
379 1.1 jruoho
380 1.1 jruoho if (WalkState->DescendingCallback == NULL)
381 1.1 jruoho {
382 1.1 jruoho return_ACPI_STATUS (AE_BAD_PARAMETER);
383 1.1 jruoho }
384 1.1 jruoho
385 1.1 jruoho ParserState = &WalkState->ParserState;
386 1.1 jruoho WalkState->ArgTypes = 0;
387 1.1 jruoho
388 1.1.1.13 christos #ifndef ACPI_CONSTANT_EVAL_ONLY
389 1.1 jruoho
390 1.1 jruoho if (WalkState->WalkType & ACPI_WALK_METHOD_RESTART)
391 1.1 jruoho {
392 1.1 jruoho /* We are restarting a preempted control method */
393 1.1 jruoho
394 1.1 jruoho if (AcpiPsHasCompletedScope (ParserState))
395 1.1 jruoho {
396 1.1 jruoho /*
397 1.1 jruoho * We must check if a predicate to an IF or WHILE statement
398 1.1 jruoho * was just completed
399 1.1 jruoho */
400 1.1 jruoho if ((ParserState->Scope->ParseScope.Op) &&
401 1.1 jruoho ((ParserState->Scope->ParseScope.Op->Common.AmlOpcode == AML_IF_OP) ||
402 1.1 jruoho (ParserState->Scope->ParseScope.Op->Common.AmlOpcode == AML_WHILE_OP)) &&
403 1.1 jruoho (WalkState->ControlState) &&
404 1.1 jruoho (WalkState->ControlState->Common.State ==
405 1.1 jruoho ACPI_CONTROL_PREDICATE_EXECUTING))
406 1.1 jruoho {
407 1.1 jruoho /*
408 1.1 jruoho * A predicate was just completed, get the value of the
409 1.1 jruoho * predicate and branch based on that value
410 1.1 jruoho */
411 1.1 jruoho WalkState->Op = NULL;
412 1.1 jruoho Status = AcpiDsGetPredicateValue (WalkState, ACPI_TO_POINTER (TRUE));
413 1.1.1.16 christos if (ACPI_FAILURE (Status) && !ACPI_CNTL_EXCEPTION (Status))
414 1.1 jruoho {
415 1.1 jruoho if (Status == AE_AML_NO_RETURN_VALUE)
416 1.1 jruoho {
417 1.1 jruoho ACPI_EXCEPTION ((AE_INFO, Status,
418 1.1 jruoho "Invoked method did not return a value"));
419 1.1 jruoho }
420 1.1 jruoho
421 1.1 jruoho ACPI_EXCEPTION ((AE_INFO, Status, "GetPredicate Failed"));
422 1.1 jruoho return_ACPI_STATUS (Status);
423 1.1 jruoho }
424 1.1 jruoho
425 1.1 jruoho Status = AcpiPsNextParseState (WalkState, Op, Status);
426 1.1 jruoho }
427 1.1 jruoho
428 1.1 jruoho AcpiPsPopScope (ParserState, &Op,
429 1.1 jruoho &WalkState->ArgTypes, &WalkState->ArgCount);
430 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Popped scope, Op=%p\n", Op));
431 1.1 jruoho }
432 1.1 jruoho else if (WalkState->PrevOp)
433 1.1 jruoho {
434 1.1 jruoho /* We were in the middle of an op */
435 1.1 jruoho
436 1.1 jruoho Op = WalkState->PrevOp;
437 1.1 jruoho WalkState->ArgTypes = WalkState->PrevArgTypes;
438 1.1 jruoho }
439 1.1 jruoho }
440 1.1 jruoho #endif
441 1.1 jruoho
442 1.1 jruoho /* Iterative parsing loop, while there is more AML to process: */
443 1.1 jruoho
444 1.1 jruoho while ((ParserState->Aml < ParserState->AmlEnd) || (Op))
445 1.1 jruoho {
446 1.1.1.9 christos ASL_CV_CAPTURE_COMMENTS (WalkState);
447 1.1.1.9 christos
448 1.1 jruoho AmlOpStart = ParserState->Aml;
449 1.1 jruoho if (!Op)
450 1.1 jruoho {
451 1.1 jruoho Status = AcpiPsCreateOp (WalkState, AmlOpStart, &Op);
452 1.1 jruoho if (ACPI_FAILURE (Status))
453 1.1 jruoho {
454 1.1.1.12 christos /*
455 1.1.1.12 christos * ACPI_PARSE_MODULE_LEVEL means that we are loading a table by
456 1.1.1.12 christos * executing it as a control method. However, if we encounter
457 1.1.1.12 christos * an error while loading the table, we need to keep trying to
458 1.1.1.12 christos * load the table rather than aborting the table load. Set the
459 1.1.1.12 christos * status to AE_OK to proceed with the table load.
460 1.1.1.12 christos */
461 1.1.1.12 christos if ((WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL) &&
462 1.1.1.13 christos ((Status == AE_ALREADY_EXISTS) || (Status == AE_NOT_FOUND)))
463 1.1.1.12 christos {
464 1.1.1.12 christos Status = AE_OK;
465 1.1.1.12 christos }
466 1.1 jruoho if (Status == AE_CTRL_PARSE_CONTINUE)
467 1.1 jruoho {
468 1.1 jruoho continue;
469 1.1 jruoho }
470 1.1 jruoho
471 1.1 jruoho if (Status == AE_CTRL_PARSE_PENDING)
472 1.1 jruoho {
473 1.1 jruoho Status = AE_OK;
474 1.1 jruoho }
475 1.1 jruoho
476 1.1.1.4 christos if (Status == AE_CTRL_TERMINATE)
477 1.1.1.4 christos {
478 1.1.1.4 christos return_ACPI_STATUS (Status);
479 1.1.1.4 christos }
480 1.1.1.4 christos
481 1.1 jruoho Status = AcpiPsCompleteOp (WalkState, &Op, Status);
482 1.1 jruoho if (ACPI_FAILURE (Status))
483 1.1 jruoho {
484 1.1 jruoho return_ACPI_STATUS (Status);
485 1.1 jruoho }
486 1.1.1.12 christos if (AcpiNsOpensScope (
487 1.1.1.12 christos AcpiPsGetOpcodeInfo (WalkState->Opcode)->ObjectType))
488 1.1.1.12 christos {
489 1.1.1.12 christos /*
490 1.1.1.12 christos * If the scope/device op fails to parse, skip the body of
491 1.1.1.12 christos * the scope op because the parse failure indicates that
492 1.1.1.12 christos * the device may not exist.
493 1.1.1.12 christos */
494 1.1.1.13 christos ACPI_INFO (("Skipping parse of AML opcode: %s (0x%4.4X)",
495 1.1.1.13 christos AcpiPsGetOpcodeName (WalkState->Opcode), WalkState->Opcode));
496 1.1.1.13 christos
497 1.1.1.13 christos /*
498 1.1.1.13 christos * Determine the opcode length before skipping the opcode.
499 1.1.1.13 christos * An opcode can be 1 byte or 2 bytes in length.
500 1.1.1.13 christos */
501 1.1.1.13 christos OpcodeLength = 1;
502 1.1.1.13 christos if ((WalkState->Opcode & 0xFF00) == AML_EXTENDED_OPCODE)
503 1.1.1.13 christos {
504 1.1.1.13 christos OpcodeLength = 2;
505 1.1.1.13 christos }
506 1.1.1.13 christos WalkState->ParserState.Aml = WalkState->Aml + OpcodeLength;
507 1.1.1.13 christos
508 1.1.1.12 christos WalkState->ParserState.Aml =
509 1.1.1.12 christos AcpiPsGetNextPackageEnd(&WalkState->ParserState);
510 1.1.1.12 christos WalkState->Aml = WalkState->ParserState.Aml;
511 1.1.1.12 christos }
512 1.1 jruoho
513 1.1 jruoho continue;
514 1.1 jruoho }
515 1.1 jruoho
516 1.1.1.6 christos AcpiExStartTraceOpcode (Op, WalkState);
517 1.1 jruoho }
518 1.1 jruoho
519 1.1 jruoho /*
520 1.1 jruoho * Start ArgCount at zero because we don't know if there are
521 1.1 jruoho * any args yet
522 1.1 jruoho */
523 1.1.1.9 christos WalkState->ArgCount = 0;
524 1.1.1.9 christos
525 1.1.1.9 christos switch (Op->Common.AmlOpcode)
526 1.1.1.9 christos {
527 1.1.1.9 christos case AML_BYTE_OP:
528 1.1.1.9 christos case AML_WORD_OP:
529 1.1.1.9 christos case AML_DWORD_OP:
530 1.1.1.9 christos case AML_QWORD_OP:
531 1.1.1.9 christos
532 1.1.1.9 christos break;
533 1.1.1.9 christos
534 1.1.1.9 christos default:
535 1.1.1.9 christos
536 1.1.1.9 christos ASL_CV_CAPTURE_COMMENTS (WalkState);
537 1.1.1.9 christos break;
538 1.1.1.9 christos }
539 1.1 jruoho
540 1.1 jruoho /* Are there any arguments that must be processed? */
541 1.1 jruoho
542 1.1 jruoho if (WalkState->ArgTypes)
543 1.1 jruoho {
544 1.1 jruoho /* Get arguments */
545 1.1 jruoho
546 1.1 jruoho Status = AcpiPsGetArguments (WalkState, AmlOpStart, Op);
547 1.1 jruoho if (ACPI_FAILURE (Status))
548 1.1 jruoho {
549 1.1 jruoho Status = AcpiPsCompleteOp (WalkState, &Op, Status);
550 1.1 jruoho if (ACPI_FAILURE (Status))
551 1.1 jruoho {
552 1.1 jruoho return_ACPI_STATUS (Status);
553 1.1 jruoho }
554 1.1.1.12 christos if ((WalkState->ControlState) &&
555 1.1.1.12 christos ((WalkState->ControlState->Control.Opcode == AML_IF_OP) ||
556 1.1.1.12 christos (WalkState->ControlState->Control.Opcode == AML_WHILE_OP)))
557 1.1.1.12 christos {
558 1.1.1.12 christos /*
559 1.1.1.12 christos * If the if/while op fails to parse, we will skip parsing
560 1.1.1.12 christos * the body of the op.
561 1.1.1.12 christos */
562 1.1.1.12 christos ParserState->Aml =
563 1.1.1.12 christos WalkState->ControlState->Control.AmlPredicateStart + 1;
564 1.1.1.12 christos ParserState->Aml =
565 1.1.1.12 christos AcpiPsGetNextPackageEnd (ParserState);
566 1.1.1.12 christos WalkState->Aml = ParserState->Aml;
567 1.1 jruoho
568 1.1.1.12 christos ACPI_ERROR ((AE_INFO, "Skipping While/If block"));
569 1.1.1.12 christos if (*WalkState->Aml == AML_ELSE_OP)
570 1.1.1.12 christos {
571 1.1.1.12 christos ACPI_ERROR ((AE_INFO, "Skipping Else block"));
572 1.1.1.12 christos WalkState->ParserState.Aml = WalkState->Aml + 1;
573 1.1.1.12 christos WalkState->ParserState.Aml =
574 1.1.1.12 christos AcpiPsGetNextPackageEnd (ParserState);
575 1.1.1.12 christos WalkState->Aml = ParserState->Aml;
576 1.1.1.12 christos }
577 1.1.1.12 christos ACPI_FREE(AcpiUtPopGenericState (&WalkState->ControlState));
578 1.1.1.12 christos }
579 1.1.1.12 christos Op = NULL;
580 1.1 jruoho continue;
581 1.1 jruoho }
582 1.1 jruoho }
583 1.1 jruoho
584 1.1 jruoho /* Check for arguments that need to be processed */
585 1.1 jruoho
586 1.1.1.10 christos ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
587 1.1.1.11 christos "Parseloop: argument count: %8.8X\n", WalkState->ArgCount));
588 1.1.1.10 christos
589 1.1 jruoho if (WalkState->ArgCount)
590 1.1 jruoho {
591 1.1 jruoho /*
592 1.1 jruoho * There are arguments (complex ones), push Op and
593 1.1 jruoho * prepare for argument
594 1.1 jruoho */
595 1.1 jruoho Status = AcpiPsPushScope (ParserState, Op,
596 1.1.1.7 christos WalkState->ArgTypes, WalkState->ArgCount);
597 1.1 jruoho if (ACPI_FAILURE (Status))
598 1.1 jruoho {
599 1.1 jruoho Status = AcpiPsCompleteOp (WalkState, &Op, Status);
600 1.1 jruoho if (ACPI_FAILURE (Status))
601 1.1 jruoho {
602 1.1 jruoho return_ACPI_STATUS (Status);
603 1.1 jruoho }
604 1.1 jruoho
605 1.1 jruoho continue;
606 1.1 jruoho }
607 1.1 jruoho
608 1.1 jruoho Op = NULL;
609 1.1 jruoho continue;
610 1.1 jruoho }
611 1.1 jruoho
612 1.1 jruoho /*
613 1.1 jruoho * All arguments have been processed -- Op is complete,
614 1.1 jruoho * prepare for next
615 1.1 jruoho */
616 1.1 jruoho WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
617 1.1 jruoho if (WalkState->OpInfo->Flags & AML_NAMED)
618 1.1 jruoho {
619 1.1 jruoho if (Op->Common.AmlOpcode == AML_REGION_OP ||
620 1.1 jruoho Op->Common.AmlOpcode == AML_DATA_REGION_OP)
621 1.1 jruoho {
622 1.1 jruoho /*
623 1.1 jruoho * Skip parsing of control method or opregion body,
624 1.1 jruoho * because we don't have enough info in the first pass
625 1.1 jruoho * to parse them correctly.
626 1.1 jruoho *
627 1.1 jruoho * Completed parsing an OpRegion declaration, we now
628 1.1 jruoho * know the length.
629 1.1 jruoho */
630 1.1 jruoho Op->Named.Length = (UINT32) (ParserState->Aml - Op->Named.Data);
631 1.1 jruoho }
632 1.1 jruoho }
633 1.1 jruoho
634 1.1 jruoho if (WalkState->OpInfo->Flags & AML_CREATE)
635 1.1 jruoho {
636 1.1 jruoho /*
637 1.1 jruoho * Backup to beginning of CreateXXXfield declaration (1 for
638 1.1 jruoho * Opcode)
639 1.1 jruoho *
640 1.1 jruoho * BodyLength is unknown until we parse the body
641 1.1 jruoho */
642 1.1 jruoho Op->Named.Length = (UINT32) (ParserState->Aml - Op->Named.Data);
643 1.1 jruoho }
644 1.1 jruoho
645 1.1 jruoho if (Op->Common.AmlOpcode == AML_BANK_FIELD_OP)
646 1.1 jruoho {
647 1.1 jruoho /*
648 1.1 jruoho * Backup to beginning of BankField declaration
649 1.1 jruoho *
650 1.1 jruoho * BodyLength is unknown until we parse the body
651 1.1 jruoho */
652 1.1 jruoho Op->Named.Length = (UINT32) (ParserState->Aml - Op->Named.Data);
653 1.1 jruoho }
654 1.1 jruoho
655 1.1 jruoho /* This op complete, notify the dispatcher */
656 1.1 jruoho
657 1.1 jruoho if (WalkState->AscendingCallback != NULL)
658 1.1 jruoho {
659 1.1 jruoho WalkState->Op = Op;
660 1.1 jruoho WalkState->Opcode = Op->Common.AmlOpcode;
661 1.1 jruoho
662 1.1 jruoho Status = WalkState->AscendingCallback (WalkState);
663 1.1 jruoho Status = AcpiPsNextParseState (WalkState, Op, Status);
664 1.1 jruoho if (Status == AE_CTRL_PENDING)
665 1.1 jruoho {
666 1.1 jruoho Status = AE_OK;
667 1.1 jruoho }
668 1.1.1.12 christos else if ((WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL) &&
669 1.1.1.12 christos (ACPI_AML_EXCEPTION(Status) || Status == AE_ALREADY_EXISTS ||
670 1.1.1.12 christos Status == AE_NOT_FOUND))
671 1.1.1.12 christos {
672 1.1.1.12 christos /*
673 1.1.1.12 christos * ACPI_PARSE_MODULE_LEVEL flag means that we are currently
674 1.1.1.12 christos * loading a table by executing it as a control method.
675 1.1.1.12 christos * However, if we encounter an error while loading the table,
676 1.1.1.12 christos * we need to keep trying to load the table rather than
677 1.1.1.12 christos * aborting the table load (setting the status to AE_OK
678 1.1.1.12 christos * continues the table load). If we get a failure at this
679 1.1.1.12 christos * point, it means that the dispatcher got an error while
680 1.1.1.12 christos * trying to execute the Op.
681 1.1.1.12 christos */
682 1.1.1.12 christos Status = AE_OK;
683 1.1.1.12 christos }
684 1.1 jruoho }
685 1.1 jruoho
686 1.1 jruoho Status = AcpiPsCompleteOp (WalkState, &Op, Status);
687 1.1 jruoho if (ACPI_FAILURE (Status))
688 1.1 jruoho {
689 1.1 jruoho return_ACPI_STATUS (Status);
690 1.1 jruoho }
691 1.1 jruoho
692 1.1 jruoho } /* while ParserState->Aml */
693 1.1 jruoho
694 1.1 jruoho Status = AcpiPsCompleteFinalOp (WalkState, Op, Status);
695 1.1 jruoho return_ACPI_STATUS (Status);
696 1.1 jruoho }
697