ACPI_PARSE_OBJECT * AcpiPsGetNextArg ( ACPI_PARSE_STATE *ParserState, UINT32 ArgType, UINT32 *ArgCount) { ACPI_PARSE_OBJECT *Arg = NULL; ACPI_PARSE_OBJECT *Prev = NULL; ACPI_PARSE_OBJECT *Field; UINT32 Subop; FUNCTION_TRACE_PTR ("PsGetNextArg", ParserState); switch (ArgType) { case ARGP_BYTEDATA: case ARGP_WORDDATA: case ARGP_DWORDDATA: case ARGP_CHARLIST: case ARGP_NAME: case ARGP_NAMESTRING: /* constants, strings, and namestrings are all the same size */ Arg = AcpiPsAllocOp (AML_BYTE_OP); if (Arg) { AcpiPsGetNextSimpleArg (ParserState, ArgType, Arg); } break; case ARGP_PKGLENGTH: /* package length, nothing returned */ ParserState->PkgEnd = AcpiPsGetNextPackageEnd (ParserState); break; case ARGP_FIELDLIST: if (ParserState->Aml < ParserState->PkgEnd) { /* non-empty list */ while (ParserState->Aml < ParserState->PkgEnd) { Field = AcpiPsGetNextField (ParserState); if (!Field) { break; } if (Prev) { Prev->Next = Field; } else { Arg = Field; } Prev = Field; } /* skip to End of byte data */ ParserState->Aml = ParserState->PkgEnd; } break; case ARGP_BYTELIST: if (ParserState->Aml < ParserState->PkgEnd) { /* non-empty list */ Arg = AcpiPsAllocOp (AML_INT_BYTELIST_OP); if (Arg) { /* fill in bytelist data */ Arg->Value.Size = (ParserState->PkgEnd - ParserState->Aml); ((ACPI_PARSE2_OBJECT *) Arg)->Data = ParserState->Aml; } /* skip to End of byte data */ ParserState->Aml = ParserState->PkgEnd; } break; case ARGP_TARGET: case ARGP_SUPERNAME: { Subop = AcpiPsPeekOpcode (ParserState); if (Subop == 0 || AcpiPsIsLeadingChar (Subop) || AcpiPsIsPrefixChar (Subop)) { /* NullName or NameString */ Arg = AcpiPsAllocOp (AML_INT_NAMEPATH_OP); if (Arg) { AcpiPsGetNextNamepath (ParserState, Arg, ArgCount, 0); } } else { /* single complex argument, nothing returned */ *ArgCount = 1; } } break; case ARGP_DATAOBJ: case ARGP_TERMARG: /* single complex argument, nothing returned */ *ArgCount = 1; break; case ARGP_DATAOBJLIST: case ARGP_TERMLIST: case ARGP_OBJLIST: if (ParserState->Aml < ParserState->PkgEnd) { /* non-empty list of variable arguments, nothing returned */ *ArgCount = ACPI_VAR_ARGS; } break; } return_PTR (Arg); }
ACPI_STATUS AcpiPsNextParseState ( ACPI_WALK_STATE *WalkState, ACPI_PARSE_OBJECT *Op, ACPI_STATUS CallbackStatus) { ACPI_PARSE_STATE *ParserState = &WalkState->ParserState; ACPI_STATUS Status = AE_CTRL_PENDING; ACPI_FUNCTION_TRACE_PTR (PsNextParseState, Op); switch (CallbackStatus) { case AE_CTRL_TERMINATE: /* * A control method was terminated via a RETURN statement. * The walk of this method is complete. */ ParserState->Aml = ParserState->AmlEnd; Status = AE_CTRL_TERMINATE; break; case AE_CTRL_BREAK: ParserState->Aml = WalkState->AmlLastWhile; WalkState->ControlState->Common.Value = FALSE; Status = AE_CTRL_BREAK; break; case AE_CTRL_CONTINUE: ParserState->Aml = WalkState->AmlLastWhile; Status = AE_CTRL_CONTINUE; break; case AE_CTRL_PENDING: ParserState->Aml = WalkState->AmlLastWhile; break; #if 0 case AE_CTRL_SKIP: ParserState->Aml = ParserState->Scope->ParseScope.PkgEnd; Status = AE_OK; break; #endif case AE_CTRL_TRUE: /* * Predicate of an IF was true, and we are at the matching ELSE. * Just close out this package */ ParserState->Aml = AcpiPsGetNextPackageEnd (ParserState); Status = AE_CTRL_PENDING; break; case AE_CTRL_FALSE: /* * Either an IF/WHILE Predicate was false or we encountered a BREAK * opcode. In both cases, we do not execute the rest of the * package; We simply close out the parent (finishing the walk of * this branch of the tree) and continue execution at the parent * level. */ ParserState->Aml = ParserState->Scope->ParseScope.PkgEnd; /* In the case of a BREAK, just force a predicate (if any) to FALSE */ WalkState->ControlState->Common.Value = FALSE; Status = AE_CTRL_END; break; case AE_CTRL_TRANSFER: /* A method call (invocation) -- transfer control */ Status = AE_CTRL_TRANSFER; WalkState->PrevOp = Op; WalkState->MethodCallOp = Op; WalkState->MethodCallNode = (Op->Common.Value.Arg)->Common.Node; /* Will return value (if any) be used by the caller? */ WalkState->ReturnUsed = AcpiDsIsResultUsed (Op, WalkState); break; default: Status = CallbackStatus; if ((CallbackStatus & AE_CODE_MASK) == AE_CODE_CONTROL) { Status = AE_OK; } break; } return_ACPI_STATUS (Status); }
ACPI_STATUS AcpiPsParseLoop ( ACPI_WALK_STATE *WalkState) { ACPI_STATUS Status = AE_OK; ACPI_PARSE_OBJECT *Op = NULL; /* current op */ ACPI_PARSE_STATE *ParserState; UINT8 *AmlOpStart = NULL; ACPI_FUNCTION_TRACE_PTR (PsParseLoop, WalkState); if (WalkState->DescendingCallback == NULL) { return_ACPI_STATUS (AE_BAD_PARAMETER); } ParserState = &WalkState->ParserState; WalkState->ArgTypes = 0; #if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY)) if (WalkState->WalkType & ACPI_WALK_METHOD_RESTART) { /* We are restarting a preempted control method */ if (AcpiPsHasCompletedScope (ParserState)) { /* * We must check if a predicate to an IF or WHILE statement * was just completed */ if ((ParserState->Scope->ParseScope.Op) && ((ParserState->Scope->ParseScope.Op->Common.AmlOpcode == AML_IF_OP) || (ParserState->Scope->ParseScope.Op->Common.AmlOpcode == AML_WHILE_OP)) && (WalkState->ControlState) && (WalkState->ControlState->Common.State == ACPI_CONTROL_PREDICATE_EXECUTING)) { /* * A predicate was just completed, get the value of the * predicate and branch based on that value */ WalkState->Op = NULL; Status = AcpiDsGetPredicateValue (WalkState, ACPI_TO_POINTER (TRUE)); if (ACPI_FAILURE (Status) && ((Status & AE_CODE_MASK) != AE_CODE_CONTROL)) { if (Status == AE_AML_NO_RETURN_VALUE) { ACPI_EXCEPTION ((AE_INFO, Status, "Invoked method did not return a value")); } ACPI_EXCEPTION ((AE_INFO, Status, "GetPredicate Failed")); return_ACPI_STATUS (Status); } Status = AcpiPsNextParseState (WalkState, Op, Status); } AcpiPsPopScope (ParserState, &Op, &WalkState->ArgTypes, &WalkState->ArgCount); ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Popped scope, Op=%p\n", Op)); } else if (WalkState->PrevOp) { /* We were in the middle of an op */ Op = WalkState->PrevOp; WalkState->ArgTypes = WalkState->PrevArgTypes; } } #endif /* Iterative parsing loop, while there is more AML to process: */ while ((ParserState->Aml < ParserState->AmlEnd) || (Op)) { ASL_CV_CAPTURE_COMMENTS (WalkState); AmlOpStart = ParserState->Aml; if (!Op) { Status = AcpiPsCreateOp (WalkState, AmlOpStart, &Op); if (ACPI_FAILURE (Status)) { /* * ACPI_PARSE_MODULE_LEVEL means that we are loading a table by * executing it as a control method. However, if we encounter * an error while loading the table, we need to keep trying to * load the table rather than aborting the table load. Set the * status to AE_OK to proceed with the table load. */ if ((WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL) && Status == AE_ALREADY_EXISTS) { Status = AE_OK; } if (Status == AE_CTRL_PARSE_CONTINUE) { continue; } if (Status == AE_CTRL_PARSE_PENDING) { Status = AE_OK; } if (Status == AE_CTRL_TERMINATE) { return_ACPI_STATUS (Status); } Status = AcpiPsCompleteOp (WalkState, &Op, Status); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } if (AcpiNsOpensScope ( AcpiPsGetOpcodeInfo (WalkState->Opcode)->ObjectType)) { /* * If the scope/device op fails to parse, skip the body of * the scope op because the parse failure indicates that * the device may not exist. */ ACPI_ERROR ((AE_INFO, "Skip parsing opcode %s", AcpiPsGetOpcodeName (WalkState->Opcode))); WalkState->ParserState.Aml = WalkState->Aml + 1; WalkState->ParserState.Aml = AcpiPsGetNextPackageEnd(&WalkState->ParserState); WalkState->Aml = WalkState->ParserState.Aml; } continue; } AcpiExStartTraceOpcode (Op, WalkState); } /* * Start ArgCount at zero because we don't know if there are * any args yet */ WalkState->ArgCount = 0; switch (Op->Common.AmlOpcode) { case AML_BYTE_OP: case AML_WORD_OP: case AML_DWORD_OP: case AML_QWORD_OP: break; default: ASL_CV_CAPTURE_COMMENTS (WalkState); break; } /* Are there any arguments that must be processed? */ if (WalkState->ArgTypes) { /* Get arguments */ Status = AcpiPsGetArguments (WalkState, AmlOpStart, Op); if (ACPI_FAILURE (Status)) { Status = AcpiPsCompleteOp (WalkState, &Op, Status); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } if ((WalkState->ControlState) && ((WalkState->ControlState->Control.Opcode == AML_IF_OP) || (WalkState->ControlState->Control.Opcode == AML_WHILE_OP))) { /* * If the if/while op fails to parse, we will skip parsing * the body of the op. */ ParserState->Aml = WalkState->ControlState->Control.AmlPredicateStart + 1; ParserState->Aml = AcpiPsGetNextPackageEnd (ParserState); WalkState->Aml = ParserState->Aml; ACPI_ERROR ((AE_INFO, "Skipping While/If block")); if (*WalkState->Aml == AML_ELSE_OP) { ACPI_ERROR ((AE_INFO, "Skipping Else block")); WalkState->ParserState.Aml = WalkState->Aml + 1; WalkState->ParserState.Aml = AcpiPsGetNextPackageEnd (ParserState); WalkState->Aml = ParserState->Aml; } ACPI_FREE(AcpiUtPopGenericState (&WalkState->ControlState)); } Op = NULL; continue; } } /* Check for arguments that need to be processed */ ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Parseloop: argument count: %8.8X\n", WalkState->ArgCount)); if (WalkState->ArgCount) { /* * There are arguments (complex ones), push Op and * prepare for argument */ Status = AcpiPsPushScope (ParserState, Op, WalkState->ArgTypes, WalkState->ArgCount); if (ACPI_FAILURE (Status)) { Status = AcpiPsCompleteOp (WalkState, &Op, Status); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } continue; } Op = NULL; continue; } /* * All arguments have been processed -- Op is complete, * prepare for next */ WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode); if (WalkState->OpInfo->Flags & AML_NAMED) { if (Op->Common.AmlOpcode == AML_REGION_OP || Op->Common.AmlOpcode == AML_DATA_REGION_OP) { /* * Skip parsing of control method or opregion body, * because we don't have enough info in the first pass * to parse them correctly. * * Completed parsing an OpRegion declaration, we now * know the length. */ Op->Named.Length = (UINT32) (ParserState->Aml - Op->Named.Data); } } if (WalkState->OpInfo->Flags & AML_CREATE) { /* * Backup to beginning of CreateXXXfield declaration (1 for * Opcode) * * BodyLength is unknown until we parse the body */ Op->Named.Length = (UINT32) (ParserState->Aml - Op->Named.Data); } if (Op->Common.AmlOpcode == AML_BANK_FIELD_OP) { /* * Backup to beginning of BankField declaration * * BodyLength is unknown until we parse the body */ Op->Named.Length = (UINT32) (ParserState->Aml - Op->Named.Data); } /* This op complete, notify the dispatcher */ if (WalkState->AscendingCallback != NULL) { WalkState->Op = Op; WalkState->Opcode = Op->Common.AmlOpcode; Status = WalkState->AscendingCallback (WalkState); Status = AcpiPsNextParseState (WalkState, Op, Status); if (Status == AE_CTRL_PENDING) { Status = AE_OK; } else if ((WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL) && (ACPI_AML_EXCEPTION(Status) || Status == AE_ALREADY_EXISTS || Status == AE_NOT_FOUND)) { /* * ACPI_PARSE_MODULE_LEVEL flag means that we are currently * loading a table by executing it as a control method. * However, if we encounter an error while loading the table, * we need to keep trying to load the table rather than * aborting the table load (setting the status to AE_OK * continues the table load). If we get a failure at this * point, it means that the dispatcher got an error while * trying to execute the Op. */ Status = AE_OK; } } Status = AcpiPsCompleteOp (WalkState, &Op, Status); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } } /* while ParserState->Aml */ Status = AcpiPsCompleteFinalOp (WalkState, Op, Status); return_ACPI_STATUS (Status); }