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 - 2020, 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 
182 /*******************************************************************************
183  *
184  * FUNCTION:    AcpiPsGetArguments
185  *
186  * PARAMETERS:  WalkState           - Current state
187  *              AmlOpStart          - Op start in AML
188  *              Op                  - Current Op
189  *
190  * RETURN:      Status
191  *
192  * DESCRIPTION: Get arguments for passed Op.
193  *
194  ******************************************************************************/
195 
196 static ACPI_STATUS
197 AcpiPsGetArguments (
198     ACPI_WALK_STATE         *WalkState,
199     UINT8                   *AmlOpStart,
200     ACPI_PARSE_OBJECT       *Op)
201 {
202     ACPI_STATUS             Status = AE_OK;
203     ACPI_PARSE_OBJECT       *Arg = NULL;
204 
205 
206     ACPI_FUNCTION_TRACE_PTR (PsGetArguments, WalkState);
207 
208 
209     ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
210         "Get arguments for opcode [%s]\n", Op->Common.AmlOpName));
211 
212     switch (Op->Common.AmlOpcode)
213     {
214     case AML_BYTE_OP:       /* AML_BYTEDATA_ARG */
215     case AML_WORD_OP:       /* AML_WORDDATA_ARG */
216     case AML_DWORD_OP:      /* AML_DWORDATA_ARG */
217     case AML_QWORD_OP:      /* AML_QWORDATA_ARG */
218     case AML_STRING_OP:     /* AML_ASCIICHARLIST_ARG */
219 
220         /* Fill in constant or string argument directly */
221 
222         AcpiPsGetNextSimpleArg (&(WalkState->ParserState),
223             GET_CURRENT_ARG_TYPE (WalkState->ArgTypes), Op);
224         break;
225 
226     case AML_INT_NAMEPATH_OP:   /* AML_NAMESTRING_ARG */
227 
228         Status = AcpiPsGetNextNamepath (WalkState,
229             &(WalkState->ParserState), Op, ACPI_POSSIBLE_METHOD_CALL);
230         if (ACPI_FAILURE (Status))
231         {
232             return_ACPI_STATUS (Status);
233         }
234 
235         WalkState->ArgTypes = 0;
236         break;
237 
238     default:
239         /*
240          * Op is not a constant or string, append each argument to the Op
241          */
242         while (GET_CURRENT_ARG_TYPE (WalkState->ArgTypes) &&
243             !WalkState->ArgCount)
244         {
245             WalkState->Aml = WalkState->ParserState.Aml;
246 
247             switch (Op->Common.AmlOpcode)
248             {
249             case AML_METHOD_OP:
250             case AML_BUFFER_OP:
251             case AML_PACKAGE_OP:
252             case AML_VARIABLE_PACKAGE_OP:
253             case AML_WHILE_OP:
254 
255                 break;
256 
257             default:
258 
259                 ASL_CV_CAPTURE_COMMENTS (WalkState);
260                 break;
261             }
262 
263             Status = AcpiPsGetNextArg (WalkState, &(WalkState->ParserState),
264                 GET_CURRENT_ARG_TYPE (WalkState->ArgTypes), &Arg);
265             if (ACPI_FAILURE (Status))
266             {
267                 return_ACPI_STATUS (Status);
268             }
269 
270             if (Arg)
271             {
272                 AcpiPsAppendArg (Op, Arg);
273             }
274 
275             INCREMENT_ARG_LIST (WalkState->ArgTypes);
276         }
277 
278         ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
279             "Final argument count: %8.8X pass %u\n",
280             WalkState->ArgCount, WalkState->PassNumber));
281 
282         /* Special processing for certain opcodes */
283 
284         switch (Op->Common.AmlOpcode)
285         {
286         case AML_METHOD_OP:
287             /*
288              * Skip parsing of control method because we don't have enough
289              * info in the first pass to parse it correctly.
290              *
291              * Save the length and address of the body
292              */
293             Op->Named.Data = WalkState->ParserState.Aml;
294             Op->Named.Length = (UINT32)
295                 (WalkState->ParserState.PkgEnd - WalkState->ParserState.Aml);
296 
297             /* Skip body of method */
298 
299             WalkState->ParserState.Aml = WalkState->ParserState.PkgEnd;
300             WalkState->ArgCount = 0;
301             break;
302 
303         case AML_BUFFER_OP:
304         case AML_PACKAGE_OP:
305         case AML_VARIABLE_PACKAGE_OP:
306 
307             if ((Op->Common.Parent) &&
308                 (Op->Common.Parent->Common.AmlOpcode == AML_NAME_OP) &&
309                 (WalkState->PassNumber <= ACPI_IMODE_LOAD_PASS2))
310             {
311                 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
312                     "Setup Package/Buffer: Pass %u, AML Ptr: %p\n",
313                     WalkState->PassNumber, AmlOpStart));
314 
315                 /*
316                  * Skip parsing of Buffers and Packages because we don't have
317                  * enough info in the first pass to parse them correctly.
318                  */
319                 Op->Named.Data = AmlOpStart;
320                 Op->Named.Length = (UINT32)
321                     (WalkState->ParserState.PkgEnd - AmlOpStart);
322 
323                 /* Skip body */
324 
325                 WalkState->ParserState.Aml = WalkState->ParserState.PkgEnd;
326                 WalkState->ArgCount = 0;
327             }
328             break;
329 
330         case AML_WHILE_OP:
331 
332             if (WalkState->ControlState)
333             {
334                 WalkState->ControlState->Control.PackageEnd =
335                     WalkState->ParserState.PkgEnd;
336             }
337             break;
338 
339         default:
340 
341             /* No action for all other opcodes */
342 
343             break;
344         }
345 
346         break;
347     }
348 
349     return_ACPI_STATUS (AE_OK);
350 }
351 
352 
353 /*******************************************************************************
354  *
355  * FUNCTION:    AcpiPsParseLoop
356  *
357  * PARAMETERS:  WalkState           - Current state
358  *
359  * RETURN:      Status
360  *
361  * DESCRIPTION: Parse AML (pointed to by the current parser state) and return
362  *              a tree of ops.
363  *
364  ******************************************************************************/
365 
366 #ifdef _KERNEL
367 #define TDTRACKER	mycpu->gd_curthread->td_tracker
368 #define TDTRACKER_INC	++mycpu->gd_curthread->td_tracker
369 #define TDTRACKER_DEC	--mycpu->gd_curthread->td_tracker
370 #else
371 #define TDTRACKER	0
372 #define TDTRACKER_INC
373 #define TDTRACKER_DEC
374 #endif
375 
376 ACPI_STATUS
377 AcpiPsParseLoop (
378     ACPI_WALK_STATE         *WalkState)
379 {
380     ACPI_STATUS             Status = AE_OK;
381     ACPI_PARSE_OBJECT       *Op = NULL;     /* current op */
382     ACPI_PARSE_STATE        *ParserState;
383     UINT8                   *AmlOpStart = NULL;
384     UINT8                   OpcodeLength;
385 
386 
387     ACPI_FUNCTION_TRACE_PTR (PsParseLoop, WalkState);
388 
389 
390     if (WalkState->DescendingCallback == NULL)
391     {
392         return_ACPI_STATUS (AE_BAD_PARAMETER);
393     }
394     if (TDTRACKER > 5) {
395 #ifdef _KERNEL
396 	kprintf("AcpiPsParseLoop - Recursed too deep\n");
397 #else
398 	printf("AcpiPsParseLoop - Recursed too deep\n");
399 #endif
400         return_ACPI_STATUS (AE_BAD_PARAMETER);
401     }
402     TDTRACKER_INC;
403 
404     ParserState = &WalkState->ParserState;
405     WalkState->ArgTypes = 0;
406 
407 #ifndef ACPI_CONSTANT_EVAL_ONLY
408 
409     if (WalkState->WalkType & ACPI_WALK_METHOD_RESTART)
410     {
411         /* We are restarting a preempted control method */
412 
413         if (AcpiPsHasCompletedScope (ParserState))
414         {
415             /*
416              * We must check if a predicate to an IF or WHILE statement
417              * was just completed
418              */
419             if ((ParserState->Scope->ParseScope.Op) &&
420                ((ParserState->Scope->ParseScope.Op->Common.AmlOpcode == AML_IF_OP) ||
421                 (ParserState->Scope->ParseScope.Op->Common.AmlOpcode == AML_WHILE_OP)) &&
422                 (WalkState->ControlState) &&
423                 (WalkState->ControlState->Common.State ==
424                     ACPI_CONTROL_PREDICATE_EXECUTING))
425             {
426                 /*
427                  * A predicate was just completed, get the value of the
428                  * predicate and branch based on that value
429                  */
430                 WalkState->Op = NULL;
431                 Status = AcpiDsGetPredicateValue (WalkState, ACPI_TO_POINTER (TRUE));
432                 if (ACPI_FAILURE (Status) &&
433                     ((Status & AE_CODE_MASK) != AE_CODE_CONTROL))
434                 {
435                     if (Status == AE_AML_NO_RETURN_VALUE)
436                     {
437                         ACPI_EXCEPTION ((AE_INFO, Status,
438                             "Invoked method did not return a value"));
439                     }
440 
441                     ACPI_EXCEPTION ((AE_INFO, Status, "GetPredicate Failed"));
442 		    TDTRACKER_DEC;
443                     return_ACPI_STATUS (Status);
444                 }
445 
446                 Status = AcpiPsNextParseState (WalkState, Op, Status);
447             }
448 
449             AcpiPsPopScope (ParserState, &Op,
450                 &WalkState->ArgTypes, &WalkState->ArgCount);
451             ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Popped scope, Op=%p\n", Op));
452         }
453         else if (WalkState->PrevOp)
454         {
455             /* We were in the middle of an op */
456 
457             Op = WalkState->PrevOp;
458             WalkState->ArgTypes = WalkState->PrevArgTypes;
459         }
460     }
461 #endif
462 
463     /* Iterative parsing loop, while there is more AML to process: */
464 
465     while ((ParserState->Aml < ParserState->AmlEnd) || (Op))
466     {
467         ASL_CV_CAPTURE_COMMENTS (WalkState);
468 
469         AmlOpStart = ParserState->Aml;
470         if (!Op)
471         {
472             Status = AcpiPsCreateOp (WalkState, AmlOpStart, &Op);
473             if (ACPI_FAILURE (Status))
474             {
475                 /*
476                  * ACPI_PARSE_MODULE_LEVEL means that we are loading a table by
477                  * executing it as a control method. However, if we encounter
478                  * an error while loading the table, we need to keep trying to
479                  * load the table rather than aborting the table load. Set the
480                  * status to AE_OK to proceed with the table load.
481                  */
482                 if ((WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL) &&
483                     ((Status == AE_ALREADY_EXISTS) || (Status == AE_NOT_FOUND)))
484                 {
485                     Status = AE_OK;
486                 }
487                 if (Status == AE_CTRL_PARSE_CONTINUE)
488                 {
489                     continue;
490                 }
491 
492                 if (Status == AE_CTRL_PARSE_PENDING)
493                 {
494                     Status = AE_OK;
495                 }
496 
497                 if (Status == AE_CTRL_TERMINATE)
498                 {
499 		    TDTRACKER_DEC;
500                     return_ACPI_STATUS (Status);
501                 }
502 
503                 Status = AcpiPsCompleteOp (WalkState, &Op, Status);
504                 if (ACPI_FAILURE (Status))
505                 {
506 		    TDTRACKER_DEC;
507                     return_ACPI_STATUS (Status);
508                 }
509                 if (AcpiNsOpensScope (
510                     AcpiPsGetOpcodeInfo (WalkState->Opcode)->ObjectType))
511                 {
512                     /*
513                      * If the scope/device op fails to parse, skip the body of
514                      * the scope op because the parse failure indicates that
515                      * the device may not exist.
516                      */
517                     ACPI_INFO (("Skipping parse of AML opcode: %s (0x%4.4X)",
518                         AcpiPsGetOpcodeName (WalkState->Opcode), WalkState->Opcode));
519 
520                     /*
521                      * Determine the opcode length before skipping the opcode.
522                      * An opcode can be 1 byte or 2 bytes in length.
523                      */
524                     OpcodeLength = 1;
525                     if ((WalkState->Opcode & 0xFF00) == AML_EXTENDED_OPCODE)
526                     {
527                         OpcodeLength = 2;
528                     }
529                     WalkState->ParserState.Aml = WalkState->Aml + OpcodeLength;
530 
531                     WalkState->ParserState.Aml =
532                         AcpiPsGetNextPackageEnd(&WalkState->ParserState);
533                     WalkState->Aml = WalkState->ParserState.Aml;
534                 }
535 
536                 continue;
537             }
538 
539             AcpiExStartTraceOpcode (Op, WalkState);
540         }
541 
542         /*
543          * Start ArgCount at zero because we don't know if there are
544          * any args yet
545          */
546         WalkState->ArgCount = 0;
547 
548         switch (Op->Common.AmlOpcode)
549         {
550         case AML_BYTE_OP:
551         case AML_WORD_OP:
552         case AML_DWORD_OP:
553         case AML_QWORD_OP:
554 
555             break;
556 
557         default:
558 
559             ASL_CV_CAPTURE_COMMENTS (WalkState);
560             break;
561         }
562 
563         /* Are there any arguments that must be processed? */
564 
565         if (WalkState->ArgTypes)
566         {
567             /* Get arguments */
568 
569             Status = AcpiPsGetArguments (WalkState, AmlOpStart, Op);
570             if (ACPI_FAILURE (Status))
571             {
572                 Status = AcpiPsCompleteOp (WalkState, &Op, Status);
573                 if (ACPI_FAILURE (Status))
574                 {
575 		    TDTRACKER_DEC;
576                     return_ACPI_STATUS (Status);
577                 }
578                 if ((WalkState->ControlState) &&
579                     ((WalkState->ControlState->Control.Opcode == AML_IF_OP) ||
580                     (WalkState->ControlState->Control.Opcode == AML_WHILE_OP)))
581                 {
582                     /*
583                      * If the if/while op fails to parse, we will skip parsing
584                      * the body of the op.
585                      */
586                     ParserState->Aml =
587                         WalkState->ControlState->Control.AmlPredicateStart + 1;
588                     ParserState->Aml =
589                         AcpiPsGetNextPackageEnd (ParserState);
590                     WalkState->Aml = ParserState->Aml;
591 
592                     ACPI_ERROR ((AE_INFO, "Skipping While/If block"));
593                     if (*WalkState->Aml == AML_ELSE_OP)
594                     {
595                         ACPI_ERROR ((AE_INFO, "Skipping Else block"));
596                         WalkState->ParserState.Aml = WalkState->Aml + 1;
597                         WalkState->ParserState.Aml =
598                             AcpiPsGetNextPackageEnd (ParserState);
599                         WalkState->Aml = ParserState->Aml;
600                     }
601                     ACPI_FREE(AcpiUtPopGenericState (&WalkState->ControlState));
602                 }
603                 Op = NULL;
604                 continue;
605             }
606         }
607 
608         /* Check for arguments that need to be processed */
609 
610         ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
611             "Parseloop: argument count: %8.8X\n", WalkState->ArgCount));
612 
613         if (WalkState->ArgCount)
614         {
615             /*
616              * There are arguments (complex ones), push Op and
617              * prepare for argument
618              */
619             Status = AcpiPsPushScope (ParserState, Op,
620                 WalkState->ArgTypes, WalkState->ArgCount);
621             if (ACPI_FAILURE (Status))
622             {
623                 Status = AcpiPsCompleteOp (WalkState, &Op, Status);
624                 if (ACPI_FAILURE (Status))
625                 {
626 		    TDTRACKER_DEC;
627                     return_ACPI_STATUS (Status);
628                 }
629 
630                 continue;
631             }
632 
633             Op = NULL;
634             continue;
635         }
636 
637         /*
638          * All arguments have been processed -- Op is complete,
639          * prepare for next
640          */
641         WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
642         if (WalkState->OpInfo->Flags & AML_NAMED)
643         {
644             if (Op->Common.AmlOpcode == AML_REGION_OP ||
645                 Op->Common.AmlOpcode == AML_DATA_REGION_OP)
646             {
647                 /*
648                  * Skip parsing of control method or opregion body,
649                  * because we don't have enough info in the first pass
650                  * to parse them correctly.
651                  *
652                  * Completed parsing an OpRegion declaration, we now
653                  * know the length.
654                  */
655                 Op->Named.Length = (UINT32) (ParserState->Aml - Op->Named.Data);
656             }
657         }
658 
659         if (WalkState->OpInfo->Flags & AML_CREATE)
660         {
661             /*
662              * Backup to beginning of CreateXXXfield declaration (1 for
663              * Opcode)
664              *
665              * BodyLength is unknown until we parse the body
666              */
667             Op->Named.Length = (UINT32) (ParserState->Aml - Op->Named.Data);
668         }
669 
670         if (Op->Common.AmlOpcode == AML_BANK_FIELD_OP)
671         {
672             /*
673              * Backup to beginning of BankField declaration
674              *
675              * BodyLength is unknown until we parse the body
676              */
677             Op->Named.Length = (UINT32) (ParserState->Aml - Op->Named.Data);
678         }
679 
680         /* This op complete, notify the dispatcher */
681 
682         if (WalkState->AscendingCallback != NULL)
683         {
684             WalkState->Op = Op;
685             WalkState->Opcode = Op->Common.AmlOpcode;
686 
687             Status = WalkState->AscendingCallback (WalkState);
688             Status = AcpiPsNextParseState (WalkState, Op, Status);
689             if (Status == AE_CTRL_PENDING)
690             {
691                 Status = AE_OK;
692             }
693             else if ((WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL) &&
694                 (ACPI_AML_EXCEPTION(Status) || Status == AE_ALREADY_EXISTS ||
695                 Status == AE_NOT_FOUND))
696             {
697                 /*
698                  * ACPI_PARSE_MODULE_LEVEL flag means that we are currently
699                  * loading a table by executing it as a control method.
700                  * However, if we encounter an error while loading the table,
701                  * we need to keep trying to load the table rather than
702                  * aborting the table load (setting the status to AE_OK
703                  * continues the table load). If we get a failure at this
704                  * point, it means that the dispatcher got an error while
705                  * trying to execute the Op.
706                  */
707                 Status = AE_OK;
708             }
709         }
710 
711         Status = AcpiPsCompleteOp (WalkState, &Op, Status);
712         if (ACPI_FAILURE (Status))
713         {
714 	    TDTRACKER_DEC;
715             return_ACPI_STATUS (Status);
716         }
717 
718     } /* while ParserState->Aml */
719 
720     Status = AcpiPsCompleteFinalOp (WalkState, Op, Status);
721     TDTRACKER_DEC;
722     return_ACPI_STATUS (Status);
723 }
724