Path: blob/main/sys/contrib/dev/acpica/components/parser/psobject.c
48524 views
/******************************************************************************1*2* Module Name: psobject - Support for parse objects3*4*****************************************************************************/56/******************************************************************************7*8* 1. Copyright Notice9*10* Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.11* All rights reserved.12*13* 2. License14*15* 2.1. This is your license from Intel Corp. under its intellectual property16* rights. You may have additional license terms from the party that provided17* you this software, covering your right to use that party's intellectual18* property rights.19*20* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a21* copy of the source code appearing in this file ("Covered Code") an22* irrevocable, perpetual, worldwide license under Intel's copyrights in the23* base code distributed originally by Intel ("Original Intel Code") to copy,24* make derivatives, distribute, use and display any portion of the Covered25* Code in any form, with the right to sublicense such rights; and26*27* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent28* license (with the right to sublicense), under only those claims of Intel29* patents that are infringed by the Original Intel Code, to make, use, sell,30* offer to sell, and import the Covered Code and derivative works thereof31* solely to the minimum extent necessary to exercise the above copyright32* license, and in no event shall the patent license extend to any additions33* to or modifications of the Original Intel Code. No other license or right34* is granted directly or by implication, estoppel or otherwise;35*36* The above copyright and patent license is granted only if the following37* conditions are met:38*39* 3. Conditions40*41* 3.1. Redistribution of Source with Rights to Further Distribute Source.42* Redistribution of source code of any substantial portion of the Covered43* Code or modification with rights to further distribute source must include44* the above Copyright Notice, the above License, this list of Conditions,45* and the following Disclaimer and Export Compliance provision. In addition,46* Licensee must cause all Covered Code to which Licensee contributes to47* contain a file documenting the changes Licensee made to create that Covered48* Code and the date of any change. Licensee must include in that file the49* documentation of any changes made by any predecessor Licensee. Licensee50* must include a prominent statement that the modification is derived,51* directly or indirectly, from Original Intel Code.52*53* 3.2. Redistribution of Source with no Rights to Further Distribute Source.54* Redistribution of source code of any substantial portion of the Covered55* Code or modification without rights to further distribute source must56* include the following Disclaimer and Export Compliance provision in the57* documentation and/or other materials provided with distribution. In58* addition, Licensee may not authorize further sublicense of source of any59* portion of the Covered Code, and must include terms to the effect that the60* license from Licensee to its licensee is limited to the intellectual61* property embodied in the software Licensee provides to its licensee, and62* not to intellectual property embodied in modifications its licensee may63* make.64*65* 3.3. Redistribution of Executable. Redistribution in executable form of any66* substantial portion of the Covered Code or modification must reproduce the67* above Copyright Notice, and the following Disclaimer and Export Compliance68* provision in the documentation and/or other materials provided with the69* distribution.70*71* 3.4. Intel retains all right, title, and interest in and to the Original72* Intel Code.73*74* 3.5. Neither the name Intel nor any other trademark owned or controlled by75* Intel shall be used in advertising or otherwise to promote the sale, use or76* other dealings in products derived from or relating to the Covered Code77* without prior written authorization from Intel.78*79* 4. Disclaimer and Export Compliance80*81* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED82* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE83* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,84* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY85* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY86* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A87* PARTICULAR PURPOSE.88*89* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES90* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR91* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,92* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY93* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL94* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS95* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY96* LIMITED REMEDY.97*98* 4.3. Licensee shall not export, either directly or indirectly, any of this99* software or system incorporating such software without first obtaining any100* required license or other approval from the U. S. Department of Commerce or101* any other agency or department of the United States Government. In the102* event Licensee exports any such software from the United States or103* re-exports any such software from a foreign destination, Licensee shall104* ensure that the distribution and export/re-export of the software is in105* compliance with all laws, regulations, orders, or other restrictions of the106* U.S. Export Administration Regulations. Licensee agrees that neither it nor107* any of its subsidiaries will export/re-export any technical data, process,108* software, or service, directly or indirectly, to any country for which the109* United States government or any agency thereof requires an export license,110* other governmental approval, or letter of assurance, without first obtaining111* such license, approval or letter.112*113*****************************************************************************114*115* Alternatively, you may choose to be licensed under the terms of the116* following license:117*118* Redistribution and use in source and binary forms, with or without119* modification, are permitted provided that the following conditions120* are met:121* 1. Redistributions of source code must retain the above copyright122* notice, this list of conditions, and the following disclaimer,123* without modification.124* 2. Redistributions in binary form must reproduce at minimum a disclaimer125* substantially similar to the "NO WARRANTY" disclaimer below126* ("Disclaimer") and any redistribution must be conditioned upon127* including a substantially similar Disclaimer requirement for further128* binary redistribution.129* 3. Neither the names of the above-listed copyright holders nor the names130* of any contributors may be used to endorse or promote products derived131* from this software without specific prior written permission.132*133* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS134* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT135* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR136* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT137* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,138* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT139* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,140* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY141* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT142* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE143* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.144*145* Alternatively, you may choose to be licensed under the terms of the146* GNU General Public License ("GPL") version 2 as published by the Free147* Software Foundation.148*149*****************************************************************************/150151#include <contrib/dev/acpica/include/acpi.h>152#include <contrib/dev/acpica/include/accommon.h>153#include <contrib/dev/acpica/include/acparser.h>154#include <contrib/dev/acpica/include/amlcode.h>155#include <contrib/dev/acpica/include/acconvert.h>156#include <contrib/dev/acpica/include/acnamesp.h>157158#define _COMPONENT ACPI_PARSER159ACPI_MODULE_NAME ("psobject")160161162/* Local prototypes */163164static ACPI_STATUS165AcpiPsGetAmlOpcode (166ACPI_WALK_STATE *WalkState);167168169/*******************************************************************************170*171* FUNCTION: AcpiPsGetAmlOpcode172*173* PARAMETERS: WalkState - Current state174*175* RETURN: Status176*177* DESCRIPTION: Extract the next AML opcode from the input stream.178*179******************************************************************************/180181static ACPI_STATUS182AcpiPsGetAmlOpcode (183ACPI_WALK_STATE *WalkState)184{185ACPI_ERROR_ONLY (UINT32 AmlOffset);186187188ACPI_FUNCTION_TRACE_PTR (PsGetAmlOpcode, WalkState);189190191WalkState->Aml = WalkState->ParserState.Aml;192WalkState->Opcode = AcpiPsPeekOpcode (&(WalkState->ParserState));193194/*195* First cut to determine what we have found:196* 1) A valid AML opcode197* 2) A name string198* 3) An unknown/invalid opcode199*/200WalkState->OpInfo = AcpiPsGetOpcodeInfo (WalkState->Opcode);201202switch (WalkState->OpInfo->Class)203{204case AML_CLASS_ASCII:205case AML_CLASS_PREFIX:206/*207* Starts with a valid prefix or ASCII char, this is a name208* string. Convert the bare name string to a namepath.209*/210WalkState->Opcode = AML_INT_NAMEPATH_OP;211WalkState->ArgTypes = ARGP_NAMESTRING;212break;213214case AML_CLASS_UNKNOWN:215216/* The opcode is unrecognized. Complain and skip unknown opcodes */217218if (WalkState->PassNumber == 2)219{220ACPI_ERROR_ONLY(AmlOffset = (UINT32) ACPI_PTR_DIFF (WalkState->Aml,221WalkState->ParserState.AmlStart));222223ACPI_ERROR ((AE_INFO,224"Unknown opcode 0x%.2X at table offset 0x%.4X, ignoring",225WalkState->Opcode,226(UINT32) (AmlOffset + sizeof (ACPI_TABLE_HEADER))));227228ACPI_DUMP_BUFFER ((WalkState->ParserState.Aml - 16), 48);229230#ifdef ACPI_ASL_COMPILER231/*232* This is executed for the disassembler only. Output goes233* to the disassembled ASL output file.234*/235AcpiOsPrintf (236"/*\nError: Unknown opcode 0x%.2X at table offset 0x%.4X, context:\n",237WalkState->Opcode,238(UINT32) (AmlOffset + sizeof (ACPI_TABLE_HEADER)));239240ACPI_ERROR ((AE_INFO,241"Aborting disassembly, AML byte code is corrupt"));242243/* Dump the context surrounding the invalid opcode */244245AcpiUtDumpBuffer (((UINT8 *) WalkState->ParserState.Aml - 16),24648, DB_BYTE_DISPLAY,247(AmlOffset + sizeof (ACPI_TABLE_HEADER) - 16));248AcpiOsPrintf (" */\n");249250/*251* Just abort the disassembly, cannot continue because the252* parser is essentially lost. The disassembler can then253* randomly fail because an ill-constructed parse tree254* can result.255*/256return_ACPI_STATUS (AE_AML_BAD_OPCODE);257#endif258}259260/* Increment past one-byte or two-byte opcode */261262WalkState->ParserState.Aml++;263if (WalkState->Opcode > 0xFF) /* Can only happen if first byte is 0x5B */264{265WalkState->ParserState.Aml++;266}267268return_ACPI_STATUS (AE_CTRL_PARSE_CONTINUE);269270default:271272/* Found opcode info, this is a normal opcode */273274WalkState->ParserState.Aml +=275AcpiPsGetOpcodeSize (WalkState->Opcode);276WalkState->ArgTypes = WalkState->OpInfo->ParseArgs;277break;278}279280return_ACPI_STATUS (AE_OK);281}282283284/*******************************************************************************285*286* FUNCTION: AcpiPsBuildNamedOp287*288* PARAMETERS: WalkState - Current state289* AmlOpStart - Begin of named Op in AML290* UnnamedOp - Early Op (not a named Op)291* Op - Returned Op292*293* RETURN: Status294*295* DESCRIPTION: Parse a named Op296*297******************************************************************************/298299ACPI_STATUS300AcpiPsBuildNamedOp (301ACPI_WALK_STATE *WalkState,302UINT8 *AmlOpStart,303ACPI_PARSE_OBJECT *UnnamedOp,304ACPI_PARSE_OBJECT **Op)305{306ACPI_STATUS Status = AE_OK;307ACPI_PARSE_OBJECT *Arg = NULL;308309310ACPI_FUNCTION_TRACE_PTR (PsBuildNamedOp, WalkState);311312313UnnamedOp->Common.Value.Arg = NULL;314UnnamedOp->Common.ArgListLength = 0;315UnnamedOp->Common.AmlOpcode = WalkState->Opcode;316317/*318* Get and append arguments until we find the node that contains319* the name (the type ARGP_NAME).320*/321while (GET_CURRENT_ARG_TYPE (WalkState->ArgTypes) &&322(GET_CURRENT_ARG_TYPE (WalkState->ArgTypes) != ARGP_NAME))323{324ASL_CV_CAPTURE_COMMENTS (WalkState);325Status = AcpiPsGetNextArg (WalkState, &(WalkState->ParserState),326GET_CURRENT_ARG_TYPE (WalkState->ArgTypes), &Arg);327if (ACPI_FAILURE (Status))328{329return_ACPI_STATUS (Status);330}331332AcpiPsAppendArg (UnnamedOp, Arg);333INCREMENT_ARG_LIST (WalkState->ArgTypes);334}335336/* are there any inline comments associated with the NameSeg?? If so, save this. */337338ASL_CV_CAPTURE_COMMENTS (WalkState);339340#ifdef ACPI_ASL_COMPILER341if (AcpiGbl_CurrentInlineComment != NULL)342{343UnnamedOp->Common.NameComment = AcpiGbl_CurrentInlineComment;344AcpiGbl_CurrentInlineComment = NULL;345}346#endif347348/*349* Make sure that we found a NAME and didn't run out of arguments350*/351if (!GET_CURRENT_ARG_TYPE (WalkState->ArgTypes))352{353return_ACPI_STATUS (AE_AML_NO_OPERAND);354}355356/* We know that this arg is a name, move to next arg */357358INCREMENT_ARG_LIST (WalkState->ArgTypes);359360/*361* Find the object. This will either insert the object into362* the namespace or simply look it up363*/364WalkState->Op = NULL;365366Status = WalkState->DescendingCallback (WalkState, Op);367if (ACPI_FAILURE (Status))368{369if (Status != AE_CTRL_TERMINATE)370{371ACPI_EXCEPTION ((AE_INFO, Status, "During name lookup/catalog"));372}373return_ACPI_STATUS (Status);374}375376if (!*Op)377{378return_ACPI_STATUS (AE_CTRL_PARSE_CONTINUE);379}380381Status = AcpiPsNextParseState (WalkState, *Op, Status);382if (ACPI_FAILURE (Status))383{384if (Status == AE_CTRL_PENDING)385{386Status = AE_CTRL_PARSE_PENDING;387}388return_ACPI_STATUS (Status);389}390391AcpiPsAppendArg (*Op, UnnamedOp->Common.Value.Arg);392393#ifdef ACPI_ASL_COMPILER394395/* save any comments that might be associated with UnnamedOp. */396397(*Op)->Common.InlineComment = UnnamedOp->Common.InlineComment;398(*Op)->Common.EndNodeComment = UnnamedOp->Common.EndNodeComment;399(*Op)->Common.CloseBraceComment = UnnamedOp->Common.CloseBraceComment;400(*Op)->Common.NameComment = UnnamedOp->Common.NameComment;401(*Op)->Common.CommentList = UnnamedOp->Common.CommentList;402(*Op)->Common.EndBlkComment = UnnamedOp->Common.EndBlkComment;403(*Op)->Common.CvFilename = UnnamedOp->Common.CvFilename;404(*Op)->Common.CvParentFilename = UnnamedOp->Common.CvParentFilename;405(*Op)->Named.Aml = UnnamedOp->Common.Aml;406407UnnamedOp->Common.InlineComment = NULL;408UnnamedOp->Common.EndNodeComment = NULL;409UnnamedOp->Common.CloseBraceComment = NULL;410UnnamedOp->Common.NameComment = NULL;411UnnamedOp->Common.CommentList = NULL;412UnnamedOp->Common.EndBlkComment = NULL;413#endif414415if ((*Op)->Common.AmlOpcode == AML_REGION_OP ||416(*Op)->Common.AmlOpcode == AML_DATA_REGION_OP)417{418/*419* Defer final parsing of an OperationRegion body, because we don't420* have enough info in the first pass to parse it correctly (i.e.,421* there may be method calls within the TermArg elements of the body.)422*423* However, we must continue parsing because the opregion is not a424* standalone package -- we don't know where the end is at this point.425*426* (Length is unknown until parse of the body complete)427*/428(*Op)->Named.Data = AmlOpStart;429(*Op)->Named.Length = 0;430}431432return_ACPI_STATUS (AE_OK);433}434435436/*******************************************************************************437*438* FUNCTION: AcpiPsCreateOp439*440* PARAMETERS: WalkState - Current state441* AmlOpStart - Op start in AML442* NewOp - Returned Op443*444* RETURN: Status445*446* DESCRIPTION: Get Op from AML447*448******************************************************************************/449450ACPI_STATUS451AcpiPsCreateOp (452ACPI_WALK_STATE *WalkState,453UINT8 *AmlOpStart,454ACPI_PARSE_OBJECT **NewOp)455{456ACPI_STATUS Status = AE_OK;457ACPI_PARSE_OBJECT *Op;458ACPI_PARSE_OBJECT *NamedOp = NULL;459ACPI_PARSE_OBJECT *ParentScope;460UINT8 ArgumentCount;461const ACPI_OPCODE_INFO *OpInfo;462463464ACPI_FUNCTION_TRACE_PTR (PsCreateOp, WalkState);465466467Status = AcpiPsGetAmlOpcode (WalkState);468if (Status == AE_CTRL_PARSE_CONTINUE)469{470return_ACPI_STATUS (AE_CTRL_PARSE_CONTINUE);471}472if (ACPI_FAILURE (Status))473{474return_ACPI_STATUS (Status);475}476477/* Create Op structure and append to parent's argument list */478479WalkState->OpInfo = AcpiPsGetOpcodeInfo (WalkState->Opcode);480Op = AcpiPsAllocOp (WalkState->Opcode, AmlOpStart);481if (!Op)482{483return_ACPI_STATUS (AE_NO_MEMORY);484}485486if (WalkState->OpInfo->Flags & AML_NAMED)487{488Status = AcpiPsBuildNamedOp (WalkState, AmlOpStart, Op, &NamedOp);489AcpiPsFreeOp (Op);490491#ifdef ACPI_ASL_COMPILER492if (AcpiGbl_DisasmFlag && WalkState->Opcode == AML_EXTERNAL_OP &&493Status == AE_NOT_FOUND)494{495/*496* If parsing of AML_EXTERNAL_OP's name path fails, then skip497* past this opcode and keep parsing. This is a much better498* alternative than to abort the entire disassembler. At this499* point, the ParserState is at the end of the namepath of the500* external declaration opcode. Setting WalkState->Aml to501* WalkState->ParserState.Aml + 2 moves increments the502* WalkState->Aml past the object type and the paramcount of the503* external opcode.504*/505WalkState->Aml = WalkState->ParserState.Aml + 2;506WalkState->ParserState.Aml = WalkState->Aml;507return_ACPI_STATUS (AE_CTRL_PARSE_CONTINUE);508}509#endif510if (ACPI_FAILURE (Status))511{512return_ACPI_STATUS (Status);513}514515*NewOp = NamedOp;516return_ACPI_STATUS (AE_OK);517}518519/* Not a named opcode, just allocate Op and append to parent */520521if (WalkState->OpInfo->Flags & AML_CREATE)522{523/*524* Backup to beginning of CreateXXXfield declaration525* BodyLength is unknown until we parse the body526*/527Op->Named.Data = AmlOpStart;528Op->Named.Length = 0;529}530531if (WalkState->Opcode == AML_BANK_FIELD_OP)532{533/*534* Backup to beginning of BankField declaration535* BodyLength is unknown until we parse the body536*/537Op->Named.Data = AmlOpStart;538Op->Named.Length = 0;539}540541ParentScope = AcpiPsGetParentScope (&(WalkState->ParserState));542AcpiPsAppendArg (ParentScope, Op);543544if (ParentScope)545{546OpInfo = AcpiPsGetOpcodeInfo (ParentScope->Common.AmlOpcode);547if (OpInfo->Flags & AML_HAS_TARGET)548{549ArgumentCount = AcpiPsGetArgumentCount (OpInfo->Type);550if (ParentScope->Common.ArgListLength > ArgumentCount)551{552Op->Common.Flags |= ACPI_PARSEOP_TARGET;553}554}555556/*557* Special case for both Increment() and Decrement(), where558* the lone argument is both a source and a target.559*/560else if ((ParentScope->Common.AmlOpcode == AML_INCREMENT_OP) ||561(ParentScope->Common.AmlOpcode == AML_DECREMENT_OP))562{563Op->Common.Flags |= ACPI_PARSEOP_TARGET;564}565}566567if (WalkState->DescendingCallback != NULL)568{569/*570* Find the object. This will either insert the object into571* the namespace or simply look it up572*/573WalkState->Op = *NewOp = Op;574575Status = WalkState->DescendingCallback (WalkState, &Op);576Status = AcpiPsNextParseState (WalkState, Op, Status);577if (Status == AE_CTRL_PENDING)578{579Status = AE_CTRL_PARSE_PENDING;580}581}582583return_ACPI_STATUS (Status);584}585586587/*******************************************************************************588*589* FUNCTION: AcpiPsCompleteOp590*591* PARAMETERS: WalkState - Current state592* Op - Returned Op593* Status - Parse status before complete Op594*595* RETURN: Status596*597* DESCRIPTION: Complete Op598*599******************************************************************************/600601ACPI_STATUS602AcpiPsCompleteOp (603ACPI_WALK_STATE *WalkState,604ACPI_PARSE_OBJECT **Op,605ACPI_STATUS Status)606{607ACPI_STATUS Status2;608609610ACPI_FUNCTION_TRACE_PTR (PsCompleteOp, WalkState);611612613/*614* Finished one argument of the containing scope615*/616WalkState->ParserState.Scope->ParseScope.ArgCount--;617618/* Close this Op (will result in parse subtree deletion) */619620Status2 = AcpiPsCompleteThisOp (WalkState, *Op);621if (ACPI_FAILURE (Status2))622{623return_ACPI_STATUS (Status2);624}625626*Op = NULL;627628switch (Status)629{630case AE_OK:631632break;633634case AE_CTRL_TRANSFER:635636/* We are about to transfer to a called method */637638WalkState->PrevOp = NULL;639WalkState->PrevArgTypes = WalkState->ArgTypes;640return_ACPI_STATUS (Status);641642case AE_CTRL_END:643644AcpiPsPopScope (&(WalkState->ParserState), Op,645&WalkState->ArgTypes, &WalkState->ArgCount);646647if (*Op)648{649WalkState->Op = *Op;650WalkState->OpInfo = AcpiPsGetOpcodeInfo ((*Op)->Common.AmlOpcode);651WalkState->Opcode = (*Op)->Common.AmlOpcode;652653Status = WalkState->AscendingCallback (WalkState);654(void) AcpiPsNextParseState (WalkState, *Op, Status);655656Status2 = AcpiPsCompleteThisOp (WalkState, *Op);657if (ACPI_FAILURE (Status2))658{659return_ACPI_STATUS (Status2);660}661}662663break;664665case AE_CTRL_BREAK:666case AE_CTRL_CONTINUE:667668/* Pop off scopes until we find the While */669670while (!(*Op) || ((*Op)->Common.AmlOpcode != AML_WHILE_OP))671{672AcpiPsPopScope (&(WalkState->ParserState), Op,673&WalkState->ArgTypes, &WalkState->ArgCount);674}675676/* Close this iteration of the While loop */677678WalkState->Op = *Op;679WalkState->OpInfo = AcpiPsGetOpcodeInfo ((*Op)->Common.AmlOpcode);680WalkState->Opcode = (*Op)->Common.AmlOpcode;681682Status = WalkState->AscendingCallback (WalkState);683(void) AcpiPsNextParseState (WalkState, *Op, Status);684685Status2 = AcpiPsCompleteThisOp (WalkState, *Op);686if (ACPI_FAILURE (Status2))687{688return_ACPI_STATUS (Status2);689}690691break;692693case AE_CTRL_TERMINATE:694695/* Clean up */696do697{698if (*Op)699{700Status2 = AcpiPsCompleteThisOp (WalkState, *Op);701if (ACPI_FAILURE (Status2))702{703return_ACPI_STATUS (Status2);704}705706AcpiUtDeleteGenericState (707AcpiUtPopGenericState (&WalkState->ControlState));708}709710AcpiPsPopScope (&(WalkState->ParserState), Op,711&WalkState->ArgTypes, &WalkState->ArgCount);712713} while (*Op);714715return_ACPI_STATUS (AE_OK);716717default: /* All other non-AE_OK status */718719do720{721if (*Op)722{723/*724* These Opcodes need to be removed from the namespace because they725* get created even if these opcodes cannot be created due to726* errors.727*/728if (((*Op)->Common.AmlOpcode == AML_REGION_OP) ||729((*Op)->Common.AmlOpcode == AML_DATA_REGION_OP))730{731AcpiNsDeleteChildren ((*Op)->Common.Node);732AcpiNsRemoveNode ((*Op)->Common.Node);733(*Op)->Common.Node = NULL;734AcpiPsDeleteParseTree (*Op);735}736737Status2 = AcpiPsCompleteThisOp (WalkState, *Op);738if (ACPI_FAILURE (Status2))739{740return_ACPI_STATUS (Status2);741}742}743744AcpiPsPopScope (&(WalkState->ParserState), Op,745&WalkState->ArgTypes, &WalkState->ArgCount);746747} while (*Op);748749750#if 0751/*752* TBD: Cleanup parse ops on error753*/754if (*Op == NULL)755{756AcpiPsPopScope (ParserState, Op,757&WalkState->ArgTypes, &WalkState->ArgCount);758}759#endif760WalkState->PrevOp = NULL;761WalkState->PrevArgTypes = WalkState->ArgTypes;762763if (WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL)764{765/*766* There was something that went wrong while executing code at the767* module-level. We need to skip parsing whatever caused the768* error and keep going. One runtime error during the table load769* should not cause the entire table to not be loaded. This is770* because there could be correct AML beyond the parts that caused771* the runtime error.772*/773ACPI_INFO (("Ignoring error and continuing table load"));774return_ACPI_STATUS (AE_OK);775}776return_ACPI_STATUS (Status);777}778779/* This scope complete? */780781if (AcpiPsHasCompletedScope (&(WalkState->ParserState)))782{783AcpiPsPopScope (&(WalkState->ParserState), Op,784&WalkState->ArgTypes, &WalkState->ArgCount);785ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Popped scope, Op=%p\n", *Op));786}787else788{789*Op = NULL;790}791792return_ACPI_STATUS (AE_OK);793}794795796/*******************************************************************************797*798* FUNCTION: AcpiPsCompleteFinalOp799*800* PARAMETERS: WalkState - Current state801* Op - Current Op802* Status - Current parse status before complete last803* Op804*805* RETURN: Status806*807* DESCRIPTION: Complete last Op.808*809******************************************************************************/810811ACPI_STATUS812AcpiPsCompleteFinalOp (813ACPI_WALK_STATE *WalkState,814ACPI_PARSE_OBJECT *Op,815ACPI_STATUS Status)816{817ACPI_STATUS ReturnStatus = Status;818BOOLEAN Ascending = TRUE;819820821ACPI_FUNCTION_TRACE_PTR (PsCompleteFinalOp, WalkState);822823824/*825* Complete the last Op (if not completed), and clear the scope stack.826* It is easily possible to end an AML "package" with an unbounded number827* of open scopes (such as when several ASL blocks are closed with828* sequential closing braces). We want to terminate each one cleanly.829*/830ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "AML package complete at Op %p\n", Op));831do832{833if (Op)834{835if (Ascending && WalkState->AscendingCallback != NULL)836{837WalkState->Op = Op;838WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);839WalkState->Opcode = Op->Common.AmlOpcode;840841Status = WalkState->AscendingCallback (WalkState);842Status = AcpiPsNextParseState (WalkState, Op, Status);843if (Status == AE_CTRL_PENDING)844{845Status = AcpiPsCompleteOp (WalkState, &Op, AE_OK);846if (ACPI_FAILURE (Status))847{848return_ACPI_STATUS (Status);849}850}851852if (Status == AE_CTRL_TERMINATE)853{854Ascending = FALSE;855ReturnStatus = AE_CTRL_TERMINATE;856}857858else if (ACPI_FAILURE (Status))859{860/* First error is most important */861862Ascending = FALSE;863ReturnStatus = Status;864}865}866867Status = AcpiPsCompleteThisOp (WalkState, Op);868if (ACPI_FAILURE (Status))869{870Ascending = FALSE;871if (ACPI_SUCCESS (ReturnStatus) ||872ReturnStatus == AE_CTRL_TERMINATE)873{874ReturnStatus = Status;875}876}877}878879AcpiPsPopScope (&(WalkState->ParserState), &Op, &WalkState->ArgTypes,880&WalkState->ArgCount);881882} while (Op);883884return_ACPI_STATUS (ReturnStatus);885}886887888