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 - 2017, 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 
168 #define _COMPONENT          ACPI_PARSER
169         ACPI_MODULE_NAME    ("psloop")
170 
171 
172 /* Local prototypes */
173 
174 static ACPI_STATUS
175 AcpiPsGetArguments (
176     ACPI_WALK_STATE         *WalkState,
177     UINT8                   *AmlOpStart,
178     ACPI_PARSE_OBJECT       *Op);
179 
180 static void
181 AcpiPsLinkModuleCode (
182     ACPI_PARSE_OBJECT       *ParentOp,
183     UINT8                   *AmlStart,
184     UINT32                  AmlLength,
185     ACPI_OWNER_ID           OwnerId);
186 
187 
188 /*******************************************************************************
189  *
190  * FUNCTION:    AcpiPsGetArguments
191  *
192  * PARAMETERS:  WalkState           - Current state
193  *              AmlOpStart          - Op start in AML
194  *              Op                  - Current Op
195  *
196  * RETURN:      Status
197  *
198  * DESCRIPTION: Get arguments for passed Op.
199  *
200  ******************************************************************************/
201 
202 static ACPI_STATUS
203 AcpiPsGetArguments (
204     ACPI_WALK_STATE         *WalkState,
205     UINT8                   *AmlOpStart,
206     ACPI_PARSE_OBJECT       *Op)
207 {
208     ACPI_STATUS             Status = AE_OK;
209     ACPI_PARSE_OBJECT       *Arg = NULL;
210     const ACPI_OPCODE_INFO  *OpInfo;
211 
212 
213     ACPI_FUNCTION_TRACE_PTR (PsGetArguments, WalkState);
214 
215 
216     ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
217         "Get arguments for opcode [%s]\n", Op->Common.AmlOpName));
218 
219     switch (Op->Common.AmlOpcode)
220     {
221     case AML_BYTE_OP:       /* AML_BYTEDATA_ARG */
222     case AML_WORD_OP:       /* AML_WORDDATA_ARG */
223     case AML_DWORD_OP:      /* AML_DWORDATA_ARG */
224     case AML_QWORD_OP:      /* AML_QWORDATA_ARG */
225     case AML_STRING_OP:     /* AML_ASCIICHARLIST_ARG */
226 
227         /* Fill in constant or string argument directly */
228 
229         AcpiPsGetNextSimpleArg (&(WalkState->ParserState),
230             GET_CURRENT_ARG_TYPE (WalkState->ArgTypes), Op);
231         break;
232 
233     case AML_INT_NAMEPATH_OP:   /* AML_NAMESTRING_ARG */
234 
235         Status = AcpiPsGetNextNamepath (WalkState,
236             &(WalkState->ParserState), Op, ACPI_POSSIBLE_METHOD_CALL);
237         if (ACPI_FAILURE (Status))
238         {
239             return_ACPI_STATUS (Status);
240         }
241 
242         WalkState->ArgTypes = 0;
243         break;
244 
245     default:
246         /*
247          * Op is not a constant or string, append each argument to the Op
248          */
249         while (GET_CURRENT_ARG_TYPE (WalkState->ArgTypes) &&
250             !WalkState->ArgCount)
251         {
252             WalkState->Aml = WalkState->ParserState.Aml;
253 
254             switch (Op->Common.AmlOpcode)
255             {
256             case AML_METHOD_OP:
257             case AML_BUFFER_OP:
258             case AML_PACKAGE_OP:
259             case AML_VARIABLE_PACKAGE_OP:
260             case AML_WHILE_OP:
261 
262                 break;
263 
264             default:
265 
266                 ASL_CV_CAPTURE_COMMENTS (WalkState);
267                 break;
268             }
269 
270             Status = AcpiPsGetNextArg (WalkState, &(WalkState->ParserState),
271                 GET_CURRENT_ARG_TYPE (WalkState->ArgTypes), &Arg);
272             if (ACPI_FAILURE (Status))
273             {
274                 return_ACPI_STATUS (Status);
275             }
276 
277             if (Arg)
278             {
279                 AcpiPsAppendArg (Op, Arg);
280             }
281 
282             INCREMENT_ARG_LIST (WalkState->ArgTypes);
283         }
284 
285         ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
286             "Final argument count: %u pass %u\n",
287             WalkState->ArgCount, WalkState->PassNumber));
288 
289         /*
290          * Handle executable code at "module-level". This refers to
291          * executable opcodes that appear outside of any control method.
292          */
293         if ((WalkState->PassNumber <= ACPI_IMODE_LOAD_PASS2) &&
294             ((WalkState->ParseFlags & ACPI_PARSE_DISASSEMBLE) == 0))
295         {
296             /*
297              * We want to skip If/Else/While constructs during Pass1 because we
298              * want to actually conditionally execute the code during Pass2.
299              *
300              * Except for disassembly, where we always want to walk the
301              * If/Else/While packages
302              */
303             switch (Op->Common.AmlOpcode)
304             {
305             case AML_IF_OP:
306             case AML_ELSE_OP:
307             case AML_WHILE_OP:
308                 /*
309                  * Currently supported module-level opcodes are:
310                  * IF/ELSE/WHILE. These appear to be the most common,
311                  * and easiest to support since they open an AML
312                  * package.
313                  */
314                 if (WalkState->PassNumber == ACPI_IMODE_LOAD_PASS1)
315                 {
316                     AcpiPsLinkModuleCode (Op->Common.Parent, AmlOpStart,
317                         (UINT32) (WalkState->ParserState.PkgEnd - AmlOpStart),
318                         WalkState->OwnerId);
319                 }
320 
321                 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
322                     "Pass1: Skipping an If/Else/While body\n"));
323 
324                 /* Skip body of if/else/while in pass 1 */
325 
326                 WalkState->ParserState.Aml = WalkState->ParserState.PkgEnd;
327                 WalkState->ArgCount = 0;
328                 break;
329 
330             default:
331                 /*
332                  * Check for an unsupported executable opcode at module
333                  * level. We must be in PASS1, the parent must be a SCOPE,
334                  * The opcode class must be EXECUTE, and the opcode must
335                  * not be an argument to another opcode.
336                  */
337                 if ((WalkState->PassNumber == ACPI_IMODE_LOAD_PASS1) &&
338                     (Op->Common.Parent->Common.AmlOpcode == AML_SCOPE_OP))
339                 {
340                     OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
341                     if ((OpInfo->Class == AML_CLASS_EXECUTE) &&
342                         (!Arg))
343                     {
344                         ACPI_WARNING ((AE_INFO,
345                             "Unsupported module-level executable opcode "
346                             "0x%.2X at table offset 0x%.4X",
347                             Op->Common.AmlOpcode,
348                             (UINT32) (ACPI_PTR_DIFF (AmlOpStart,
349                                 WalkState->ParserState.AmlStart) +
350                                 sizeof (ACPI_TABLE_HEADER))));
351                     }
352                 }
353                 break;
354             }
355         }
356 
357         /* Special processing for certain opcodes */
358 
359         switch (Op->Common.AmlOpcode)
360         {
361         case AML_METHOD_OP:
362             /*
363              * Skip parsing of control method because we don't have enough
364              * info in the first pass to parse it correctly.
365              *
366              * Save the length and address of the body
367              */
368             Op->Named.Data = WalkState->ParserState.Aml;
369             Op->Named.Length = (UINT32)
370                 (WalkState->ParserState.PkgEnd - WalkState->ParserState.Aml);
371 
372             /* Skip body of method */
373 
374             WalkState->ParserState.Aml = WalkState->ParserState.PkgEnd;
375             WalkState->ArgCount = 0;
376             break;
377 
378         case AML_BUFFER_OP:
379         case AML_PACKAGE_OP:
380         case AML_VARIABLE_PACKAGE_OP:
381 
382             if ((Op->Common.Parent) &&
383                 (Op->Common.Parent->Common.AmlOpcode == AML_NAME_OP) &&
384                 (WalkState->PassNumber <= ACPI_IMODE_LOAD_PASS2))
385             {
386                 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
387                     "Setup Package/Buffer: Pass %u, AML Ptr: %p\n",
388                     WalkState->PassNumber, AmlOpStart));
389 
390                 /*
391                  * Skip parsing of Buffers and Packages because we don't have
392                  * enough info in the first pass to parse them correctly.
393                  */
394                 Op->Named.Data = AmlOpStart;
395                 Op->Named.Length = (UINT32)
396                     (WalkState->ParserState.PkgEnd - AmlOpStart);
397 
398                 /* Skip body */
399 
400                 WalkState->ParserState.Aml = WalkState->ParserState.PkgEnd;
401                 WalkState->ArgCount = 0;
402             }
403             break;
404 
405         case AML_WHILE_OP:
406 
407             if (WalkState->ControlState)
408             {
409                 WalkState->ControlState->Control.PackageEnd =
410                     WalkState->ParserState.PkgEnd;
411             }
412             break;
413 
414         default:
415 
416             /* No action for all other opcodes */
417 
418             break;
419         }
420 
421         break;
422     }
423 
424     return_ACPI_STATUS (AE_OK);
425 }
426 
427 
428 /*******************************************************************************
429  *
430  * FUNCTION:    AcpiPsLinkModuleCode
431  *
432  * PARAMETERS:  ParentOp            - Parent parser op
433  *              AmlStart            - Pointer to the AML
434  *              AmlLength           - Length of executable AML
435  *              OwnerId             - OwnerId of module level code
436  *
437  * RETURN:      None.
438  *
439  * DESCRIPTION: Wrap the module-level code with a method object and link the
440  *              object to the global list. Note, the mutex field of the method
441  *              object is used to link multiple module-level code objects.
442  *
443  ******************************************************************************/
444 
445 static void
446 AcpiPsLinkModuleCode (
447     ACPI_PARSE_OBJECT       *ParentOp,
448     UINT8                   *AmlStart,
449     UINT32                  AmlLength,
450     ACPI_OWNER_ID           OwnerId)
451 {
452     ACPI_OPERAND_OBJECT     *Prev;
453     ACPI_OPERAND_OBJECT     *Next;
454     ACPI_OPERAND_OBJECT     *MethodObj;
455     ACPI_NAMESPACE_NODE     *ParentNode;
456 
457 
458     ACPI_FUNCTION_TRACE (PsLinkModuleCode);
459 
460 
461     /* Get the tail of the list */
462 
463     Prev = Next = AcpiGbl_ModuleCodeList;
464     while (Next)
465     {
466         Prev = Next;
467         Next = Next->Method.Mutex;
468     }
469 
470     /*
471      * Insert the module level code into the list. Merge it if it is
472      * adjacent to the previous element.
473      */
474     if (!Prev ||
475        ((Prev->Method.AmlStart + Prev->Method.AmlLength) != AmlStart))
476     {
477         /* Create, initialize, and link a new temporary method object */
478 
479         MethodObj = AcpiUtCreateInternalObject (ACPI_TYPE_METHOD);
480         if (!MethodObj)
481         {
482             return_VOID;
483         }
484 
485         ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
486             "Create/Link new code block: %p\n", MethodObj));
487 
488         if (ParentOp->Common.Node)
489         {
490             ParentNode = ParentOp->Common.Node;
491         }
492         else
493         {
494             ParentNode = AcpiGbl_RootNode;
495         }
496 
497         MethodObj->Method.AmlStart = AmlStart;
498         MethodObj->Method.AmlLength = AmlLength;
499         MethodObj->Method.OwnerId = OwnerId;
500         MethodObj->Method.InfoFlags |= ACPI_METHOD_MODULE_LEVEL;
501 
502         /*
503          * Save the parent node in NextObject. This is cheating, but we
504          * don't want to expand the method object.
505          */
506         MethodObj->Method.NextObject =
507             ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, ParentNode);
508 
509         if (!Prev)
510         {
511             AcpiGbl_ModuleCodeList = MethodObj;
512         }
513         else
514         {
515             Prev->Method.Mutex = MethodObj;
516         }
517     }
518     else
519     {
520         ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
521             "Appending to existing code block: %p\n", Prev));
522 
523         Prev->Method.AmlLength += AmlLength;
524     }
525 
526     return_VOID;
527 }
528 
529 /*******************************************************************************
530  *
531  * FUNCTION:    AcpiPsParseLoop
532  *
533  * PARAMETERS:  WalkState           - Current state
534  *
535  * RETURN:      Status
536  *
537  * DESCRIPTION: Parse AML (pointed to by the current parser state) and return
538  *              a tree of ops.
539  *
540  ******************************************************************************/
541 
542 ACPI_STATUS
543 AcpiPsParseLoop (
544     ACPI_WALK_STATE         *WalkState)
545 {
546     ACPI_STATUS             Status = AE_OK;
547     ACPI_PARSE_OBJECT       *Op = NULL;     /* current op */
548     ACPI_PARSE_STATE        *ParserState;
549     UINT8                   *AmlOpStart = NULL;
550 
551 
552     ACPI_FUNCTION_TRACE_PTR (PsParseLoop, WalkState);
553 
554 
555     if (WalkState->DescendingCallback == NULL)
556     {
557         return_ACPI_STATUS (AE_BAD_PARAMETER);
558     }
559 
560     ParserState = &WalkState->ParserState;
561     WalkState->ArgTypes = 0;
562 
563 #if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
564 
565     if (WalkState->WalkType & ACPI_WALK_METHOD_RESTART)
566     {
567         /* We are restarting a preempted control method */
568 
569         if (AcpiPsHasCompletedScope (ParserState))
570         {
571             /*
572              * We must check if a predicate to an IF or WHILE statement
573              * was just completed
574              */
575             if ((ParserState->Scope->ParseScope.Op) &&
576                ((ParserState->Scope->ParseScope.Op->Common.AmlOpcode == AML_IF_OP) ||
577                 (ParserState->Scope->ParseScope.Op->Common.AmlOpcode == AML_WHILE_OP)) &&
578                 (WalkState->ControlState) &&
579                 (WalkState->ControlState->Common.State ==
580                     ACPI_CONTROL_PREDICATE_EXECUTING))
581             {
582                 /*
583                  * A predicate was just completed, get the value of the
584                  * predicate and branch based on that value
585                  */
586                 WalkState->Op = NULL;
587                 Status = AcpiDsGetPredicateValue (WalkState, ACPI_TO_POINTER (TRUE));
588                 if (ACPI_FAILURE (Status) &&
589                     ((Status & AE_CODE_MASK) != AE_CODE_CONTROL))
590                 {
591                     if (Status == AE_AML_NO_RETURN_VALUE)
592                     {
593                         ACPI_EXCEPTION ((AE_INFO, Status,
594                             "Invoked method did not return a value"));
595                     }
596 
597                     ACPI_EXCEPTION ((AE_INFO, Status, "GetPredicate Failed"));
598                     return_ACPI_STATUS (Status);
599                 }
600 
601                 Status = AcpiPsNextParseState (WalkState, Op, Status);
602             }
603 
604             AcpiPsPopScope (ParserState, &Op,
605                 &WalkState->ArgTypes, &WalkState->ArgCount);
606             ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Popped scope, Op=%p\n", Op));
607         }
608         else if (WalkState->PrevOp)
609         {
610             /* We were in the middle of an op */
611 
612             Op = WalkState->PrevOp;
613             WalkState->ArgTypes = WalkState->PrevArgTypes;
614         }
615     }
616 #endif
617 
618     /* Iterative parsing loop, while there is more AML to process: */
619 
620     while ((ParserState->Aml < ParserState->AmlEnd) || (Op))
621     {
622         ASL_CV_CAPTURE_COMMENTS (WalkState);
623 
624         AmlOpStart = ParserState->Aml;
625         if (!Op)
626         {
627             Status = AcpiPsCreateOp (WalkState, AmlOpStart, &Op);
628             if (ACPI_FAILURE (Status))
629             {
630                 if (Status == AE_CTRL_PARSE_CONTINUE)
631                 {
632                     continue;
633                 }
634 
635                 if (Status == AE_CTRL_PARSE_PENDING)
636                 {
637                     Status = AE_OK;
638                 }
639 
640                 if (Status == AE_CTRL_TERMINATE)
641                 {
642                     return_ACPI_STATUS (Status);
643                 }
644 
645                 Status = AcpiPsCompleteOp (WalkState, &Op, Status);
646                 if (ACPI_FAILURE (Status))
647                 {
648                     return_ACPI_STATUS (Status);
649                 }
650 
651                 continue;
652             }
653 
654             AcpiExStartTraceOpcode (Op, WalkState);
655         }
656 
657         /*
658          * Start ArgCount at zero because we don't know if there are
659          * any args yet
660          */
661         WalkState->ArgCount = 0;
662 
663         switch (Op->Common.AmlOpcode)
664         {
665         case AML_BYTE_OP:
666         case AML_WORD_OP:
667         case AML_DWORD_OP:
668         case AML_QWORD_OP:
669 
670             break;
671 
672         default:
673 
674             ASL_CV_CAPTURE_COMMENTS (WalkState);
675             break;
676         }
677 
678         /* Are there any arguments that must be processed? */
679 
680         if (WalkState->ArgTypes)
681         {
682             /* Get arguments */
683 
684             Status = AcpiPsGetArguments (WalkState, AmlOpStart, Op);
685             if (ACPI_FAILURE (Status))
686             {
687                 Status = AcpiPsCompleteOp (WalkState, &Op, Status);
688                 if (ACPI_FAILURE (Status))
689                 {
690                     return_ACPI_STATUS (Status);
691                 }
692 
693                 continue;
694             }
695         }
696 
697         /* Check for arguments that need to be processed */
698 
699         ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
700             "Parseloop: argument count: %u\n", WalkState->ArgCount));
701 
702         if (WalkState->ArgCount)
703         {
704             /*
705              * There are arguments (complex ones), push Op and
706              * prepare for argument
707              */
708             Status = AcpiPsPushScope (ParserState, Op,
709                 WalkState->ArgTypes, WalkState->ArgCount);
710             if (ACPI_FAILURE (Status))
711             {
712                 Status = AcpiPsCompleteOp (WalkState, &Op, Status);
713                 if (ACPI_FAILURE (Status))
714                 {
715                     return_ACPI_STATUS (Status);
716                 }
717 
718                 continue;
719             }
720 
721             Op = NULL;
722             continue;
723         }
724 
725         /*
726          * All arguments have been processed -- Op is complete,
727          * prepare for next
728          */
729         WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
730         if (WalkState->OpInfo->Flags & AML_NAMED)
731         {
732             if (Op->Common.AmlOpcode == AML_REGION_OP ||
733                 Op->Common.AmlOpcode == AML_DATA_REGION_OP)
734             {
735                 /*
736                  * Skip parsing of control method or opregion body,
737                  * because we don't have enough info in the first pass
738                  * to parse them correctly.
739                  *
740                  * Completed parsing an OpRegion declaration, we now
741                  * know the length.
742                  */
743                 Op->Named.Length = (UINT32) (ParserState->Aml - Op->Named.Data);
744             }
745         }
746 
747         if (WalkState->OpInfo->Flags & AML_CREATE)
748         {
749             /*
750              * Backup to beginning of CreateXXXfield declaration (1 for
751              * Opcode)
752              *
753              * BodyLength is unknown until we parse the body
754              */
755             Op->Named.Length = (UINT32) (ParserState->Aml - Op->Named.Data);
756         }
757 
758         if (Op->Common.AmlOpcode == AML_BANK_FIELD_OP)
759         {
760             /*
761              * Backup to beginning of BankField declaration
762              *
763              * BodyLength is unknown until we parse the body
764              */
765             Op->Named.Length = (UINT32) (ParserState->Aml - Op->Named.Data);
766         }
767 
768         /* This op complete, notify the dispatcher */
769 
770         if (WalkState->AscendingCallback != NULL)
771         {
772             WalkState->Op = Op;
773             WalkState->Opcode = Op->Common.AmlOpcode;
774 
775             Status = WalkState->AscendingCallback (WalkState);
776             Status = AcpiPsNextParseState (WalkState, Op, Status);
777             if (Status == AE_CTRL_PENDING)
778             {
779                 Status = AE_OK;
780             }
781         }
782 
783         Status = AcpiPsCompleteOp (WalkState, &Op, Status);
784         if (ACPI_FAILURE (Status))
785         {
786             return_ACPI_STATUS (Status);
787         }
788 
789     } /* while ParserState->Aml */
790 
791     Status = AcpiPsCompleteFinalOp (WalkState, Op, Status);
792     return_ACPI_STATUS (Status);
793 }
794