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