Back to home page

LXR

 
 

    


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

0001 /******************************************************************************
0002  *
0003  * Module Name: psobject - Support for parse objects
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 #include "acpi.h"
0153 #include "accommon.h"
0154 #include "acparser.h"
0155 #include "amlcode.h"
0156 #include "acconvert.h"
0157 #include "acnamesp.h"
0158 
0159 #define _COMPONENT          ACPI_PARSER
0160         ACPI_MODULE_NAME    ("psobject")
0161 
0162 
0163 /* Local prototypes */
0164 
0165 static ACPI_STATUS
0166 AcpiPsGetAmlOpcode (
0167     ACPI_WALK_STATE         *WalkState);
0168 
0169 
0170 /*******************************************************************************
0171  *
0172  * FUNCTION:    AcpiPsGetAmlOpcode
0173  *
0174  * PARAMETERS:  WalkState           - Current state
0175  *
0176  * RETURN:      Status
0177  *
0178  * DESCRIPTION: Extract the next AML opcode from the input stream.
0179  *
0180  ******************************************************************************/
0181 
0182 static ACPI_STATUS
0183 AcpiPsGetAmlOpcode (
0184     ACPI_WALK_STATE         *WalkState)
0185 {
0186     ACPI_ERROR_ONLY (UINT32 AmlOffset);
0187 
0188 
0189     ACPI_FUNCTION_TRACE_PTR (PsGetAmlOpcode, WalkState);
0190 
0191 
0192     WalkState->Aml = WalkState->ParserState.Aml;
0193     WalkState->Opcode = AcpiPsPeekOpcode (&(WalkState->ParserState));
0194 
0195     /*
0196      * First cut to determine what we have found:
0197      * 1) A valid AML opcode
0198      * 2) A name string
0199      * 3) An unknown/invalid opcode
0200      */
0201     WalkState->OpInfo = AcpiPsGetOpcodeInfo (WalkState->Opcode);
0202 
0203     switch (WalkState->OpInfo->Class)
0204     {
0205     case AML_CLASS_ASCII:
0206     case AML_CLASS_PREFIX:
0207         /*
0208          * Starts with a valid prefix or ASCII char, this is a name
0209          * string. Convert the bare name string to a namepath.
0210          */
0211         WalkState->Opcode = AML_INT_NAMEPATH_OP;
0212         WalkState->ArgTypes = ARGP_NAMESTRING;
0213         break;
0214 
0215     case AML_CLASS_UNKNOWN:
0216 
0217         /* The opcode is unrecognized. Complain and skip unknown opcodes */
0218 
0219         if (WalkState->PassNumber == 2)
0220         {
0221             ACPI_ERROR_ONLY(AmlOffset = (UINT32) ACPI_PTR_DIFF (WalkState->Aml,
0222                 WalkState->ParserState.AmlStart));
0223 
0224             ACPI_ERROR ((AE_INFO,
0225                 "Unknown opcode 0x%.2X at table offset 0x%.4X, ignoring",
0226                 WalkState->Opcode,
0227                 (UINT32) (AmlOffset + sizeof (ACPI_TABLE_HEADER))));
0228 
0229             ACPI_DUMP_BUFFER ((WalkState->ParserState.Aml - 16), 48);
0230 
0231 #ifdef ACPI_ASL_COMPILER
0232             /*
0233              * This is executed for the disassembler only. Output goes
0234              * to the disassembled ASL output file.
0235              */
0236             AcpiOsPrintf (
0237                 "/*\nError: Unknown opcode 0x%.2X at table offset 0x%.4X, context:\n",
0238                 WalkState->Opcode,
0239                 (UINT32) (AmlOffset + sizeof (ACPI_TABLE_HEADER)));
0240 
0241             ACPI_ERROR ((AE_INFO,
0242                 "Aborting disassembly, AML byte code is corrupt"));
0243 
0244             /* Dump the context surrounding the invalid opcode */
0245 
0246             AcpiUtDumpBuffer (((UINT8 *) WalkState->ParserState.Aml - 16),
0247                 48, DB_BYTE_DISPLAY,
0248                 (AmlOffset + sizeof (ACPI_TABLE_HEADER) - 16));
0249             AcpiOsPrintf (" */\n");
0250 
0251             /*
0252              * Just abort the disassembly, cannot continue because the
0253              * parser is essentially lost. The disassembler can then
0254              * randomly fail because an ill-constructed parse tree
0255              * can result.
0256              */
0257             return_ACPI_STATUS (AE_AML_BAD_OPCODE);
0258 #endif
0259         }
0260 
0261         /* Increment past one-byte or two-byte opcode */
0262 
0263         WalkState->ParserState.Aml++;
0264         if (WalkState->Opcode > 0xFF) /* Can only happen if first byte is 0x5B */
0265         {
0266             WalkState->ParserState.Aml++;
0267         }
0268 
0269         return_ACPI_STATUS (AE_CTRL_PARSE_CONTINUE);
0270 
0271     default:
0272 
0273         /* Found opcode info, this is a normal opcode */
0274 
0275         WalkState->ParserState.Aml +=
0276             AcpiPsGetOpcodeSize (WalkState->Opcode);
0277         WalkState->ArgTypes = WalkState->OpInfo->ParseArgs;
0278         break;
0279     }
0280 
0281     return_ACPI_STATUS (AE_OK);
0282 }
0283 
0284 
0285 /*******************************************************************************
0286  *
0287  * FUNCTION:    AcpiPsBuildNamedOp
0288  *
0289  * PARAMETERS:  WalkState           - Current state
0290  *              AmlOpStart          - Begin of named Op in AML
0291  *              UnnamedOp           - Early Op (not a named Op)
0292  *              Op                  - Returned Op
0293  *
0294  * RETURN:      Status
0295  *
0296  * DESCRIPTION: Parse a named Op
0297  *
0298  ******************************************************************************/
0299 
0300 ACPI_STATUS
0301 AcpiPsBuildNamedOp (
0302     ACPI_WALK_STATE         *WalkState,
0303     UINT8                   *AmlOpStart,
0304     ACPI_PARSE_OBJECT       *UnnamedOp,
0305     ACPI_PARSE_OBJECT       **Op)
0306 {
0307     ACPI_STATUS             Status = AE_OK;
0308     ACPI_PARSE_OBJECT       *Arg = NULL;
0309 
0310 
0311     ACPI_FUNCTION_TRACE_PTR (PsBuildNamedOp, WalkState);
0312 
0313 
0314     UnnamedOp->Common.Value.Arg = NULL;
0315     UnnamedOp->Common.ArgListLength = 0;
0316     UnnamedOp->Common.AmlOpcode = WalkState->Opcode;
0317 
0318     /*
0319      * Get and append arguments until we find the node that contains
0320      * the name (the type ARGP_NAME).
0321      */
0322     while (GET_CURRENT_ARG_TYPE (WalkState->ArgTypes) &&
0323           (GET_CURRENT_ARG_TYPE (WalkState->ArgTypes) != ARGP_NAME))
0324     {
0325         ASL_CV_CAPTURE_COMMENTS (WalkState);
0326         Status = AcpiPsGetNextArg (WalkState, &(WalkState->ParserState),
0327             GET_CURRENT_ARG_TYPE (WalkState->ArgTypes), &Arg);
0328         if (ACPI_FAILURE (Status))
0329         {
0330             return_ACPI_STATUS (Status);
0331         }
0332 
0333         AcpiPsAppendArg (UnnamedOp, Arg);
0334         INCREMENT_ARG_LIST (WalkState->ArgTypes);
0335     }
0336 
0337     /* are there any inline comments associated with the NameSeg?? If so, save this. */
0338 
0339     ASL_CV_CAPTURE_COMMENTS (WalkState);
0340 
0341 #ifdef ACPI_ASL_COMPILER
0342     if (AcpiGbl_CurrentInlineComment != NULL)
0343     {
0344         UnnamedOp->Common.NameComment = AcpiGbl_CurrentInlineComment;
0345         AcpiGbl_CurrentInlineComment = NULL;
0346     }
0347 #endif
0348 
0349     /*
0350      * Make sure that we found a NAME and didn't run out of arguments
0351      */
0352     if (!GET_CURRENT_ARG_TYPE (WalkState->ArgTypes))
0353     {
0354         return_ACPI_STATUS (AE_AML_NO_OPERAND);
0355     }
0356 
0357     /* We know that this arg is a name, move to next arg */
0358 
0359     INCREMENT_ARG_LIST (WalkState->ArgTypes);
0360 
0361     /*
0362      * Find the object. This will either insert the object into
0363      * the namespace or simply look it up
0364      */
0365     WalkState->Op = NULL;
0366 
0367     Status = WalkState->DescendingCallback (WalkState, Op);
0368     if (ACPI_FAILURE (Status))
0369     {
0370         if (Status != AE_CTRL_TERMINATE)
0371         {
0372             ACPI_EXCEPTION ((AE_INFO, Status, "During name lookup/catalog"));
0373         }
0374         return_ACPI_STATUS (Status);
0375     }
0376 
0377     if (!*Op)
0378     {
0379         return_ACPI_STATUS (AE_CTRL_PARSE_CONTINUE);
0380     }
0381 
0382     Status = AcpiPsNextParseState (WalkState, *Op, Status);
0383     if (ACPI_FAILURE (Status))
0384     {
0385         if (Status == AE_CTRL_PENDING)
0386         {
0387             Status = AE_CTRL_PARSE_PENDING;
0388         }
0389         return_ACPI_STATUS (Status);
0390     }
0391 
0392     AcpiPsAppendArg (*Op, UnnamedOp->Common.Value.Arg);
0393 
0394 #ifdef ACPI_ASL_COMPILER
0395 
0396     /* save any comments that might be associated with UnnamedOp. */
0397 
0398     (*Op)->Common.InlineComment     = UnnamedOp->Common.InlineComment;
0399     (*Op)->Common.EndNodeComment    = UnnamedOp->Common.EndNodeComment;
0400     (*Op)->Common.CloseBraceComment = UnnamedOp->Common.CloseBraceComment;
0401     (*Op)->Common.NameComment       = UnnamedOp->Common.NameComment;
0402     (*Op)->Common.CommentList       = UnnamedOp->Common.CommentList;
0403     (*Op)->Common.EndBlkComment     = UnnamedOp->Common.EndBlkComment;
0404     (*Op)->Common.CvFilename        = UnnamedOp->Common.CvFilename;
0405     (*Op)->Common.CvParentFilename  = UnnamedOp->Common.CvParentFilename;
0406     (*Op)->Named.Aml                = UnnamedOp->Common.Aml;
0407 
0408     UnnamedOp->Common.InlineComment     = NULL;
0409     UnnamedOp->Common.EndNodeComment    = NULL;
0410     UnnamedOp->Common.CloseBraceComment = NULL;
0411     UnnamedOp->Common.NameComment       = NULL;
0412     UnnamedOp->Common.CommentList       = NULL;
0413     UnnamedOp->Common.EndBlkComment     = NULL;
0414 #endif
0415 
0416     if ((*Op)->Common.AmlOpcode == AML_REGION_OP ||
0417         (*Op)->Common.AmlOpcode == AML_DATA_REGION_OP)
0418     {
0419         /*
0420          * Defer final parsing of an OperationRegion body, because we don't
0421          * have enough info in the first pass to parse it correctly (i.e.,
0422          * there may be method calls within the TermArg elements of the body.)
0423          *
0424          * However, we must continue parsing because the opregion is not a
0425          * standalone package -- we don't know where the end is at this point.
0426          *
0427          * (Length is unknown until parse of the body complete)
0428          */
0429         (*Op)->Named.Data = AmlOpStart;
0430         (*Op)->Named.Length = 0;
0431     }
0432 
0433     return_ACPI_STATUS (AE_OK);
0434 }
0435 
0436 
0437 /*******************************************************************************
0438  *
0439  * FUNCTION:    AcpiPsCreateOp
0440  *
0441  * PARAMETERS:  WalkState           - Current state
0442  *              AmlOpStart          - Op start in AML
0443  *              NewOp               - Returned Op
0444  *
0445  * RETURN:      Status
0446  *
0447  * DESCRIPTION: Get Op from AML
0448  *
0449  ******************************************************************************/
0450 
0451 ACPI_STATUS
0452 AcpiPsCreateOp (
0453     ACPI_WALK_STATE         *WalkState,
0454     UINT8                   *AmlOpStart,
0455     ACPI_PARSE_OBJECT       **NewOp)
0456 {
0457     ACPI_STATUS             Status = AE_OK;
0458     ACPI_PARSE_OBJECT       *Op;
0459     ACPI_PARSE_OBJECT       *NamedOp = NULL;
0460     ACPI_PARSE_OBJECT       *ParentScope;
0461     UINT8                   ArgumentCount;
0462     const ACPI_OPCODE_INFO  *OpInfo;
0463 
0464 
0465     ACPI_FUNCTION_TRACE_PTR (PsCreateOp, WalkState);
0466 
0467 
0468     Status = AcpiPsGetAmlOpcode (WalkState);
0469     if (Status == AE_CTRL_PARSE_CONTINUE)
0470     {
0471         return_ACPI_STATUS (AE_CTRL_PARSE_CONTINUE);
0472     }
0473     if (ACPI_FAILURE (Status))
0474     {
0475         return_ACPI_STATUS (Status);
0476     }
0477 
0478     /* Create Op structure and append to parent's argument list */
0479 
0480     WalkState->OpInfo = AcpiPsGetOpcodeInfo (WalkState->Opcode);
0481     Op = AcpiPsAllocOp (WalkState->Opcode, AmlOpStart);
0482     if (!Op)
0483     {
0484         return_ACPI_STATUS (AE_NO_MEMORY);
0485     }
0486 
0487     if (WalkState->OpInfo->Flags & AML_NAMED)
0488     {
0489         Status = AcpiPsBuildNamedOp (WalkState, AmlOpStart, Op, &NamedOp);
0490         AcpiPsFreeOp (Op);
0491 
0492 #ifdef ACPI_ASL_COMPILER
0493         if (AcpiGbl_DisasmFlag && WalkState->Opcode == AML_EXTERNAL_OP &&
0494             Status == AE_NOT_FOUND)
0495         {
0496             /*
0497              * If parsing of AML_EXTERNAL_OP's name path fails, then skip
0498              * past this opcode and keep parsing. This is a much better
0499              * alternative than to abort the entire disassembler. At this
0500              * point, the ParserState is at the end of the namepath of the
0501              * external declaration opcode. Setting WalkState->Aml to
0502              * WalkState->ParserState.Aml + 2 moves increments the
0503              * WalkState->Aml past the object type and the paramcount of the
0504              * external opcode.
0505              */
0506             WalkState->Aml = WalkState->ParserState.Aml + 2;
0507             WalkState->ParserState.Aml = WalkState->Aml;
0508             return_ACPI_STATUS (AE_CTRL_PARSE_CONTINUE);
0509         }
0510 #endif
0511         if (ACPI_FAILURE (Status))
0512         {
0513             return_ACPI_STATUS (Status);
0514         }
0515 
0516         *NewOp = NamedOp;
0517         return_ACPI_STATUS (AE_OK);
0518     }
0519 
0520     /* Not a named opcode, just allocate Op and append to parent */
0521 
0522     if (WalkState->OpInfo->Flags & AML_CREATE)
0523     {
0524         /*
0525          * Backup to beginning of CreateXXXfield declaration
0526          * BodyLength is unknown until we parse the body
0527          */
0528         Op->Named.Data = AmlOpStart;
0529         Op->Named.Length = 0;
0530     }
0531 
0532     if (WalkState->Opcode == AML_BANK_FIELD_OP)
0533     {
0534         /*
0535          * Backup to beginning of BankField declaration
0536          * BodyLength is unknown until we parse the body
0537          */
0538         Op->Named.Data = AmlOpStart;
0539         Op->Named.Length = 0;
0540     }
0541 
0542     ParentScope = AcpiPsGetParentScope (&(WalkState->ParserState));
0543     AcpiPsAppendArg (ParentScope, Op);
0544 
0545     if (ParentScope)
0546     {
0547         OpInfo = AcpiPsGetOpcodeInfo (ParentScope->Common.AmlOpcode);
0548         if (OpInfo->Flags & AML_HAS_TARGET)
0549         {
0550             ArgumentCount = AcpiPsGetArgumentCount (OpInfo->Type);
0551             if (ParentScope->Common.ArgListLength > ArgumentCount)
0552             {
0553                 Op->Common.Flags |= ACPI_PARSEOP_TARGET;
0554             }
0555         }
0556 
0557         /*
0558          * Special case for both Increment() and Decrement(), where
0559          * the lone argument is both a source and a target.
0560          */
0561         else if ((ParentScope->Common.AmlOpcode == AML_INCREMENT_OP) ||
0562                 (ParentScope->Common.AmlOpcode == AML_DECREMENT_OP))
0563         {
0564             Op->Common.Flags |= ACPI_PARSEOP_TARGET;
0565         }
0566     }
0567 
0568     if (WalkState->DescendingCallback != NULL)
0569     {
0570         /*
0571          * Find the object. This will either insert the object into
0572          * the namespace or simply look it up
0573          */
0574         WalkState->Op = *NewOp = Op;
0575 
0576         Status = WalkState->DescendingCallback (WalkState, &Op);
0577         Status = AcpiPsNextParseState (WalkState, Op, Status);
0578         if (Status == AE_CTRL_PENDING)
0579         {
0580             Status = AE_CTRL_PARSE_PENDING;
0581         }
0582     }
0583 
0584     return_ACPI_STATUS (Status);
0585 }
0586 
0587 
0588 /*******************************************************************************
0589  *
0590  * FUNCTION:    AcpiPsCompleteOp
0591  *
0592  * PARAMETERS:  WalkState           - Current state
0593  *              Op                  - Returned Op
0594  *              Status              - Parse status before complete Op
0595  *
0596  * RETURN:      Status
0597  *
0598  * DESCRIPTION: Complete Op
0599  *
0600  ******************************************************************************/
0601 
0602 ACPI_STATUS
0603 AcpiPsCompleteOp (
0604     ACPI_WALK_STATE         *WalkState,
0605     ACPI_PARSE_OBJECT       **Op,
0606     ACPI_STATUS             Status)
0607 {
0608     ACPI_STATUS             Status2;
0609 
0610 
0611     ACPI_FUNCTION_TRACE_PTR (PsCompleteOp, WalkState);
0612 
0613 
0614     /*
0615      * Finished one argument of the containing scope
0616      */
0617     WalkState->ParserState.Scope->ParseScope.ArgCount--;
0618 
0619     /* Close this Op (will result in parse subtree deletion) */
0620 
0621     Status2 = AcpiPsCompleteThisOp (WalkState, *Op);
0622     if (ACPI_FAILURE (Status2))
0623     {
0624         return_ACPI_STATUS (Status2);
0625     }
0626 
0627     *Op = NULL;
0628 
0629     switch (Status)
0630     {
0631     case AE_OK:
0632 
0633         break;
0634 
0635     case AE_CTRL_TRANSFER:
0636 
0637         /* We are about to transfer to a called method */
0638 
0639         WalkState->PrevOp = NULL;
0640         WalkState->PrevArgTypes = WalkState->ArgTypes;
0641         return_ACPI_STATUS (Status);
0642 
0643     case AE_CTRL_END:
0644 
0645         AcpiPsPopScope (&(WalkState->ParserState), Op,
0646             &WalkState->ArgTypes, &WalkState->ArgCount);
0647 
0648         if (*Op)
0649         {
0650             WalkState->Op = *Op;
0651             WalkState->OpInfo = AcpiPsGetOpcodeInfo ((*Op)->Common.AmlOpcode);
0652             WalkState->Opcode = (*Op)->Common.AmlOpcode;
0653 
0654             Status = WalkState->AscendingCallback (WalkState);
0655             (void) AcpiPsNextParseState (WalkState, *Op, Status);
0656 
0657             Status2 = AcpiPsCompleteThisOp (WalkState, *Op);
0658             if (ACPI_FAILURE (Status2))
0659             {
0660                 return_ACPI_STATUS (Status2);
0661             }
0662         }
0663 
0664         break;
0665 
0666     case AE_CTRL_BREAK:
0667     case AE_CTRL_CONTINUE:
0668 
0669         /* Pop off scopes until we find the While */
0670 
0671         while (!(*Op) || ((*Op)->Common.AmlOpcode != AML_WHILE_OP))
0672         {
0673             AcpiPsPopScope (&(WalkState->ParserState), Op,
0674                 &WalkState->ArgTypes, &WalkState->ArgCount);
0675         }
0676 
0677         /* Close this iteration of the While loop */
0678 
0679         WalkState->Op = *Op;
0680         WalkState->OpInfo = AcpiPsGetOpcodeInfo ((*Op)->Common.AmlOpcode);
0681         WalkState->Opcode = (*Op)->Common.AmlOpcode;
0682 
0683         Status = WalkState->AscendingCallback (WalkState);
0684         (void) AcpiPsNextParseState (WalkState, *Op, Status);
0685 
0686         Status2 = AcpiPsCompleteThisOp (WalkState, *Op);
0687         if (ACPI_FAILURE (Status2))
0688         {
0689             return_ACPI_STATUS (Status2);
0690         }
0691 
0692         break;
0693 
0694     case AE_CTRL_TERMINATE:
0695 
0696         /* Clean up */
0697         do
0698         {
0699             if (*Op)
0700             {
0701                 Status2 = AcpiPsCompleteThisOp (WalkState, *Op);
0702                 if (ACPI_FAILURE (Status2))
0703                 {
0704                     return_ACPI_STATUS (Status2);
0705                 }
0706 
0707                 AcpiUtDeleteGenericState (
0708                     AcpiUtPopGenericState (&WalkState->ControlState));
0709             }
0710 
0711             AcpiPsPopScope (&(WalkState->ParserState), Op,
0712                 &WalkState->ArgTypes, &WalkState->ArgCount);
0713 
0714         } while (*Op);
0715 
0716         return_ACPI_STATUS (AE_OK);
0717 
0718     default:  /* All other non-AE_OK status */
0719 
0720         do
0721         {
0722             if (*Op)
0723             {
0724                 /*
0725                  * These Opcodes need to be removed from the namespace because they
0726                  * get created even if these opcodes cannot be created due to
0727                  * errors.
0728                  */
0729                 if (((*Op)->Common.AmlOpcode == AML_REGION_OP) ||
0730                     ((*Op)->Common.AmlOpcode == AML_DATA_REGION_OP))
0731                 {
0732                     AcpiNsDeleteChildren ((*Op)->Common.Node);
0733                     AcpiNsRemoveNode ((*Op)->Common.Node);
0734                     (*Op)->Common.Node = NULL;
0735                     AcpiPsDeleteParseTree (*Op);
0736                 }
0737 
0738                 Status2 = AcpiPsCompleteThisOp (WalkState, *Op);
0739                 if (ACPI_FAILURE (Status2))
0740                 {
0741                     return_ACPI_STATUS (Status2);
0742                 }
0743             }
0744 
0745             AcpiPsPopScope (&(WalkState->ParserState), Op,
0746                 &WalkState->ArgTypes, &WalkState->ArgCount);
0747 
0748         } while (*Op);
0749 
0750 
0751 #if 0
0752         /*
0753          * TBD: Cleanup parse ops on error
0754          */
0755         if (*Op == NULL)
0756         {
0757             AcpiPsPopScope (ParserState, Op,
0758                 &WalkState->ArgTypes, &WalkState->ArgCount);
0759         }
0760 #endif
0761         WalkState->PrevOp = NULL;
0762         WalkState->PrevArgTypes = WalkState->ArgTypes;
0763 
0764         if (WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL)
0765         {
0766             /*
0767              * There was something that went wrong while executing code at the
0768              * module-level. We need to skip parsing whatever caused the
0769              * error and keep going. One runtime error during the table load
0770              * should not cause the entire table to not be loaded. This is
0771              * because there could be correct AML beyond the parts that caused
0772              * the runtime error.
0773              */
0774             ACPI_INFO (("Ignoring error and continuing table load"));
0775             return_ACPI_STATUS (AE_OK);
0776         }
0777         return_ACPI_STATUS (Status);
0778     }
0779 
0780     /* This scope complete? */
0781 
0782     if (AcpiPsHasCompletedScope (&(WalkState->ParserState)))
0783     {
0784         AcpiPsPopScope (&(WalkState->ParserState), Op,
0785             &WalkState->ArgTypes, &WalkState->ArgCount);
0786         ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Popped scope, Op=%p\n", *Op));
0787     }
0788     else
0789     {
0790         *Op = NULL;
0791     }
0792 
0793     return_ACPI_STATUS (AE_OK);
0794 }
0795 
0796 
0797 /*******************************************************************************
0798  *
0799  * FUNCTION:    AcpiPsCompleteFinalOp
0800  *
0801  * PARAMETERS:  WalkState           - Current state
0802  *              Op                  - Current Op
0803  *              Status              - Current parse status before complete last
0804  *                                    Op
0805  *
0806  * RETURN:      Status
0807  *
0808  * DESCRIPTION: Complete last Op.
0809  *
0810  ******************************************************************************/
0811 
0812 ACPI_STATUS
0813 AcpiPsCompleteFinalOp (
0814     ACPI_WALK_STATE         *WalkState,
0815     ACPI_PARSE_OBJECT       *Op,
0816     ACPI_STATUS             Status)
0817 {
0818     ACPI_STATUS             Status2;
0819 
0820 
0821     ACPI_FUNCTION_TRACE_PTR (PsCompleteFinalOp, WalkState);
0822 
0823 
0824     /*
0825      * Complete the last Op (if not completed), and clear the scope stack.
0826      * It is easily possible to end an AML "package" with an unbounded number
0827      * of open scopes (such as when several ASL blocks are closed with
0828      * sequential closing braces). We want to terminate each one cleanly.
0829      */
0830     ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "AML package complete at Op %p\n", Op));
0831     do
0832     {
0833         if (Op)
0834         {
0835             if (WalkState->AscendingCallback != NULL)
0836             {
0837                 WalkState->Op = Op;
0838                 WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
0839                 WalkState->Opcode = Op->Common.AmlOpcode;
0840 
0841                 Status = WalkState->AscendingCallback (WalkState);
0842                 Status = AcpiPsNextParseState (WalkState, Op, Status);
0843                 if (Status == AE_CTRL_PENDING)
0844                 {
0845                     Status = AcpiPsCompleteOp (WalkState, &Op, AE_OK);
0846                     if (ACPI_FAILURE (Status))
0847                     {
0848                         return_ACPI_STATUS (Status);
0849                     }
0850                 }
0851 
0852                 if (Status == AE_CTRL_TERMINATE)
0853                 {
0854                     Status = AE_OK;
0855 
0856                     /* Clean up */
0857                     do
0858                     {
0859                         if (Op)
0860                         {
0861                             Status2 = AcpiPsCompleteThisOp (WalkState, Op);
0862                             if (ACPI_FAILURE (Status2))
0863                             {
0864                                 return_ACPI_STATUS (Status2);
0865                             }
0866                         }
0867 
0868                         AcpiPsPopScope (&(WalkState->ParserState), &Op,
0869                             &WalkState->ArgTypes, &WalkState->ArgCount);
0870 
0871                     } while (Op);
0872 
0873                     return_ACPI_STATUS (Status);
0874                 }
0875 
0876                 else if (ACPI_FAILURE (Status))
0877                 {
0878                     /* First error is most important */
0879 
0880                     (void) AcpiPsCompleteThisOp (WalkState, Op);
0881                     return_ACPI_STATUS (Status);
0882                 }
0883             }
0884 
0885             Status2 = AcpiPsCompleteThisOp (WalkState, Op);
0886             if (ACPI_FAILURE (Status2))
0887             {
0888                 return_ACPI_STATUS (Status2);
0889             }
0890         }
0891 
0892         AcpiPsPopScope (&(WalkState->ParserState), &Op, &WalkState->ArgTypes,
0893             &WalkState->ArgCount);
0894 
0895     } while (Op);
0896 
0897     return_ACPI_STATUS (Status);
0898 }