Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:03

0001 /******************************************************************************
0002  *
0003  * Module Name: psparse - Parser top level AML parse routines
0004  *
0005  *****************************************************************************/
0006 
0007 /******************************************************************************
0008  *
0009  * 1. Copyright Notice
0010  *
0011  * Some or all of this work - Copyright (c) 1999 - 2024, Intel Corp.
0012  * All rights reserved.
0013  *
0014  * 2. License
0015  *
0016  * 2.1. This is your license from Intel Corp. under its intellectual property
0017  * rights. You may have additional license terms from the party that provided
0018  * you this software, covering your right to use that party's intellectual
0019  * property rights.
0020  *
0021  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
0022  * copy of the source code appearing in this file ("Covered Code") an
0023  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
0024  * base code distributed originally by Intel ("Original Intel Code") to copy,
0025  * make derivatives, distribute, use and display any portion of the Covered
0026  * Code in any form, with the right to sublicense such rights; and
0027  *
0028  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
0029  * license (with the right to sublicense), under only those claims of Intel
0030  * patents that are infringed by the Original Intel Code, to make, use, sell,
0031  * offer to sell, and import the Covered Code and derivative works thereof
0032  * solely to the minimum extent necessary to exercise the above copyright
0033  * license, and in no event shall the patent license extend to any additions
0034  * to or modifications of the Original Intel Code. No other license or right
0035  * is granted directly or by implication, estoppel or otherwise;
0036  *
0037  * The above copyright and patent license is granted only if the following
0038  * conditions are met:
0039  *
0040  * 3. Conditions
0041  *
0042  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
0043  * Redistribution of source code of any substantial portion of the Covered
0044  * Code or modification with rights to further distribute source must include
0045  * the above Copyright Notice, the above License, this list of Conditions,
0046  * and the following Disclaimer and Export Compliance provision. In addition,
0047  * Licensee must cause all Covered Code to which Licensee contributes to
0048  * contain a file documenting the changes Licensee made to create that Covered
0049  * Code and the date of any change. Licensee must include in that file the
0050  * documentation of any changes made by any predecessor Licensee. Licensee
0051  * must include a prominent statement that the modification is derived,
0052  * directly or indirectly, from Original Intel Code.
0053  *
0054  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
0055  * Redistribution of source code of any substantial portion of the Covered
0056  * Code or modification without rights to further distribute source must
0057  * include the following Disclaimer and Export Compliance provision in the
0058  * documentation and/or other materials provided with distribution. In
0059  * addition, Licensee may not authorize further sublicense of source of any
0060  * portion of the Covered Code, and must include terms to the effect that the
0061  * license from Licensee to its licensee is limited to the intellectual
0062  * property embodied in the software Licensee provides to its licensee, and
0063  * not to intellectual property embodied in modifications its licensee may
0064  * make.
0065  *
0066  * 3.3. Redistribution of Executable. Redistribution in executable form of any
0067  * substantial portion of the Covered Code or modification must reproduce the
0068  * above Copyright Notice, and the following Disclaimer and Export Compliance
0069  * provision in the documentation and/or other materials provided with the
0070  * distribution.
0071  *
0072  * 3.4. Intel retains all right, title, and interest in and to the Original
0073  * Intel Code.
0074  *
0075  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
0076  * Intel shall be used in advertising or otherwise to promote the sale, use or
0077  * other dealings in products derived from or relating to the Covered Code
0078  * without prior written authorization from Intel.
0079  *
0080  * 4. Disclaimer and Export Compliance
0081  *
0082  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
0083  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
0084  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
0085  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
0086  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
0087  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
0088  * PARTICULAR PURPOSE.
0089  *
0090  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
0091  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
0092  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
0093  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
0094  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
0095  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
0096  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
0097  * LIMITED REMEDY.
0098  *
0099  * 4.3. Licensee shall not export, either directly or indirectly, any of this
0100  * software or system incorporating such software without first obtaining any
0101  * required license or other approval from the U. S. Department of Commerce or
0102  * any other agency or department of the United States Government. In the
0103  * event Licensee exports any such software from the United States or
0104  * re-exports any such software from a foreign destination, Licensee shall
0105  * ensure that the distribution and export/re-export of the software is in
0106  * compliance with all laws, regulations, orders, or other restrictions of the
0107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
0108  * any of its subsidiaries will export/re-export any technical data, process,
0109  * software, or service, directly or indirectly, to any country for which the
0110  * United States government or any agency thereof requires an export license,
0111  * other governmental approval, or letter of assurance, without first obtaining
0112  * such license, approval or letter.
0113  *
0114  *****************************************************************************
0115  *
0116  * Alternatively, you may choose to be licensed under the terms of the
0117  * following license:
0118  *
0119  * Redistribution and use in source and binary forms, with or without
0120  * modification, are permitted provided that the following conditions
0121  * are met:
0122  * 1. Redistributions of source code must retain the above copyright
0123  *    notice, this list of conditions, and the following disclaimer,
0124  *    without modification.
0125  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
0126  *    substantially similar to the "NO WARRANTY" disclaimer below
0127  *    ("Disclaimer") and any redistribution must be conditioned upon
0128  *    including a substantially similar Disclaimer requirement for further
0129  *    binary redistribution.
0130  * 3. Neither the names of the above-listed copyright holders nor the names
0131  *    of any contributors may be used to endorse or promote products derived
0132  *    from this software without specific prior written permission.
0133  *
0134  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0135  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0136  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0137  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0138  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0139  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0140  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0141  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0142  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0143  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0144  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0145  *
0146  * Alternatively, you may choose to be licensed under the terms of the
0147  * GNU General Public License ("GPL") version 2 as published by the Free
0148  * Software Foundation.
0149  *
0150  *****************************************************************************/
0151 
0152 /*
0153  * Parse the AML and build an operation tree as most interpreters,
0154  * like Perl, do. Parsing is done by hand rather than with a YACC
0155  * generated parser to tightly constrain stack and dynamic memory
0156  * usage. At the same time, parsing is kept flexible and the code
0157  * fairly compact by parsing based on a list of AML opcode
0158  * templates in AmlOpInfo[]
0159  */
0160 
0161 #include "acpi.h"
0162 #include "accommon.h"
0163 #include "acparser.h"
0164 #include "acdispat.h"
0165 #include "amlcode.h"
0166 #include "acinterp.h"
0167 #include "acnamesp.h"
0168 
0169 #define _COMPONENT          ACPI_PARSER
0170         ACPI_MODULE_NAME    ("psparse")
0171 
0172 
0173 /*******************************************************************************
0174  *
0175  * FUNCTION:    AcpiPsGetOpcodeSize
0176  *
0177  * PARAMETERS:  Opcode          - An AML opcode
0178  *
0179  * RETURN:      Size of the opcode, in bytes (1 or 2)
0180  *
0181  * DESCRIPTION: Get the size of the current opcode.
0182  *
0183  ******************************************************************************/
0184 
0185 UINT32
0186 AcpiPsGetOpcodeSize (
0187     UINT32                  Opcode)
0188 {
0189 
0190     /* Extended (2-byte) opcode if > 255 */
0191 
0192     if (Opcode > 0x00FF)
0193     {
0194         return (2);
0195     }
0196 
0197     /* Otherwise, just a single byte opcode */
0198 
0199     return (1);
0200 }
0201 
0202 
0203 /*******************************************************************************
0204  *
0205  * FUNCTION:    AcpiPsPeekOpcode
0206  *
0207  * PARAMETERS:  ParserState         - A parser state object
0208  *
0209  * RETURN:      Next AML opcode
0210  *
0211  * DESCRIPTION: Get next AML opcode (without incrementing AML pointer)
0212  *
0213  ******************************************************************************/
0214 
0215 UINT16
0216 AcpiPsPeekOpcode (
0217     ACPI_PARSE_STATE        *ParserState)
0218 {
0219     UINT8                   *Aml;
0220     UINT16                  Opcode;
0221 
0222 
0223     Aml = ParserState->Aml;
0224     Opcode = (UINT16) ACPI_GET8 (Aml);
0225 
0226     if (Opcode == AML_EXTENDED_PREFIX)
0227     {
0228         /* Extended opcode, get the second opcode byte */
0229 
0230         Aml++;
0231         Opcode = (UINT16) ((Opcode << 8) | ACPI_GET8 (Aml));
0232     }
0233 
0234     return (Opcode);
0235 }
0236 
0237 
0238 /*******************************************************************************
0239  *
0240  * FUNCTION:    AcpiPsCompleteThisOp
0241  *
0242  * PARAMETERS:  WalkState       - Current State
0243  *              Op              - Op to complete
0244  *
0245  * RETURN:      Status
0246  *
0247  * DESCRIPTION: Perform any cleanup at the completion of an Op.
0248  *
0249  ******************************************************************************/
0250 
0251 ACPI_STATUS
0252 AcpiPsCompleteThisOp (
0253     ACPI_WALK_STATE         *WalkState,
0254     ACPI_PARSE_OBJECT       *Op)
0255 {
0256     ACPI_PARSE_OBJECT       *Prev;
0257     ACPI_PARSE_OBJECT       *Next;
0258     const ACPI_OPCODE_INFO  *ParentInfo;
0259     ACPI_PARSE_OBJECT       *ReplacementOp = NULL;
0260     ACPI_STATUS             Status = AE_OK;
0261 
0262 
0263     ACPI_FUNCTION_TRACE_PTR (PsCompleteThisOp, Op);
0264 
0265 
0266     /* Check for null Op, can happen if AML code is corrupt */
0267 
0268     if (!Op)
0269     {
0270         return_ACPI_STATUS (AE_OK);  /* OK for now */
0271     }
0272 
0273     AcpiExStopTraceOpcode (Op, WalkState);
0274 
0275     /* Delete this op and the subtree below it if asked to */
0276 
0277     if (((WalkState->ParseFlags & ACPI_PARSE_TREE_MASK) != ACPI_PARSE_DELETE_TREE) ||
0278          (WalkState->OpInfo->Class == AML_CLASS_ARGUMENT))
0279     {
0280         return_ACPI_STATUS (AE_OK);
0281     }
0282 
0283     /* Make sure that we only delete this subtree */
0284 
0285     if (Op->Common.Parent)
0286     {
0287         Prev = Op->Common.Parent->Common.Value.Arg;
0288         if (!Prev)
0289         {
0290             /* Nothing more to do */
0291 
0292             goto Cleanup;
0293         }
0294 
0295         /*
0296          * Check if we need to replace the operator and its subtree
0297          * with a return value op (placeholder op)
0298          */
0299         ParentInfo = AcpiPsGetOpcodeInfo (Op->Common.Parent->Common.AmlOpcode);
0300 
0301         switch (ParentInfo->Class)
0302         {
0303         case AML_CLASS_CONTROL:
0304 
0305             break;
0306 
0307         case AML_CLASS_CREATE:
0308             /*
0309              * These opcodes contain TermArg operands. The current
0310              * op must be replaced by a placeholder return op
0311              */
0312             ReplacementOp = AcpiPsAllocOp (
0313                 AML_INT_RETURN_VALUE_OP, Op->Common.Aml);
0314             if (!ReplacementOp)
0315             {
0316                 Status = AE_NO_MEMORY;
0317             }
0318             break;
0319 
0320         case AML_CLASS_NAMED_OBJECT:
0321             /*
0322              * These opcodes contain TermArg operands. The current
0323              * op must be replaced by a placeholder return op
0324              */
0325             if ((Op->Common.Parent->Common.AmlOpcode == AML_REGION_OP)       ||
0326                 (Op->Common.Parent->Common.AmlOpcode == AML_DATA_REGION_OP)  ||
0327                 (Op->Common.Parent->Common.AmlOpcode == AML_BUFFER_OP)       ||
0328                 (Op->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP)      ||
0329                 (Op->Common.Parent->Common.AmlOpcode == AML_BANK_FIELD_OP)   ||
0330                 (Op->Common.Parent->Common.AmlOpcode == AML_VARIABLE_PACKAGE_OP))
0331             {
0332                 ReplacementOp = AcpiPsAllocOp (
0333                     AML_INT_RETURN_VALUE_OP, Op->Common.Aml);
0334                 if (!ReplacementOp)
0335                 {
0336                     Status = AE_NO_MEMORY;
0337                 }
0338             }
0339             else if ((Op->Common.Parent->Common.AmlOpcode == AML_NAME_OP) &&
0340                      (WalkState->PassNumber <= ACPI_IMODE_LOAD_PASS2))
0341             {
0342                 if ((Op->Common.AmlOpcode == AML_BUFFER_OP) ||
0343                     (Op->Common.AmlOpcode == AML_PACKAGE_OP) ||
0344                     (Op->Common.AmlOpcode == AML_VARIABLE_PACKAGE_OP))
0345                 {
0346                     ReplacementOp = AcpiPsAllocOp (Op->Common.AmlOpcode,
0347                         Op->Common.Aml);
0348                     if (!ReplacementOp)
0349                     {
0350                         Status = AE_NO_MEMORY;
0351                     }
0352                     else
0353                     {
0354                         ReplacementOp->Named.Data = Op->Named.Data;
0355                         ReplacementOp->Named.Length = Op->Named.Length;
0356                     }
0357                 }
0358             }
0359             break;
0360 
0361         default:
0362 
0363             ReplacementOp = AcpiPsAllocOp (
0364                 AML_INT_RETURN_VALUE_OP, Op->Common.Aml);
0365             if (!ReplacementOp)
0366             {
0367                 Status = AE_NO_MEMORY;
0368             }
0369         }
0370 
0371         /* We must unlink this op from the parent tree */
0372 
0373         if (Prev == Op)
0374         {
0375             /* This op is the first in the list */
0376 
0377             if (ReplacementOp)
0378             {
0379                 ReplacementOp->Common.Parent = Op->Common.Parent;
0380                 ReplacementOp->Common.Value.Arg = NULL;
0381                 ReplacementOp->Common.Node = Op->Common.Node;
0382                 Op->Common.Parent->Common.Value.Arg = ReplacementOp;
0383                 ReplacementOp->Common.Next = Op->Common.Next;
0384             }
0385             else
0386             {
0387                 Op->Common.Parent->Common.Value.Arg = Op->Common.Next;
0388             }
0389         }
0390 
0391         /* Search the parent list */
0392 
0393         else while (Prev)
0394         {
0395             /* Traverse all siblings in the parent's argument list */
0396 
0397             Next = Prev->Common.Next;
0398             if (Next == Op)
0399             {
0400                 if (ReplacementOp)
0401                 {
0402                     ReplacementOp->Common.Parent = Op->Common.Parent;
0403                     ReplacementOp->Common.Value.Arg = NULL;
0404                     ReplacementOp->Common.Node = Op->Common.Node;
0405                     Prev->Common.Next = ReplacementOp;
0406                     ReplacementOp->Common.Next = Op->Common.Next;
0407                     Next = NULL;
0408                 }
0409                 else
0410                 {
0411                     Prev->Common.Next = Op->Common.Next;
0412                     Next = NULL;
0413                 }
0414             }
0415             Prev = Next;
0416         }
0417     }
0418 
0419 
0420 Cleanup:
0421 
0422     /* Now we can actually delete the subtree rooted at Op */
0423 
0424     AcpiPsDeleteParseTree (Op);
0425     return_ACPI_STATUS (Status);
0426 }
0427 
0428 
0429 /*******************************************************************************
0430  *
0431  * FUNCTION:    AcpiPsNextParseState
0432  *
0433  * PARAMETERS:  WalkState           - Current state
0434  *              Op                  - Current parse op
0435  *              CallbackStatus      - Status from previous operation
0436  *
0437  * RETURN:      Status
0438  *
0439  * DESCRIPTION: Update the parser state based upon the return exception from
0440  *              the parser callback.
0441  *
0442  ******************************************************************************/
0443 
0444 ACPI_STATUS
0445 AcpiPsNextParseState (
0446     ACPI_WALK_STATE         *WalkState,
0447     ACPI_PARSE_OBJECT       *Op,
0448     ACPI_STATUS             CallbackStatus)
0449 {
0450     ACPI_PARSE_STATE        *ParserState = &WalkState->ParserState;
0451     ACPI_STATUS             Status = AE_CTRL_PENDING;
0452 
0453 
0454     ACPI_FUNCTION_TRACE_PTR (PsNextParseState, Op);
0455 
0456 
0457     switch (CallbackStatus)
0458     {
0459     case AE_CTRL_TERMINATE:
0460         /*
0461          * A control method was terminated via a RETURN statement.
0462          * The walk of this method is complete.
0463          */
0464         ParserState->Aml = ParserState->AmlEnd;
0465         Status = AE_CTRL_TERMINATE;
0466         break;
0467 
0468     case AE_CTRL_BREAK:
0469 
0470         ParserState->Aml = WalkState->AmlLastWhile;
0471         WalkState->ControlState->Common.Value = FALSE;
0472         Status = AE_CTRL_BREAK;
0473         break;
0474 
0475     case AE_CTRL_CONTINUE:
0476 
0477         ParserState->Aml = WalkState->AmlLastWhile;
0478         Status = AE_CTRL_CONTINUE;
0479         break;
0480 
0481     case AE_CTRL_PENDING:
0482 
0483         ParserState->Aml = WalkState->AmlLastWhile;
0484         break;
0485 
0486 #if 0
0487     case AE_CTRL_SKIP:
0488 
0489         ParserState->Aml = ParserState->Scope->ParseScope.PkgEnd;
0490         Status = AE_OK;
0491         break;
0492 #endif
0493 
0494     case AE_CTRL_TRUE:
0495         /*
0496          * Predicate of an IF was true, and we are at the matching ELSE.
0497          * Just close out this package
0498          */
0499         ParserState->Aml = AcpiPsGetNextPackageEnd (ParserState);
0500         Status = AE_CTRL_PENDING;
0501         break;
0502 
0503     case AE_CTRL_FALSE:
0504         /*
0505          * Either an IF/WHILE Predicate was false or we encountered a BREAK
0506          * opcode. In both cases, we do not execute the rest of the
0507          * package;  We simply close out the parent (finishing the walk of
0508          * this branch of the tree) and continue execution at the parent
0509          * level.
0510          */
0511         ParserState->Aml = ParserState->Scope->ParseScope.PkgEnd;
0512 
0513         /* In the case of a BREAK, just force a predicate (if any) to FALSE */
0514 
0515         WalkState->ControlState->Common.Value = FALSE;
0516         Status = AE_CTRL_END;
0517         break;
0518 
0519     case AE_CTRL_TRANSFER:
0520 
0521         /* A method call (invocation) -- transfer control */
0522 
0523         Status = AE_CTRL_TRANSFER;
0524         WalkState->PrevOp = Op;
0525         WalkState->MethodCallOp = Op;
0526         WalkState->MethodCallNode = (Op->Common.Value.Arg)->Common.Node;
0527 
0528         /* Will return value (if any) be used by the caller? */
0529 
0530         WalkState->ReturnUsed = AcpiDsIsResultUsed (Op, WalkState);
0531         break;
0532 
0533     default:
0534 
0535         Status = CallbackStatus;
0536         if (ACPI_CNTL_EXCEPTION (CallbackStatus))
0537         {
0538             Status = AE_OK;
0539         }
0540         break;
0541     }
0542 
0543     return_ACPI_STATUS (Status);
0544 }
0545 
0546 
0547 /*******************************************************************************
0548  *
0549  * FUNCTION:    AcpiPsParseAml
0550  *
0551  * PARAMETERS:  WalkState       - Current state
0552  *
0553  *
0554  * RETURN:      Status
0555  *
0556  * DESCRIPTION: Parse raw AML and return a tree of ops
0557  *
0558  ******************************************************************************/
0559 
0560 ACPI_STATUS
0561 AcpiPsParseAml (
0562     ACPI_WALK_STATE         *WalkState)
0563 {
0564     ACPI_STATUS             Status;
0565     ACPI_THREAD_STATE       *Thread;
0566     ACPI_THREAD_STATE       *PrevWalkList = AcpiGbl_CurrentWalkList;
0567     ACPI_WALK_STATE         *PreviousWalkState;
0568 
0569 
0570     ACPI_FUNCTION_TRACE (PsParseAml);
0571 
0572     ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
0573         "Entered with WalkState=%p Aml=%p size=%X\n",
0574         WalkState, WalkState->ParserState.Aml,
0575         WalkState->ParserState.AmlSize));
0576 
0577     if (!WalkState->ParserState.Aml)
0578     {
0579         return_ACPI_STATUS (AE_BAD_ADDRESS);
0580     }
0581 
0582     /* Create and initialize a new thread state */
0583 
0584     Thread = AcpiUtCreateThreadState ();
0585     if (!Thread)
0586     {
0587         if (WalkState->MethodDesc)
0588         {
0589             /* Executing a control method - additional cleanup */
0590 
0591             AcpiDsTerminateControlMethod (WalkState->MethodDesc, WalkState);
0592         }
0593 
0594         AcpiDsDeleteWalkState (WalkState);
0595         return_ACPI_STATUS (AE_NO_MEMORY);
0596     }
0597 
0598     WalkState->Thread = Thread;
0599 
0600     /*
0601      * If executing a method, the starting SyncLevel is this method's
0602      * SyncLevel
0603      */
0604     if (WalkState->MethodDesc)
0605     {
0606         WalkState->Thread->CurrentSyncLevel =
0607             WalkState->MethodDesc->Method.SyncLevel;
0608     }
0609 
0610     AcpiDsPushWalkState (WalkState, Thread);
0611 
0612     /*
0613      * This global allows the AML debugger to get a handle to the currently
0614      * executing control method.
0615      */
0616     AcpiGbl_CurrentWalkList = Thread;
0617 
0618     /*
0619      * Execute the walk loop as long as there is a valid Walk State. This
0620      * handles nested control method invocations without recursion.
0621      */
0622     ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "State=%p\n", WalkState));
0623 
0624     Status = AE_OK;
0625     while (WalkState)
0626     {
0627         if (ACPI_SUCCESS (Status))
0628         {
0629             /*
0630              * The ParseLoop executes AML until the method terminates
0631              * or calls another method.
0632              */
0633             Status = AcpiPsParseLoop (WalkState);
0634         }
0635 
0636         ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
0637             "Completed one call to walk loop, %s State=%p\n",
0638             AcpiFormatException (Status), WalkState));
0639 
0640         if (WalkState->MethodPathname && WalkState->MethodIsNested)
0641         {
0642             /* Optional object evaluation log */
0643 
0644             ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EVALUATION, "%-26s:  %*s%s\n",
0645                 "   Exit nested method",
0646                 (WalkState->MethodNestingDepth + 1) * 3, " ",
0647                 &WalkState->MethodPathname[1]));
0648 
0649             ACPI_FREE (WalkState->MethodPathname);
0650             WalkState->MethodIsNested = FALSE;
0651         }
0652         if (Status == AE_CTRL_TRANSFER)
0653         {
0654             /*
0655              * A method call was detected.
0656              * Transfer control to the called control method
0657              */
0658             Status = AcpiDsCallControlMethod (Thread, WalkState, NULL);
0659             if (ACPI_FAILURE (Status))
0660             {
0661                 Status = AcpiDsMethodError (Status, WalkState);
0662             }
0663 
0664             /*
0665              * If the transfer to the new method method call worked,
0666              * a new walk state was created -- get it
0667              */
0668             WalkState = AcpiDsGetCurrentWalkState (Thread);
0669             continue;
0670         }
0671         else if (Status == AE_CTRL_TERMINATE)
0672         {
0673             Status = AE_OK;
0674         }
0675         else if ((Status != AE_OK) && (WalkState->MethodDesc))
0676         {
0677             /* Either the method parse or actual execution failed */
0678 
0679             AcpiExExitInterpreter ();
0680             if (Status == AE_ABORT_METHOD)
0681             {
0682                 AcpiNsPrintNodePathname (
0683                     WalkState->MethodNode, "Aborting method");
0684                 AcpiOsPrintf ("\n");
0685             }
0686             else
0687             {
0688                 ACPI_ERROR_METHOD ("Aborting method",
0689                     WalkState->MethodNode, NULL, Status);
0690             }
0691             AcpiExEnterInterpreter ();
0692 
0693             /* Check for possible multi-thread reentrancy problem */
0694 
0695             if ((Status == AE_ALREADY_EXISTS) &&
0696                 (!(WalkState->MethodDesc->Method.InfoFlags &
0697                     ACPI_METHOD_SERIALIZED)))
0698             {
0699                 /*
0700                  * Method is not serialized and tried to create an object
0701                  * twice. The probable cause is that the method cannot
0702                  * handle reentrancy. Mark as "pending serialized" now, and
0703                  * then mark "serialized" when the last thread exits.
0704                  */
0705                 WalkState->MethodDesc->Method.InfoFlags |=
0706                     ACPI_METHOD_SERIALIZED_PENDING;
0707             }
0708         }
0709 
0710         /* We are done with this walk, move on to the parent if any */
0711 
0712         WalkState = AcpiDsPopWalkState (Thread);
0713 
0714         /* Reset the current scope to the beginning of scope stack */
0715 
0716         AcpiDsScopeStackClear (WalkState);
0717 
0718         /*
0719          * If we just returned from the execution of a control method or if we
0720          * encountered an error during the method parse phase, there's lots of
0721          * cleanup to do
0722          */
0723         if (((WalkState->ParseFlags & ACPI_PARSE_MODE_MASK) ==
0724             ACPI_PARSE_EXECUTE &&
0725             !(WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL)) ||
0726             (ACPI_FAILURE (Status)))
0727         {
0728             AcpiDsTerminateControlMethod (WalkState->MethodDesc, WalkState);
0729         }
0730 
0731         /* Delete this walk state and all linked control states */
0732 
0733         AcpiPsCleanupScope (&WalkState->ParserState);
0734         PreviousWalkState = WalkState;
0735 
0736         ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
0737             "ReturnValue=%p, ImplicitValue=%p State=%p\n",
0738             WalkState->ReturnDesc, WalkState->ImplicitReturnObj, WalkState));
0739 
0740         /* Check if we have restarted a preempted walk */
0741 
0742         WalkState = AcpiDsGetCurrentWalkState (Thread);
0743         if (WalkState)
0744         {
0745             if (ACPI_SUCCESS (Status))
0746             {
0747                 /*
0748                  * There is another walk state, restart it.
0749                  * If the method return value is not used by the parent,
0750                  * The object is deleted
0751                  */
0752                 if (!PreviousWalkState->ReturnDesc)
0753                 {
0754                     /*
0755                      * In slack mode execution, if there is no return value
0756                      * we should implicitly return zero (0) as a default value.
0757                      */
0758                     if (AcpiGbl_EnableInterpreterSlack &&
0759                         !PreviousWalkState->ImplicitReturnObj)
0760                     {
0761                         PreviousWalkState->ImplicitReturnObj =
0762                             AcpiUtCreateIntegerObject ((UINT64) 0);
0763                         if (!PreviousWalkState->ImplicitReturnObj)
0764                         {
0765                             return_ACPI_STATUS (AE_NO_MEMORY);
0766                         }
0767                     }
0768 
0769                     /* Restart the calling control method */
0770 
0771                     Status = AcpiDsRestartControlMethod (WalkState,
0772                         PreviousWalkState->ImplicitReturnObj);
0773                 }
0774                 else
0775                 {
0776                     /*
0777                      * We have a valid return value, delete any implicit
0778                      * return value.
0779                      */
0780                     AcpiDsClearImplicitReturn (PreviousWalkState);
0781 
0782                     Status = AcpiDsRestartControlMethod (WalkState,
0783                         PreviousWalkState->ReturnDesc);
0784                 }
0785                 if (ACPI_SUCCESS (Status))
0786                 {
0787                     WalkState->WalkType |= ACPI_WALK_METHOD_RESTART;
0788                 }
0789             }
0790             else
0791             {
0792                 /* On error, delete any return object or implicit return */
0793 
0794                 AcpiUtRemoveReference (PreviousWalkState->ReturnDesc);
0795                 AcpiDsClearImplicitReturn (PreviousWalkState);
0796             }
0797         }
0798 
0799         /*
0800          * Just completed a 1st-level method, save the final internal return
0801          * value (if any)
0802          */
0803         else if (PreviousWalkState->CallerReturnDesc)
0804         {
0805             if (PreviousWalkState->ImplicitReturnObj)
0806             {
0807                 *(PreviousWalkState->CallerReturnDesc) =
0808                     PreviousWalkState->ImplicitReturnObj;
0809             }
0810             else
0811             {
0812                  /* NULL if no return value */
0813 
0814                 *(PreviousWalkState->CallerReturnDesc) =
0815                     PreviousWalkState->ReturnDesc;
0816             }
0817         }
0818         else
0819         {
0820             if (PreviousWalkState->ReturnDesc)
0821             {
0822                 /* Caller doesn't want it, must delete it */
0823 
0824                 AcpiUtRemoveReference (PreviousWalkState->ReturnDesc);
0825             }
0826             if (PreviousWalkState->ImplicitReturnObj)
0827             {
0828                 /* Caller doesn't want it, must delete it */
0829 
0830                 AcpiUtRemoveReference (PreviousWalkState->ImplicitReturnObj);
0831             }
0832         }
0833 
0834         AcpiDsDeleteWalkState (PreviousWalkState);
0835     }
0836 
0837     /* Normal exit */
0838 
0839     AcpiExReleaseAllMutexes (Thread);
0840     AcpiUtDeleteGenericState (ACPI_CAST_PTR (ACPI_GENERIC_STATE, Thread));
0841     AcpiGbl_CurrentWalkList = PrevWalkList;
0842     return_ACPI_STATUS (Status);
0843 }