9625834c56f6b14b2a405edeec7c0e6343953c99
[dragonfly.git] / sys / contrib / dev / acpica / source / components / parser / psloop.c
1 /******************************************************************************
2  *
3  * Module Name: psloop - Main AML parse loop
4  *
5  *****************************************************************************/
6
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
12  * All rights reserved.
13  *
14  * 2. License
15  *
16  * 2.1. This is your license from Intel Corp. under its intellectual property
17  * rights. You may have additional license terms from the party that provided
18  * you this software, covering your right to use that party's intellectual
19  * property rights.
20  *
21  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22  * copy of the source code appearing in this file ("Covered Code") an
23  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24  * base code distributed originally by Intel ("Original Intel Code") to copy,
25  * make derivatives, distribute, use and display any portion of the Covered
26  * Code in any form, with the right to sublicense such rights; and
27  *
28  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29  * license (with the right to sublicense), under only those claims of Intel
30  * patents that are infringed by the Original Intel Code, to make, use, sell,
31  * offer to sell, and import the Covered Code and derivative works thereof
32  * solely to the minimum extent necessary to exercise the above copyright
33  * license, and in no event shall the patent license extend to any additions
34  * to or modifications of the Original Intel Code. No other license or right
35  * is granted directly or by implication, estoppel or otherwise;
36  *
37  * The above copyright and patent license is granted only if the following
38  * conditions are met:
39  *
40  * 3. Conditions
41  *
42  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43  * Redistribution of source code of any substantial portion of the Covered
44  * Code or modification with rights to further distribute source must include
45  * the above Copyright Notice, the above License, this list of Conditions,
46  * and the following Disclaimer and Export Compliance provision. In addition,
47  * Licensee must cause all Covered Code to which Licensee contributes to
48  * contain a file documenting the changes Licensee made to create that Covered
49  * Code and the date of any change. Licensee must include in that file the
50  * documentation of any changes made by any predecessor Licensee. Licensee
51  * must include a prominent statement that the modification is derived,
52  * directly or indirectly, from Original Intel Code.
53  *
54  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55  * Redistribution of source code of any substantial portion of the Covered
56  * Code or modification without rights to further distribute source must
57  * include the following Disclaimer and Export Compliance provision in the
58  * documentation and/or other materials provided with distribution. In
59  * addition, Licensee may not authorize further sublicense of source of any
60  * portion of the Covered Code, and must include terms to the effect that the
61  * license from Licensee to its licensee is limited to the intellectual
62  * property embodied in the software Licensee provides to its licensee, and
63  * not to intellectual property embodied in modifications its licensee may
64  * make.
65  *
66  * 3.3. Redistribution of Executable. Redistribution in executable form of any
67  * substantial portion of the Covered Code or modification must reproduce the
68  * above Copyright Notice, and the following Disclaimer and Export Compliance
69  * provision in the documentation and/or other materials provided with the
70  * distribution.
71  *
72  * 3.4. Intel retains all right, title, and interest in and to the Original
73  * Intel Code.
74  *
75  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76  * Intel shall be used in advertising or otherwise to promote the sale, use or
77  * other dealings in products derived from or relating to the Covered Code
78  * without prior written authorization from Intel.
79  *
80  * 4. Disclaimer and Export Compliance
81  *
82  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88  * PARTICULAR PURPOSE.
89  *
90  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97  * LIMITED REMEDY.
98  *
99  * 4.3. Licensee shall not export, either directly or indirectly, any of this
100  * software or system incorporating such software without first obtaining any
101  * required license or other approval from the U. S. Department of Commerce or
102  * any other agency or department of the United States Government. In the
103  * event Licensee exports any such software from the United States or
104  * re-exports any such software from a foreign destination, Licensee shall
105  * ensure that the distribution and export/re-export of the software is in
106  * compliance with all laws, regulations, orders, or other restrictions of the
107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108  * any of its subsidiaries will export/re-export any technical data, process,
109  * software, or service, directly or indirectly, to any country for which the
110  * United States government or any agency thereof requires an export license,
111  * other governmental approval, or letter of assurance, without first obtaining
112  * such license, approval or letter.
113  *
114  *****************************************************************************
115  *
116  * Alternatively, you may choose to be licensed under the terms of the
117  * following license:
118  *
119  * Redistribution and use in source and binary forms, with or without
120  * modification, are permitted provided that the following conditions
121  * are met:
122  * 1. Redistributions of source code must retain the above copyright
123  *    notice, this list of conditions, and the following disclaimer,
124  *    without modification.
125  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126  *    substantially similar to the "NO WARRANTY" disclaimer below
127  *    ("Disclaimer") and any redistribution must be conditioned upon
128  *    including a substantially similar Disclaimer requirement for further
129  *    binary redistribution.
130  * 3. Neither the names of the above-listed copyright holders nor the names
131  *    of any contributors may be used to endorse or promote products derived
132  *    from this software without specific prior written permission.
133  *
134  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145  *
146  * Alternatively, you may choose to be licensed under the terms of the
147  * GNU General Public License ("GPL") version 2 as published by the Free
148  * Software Foundation.
149  *
150  *****************************************************************************/
151
152 /*
153  * Parse the AML and build an operation tree as most interpreters, (such as
154  * Perl) do. Parsing is done by hand rather than with a YACC generated parser
155  * to tightly constrain stack and dynamic memory usage. Parsing is kept
156  * flexible and the code fairly compact by parsing based on a list of AML
157  * opcode templates in AmlOpInfo[].
158  */
159
160 #include "acpi.h"
161 #include "accommon.h"
162 #include "acinterp.h"
163 #include "acparser.h"
164 #include "acdispat.h"
165 #include "amlcode.h"
166 #include "acconvert.h"
167 #include "acnamesp.h"
168
169 #define _COMPONENT          ACPI_PARSER
170         ACPI_MODULE_NAME    ("psloop")
171
172
173 /* Local prototypes */
174
175 static ACPI_STATUS
176 AcpiPsGetArguments (
177     ACPI_WALK_STATE         *WalkState,
178     UINT8                   *AmlOpStart,
179     ACPI_PARSE_OBJECT       *Op);
180
181 static void
182 AcpiPsLinkModuleCode (
183     ACPI_PARSE_OBJECT       *ParentOp,
184     UINT8                   *AmlStart,
185     UINT32                  AmlLength,
186     ACPI_OWNER_ID           OwnerId);
187
188
189 /*******************************************************************************
190  *
191  * FUNCTION:    AcpiPsGetArguments
192  *
193  * PARAMETERS:  WalkState           - Current state
194  *              AmlOpStart          - Op start in AML
195  *              Op                  - Current Op
196  *
197  * RETURN:      Status
198  *
199  * DESCRIPTION: Get arguments for passed Op.
200  *
201  ******************************************************************************/
202
203 static ACPI_STATUS
204 AcpiPsGetArguments (
205     ACPI_WALK_STATE         *WalkState,
206     UINT8                   *AmlOpStart,
207     ACPI_PARSE_OBJECT       *Op)
208 {
209     ACPI_STATUS             Status = AE_OK;
210     ACPI_PARSE_OBJECT       *Arg = NULL;
211     const ACPI_OPCODE_INFO  *OpInfo;
212
213
214     ACPI_FUNCTION_TRACE_PTR (PsGetArguments, WalkState);
215
216
217     ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
218         "Get arguments for opcode [%s]\n", Op->Common.AmlOpName));
219
220     switch (Op->Common.AmlOpcode)
221     {
222     case AML_BYTE_OP:       /* AML_BYTEDATA_ARG */
223     case AML_WORD_OP:       /* AML_WORDDATA_ARG */
224     case AML_DWORD_OP:      /* AML_DWORDATA_ARG */
225     case AML_QWORD_OP:      /* AML_QWORDATA_ARG */
226     case AML_STRING_OP:     /* AML_ASCIICHARLIST_ARG */
227
228         /* Fill in constant or string argument directly */
229
230         AcpiPsGetNextSimpleArg (&(WalkState->ParserState),
231             GET_CURRENT_ARG_TYPE (WalkState->ArgTypes), Op);
232         break;
233
234     case AML_INT_NAMEPATH_OP:   /* AML_NAMESTRING_ARG */
235
236         Status = AcpiPsGetNextNamepath (WalkState,
237             &(WalkState->ParserState), Op, ACPI_POSSIBLE_METHOD_CALL);
238         if (ACPI_FAILURE (Status))
239         {
240             return_ACPI_STATUS (Status);
241         }
242
243         WalkState->ArgTypes = 0;
244         break;
245
246     default:
247         /*
248          * Op is not a constant or string, append each argument to the Op
249          */
250         while (GET_CURRENT_ARG_TYPE (WalkState->ArgTypes) &&
251             !WalkState->ArgCount)
252         {
253             WalkState->Aml = WalkState->ParserState.Aml;
254
255             switch (Op->Common.AmlOpcode)
256             {
257             case AML_METHOD_OP:
258             case AML_BUFFER_OP:
259             case AML_PACKAGE_OP:
260             case AML_VARIABLE_PACKAGE_OP:
261             case AML_WHILE_OP:
262
263                 break;
264
265             default:
266
267                 ASL_CV_CAPTURE_COMMENTS (WalkState);
268                 break;
269             }
270
271             Status = AcpiPsGetNextArg (WalkState, &(WalkState->ParserState),
272                 GET_CURRENT_ARG_TYPE (WalkState->ArgTypes), &Arg);
273             if (ACPI_FAILURE (Status))
274             {
275                 return_ACPI_STATUS (Status);
276             }
277
278             if (Arg)
279             {
280                 AcpiPsAppendArg (Op, Arg);
281             }
282
283             INCREMENT_ARG_LIST (WalkState->ArgTypes);
284         }
285
286         ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
287             "Final argument count: %8.8X pass %u\n",
288             WalkState->ArgCount, WalkState->PassNumber));
289
290         /*
291          * This case handles the legacy option that groups all module-level
292          * code blocks together and defers execution until all of the tables
293          * are loaded. Execute all of these blocks at this time.
294          * Execute any module-level code that was detected during the table
295          * load phase.
296          *
297          * Note: this option is deprecated and will be eliminated in the
298          * future. Use of this option can cause problems with AML code that
299          * depends upon in-order immediate execution of module-level code.
300          */
301         if (!AcpiGbl_ExecuteTablesAsMethods &&
302             (WalkState->PassNumber <= ACPI_IMODE_LOAD_PASS2) &&
303             ((WalkState->ParseFlags & ACPI_PARSE_DISASSEMBLE) == 0))
304         {
305             /*
306              * We want to skip If/Else/While constructs during Pass1 because we
307              * want to actually conditionally execute the code during Pass2.
308              *
309              * Except for disassembly, where we always want to walk the
310              * If/Else/While packages
311              */
312             switch (Op->Common.AmlOpcode)
313             {
314             case AML_IF_OP:
315             case AML_ELSE_OP:
316             case AML_WHILE_OP:
317                 /*
318                  * Currently supported module-level opcodes are:
319                  * IF/ELSE/WHILE. These appear to be the most common,
320                  * and easiest to support since they open an AML
321                  * package.
322                  */
323                 if (WalkState->PassNumber == ACPI_IMODE_LOAD_PASS1)
324                 {
325                     AcpiPsLinkModuleCode (Op->Common.Parent, AmlOpStart,
326                         (UINT32) (WalkState->ParserState.PkgEnd - AmlOpStart),
327                         WalkState->OwnerId);
328                 }
329
330                 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
331                     "Pass1: Skipping an If/Else/While body\n"));
332
333                 /* Skip body of if/else/while in pass 1 */
334
335                 WalkState->ParserState.Aml = WalkState->ParserState.PkgEnd;
336                 WalkState->ArgCount = 0;
337                 break;
338
339             default:
340                 /*
341                  * Check for an unsupported executable opcode at module
342                  * level. We must be in PASS1, the parent must be a SCOPE,
343                  * The opcode class must be EXECUTE, and the opcode must
344                  * not be an argument to another opcode.
345                  */
346                 if ((WalkState->PassNumber == ACPI_IMODE_LOAD_PASS1) &&
347                     (Op->Common.Parent->Common.AmlOpcode == AML_SCOPE_OP))
348                 {
349                     OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
350                     if ((OpInfo->Class == AML_CLASS_EXECUTE) &&
351                         (!Arg))
352                     {
353                         ACPI_WARNING ((AE_INFO,
354                             "Unsupported module-level executable opcode "
355                             "0x%.2X at table offset 0x%.4X",
356                             Op->Common.AmlOpcode,
357                             (UINT32) (ACPI_PTR_DIFF (AmlOpStart,
358                                 WalkState->ParserState.AmlStart) +
359                                 sizeof (ACPI_TABLE_HEADER))));
360                     }
361                 }
362                 break;
363             }
364         }
365
366         /* Special processing for certain opcodes */
367
368         switch (Op->Common.AmlOpcode)
369         {
370         case AML_METHOD_OP:
371             /*
372              * Skip parsing of control method because we don't have enough
373              * info in the first pass to parse it correctly.
374              *
375              * Save the length and address of the body
376              */
377             Op->Named.Data = WalkState->ParserState.Aml;
378             Op->Named.Length = (UINT32)
379                 (WalkState->ParserState.PkgEnd - WalkState->ParserState.Aml);
380
381             /* Skip body of method */
382
383             WalkState->ParserState.Aml = WalkState->ParserState.PkgEnd;
384             WalkState->ArgCount = 0;
385             break;
386
387         case AML_BUFFER_OP:
388         case AML_PACKAGE_OP:
389         case AML_VARIABLE_PACKAGE_OP:
390
391             if ((Op->Common.Parent) &&
392                 (Op->Common.Parent->Common.AmlOpcode == AML_NAME_OP) &&
393                 (WalkState->PassNumber <= ACPI_IMODE_LOAD_PASS2))
394             {
395                 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
396                     "Setup Package/Buffer: Pass %u, AML Ptr: %p\n",
397                     WalkState->PassNumber, AmlOpStart));
398
399                 /*
400                  * Skip parsing of Buffers and Packages because we don't have
401                  * enough info in the first pass to parse them correctly.
402                  */
403                 Op->Named.Data = AmlOpStart;
404                 Op->Named.Length = (UINT32)
405                     (WalkState->ParserState.PkgEnd - AmlOpStart);
406
407                 /* Skip body */
408
409                 WalkState->ParserState.Aml = WalkState->ParserState.PkgEnd;
410                 WalkState->ArgCount = 0;
411             }
412             break;
413
414         case AML_WHILE_OP:
415
416             if (WalkState->ControlState)
417             {
418                 WalkState->ControlState->Control.PackageEnd =
419                     WalkState->ParserState.PkgEnd;
420             }
421             break;
422
423         default:
424
425             /* No action for all other opcodes */
426
427             break;
428         }
429
430         break;
431     }
432
433     return_ACPI_STATUS (AE_OK);
434 }
435
436
437 /*******************************************************************************
438  *
439  * FUNCTION:    AcpiPsLinkModuleCode
440  *
441  * PARAMETERS:  ParentOp            - Parent parser op
442  *              AmlStart            - Pointer to the AML
443  *              AmlLength           - Length of executable AML
444  *              OwnerId             - OwnerId of module level code
445  *
446  * RETURN:      None.
447  *
448  * DESCRIPTION: Wrap the module-level code with a method object and link the
449  *              object to the global list. Note, the mutex field of the method
450  *              object is used to link multiple module-level code objects.
451  *
452  * NOTE: In this legacy option, each block of detected executable AML
453  * code that is outside of any control method is wrapped with a temporary
454  * control method object and placed on a global list below.
455  *
456  * This function executes the module-level code for all tables only after
457  * all of the tables have been loaded. It is a legacy option and is
458  * not compatible with other ACPI implementations. See AcpiNsLoadTable.
459  *
460  * This function will be removed when the legacy option is removed.
461  *
462  ******************************************************************************/
463
464 static void
465 AcpiPsLinkModuleCode (
466     ACPI_PARSE_OBJECT       *ParentOp,
467     UINT8                   *AmlStart,
468     UINT32                  AmlLength,
469     ACPI_OWNER_ID           OwnerId)
470 {
471     ACPI_OPERAND_OBJECT     *Prev;
472     ACPI_OPERAND_OBJECT     *Next;
473     ACPI_OPERAND_OBJECT     *MethodObj;
474     ACPI_NAMESPACE_NODE     *ParentNode;
475
476
477     ACPI_FUNCTION_TRACE (PsLinkModuleCode);
478
479
480     /* Get the tail of the list */
481
482     Prev = Next = AcpiGbl_ModuleCodeList;
483     while (Next)
484     {
485         Prev = Next;
486         Next = Next->Method.Mutex;
487     }
488
489     /*
490      * Insert the module level code into the list. Merge it if it is
491      * adjacent to the previous element.
492      */
493     if (!Prev ||
494        ((Prev->Method.AmlStart + Prev->Method.AmlLength) != AmlStart))
495     {
496         /* Create, initialize, and link a new temporary method object */
497
498         MethodObj = AcpiUtCreateInternalObject (ACPI_TYPE_METHOD);
499         if (!MethodObj)
500         {
501             return_VOID;
502         }
503
504         ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
505             "Create/Link new code block: %p\n", MethodObj));
506
507         if (ParentOp->Common.Node)
508         {
509             ParentNode = ParentOp->Common.Node;
510         }
511         else
512         {
513             ParentNode = AcpiGbl_RootNode;
514         }
515
516         MethodObj->Method.AmlStart = AmlStart;
517         MethodObj->Method.AmlLength = AmlLength;
518         MethodObj->Method.OwnerId = OwnerId;
519         MethodObj->Method.InfoFlags |= ACPI_METHOD_MODULE_LEVEL;
520
521         /*
522          * Save the parent node in NextObject. This is cheating, but we
523          * don't want to expand the method object.
524          */
525         MethodObj->Method.NextObject =
526             ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, ParentNode);
527
528         if (!Prev)
529         {
530             AcpiGbl_ModuleCodeList = MethodObj;
531         }
532         else
533         {
534             Prev->Method.Mutex = MethodObj;
535         }
536     }
537     else
538     {
539         ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
540             "Appending to existing code block: %p\n", Prev));
541
542         Prev->Method.AmlLength += AmlLength;
543     }
544
545     return_VOID;
546 }
547
548 /*******************************************************************************
549  *
550  * FUNCTION:    AcpiPsParseLoop
551  *
552  * PARAMETERS:  WalkState           - Current state
553  *
554  * RETURN:      Status
555  *
556  * DESCRIPTION: Parse AML (pointed to by the current parser state) and return
557  *              a tree of ops.
558  *
559  ******************************************************************************/
560
561 ACPI_STATUS
562 AcpiPsParseLoop (
563     ACPI_WALK_STATE         *WalkState)
564 {
565     ACPI_STATUS             Status = AE_OK;
566     ACPI_PARSE_OBJECT       *Op = NULL;     /* current op */
567     ACPI_PARSE_STATE        *ParserState;
568     UINT8                   *AmlOpStart = NULL;
569     UINT8                   OpcodeLength;
570
571
572     ACPI_FUNCTION_TRACE_PTR (PsParseLoop, WalkState);
573
574
575     if (WalkState->DescendingCallback == NULL)
576     {
577         return_ACPI_STATUS (AE_BAD_PARAMETER);
578     }
579
580     ParserState = &WalkState->ParserState;
581     WalkState->ArgTypes = 0;
582
583 #if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
584
585     if (WalkState->WalkType & ACPI_WALK_METHOD_RESTART)
586     {
587         /* We are restarting a preempted control method */
588
589         if (AcpiPsHasCompletedScope (ParserState))
590         {
591             /*
592              * We must check if a predicate to an IF or WHILE statement
593              * was just completed
594              */
595             if ((ParserState->Scope->ParseScope.Op) &&
596                ((ParserState->Scope->ParseScope.Op->Common.AmlOpcode == AML_IF_OP) ||
597                 (ParserState->Scope->ParseScope.Op->Common.AmlOpcode == AML_WHILE_OP)) &&
598                 (WalkState->ControlState) &&
599                 (WalkState->ControlState->Common.State ==
600                     ACPI_CONTROL_PREDICATE_EXECUTING))
601             {
602                 /*
603                  * A predicate was just completed, get the value of the
604                  * predicate and branch based on that value
605                  */
606                 WalkState->Op = NULL;
607                 Status = AcpiDsGetPredicateValue (WalkState, ACPI_TO_POINTER (TRUE));
608                 if (ACPI_FAILURE (Status) &&
609                     ((Status & AE_CODE_MASK) != AE_CODE_CONTROL))
610                 {
611                     if (Status == AE_AML_NO_RETURN_VALUE)
612                     {
613                         ACPI_EXCEPTION ((AE_INFO, Status,
614                             "Invoked method did not return a value"));
615                     }
616
617                     ACPI_EXCEPTION ((AE_INFO, Status, "GetPredicate Failed"));
618                     return_ACPI_STATUS (Status);
619                 }
620
621                 Status = AcpiPsNextParseState (WalkState, Op, Status);
622             }
623
624             AcpiPsPopScope (ParserState, &Op,
625                 &WalkState->ArgTypes, &WalkState->ArgCount);
626             ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Popped scope, Op=%p\n", Op));
627         }
628         else if (WalkState->PrevOp)
629         {
630             /* We were in the middle of an op */
631
632             Op = WalkState->PrevOp;
633             WalkState->ArgTypes = WalkState->PrevArgTypes;
634         }
635     }
636 #endif
637
638     /* Iterative parsing loop, while there is more AML to process: */
639
640     while ((ParserState->Aml < ParserState->AmlEnd) || (Op))
641     {
642         ASL_CV_CAPTURE_COMMENTS (WalkState);
643
644         AmlOpStart = ParserState->Aml;
645         if (!Op)
646         {
647             Status = AcpiPsCreateOp (WalkState, AmlOpStart, &Op);
648             if (ACPI_FAILURE (Status))
649             {
650                 /*
651                  * ACPI_PARSE_MODULE_LEVEL means that we are loading a table by
652                  * executing it as a control method. However, if we encounter
653                  * an error while loading the table, we need to keep trying to
654                  * load the table rather than aborting the table load. Set the
655                  * status to AE_OK to proceed with the table load.
656                  */
657                 if ((WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL) &&
658                     ((Status == AE_ALREADY_EXISTS) || (Status == AE_NOT_FOUND)))
659                 {
660                     Status = AE_OK;
661                 }
662                 if (Status == AE_CTRL_PARSE_CONTINUE)
663                 {
664                     continue;
665                 }
666
667                 if (Status == AE_CTRL_PARSE_PENDING)
668                 {
669                     Status = AE_OK;
670                 }
671
672                 if (Status == AE_CTRL_TERMINATE)
673                 {
674                     return_ACPI_STATUS (Status);
675                 }
676
677                 Status = AcpiPsCompleteOp (WalkState, &Op, Status);
678                 if (ACPI_FAILURE (Status))
679                 {
680                     return_ACPI_STATUS (Status);
681                 }
682                 if (AcpiNsOpensScope (
683                     AcpiPsGetOpcodeInfo (WalkState->Opcode)->ObjectType))
684                 {
685                     /*
686                      * If the scope/device op fails to parse, skip the body of
687                      * the scope op because the parse failure indicates that
688                      * the device may not exist.
689                      */
690                     ACPI_INFO (("Skipping parse of AML opcode: %s (0x%4.4X)",
691                         AcpiPsGetOpcodeName (WalkState->Opcode), WalkState->Opcode));
692
693                     /*
694                      * Determine the opcode length before skipping the opcode.
695                      * An opcode can be 1 byte or 2 bytes in length.
696                      */
697                     OpcodeLength = 1;
698                     if ((WalkState->Opcode & 0xFF00) == AML_EXTENDED_OPCODE)
699                     {
700                         OpcodeLength = 2;
701                     }
702                     WalkState->ParserState.Aml = WalkState->Aml + OpcodeLength;
703
704                     WalkState->ParserState.Aml =
705                         AcpiPsGetNextPackageEnd(&WalkState->ParserState);
706                     WalkState->Aml = WalkState->ParserState.Aml;
707                 }
708
709                 continue;
710             }
711
712             AcpiExStartTraceOpcode (Op, WalkState);
713         }
714
715         /*
716          * Start ArgCount at zero because we don't know if there are
717          * any args yet
718          */
719         WalkState->ArgCount = 0;
720
721         switch (Op->Common.AmlOpcode)
722         {
723         case AML_BYTE_OP:
724         case AML_WORD_OP:
725         case AML_DWORD_OP:
726         case AML_QWORD_OP:
727
728             break;
729
730         default:
731
732             ASL_CV_CAPTURE_COMMENTS (WalkState);
733             break;
734         }
735
736         /* Are there any arguments that must be processed? */
737
738         if (WalkState->ArgTypes)
739         {
740             /* Get arguments */
741
742             Status = AcpiPsGetArguments (WalkState, AmlOpStart, Op);
743             if (ACPI_FAILURE (Status))
744             {
745                 Status = AcpiPsCompleteOp (WalkState, &Op, Status);
746                 if (ACPI_FAILURE (Status))
747                 {
748                     return_ACPI_STATUS (Status);
749                 }
750                 if ((WalkState->ControlState) &&
751                     ((WalkState->ControlState->Control.Opcode == AML_IF_OP) ||
752                     (WalkState->ControlState->Control.Opcode == AML_WHILE_OP)))
753                 {
754                     /*
755                      * If the if/while op fails to parse, we will skip parsing
756                      * the body of the op.
757                      */
758                     ParserState->Aml =
759                         WalkState->ControlState->Control.AmlPredicateStart + 1;
760                     ParserState->Aml =
761                         AcpiPsGetNextPackageEnd (ParserState);
762                     WalkState->Aml = ParserState->Aml;
763
764                     ACPI_ERROR ((AE_INFO, "Skipping While/If block"));
765                     if (*WalkState->Aml == AML_ELSE_OP)
766                     {
767                         ACPI_ERROR ((AE_INFO, "Skipping Else block"));
768                         WalkState->ParserState.Aml = WalkState->Aml + 1;
769                         WalkState->ParserState.Aml =
770                             AcpiPsGetNextPackageEnd (ParserState);
771                         WalkState->Aml = ParserState->Aml;
772                     }
773                     ACPI_FREE(AcpiUtPopGenericState (&WalkState->ControlState));
774                 }
775                 Op = NULL;
776                 continue;
777             }
778         }
779
780         /* Check for arguments that need to be processed */
781
782         ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
783             "Parseloop: argument count: %8.8X\n", WalkState->ArgCount));
784
785         if (WalkState->ArgCount)
786         {
787             /*
788              * There are arguments (complex ones), push Op and
789              * prepare for argument
790              */
791             Status = AcpiPsPushScope (ParserState, Op,
792                 WalkState->ArgTypes, WalkState->ArgCount);
793             if (ACPI_FAILURE (Status))
794             {
795                 Status = AcpiPsCompleteOp (WalkState, &Op, Status);
796                 if (ACPI_FAILURE (Status))
797                 {
798                     return_ACPI_STATUS (Status);
799                 }
800
801                 continue;
802             }
803
804             Op = NULL;
805             continue;
806         }
807
808         /*
809          * All arguments have been processed -- Op is complete,
810          * prepare for next
811          */
812         WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
813         if (WalkState->OpInfo->Flags & AML_NAMED)
814         {
815             if (Op->Common.AmlOpcode == AML_REGION_OP ||
816                 Op->Common.AmlOpcode == AML_DATA_REGION_OP)
817             {
818                 /*
819                  * Skip parsing of control method or opregion body,
820                  * because we don't have enough info in the first pass
821                  * to parse them correctly.
822                  *
823                  * Completed parsing an OpRegion declaration, we now
824                  * know the length.
825                  */
826                 Op->Named.Length = (UINT32) (ParserState->Aml - Op->Named.Data);
827             }
828         }
829
830         if (WalkState->OpInfo->Flags & AML_CREATE)
831         {
832             /*
833              * Backup to beginning of CreateXXXfield declaration (1 for
834              * Opcode)
835              *
836              * BodyLength is unknown until we parse the body
837              */
838             Op->Named.Length = (UINT32) (ParserState->Aml - Op->Named.Data);
839         }
840
841         if (Op->Common.AmlOpcode == AML_BANK_FIELD_OP)
842         {
843             /*
844              * Backup to beginning of BankField declaration
845              *
846              * BodyLength is unknown until we parse the body
847              */
848             Op->Named.Length = (UINT32) (ParserState->Aml - Op->Named.Data);
849         }
850
851         /* This op complete, notify the dispatcher */
852
853         if (WalkState->AscendingCallback != NULL)
854         {
855             WalkState->Op = Op;
856             WalkState->Opcode = Op->Common.AmlOpcode;
857
858             Status = WalkState->AscendingCallback (WalkState);
859             Status = AcpiPsNextParseState (WalkState, Op, Status);
860             if (Status == AE_CTRL_PENDING)
861             {
862                 Status = AE_OK;
863             }
864             else if ((WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL) &&
865                 (ACPI_AML_EXCEPTION(Status) || Status == AE_ALREADY_EXISTS ||
866                 Status == AE_NOT_FOUND))
867             {
868                 /*
869                  * ACPI_PARSE_MODULE_LEVEL flag means that we are currently
870                  * loading a table by executing it as a control method.
871                  * However, if we encounter an error while loading the table,
872                  * we need to keep trying to load the table rather than
873                  * aborting the table load (setting the status to AE_OK
874                  * continues the table load). If we get a failure at this
875                  * point, it means that the dispatcher got an error while
876                  * trying to execute the Op.
877                  */
878                 Status = AE_OK;
879             }
880         }
881
882         Status = AcpiPsCompleteOp (WalkState, &Op, Status);
883         if (ACPI_FAILURE (Status))
884         {
885             return_ACPI_STATUS (Status);
886         }
887
888     } /* while ParserState->Aml */
889
890     Status = AcpiPsCompleteFinalOp (WalkState, Op, Status);
891     return_ACPI_STATUS (Status);
892 }