Home | History | Annotate | Line # | Download | only in parser
psloop.c revision 1.1.1.15.4.1
      1           1.1    jruoho /******************************************************************************
      2           1.1    jruoho  *
      3           1.1    jruoho  * Module Name: psloop - Main AML parse loop
      4           1.1    jruoho  *
      5           1.1    jruoho  *****************************************************************************/
      6           1.1    jruoho 
      7       1.1.1.2    jruoho /*
      8  1.1.1.15.4.1   thorpej  * Copyright (C) 2000 - 2021, Intel Corp.
      9           1.1    jruoho  * All rights reserved.
     10           1.1    jruoho  *
     11       1.1.1.2    jruoho  * Redistribution and use in source and binary forms, with or without
     12       1.1.1.2    jruoho  * modification, are permitted provided that the following conditions
     13       1.1.1.2    jruoho  * are met:
     14       1.1.1.2    jruoho  * 1. Redistributions of source code must retain the above copyright
     15       1.1.1.2    jruoho  *    notice, this list of conditions, and the following disclaimer,
     16       1.1.1.2    jruoho  *    without modification.
     17       1.1.1.2    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18       1.1.1.2    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19       1.1.1.2    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20       1.1.1.2    jruoho  *    including a substantially similar Disclaimer requirement for further
     21       1.1.1.2    jruoho  *    binary redistribution.
     22       1.1.1.2    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23       1.1.1.2    jruoho  *    of any contributors may be used to endorse or promote products derived
     24       1.1.1.2    jruoho  *    from this software without specific prior written permission.
     25       1.1.1.2    jruoho  *
     26       1.1.1.2    jruoho  * Alternatively, this software may be distributed under the terms of the
     27       1.1.1.2    jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28       1.1.1.2    jruoho  * Software Foundation.
     29       1.1.1.2    jruoho  *
     30       1.1.1.2    jruoho  * NO WARRANTY
     31       1.1.1.2    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32       1.1.1.2    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.1.1.15.4.1   thorpej  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     34       1.1.1.2    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35       1.1.1.2    jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36       1.1.1.2    jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37       1.1.1.2    jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38       1.1.1.2    jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39       1.1.1.2    jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40       1.1.1.2    jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41       1.1.1.2    jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42       1.1.1.2    jruoho  */
     43           1.1    jruoho 
     44           1.1    jruoho /*
     45           1.1    jruoho  * Parse the AML and build an operation tree as most interpreters, (such as
     46           1.1    jruoho  * Perl) do. Parsing is done by hand rather than with a YACC generated parser
     47           1.1    jruoho  * to tightly constrain stack and dynamic memory usage. Parsing is kept
     48           1.1    jruoho  * flexible and the code fairly compact by parsing based on a list of AML
     49           1.1    jruoho  * opcode templates in AmlOpInfo[].
     50           1.1    jruoho  */
     51           1.1    jruoho 
     52           1.1    jruoho #include "acpi.h"
     53           1.1    jruoho #include "accommon.h"
     54       1.1.1.6  christos #include "acinterp.h"
     55           1.1    jruoho #include "acparser.h"
     56           1.1    jruoho #include "acdispat.h"
     57           1.1    jruoho #include "amlcode.h"
     58       1.1.1.9  christos #include "acconvert.h"
     59      1.1.1.12  christos #include "acnamesp.h"
     60           1.1    jruoho 
     61           1.1    jruoho #define _COMPONENT          ACPI_PARSER
     62           1.1    jruoho         ACPI_MODULE_NAME    ("psloop")
     63           1.1    jruoho 
     64           1.1    jruoho 
     65           1.1    jruoho /* Local prototypes */
     66           1.1    jruoho 
     67           1.1    jruoho static ACPI_STATUS
     68           1.1    jruoho AcpiPsGetArguments (
     69           1.1    jruoho     ACPI_WALK_STATE         *WalkState,
     70           1.1    jruoho     UINT8                   *AmlOpStart,
     71           1.1    jruoho     ACPI_PARSE_OBJECT       *Op);
     72           1.1    jruoho 
     73           1.1    jruoho 
     74           1.1    jruoho /*******************************************************************************
     75           1.1    jruoho  *
     76           1.1    jruoho  * FUNCTION:    AcpiPsGetArguments
     77           1.1    jruoho  *
     78           1.1    jruoho  * PARAMETERS:  WalkState           - Current state
     79           1.1    jruoho  *              AmlOpStart          - Op start in AML
     80           1.1    jruoho  *              Op                  - Current Op
     81           1.1    jruoho  *
     82           1.1    jruoho  * RETURN:      Status
     83           1.1    jruoho  *
     84           1.1    jruoho  * DESCRIPTION: Get arguments for passed Op.
     85           1.1    jruoho  *
     86           1.1    jruoho  ******************************************************************************/
     87           1.1    jruoho 
     88           1.1    jruoho static ACPI_STATUS
     89           1.1    jruoho AcpiPsGetArguments (
     90           1.1    jruoho     ACPI_WALK_STATE         *WalkState,
     91           1.1    jruoho     UINT8                   *AmlOpStart,
     92           1.1    jruoho     ACPI_PARSE_OBJECT       *Op)
     93           1.1    jruoho {
     94           1.1    jruoho     ACPI_STATUS             Status = AE_OK;
     95           1.1    jruoho     ACPI_PARSE_OBJECT       *Arg = NULL;
     96           1.1    jruoho 
     97           1.1    jruoho 
     98           1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (PsGetArguments, WalkState);
     99           1.1    jruoho 
    100           1.1    jruoho 
    101       1.1.1.8  christos     ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
    102       1.1.1.8  christos         "Get arguments for opcode [%s]\n", Op->Common.AmlOpName));
    103       1.1.1.8  christos 
    104           1.1    jruoho     switch (Op->Common.AmlOpcode)
    105           1.1    jruoho     {
    106           1.1    jruoho     case AML_BYTE_OP:       /* AML_BYTEDATA_ARG */
    107           1.1    jruoho     case AML_WORD_OP:       /* AML_WORDDATA_ARG */
    108           1.1    jruoho     case AML_DWORD_OP:      /* AML_DWORDATA_ARG */
    109           1.1    jruoho     case AML_QWORD_OP:      /* AML_QWORDATA_ARG */
    110           1.1    jruoho     case AML_STRING_OP:     /* AML_ASCIICHARLIST_ARG */
    111           1.1    jruoho 
    112           1.1    jruoho         /* Fill in constant or string argument directly */
    113           1.1    jruoho 
    114           1.1    jruoho         AcpiPsGetNextSimpleArg (&(WalkState->ParserState),
    115           1.1    jruoho             GET_CURRENT_ARG_TYPE (WalkState->ArgTypes), Op);
    116           1.1    jruoho         break;
    117           1.1    jruoho 
    118           1.1    jruoho     case AML_INT_NAMEPATH_OP:   /* AML_NAMESTRING_ARG */
    119           1.1    jruoho 
    120       1.1.1.7  christos         Status = AcpiPsGetNextNamepath (WalkState,
    121       1.1.1.7  christos             &(WalkState->ParserState), Op, ACPI_POSSIBLE_METHOD_CALL);
    122           1.1    jruoho         if (ACPI_FAILURE (Status))
    123           1.1    jruoho         {
    124           1.1    jruoho             return_ACPI_STATUS (Status);
    125           1.1    jruoho         }
    126           1.1    jruoho 
    127           1.1    jruoho         WalkState->ArgTypes = 0;
    128           1.1    jruoho         break;
    129           1.1    jruoho 
    130           1.1    jruoho     default:
    131           1.1    jruoho         /*
    132           1.1    jruoho          * Op is not a constant or string, append each argument to the Op
    133           1.1    jruoho          */
    134       1.1.1.7  christos         while (GET_CURRENT_ARG_TYPE (WalkState->ArgTypes) &&
    135       1.1.1.7  christos             !WalkState->ArgCount)
    136           1.1    jruoho         {
    137       1.1.1.6  christos             WalkState->Aml = WalkState->ParserState.Aml;
    138           1.1    jruoho 
    139       1.1.1.9  christos             switch (Op->Common.AmlOpcode)
    140       1.1.1.9  christos             {
    141       1.1.1.9  christos             case AML_METHOD_OP:
    142       1.1.1.9  christos             case AML_BUFFER_OP:
    143       1.1.1.9  christos             case AML_PACKAGE_OP:
    144       1.1.1.9  christos             case AML_VARIABLE_PACKAGE_OP:
    145       1.1.1.9  christos             case AML_WHILE_OP:
    146       1.1.1.9  christos 
    147       1.1.1.9  christos                 break;
    148       1.1.1.9  christos 
    149       1.1.1.9  christos             default:
    150       1.1.1.9  christos 
    151       1.1.1.9  christos                 ASL_CV_CAPTURE_COMMENTS (WalkState);
    152       1.1.1.9  christos                 break;
    153       1.1.1.9  christos             }
    154       1.1.1.9  christos 
    155           1.1    jruoho             Status = AcpiPsGetNextArg (WalkState, &(WalkState->ParserState),
    156       1.1.1.7  christos                 GET_CURRENT_ARG_TYPE (WalkState->ArgTypes), &Arg);
    157           1.1    jruoho             if (ACPI_FAILURE (Status))
    158           1.1    jruoho             {
    159           1.1    jruoho                 return_ACPI_STATUS (Status);
    160           1.1    jruoho             }
    161           1.1    jruoho 
    162           1.1    jruoho             if (Arg)
    163           1.1    jruoho             {
    164           1.1    jruoho                 AcpiPsAppendArg (Op, Arg);
    165           1.1    jruoho             }
    166           1.1    jruoho 
    167           1.1    jruoho             INCREMENT_ARG_LIST (WalkState->ArgTypes);
    168           1.1    jruoho         }
    169           1.1    jruoho 
    170      1.1.1.10  christos         ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
    171      1.1.1.11  christos             "Final argument count: %8.8X pass %u\n",
    172      1.1.1.10  christos             WalkState->ArgCount, WalkState->PassNumber));
    173           1.1    jruoho 
    174           1.1    jruoho         /* Special processing for certain opcodes */
    175           1.1    jruoho 
    176           1.1    jruoho         switch (Op->Common.AmlOpcode)
    177           1.1    jruoho         {
    178           1.1    jruoho         case AML_METHOD_OP:
    179           1.1    jruoho             /*
    180           1.1    jruoho              * Skip parsing of control method because we don't have enough
    181           1.1    jruoho              * info in the first pass to parse it correctly.
    182           1.1    jruoho              *
    183           1.1    jruoho              * Save the length and address of the body
    184           1.1    jruoho              */
    185           1.1    jruoho             Op->Named.Data = WalkState->ParserState.Aml;
    186           1.1    jruoho             Op->Named.Length = (UINT32)
    187           1.1    jruoho                 (WalkState->ParserState.PkgEnd - WalkState->ParserState.Aml);
    188           1.1    jruoho 
    189           1.1    jruoho             /* Skip body of method */
    190           1.1    jruoho 
    191           1.1    jruoho             WalkState->ParserState.Aml = WalkState->ParserState.PkgEnd;
    192           1.1    jruoho             WalkState->ArgCount = 0;
    193           1.1    jruoho             break;
    194           1.1    jruoho 
    195           1.1    jruoho         case AML_BUFFER_OP:
    196           1.1    jruoho         case AML_PACKAGE_OP:
    197       1.1.1.9  christos         case AML_VARIABLE_PACKAGE_OP:
    198           1.1    jruoho 
    199           1.1    jruoho             if ((Op->Common.Parent) &&
    200           1.1    jruoho                 (Op->Common.Parent->Common.AmlOpcode == AML_NAME_OP) &&
    201           1.1    jruoho                 (WalkState->PassNumber <= ACPI_IMODE_LOAD_PASS2))
    202           1.1    jruoho             {
    203      1.1.1.10  christos                 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
    204      1.1.1.10  christos                     "Setup Package/Buffer: Pass %u, AML Ptr: %p\n",
    205      1.1.1.10  christos                     WalkState->PassNumber, AmlOpStart));
    206      1.1.1.10  christos 
    207           1.1    jruoho                 /*
    208           1.1    jruoho                  * Skip parsing of Buffers and Packages because we don't have
    209           1.1    jruoho                  * enough info in the first pass to parse them correctly.
    210           1.1    jruoho                  */
    211           1.1    jruoho                 Op->Named.Data = AmlOpStart;
    212           1.1    jruoho                 Op->Named.Length = (UINT32)
    213           1.1    jruoho                     (WalkState->ParserState.PkgEnd - AmlOpStart);
    214           1.1    jruoho 
    215           1.1    jruoho                 /* Skip body */
    216           1.1    jruoho 
    217           1.1    jruoho                 WalkState->ParserState.Aml = WalkState->ParserState.PkgEnd;
    218           1.1    jruoho                 WalkState->ArgCount = 0;
    219           1.1    jruoho             }
    220           1.1    jruoho             break;
    221           1.1    jruoho 
    222           1.1    jruoho         case AML_WHILE_OP:
    223           1.1    jruoho 
    224           1.1    jruoho             if (WalkState->ControlState)
    225           1.1    jruoho             {
    226           1.1    jruoho                 WalkState->ControlState->Control.PackageEnd =
    227           1.1    jruoho                     WalkState->ParserState.PkgEnd;
    228           1.1    jruoho             }
    229           1.1    jruoho             break;
    230           1.1    jruoho 
    231           1.1    jruoho         default:
    232           1.1    jruoho 
    233           1.1    jruoho             /* No action for all other opcodes */
    234       1.1.1.3  christos 
    235           1.1    jruoho             break;
    236           1.1    jruoho         }
    237           1.1    jruoho 
    238           1.1    jruoho         break;
    239           1.1    jruoho     }
    240           1.1    jruoho 
    241           1.1    jruoho     return_ACPI_STATUS (AE_OK);
    242           1.1    jruoho }
    243           1.1    jruoho 
    244           1.1    jruoho 
    245           1.1    jruoho /*******************************************************************************
    246           1.1    jruoho  *
    247           1.1    jruoho  * FUNCTION:    AcpiPsParseLoop
    248           1.1    jruoho  *
    249           1.1    jruoho  * PARAMETERS:  WalkState           - Current state
    250           1.1    jruoho  *
    251           1.1    jruoho  * RETURN:      Status
    252           1.1    jruoho  *
    253           1.1    jruoho  * DESCRIPTION: Parse AML (pointed to by the current parser state) and return
    254           1.1    jruoho  *              a tree of ops.
    255           1.1    jruoho  *
    256           1.1    jruoho  ******************************************************************************/
    257           1.1    jruoho 
    258           1.1    jruoho ACPI_STATUS
    259           1.1    jruoho AcpiPsParseLoop (
    260           1.1    jruoho     ACPI_WALK_STATE         *WalkState)
    261           1.1    jruoho {
    262           1.1    jruoho     ACPI_STATUS             Status = AE_OK;
    263           1.1    jruoho     ACPI_PARSE_OBJECT       *Op = NULL;     /* current op */
    264           1.1    jruoho     ACPI_PARSE_STATE        *ParserState;
    265           1.1    jruoho     UINT8                   *AmlOpStart = NULL;
    266      1.1.1.13  christos     UINT8                   OpcodeLength;
    267           1.1    jruoho 
    268           1.1    jruoho 
    269           1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (PsParseLoop, WalkState);
    270           1.1    jruoho 
    271           1.1    jruoho 
    272           1.1    jruoho     if (WalkState->DescendingCallback == NULL)
    273           1.1    jruoho     {
    274           1.1    jruoho         return_ACPI_STATUS (AE_BAD_PARAMETER);
    275           1.1    jruoho     }
    276           1.1    jruoho 
    277           1.1    jruoho     ParserState = &WalkState->ParserState;
    278           1.1    jruoho     WalkState->ArgTypes = 0;
    279           1.1    jruoho 
    280      1.1.1.13  christos #ifndef ACPI_CONSTANT_EVAL_ONLY
    281           1.1    jruoho 
    282           1.1    jruoho     if (WalkState->WalkType & ACPI_WALK_METHOD_RESTART)
    283           1.1    jruoho     {
    284           1.1    jruoho         /* We are restarting a preempted control method */
    285           1.1    jruoho 
    286           1.1    jruoho         if (AcpiPsHasCompletedScope (ParserState))
    287           1.1    jruoho         {
    288           1.1    jruoho             /*
    289           1.1    jruoho              * We must check if a predicate to an IF or WHILE statement
    290           1.1    jruoho              * was just completed
    291           1.1    jruoho              */
    292           1.1    jruoho             if ((ParserState->Scope->ParseScope.Op) &&
    293           1.1    jruoho                ((ParserState->Scope->ParseScope.Op->Common.AmlOpcode == AML_IF_OP) ||
    294           1.1    jruoho                 (ParserState->Scope->ParseScope.Op->Common.AmlOpcode == AML_WHILE_OP)) &&
    295           1.1    jruoho                 (WalkState->ControlState) &&
    296           1.1    jruoho                 (WalkState->ControlState->Common.State ==
    297           1.1    jruoho                     ACPI_CONTROL_PREDICATE_EXECUTING))
    298           1.1    jruoho             {
    299           1.1    jruoho                 /*
    300           1.1    jruoho                  * A predicate was just completed, get the value of the
    301           1.1    jruoho                  * predicate and branch based on that value
    302           1.1    jruoho                  */
    303           1.1    jruoho                 WalkState->Op = NULL;
    304           1.1    jruoho                 Status = AcpiDsGetPredicateValue (WalkState, ACPI_TO_POINTER (TRUE));
    305  1.1.1.15.4.1   thorpej                 if (ACPI_FAILURE (Status) && !ACPI_CNTL_EXCEPTION (Status))
    306           1.1    jruoho                 {
    307           1.1    jruoho                     if (Status == AE_AML_NO_RETURN_VALUE)
    308           1.1    jruoho                     {
    309           1.1    jruoho                         ACPI_EXCEPTION ((AE_INFO, Status,
    310           1.1    jruoho                             "Invoked method did not return a value"));
    311           1.1    jruoho                     }
    312           1.1    jruoho 
    313           1.1    jruoho                     ACPI_EXCEPTION ((AE_INFO, Status, "GetPredicate Failed"));
    314           1.1    jruoho                     return_ACPI_STATUS (Status);
    315           1.1    jruoho                 }
    316           1.1    jruoho 
    317           1.1    jruoho                 Status = AcpiPsNextParseState (WalkState, Op, Status);
    318           1.1    jruoho             }
    319           1.1    jruoho 
    320           1.1    jruoho             AcpiPsPopScope (ParserState, &Op,
    321           1.1    jruoho                 &WalkState->ArgTypes, &WalkState->ArgCount);
    322           1.1    jruoho             ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Popped scope, Op=%p\n", Op));
    323           1.1    jruoho         }
    324           1.1    jruoho         else if (WalkState->PrevOp)
    325           1.1    jruoho         {
    326           1.1    jruoho             /* We were in the middle of an op */
    327           1.1    jruoho 
    328           1.1    jruoho             Op = WalkState->PrevOp;
    329           1.1    jruoho             WalkState->ArgTypes = WalkState->PrevArgTypes;
    330           1.1    jruoho         }
    331           1.1    jruoho     }
    332           1.1    jruoho #endif
    333           1.1    jruoho 
    334           1.1    jruoho     /* Iterative parsing loop, while there is more AML to process: */
    335           1.1    jruoho 
    336           1.1    jruoho     while ((ParserState->Aml < ParserState->AmlEnd) || (Op))
    337           1.1    jruoho     {
    338       1.1.1.9  christos         ASL_CV_CAPTURE_COMMENTS (WalkState);
    339       1.1.1.9  christos 
    340           1.1    jruoho         AmlOpStart = ParserState->Aml;
    341           1.1    jruoho         if (!Op)
    342           1.1    jruoho         {
    343           1.1    jruoho             Status = AcpiPsCreateOp (WalkState, AmlOpStart, &Op);
    344           1.1    jruoho             if (ACPI_FAILURE (Status))
    345           1.1    jruoho             {
    346      1.1.1.12  christos                 /*
    347      1.1.1.12  christos                  * ACPI_PARSE_MODULE_LEVEL means that we are loading a table by
    348      1.1.1.12  christos                  * executing it as a control method. However, if we encounter
    349      1.1.1.12  christos                  * an error while loading the table, we need to keep trying to
    350      1.1.1.12  christos                  * load the table rather than aborting the table load. Set the
    351      1.1.1.12  christos                  * status to AE_OK to proceed with the table load.
    352      1.1.1.12  christos                  */
    353      1.1.1.12  christos                 if ((WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL) &&
    354      1.1.1.13  christos                     ((Status == AE_ALREADY_EXISTS) || (Status == AE_NOT_FOUND)))
    355      1.1.1.12  christos                 {
    356      1.1.1.12  christos                     Status = AE_OK;
    357      1.1.1.12  christos                 }
    358           1.1    jruoho                 if (Status == AE_CTRL_PARSE_CONTINUE)
    359           1.1    jruoho                 {
    360           1.1    jruoho                     continue;
    361           1.1    jruoho                 }
    362           1.1    jruoho 
    363           1.1    jruoho                 if (Status == AE_CTRL_PARSE_PENDING)
    364           1.1    jruoho                 {
    365           1.1    jruoho                     Status = AE_OK;
    366           1.1    jruoho                 }
    367           1.1    jruoho 
    368       1.1.1.4  christos                 if (Status == AE_CTRL_TERMINATE)
    369       1.1.1.4  christos                 {
    370       1.1.1.4  christos                     return_ACPI_STATUS (Status);
    371       1.1.1.4  christos                 }
    372       1.1.1.4  christos 
    373           1.1    jruoho                 Status = AcpiPsCompleteOp (WalkState, &Op, Status);
    374           1.1    jruoho                 if (ACPI_FAILURE (Status))
    375           1.1    jruoho                 {
    376           1.1    jruoho                     return_ACPI_STATUS (Status);
    377           1.1    jruoho                 }
    378      1.1.1.12  christos                 if (AcpiNsOpensScope (
    379      1.1.1.12  christos                     AcpiPsGetOpcodeInfo (WalkState->Opcode)->ObjectType))
    380      1.1.1.12  christos                 {
    381      1.1.1.12  christos                     /*
    382      1.1.1.12  christos                      * If the scope/device op fails to parse, skip the body of
    383      1.1.1.12  christos                      * the scope op because the parse failure indicates that
    384      1.1.1.12  christos                      * the device may not exist.
    385      1.1.1.12  christos                      */
    386      1.1.1.13  christos                     ACPI_INFO (("Skipping parse of AML opcode: %s (0x%4.4X)",
    387      1.1.1.13  christos                         AcpiPsGetOpcodeName (WalkState->Opcode), WalkState->Opcode));
    388      1.1.1.13  christos 
    389      1.1.1.13  christos                     /*
    390      1.1.1.13  christos                      * Determine the opcode length before skipping the opcode.
    391      1.1.1.13  christos                      * An opcode can be 1 byte or 2 bytes in length.
    392      1.1.1.13  christos                      */
    393      1.1.1.13  christos                     OpcodeLength = 1;
    394      1.1.1.13  christos                     if ((WalkState->Opcode & 0xFF00) == AML_EXTENDED_OPCODE)
    395      1.1.1.13  christos                     {
    396      1.1.1.13  christos                         OpcodeLength = 2;
    397      1.1.1.13  christos                     }
    398      1.1.1.13  christos                     WalkState->ParserState.Aml = WalkState->Aml + OpcodeLength;
    399      1.1.1.13  christos 
    400      1.1.1.12  christos                     WalkState->ParserState.Aml =
    401      1.1.1.12  christos                         AcpiPsGetNextPackageEnd(&WalkState->ParserState);
    402      1.1.1.12  christos                     WalkState->Aml = WalkState->ParserState.Aml;
    403      1.1.1.12  christos                 }
    404           1.1    jruoho 
    405           1.1    jruoho                 continue;
    406           1.1    jruoho             }
    407           1.1    jruoho 
    408       1.1.1.6  christos             AcpiExStartTraceOpcode (Op, WalkState);
    409           1.1    jruoho         }
    410           1.1    jruoho 
    411           1.1    jruoho         /*
    412           1.1    jruoho          * Start ArgCount at zero because we don't know if there are
    413           1.1    jruoho          * any args yet
    414           1.1    jruoho          */
    415       1.1.1.9  christos         WalkState->ArgCount = 0;
    416       1.1.1.9  christos 
    417       1.1.1.9  christos         switch (Op->Common.AmlOpcode)
    418       1.1.1.9  christos         {
    419       1.1.1.9  christos         case AML_BYTE_OP:
    420       1.1.1.9  christos         case AML_WORD_OP:
    421       1.1.1.9  christos         case AML_DWORD_OP:
    422       1.1.1.9  christos         case AML_QWORD_OP:
    423       1.1.1.9  christos 
    424       1.1.1.9  christos             break;
    425       1.1.1.9  christos 
    426       1.1.1.9  christos         default:
    427       1.1.1.9  christos 
    428       1.1.1.9  christos             ASL_CV_CAPTURE_COMMENTS (WalkState);
    429       1.1.1.9  christos             break;
    430       1.1.1.9  christos         }
    431           1.1    jruoho 
    432           1.1    jruoho         /* Are there any arguments that must be processed? */
    433           1.1    jruoho 
    434           1.1    jruoho         if (WalkState->ArgTypes)
    435           1.1    jruoho         {
    436           1.1    jruoho             /* Get arguments */
    437           1.1    jruoho 
    438           1.1    jruoho             Status = AcpiPsGetArguments (WalkState, AmlOpStart, Op);
    439           1.1    jruoho             if (ACPI_FAILURE (Status))
    440           1.1    jruoho             {
    441           1.1    jruoho                 Status = AcpiPsCompleteOp (WalkState, &Op, Status);
    442           1.1    jruoho                 if (ACPI_FAILURE (Status))
    443           1.1    jruoho                 {
    444           1.1    jruoho                     return_ACPI_STATUS (Status);
    445           1.1    jruoho                 }
    446      1.1.1.12  christos                 if ((WalkState->ControlState) &&
    447      1.1.1.12  christos                     ((WalkState->ControlState->Control.Opcode == AML_IF_OP) ||
    448      1.1.1.12  christos                     (WalkState->ControlState->Control.Opcode == AML_WHILE_OP)))
    449      1.1.1.12  christos                 {
    450      1.1.1.12  christos                     /*
    451      1.1.1.12  christos                      * If the if/while op fails to parse, we will skip parsing
    452      1.1.1.12  christos                      * the body of the op.
    453      1.1.1.12  christos                      */
    454      1.1.1.12  christos                     ParserState->Aml =
    455      1.1.1.12  christos                         WalkState->ControlState->Control.AmlPredicateStart + 1;
    456      1.1.1.12  christos                     ParserState->Aml =
    457      1.1.1.12  christos                         AcpiPsGetNextPackageEnd (ParserState);
    458      1.1.1.12  christos                     WalkState->Aml = ParserState->Aml;
    459           1.1    jruoho 
    460      1.1.1.12  christos                     ACPI_ERROR ((AE_INFO, "Skipping While/If block"));
    461      1.1.1.12  christos                     if (*WalkState->Aml == AML_ELSE_OP)
    462      1.1.1.12  christos                     {
    463      1.1.1.12  christos                         ACPI_ERROR ((AE_INFO, "Skipping Else block"));
    464      1.1.1.12  christos                         WalkState->ParserState.Aml = WalkState->Aml + 1;
    465      1.1.1.12  christos                         WalkState->ParserState.Aml =
    466      1.1.1.12  christos                             AcpiPsGetNextPackageEnd (ParserState);
    467      1.1.1.12  christos                         WalkState->Aml = ParserState->Aml;
    468      1.1.1.12  christos                     }
    469      1.1.1.12  christos                     ACPI_FREE(AcpiUtPopGenericState (&WalkState->ControlState));
    470      1.1.1.12  christos                 }
    471      1.1.1.12  christos                 Op = NULL;
    472           1.1    jruoho                 continue;
    473           1.1    jruoho             }
    474           1.1    jruoho         }
    475           1.1    jruoho 
    476           1.1    jruoho         /* Check for arguments that need to be processed */
    477           1.1    jruoho 
    478      1.1.1.10  christos         ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
    479      1.1.1.11  christos             "Parseloop: argument count: %8.8X\n", WalkState->ArgCount));
    480      1.1.1.10  christos 
    481           1.1    jruoho         if (WalkState->ArgCount)
    482           1.1    jruoho         {
    483           1.1    jruoho             /*
    484           1.1    jruoho              * There are arguments (complex ones), push Op and
    485           1.1    jruoho              * prepare for argument
    486           1.1    jruoho              */
    487           1.1    jruoho             Status = AcpiPsPushScope (ParserState, Op,
    488       1.1.1.7  christos                 WalkState->ArgTypes, WalkState->ArgCount);
    489           1.1    jruoho             if (ACPI_FAILURE (Status))
    490           1.1    jruoho             {
    491           1.1    jruoho                 Status = AcpiPsCompleteOp (WalkState, &Op, Status);
    492           1.1    jruoho                 if (ACPI_FAILURE (Status))
    493           1.1    jruoho                 {
    494           1.1    jruoho                     return_ACPI_STATUS (Status);
    495           1.1    jruoho                 }
    496           1.1    jruoho 
    497           1.1    jruoho                 continue;
    498           1.1    jruoho             }
    499           1.1    jruoho 
    500           1.1    jruoho             Op = NULL;
    501           1.1    jruoho             continue;
    502           1.1    jruoho         }
    503           1.1    jruoho 
    504           1.1    jruoho         /*
    505           1.1    jruoho          * All arguments have been processed -- Op is complete,
    506           1.1    jruoho          * prepare for next
    507           1.1    jruoho          */
    508           1.1    jruoho         WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
    509           1.1    jruoho         if (WalkState->OpInfo->Flags & AML_NAMED)
    510           1.1    jruoho         {
    511           1.1    jruoho             if (Op->Common.AmlOpcode == AML_REGION_OP ||
    512           1.1    jruoho                 Op->Common.AmlOpcode == AML_DATA_REGION_OP)
    513           1.1    jruoho             {
    514           1.1    jruoho                 /*
    515           1.1    jruoho                  * Skip parsing of control method or opregion body,
    516           1.1    jruoho                  * because we don't have enough info in the first pass
    517           1.1    jruoho                  * to parse them correctly.
    518           1.1    jruoho                  *
    519           1.1    jruoho                  * Completed parsing an OpRegion declaration, we now
    520           1.1    jruoho                  * know the length.
    521           1.1    jruoho                  */
    522           1.1    jruoho                 Op->Named.Length = (UINT32) (ParserState->Aml - Op->Named.Data);
    523           1.1    jruoho             }
    524           1.1    jruoho         }
    525           1.1    jruoho 
    526           1.1    jruoho         if (WalkState->OpInfo->Flags & AML_CREATE)
    527           1.1    jruoho         {
    528           1.1    jruoho             /*
    529           1.1    jruoho              * Backup to beginning of CreateXXXfield declaration (1 for
    530           1.1    jruoho              * Opcode)
    531           1.1    jruoho              *
    532           1.1    jruoho              * BodyLength is unknown until we parse the body
    533           1.1    jruoho              */
    534           1.1    jruoho             Op->Named.Length = (UINT32) (ParserState->Aml - Op->Named.Data);
    535           1.1    jruoho         }
    536           1.1    jruoho 
    537           1.1    jruoho         if (Op->Common.AmlOpcode == AML_BANK_FIELD_OP)
    538           1.1    jruoho         {
    539           1.1    jruoho             /*
    540           1.1    jruoho              * Backup to beginning of BankField declaration
    541           1.1    jruoho              *
    542           1.1    jruoho              * BodyLength is unknown until we parse the body
    543           1.1    jruoho              */
    544           1.1    jruoho             Op->Named.Length = (UINT32) (ParserState->Aml - Op->Named.Data);
    545           1.1    jruoho         }
    546           1.1    jruoho 
    547           1.1    jruoho         /* This op complete, notify the dispatcher */
    548           1.1    jruoho 
    549           1.1    jruoho         if (WalkState->AscendingCallback != NULL)
    550           1.1    jruoho         {
    551           1.1    jruoho             WalkState->Op = Op;
    552           1.1    jruoho             WalkState->Opcode = Op->Common.AmlOpcode;
    553           1.1    jruoho 
    554           1.1    jruoho             Status = WalkState->AscendingCallback (WalkState);
    555           1.1    jruoho             Status = AcpiPsNextParseState (WalkState, Op, Status);
    556           1.1    jruoho             if (Status == AE_CTRL_PENDING)
    557           1.1    jruoho             {
    558           1.1    jruoho                 Status = AE_OK;
    559           1.1    jruoho             }
    560      1.1.1.12  christos             else if ((WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL) &&
    561      1.1.1.12  christos                 (ACPI_AML_EXCEPTION(Status) || Status == AE_ALREADY_EXISTS ||
    562      1.1.1.12  christos                 Status == AE_NOT_FOUND))
    563      1.1.1.12  christos             {
    564      1.1.1.12  christos                 /*
    565      1.1.1.12  christos                  * ACPI_PARSE_MODULE_LEVEL flag means that we are currently
    566      1.1.1.12  christos                  * loading a table by executing it as a control method.
    567      1.1.1.12  christos                  * However, if we encounter an error while loading the table,
    568      1.1.1.12  christos                  * we need to keep trying to load the table rather than
    569      1.1.1.12  christos                  * aborting the table load (setting the status to AE_OK
    570      1.1.1.12  christos                  * continues the table load). If we get a failure at this
    571      1.1.1.12  christos                  * point, it means that the dispatcher got an error while
    572      1.1.1.12  christos                  * trying to execute the Op.
    573      1.1.1.12  christos                  */
    574      1.1.1.12  christos                 Status = AE_OK;
    575      1.1.1.12  christos             }
    576           1.1    jruoho         }
    577           1.1    jruoho 
    578           1.1    jruoho         Status = AcpiPsCompleteOp (WalkState, &Op, Status);
    579           1.1    jruoho         if (ACPI_FAILURE (Status))
    580           1.1    jruoho         {
    581           1.1    jruoho             return_ACPI_STATUS (Status);
    582           1.1    jruoho         }
    583           1.1    jruoho 
    584           1.1    jruoho     } /* while ParserState->Aml */
    585           1.1    jruoho 
    586           1.1    jruoho     Status = AcpiPsCompleteFinalOp (WalkState, Op, Status);
    587           1.1    jruoho     return_ACPI_STATUS (Status);
    588           1.1    jruoho }
    589