Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenpsparse.c
Go to the documentation of this file.
00001 /****************************************************************************** 00002 * 00003 * Module Name: psparse - Parser top level AML parse routines 00004 * 00005 *****************************************************************************/ 00006 00007 /****************************************************************************** 00008 * 00009 * 1. Copyright Notice 00010 * 00011 * Some or all of this work - Copyright (c) 1999 - 2011, Intel Corp. 00012 * All rights reserved. 00013 * 00014 * 2. License 00015 * 00016 * 2.1. This is your license from Intel Corp. under its intellectual property 00017 * rights. You may have additional license terms from the party that provided 00018 * you this software, covering your right to use that party's intellectual 00019 * property rights. 00020 * 00021 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 00022 * copy of the source code appearing in this file ("Covered Code") an 00023 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 00024 * base code distributed originally by Intel ("Original Intel Code") to copy, 00025 * make derivatives, distribute, use and display any portion of the Covered 00026 * Code in any form, with the right to sublicense such rights; and 00027 * 00028 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 00029 * license (with the right to sublicense), under only those claims of Intel 00030 * patents that are infringed by the Original Intel Code, to make, use, sell, 00031 * offer to sell, and import the Covered Code and derivative works thereof 00032 * solely to the minimum extent necessary to exercise the above copyright 00033 * license, and in no event shall the patent license extend to any additions 00034 * to or modifications of the Original Intel Code. No other license or right 00035 * is granted directly or by implication, estoppel or otherwise; 00036 * 00037 * The above copyright and patent license is granted only if the following 00038 * conditions are met: 00039 * 00040 * 3. Conditions 00041 * 00042 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 00043 * Redistribution of source code of any substantial portion of the Covered 00044 * Code or modification with rights to further distribute source must include 00045 * the above Copyright Notice, the above License, this list of Conditions, 00046 * and the following Disclaimer and Export Compliance provision. In addition, 00047 * Licensee must cause all Covered Code to which Licensee contributes to 00048 * contain a file documenting the changes Licensee made to create that Covered 00049 * Code and the date of any change. Licensee must include in that file the 00050 * documentation of any changes made by any predecessor Licensee. Licensee 00051 * must include a prominent statement that the modification is derived, 00052 * directly or indirectly, from Original Intel Code. 00053 * 00054 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 00055 * Redistribution of source code of any substantial portion of the Covered 00056 * Code or modification without rights to further distribute source must 00057 * include the following Disclaimer and Export Compliance provision in the 00058 * documentation and/or other materials provided with distribution. In 00059 * addition, Licensee may not authorize further sublicense of source of any 00060 * portion of the Covered Code, and must include terms to the effect that the 00061 * license from Licensee to its licensee is limited to the intellectual 00062 * property embodied in the software Licensee provides to its licensee, and 00063 * not to intellectual property embodied in modifications its licensee may 00064 * make. 00065 * 00066 * 3.3. Redistribution of Executable. Redistribution in executable form of any 00067 * substantial portion of the Covered Code or modification must reproduce the 00068 * above Copyright Notice, and the following Disclaimer and Export Compliance 00069 * provision in the documentation and/or other materials provided with the 00070 * distribution. 00071 * 00072 * 3.4. Intel retains all right, title, and interest in and to the Original 00073 * Intel Code. 00074 * 00075 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 00076 * Intel shall be used in advertising or otherwise to promote the sale, use or 00077 * other dealings in products derived from or relating to the Covered Code 00078 * without prior written authorization from Intel. 00079 * 00080 * 4. Disclaimer and Export Compliance 00081 * 00082 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 00083 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 00084 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 00085 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 00086 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 00087 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 00088 * PARTICULAR PURPOSE. 00089 * 00090 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 00091 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 00092 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 00093 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 00094 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 00095 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 00096 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 00097 * LIMITED REMEDY. 00098 * 00099 * 4.3. Licensee shall not export, either directly or indirectly, any of this 00100 * software or system incorporating such software without first obtaining any 00101 * required license or other approval from the U. S. Department of Commerce or 00102 * any other agency or department of the United States Government. In the 00103 * event Licensee exports any such software from the United States or 00104 * re-exports any such software from a foreign destination, Licensee shall 00105 * ensure that the distribution and export/re-export of the software is in 00106 * compliance with all laws, regulations, orders, or other restrictions of the 00107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 00108 * any of its subsidiaries will export/re-export any technical data, process, 00109 * software, or service, directly or indirectly, to any country for which the 00110 * United States government or any agency thereof requires an export license, 00111 * other governmental approval, or letter of assurance, without first obtaining 00112 * such license, approval or letter. 00113 * 00114 *****************************************************************************/ 00115 00116 00117 /* 00118 * Parse the AML and build an operation tree as most interpreters, 00119 * like Perl, do. Parsing is done by hand rather than with a YACC 00120 * generated parser to tightly constrain stack and dynamic memory 00121 * usage. At the same time, parsing is kept flexible and the code 00122 * fairly compact by parsing based on a list of AML opcode 00123 * templates in AmlOpInfo[] 00124 */ 00125 00126 #include "acpi.h" 00127 #include "accommon.h" 00128 #include "acparser.h" 00129 #include "acdispat.h" 00130 #include "amlcode.h" 00131 #include "acinterp.h" 00132 00133 #define _COMPONENT ACPI_PARSER 00134 ACPI_MODULE_NAME ("psparse") 00135 00136 00137 /******************************************************************************* 00138 * 00139 * FUNCTION: AcpiPsGetOpcodeSize 00140 * 00141 * PARAMETERS: Opcode - An AML opcode 00142 * 00143 * RETURN: Size of the opcode, in bytes (1 or 2) 00144 * 00145 * DESCRIPTION: Get the size of the current opcode. 00146 * 00147 ******************************************************************************/ 00148 00149 UINT32 00150 AcpiPsGetOpcodeSize ( 00151 UINT32 Opcode) 00152 { 00153 00154 /* Extended (2-byte) opcode if > 255 */ 00155 00156 if (Opcode > 0x00FF) 00157 { 00158 return (2); 00159 } 00160 00161 /* Otherwise, just a single byte opcode */ 00162 00163 return (1); 00164 } 00165 00166 00167 /******************************************************************************* 00168 * 00169 * FUNCTION: AcpiPsPeekOpcode 00170 * 00171 * PARAMETERS: ParserState - A parser state object 00172 * 00173 * RETURN: Next AML opcode 00174 * 00175 * DESCRIPTION: Get next AML opcode (without incrementing AML pointer) 00176 * 00177 ******************************************************************************/ 00178 00179 UINT16 00180 AcpiPsPeekOpcode ( 00181 ACPI_PARSE_STATE *ParserState) 00182 { 00183 UINT8 *Aml; 00184 UINT16 Opcode; 00185 00186 00187 Aml = ParserState->Aml; 00188 Opcode = (UINT16) ACPI_GET8 (Aml); 00189 00190 if (Opcode == AML_EXTENDED_OP_PREFIX) 00191 { 00192 /* Extended opcode, get the second opcode byte */ 00193 00194 Aml++; 00195 Opcode = (UINT16) ((Opcode << 8) | ACPI_GET8 (Aml)); 00196 } 00197 00198 return (Opcode); 00199 } 00200 00201 00202 /******************************************************************************* 00203 * 00204 * FUNCTION: AcpiPsCompleteThisOp 00205 * 00206 * PARAMETERS: WalkState - Current State 00207 * Op - Op to complete 00208 * 00209 * RETURN: Status 00210 * 00211 * DESCRIPTION: Perform any cleanup at the completion of an Op. 00212 * 00213 ******************************************************************************/ 00214 00215 ACPI_STATUS 00216 AcpiPsCompleteThisOp ( 00217 ACPI_WALK_STATE *WalkState, 00218 ACPI_PARSE_OBJECT *Op) 00219 { 00220 ACPI_PARSE_OBJECT *Prev; 00221 ACPI_PARSE_OBJECT *Next; 00222 const ACPI_OPCODE_INFO *ParentInfo; 00223 ACPI_PARSE_OBJECT *ReplacementOp = NULL; 00224 ACPI_STATUS Status = AE_OK; 00225 00226 00227 ACPI_FUNCTION_TRACE_PTR (PsCompleteThisOp, Op); 00228 00229 00230 /* Check for null Op, can happen if AML code is corrupt */ 00231 00232 if (!Op) 00233 { 00234 return_ACPI_STATUS (AE_OK); /* OK for now */ 00235 } 00236 00237 /* Delete this op and the subtree below it if asked to */ 00238 00239 if (((WalkState->ParseFlags & ACPI_PARSE_TREE_MASK) != ACPI_PARSE_DELETE_TREE) || 00240 (WalkState->OpInfo->Class == AML_CLASS_ARGUMENT)) 00241 { 00242 return_ACPI_STATUS (AE_OK); 00243 } 00244 00245 /* Make sure that we only delete this subtree */ 00246 00247 if (Op->Common.Parent) 00248 { 00249 Prev = Op->Common.Parent->Common.Value.Arg; 00250 if (!Prev) 00251 { 00252 /* Nothing more to do */ 00253 00254 goto Cleanup; 00255 } 00256 00257 /* 00258 * Check if we need to replace the operator and its subtree 00259 * with a return value op (placeholder op) 00260 */ 00261 ParentInfo = AcpiPsGetOpcodeInfo (Op->Common.Parent->Common.AmlOpcode); 00262 00263 switch (ParentInfo->Class) 00264 { 00265 case AML_CLASS_CONTROL: 00266 break; 00267 00268 case AML_CLASS_CREATE: 00269 00270 /* 00271 * These opcodes contain TermArg operands. The current 00272 * op must be replaced by a placeholder return op 00273 */ 00274 ReplacementOp = AcpiPsAllocOp (AML_INT_RETURN_VALUE_OP); 00275 if (!ReplacementOp) 00276 { 00277 Status = AE_NO_MEMORY; 00278 } 00279 break; 00280 00281 case AML_CLASS_NAMED_OBJECT: 00282 00283 /* 00284 * These opcodes contain TermArg operands. The current 00285 * op must be replaced by a placeholder return op 00286 */ 00287 if ((Op->Common.Parent->Common.AmlOpcode == AML_REGION_OP) || 00288 (Op->Common.Parent->Common.AmlOpcode == AML_DATA_REGION_OP) || 00289 (Op->Common.Parent->Common.AmlOpcode == AML_BUFFER_OP) || 00290 (Op->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP) || 00291 (Op->Common.Parent->Common.AmlOpcode == AML_BANK_FIELD_OP) || 00292 (Op->Common.Parent->Common.AmlOpcode == AML_VAR_PACKAGE_OP)) 00293 { 00294 ReplacementOp = AcpiPsAllocOp (AML_INT_RETURN_VALUE_OP); 00295 if (!ReplacementOp) 00296 { 00297 Status = AE_NO_MEMORY; 00298 } 00299 } 00300 else if ((Op->Common.Parent->Common.AmlOpcode == AML_NAME_OP) && 00301 (WalkState->PassNumber <= ACPI_IMODE_LOAD_PASS2)) 00302 { 00303 if ((Op->Common.AmlOpcode == AML_BUFFER_OP) || 00304 (Op->Common.AmlOpcode == AML_PACKAGE_OP) || 00305 (Op->Common.AmlOpcode == AML_VAR_PACKAGE_OP)) 00306 { 00307 ReplacementOp = AcpiPsAllocOp (Op->Common.AmlOpcode); 00308 if (!ReplacementOp) 00309 { 00310 Status = AE_NO_MEMORY; 00311 } 00312 else 00313 { 00314 ReplacementOp->Named.Data = Op->Named.Data; 00315 ReplacementOp->Named.Length = Op->Named.Length; 00316 } 00317 } 00318 } 00319 break; 00320 00321 default: 00322 00323 ReplacementOp = AcpiPsAllocOp (AML_INT_RETURN_VALUE_OP); 00324 if (!ReplacementOp) 00325 { 00326 Status = AE_NO_MEMORY; 00327 } 00328 } 00329 00330 /* We must unlink this op from the parent tree */ 00331 00332 if (Prev == Op) 00333 { 00334 /* This op is the first in the list */ 00335 00336 if (ReplacementOp) 00337 { 00338 ReplacementOp->Common.Parent = Op->Common.Parent; 00339 ReplacementOp->Common.Value.Arg = NULL; 00340 ReplacementOp->Common.Node = Op->Common.Node; 00341 Op->Common.Parent->Common.Value.Arg = ReplacementOp; 00342 ReplacementOp->Common.Next = Op->Common.Next; 00343 } 00344 else 00345 { 00346 Op->Common.Parent->Common.Value.Arg = Op->Common.Next; 00347 } 00348 } 00349 00350 /* Search the parent list */ 00351 00352 else while (Prev) 00353 { 00354 /* Traverse all siblings in the parent's argument list */ 00355 00356 Next = Prev->Common.Next; 00357 if (Next == Op) 00358 { 00359 if (ReplacementOp) 00360 { 00361 ReplacementOp->Common.Parent = Op->Common.Parent; 00362 ReplacementOp->Common.Value.Arg = NULL; 00363 ReplacementOp->Common.Node = Op->Common.Node; 00364 Prev->Common.Next = ReplacementOp; 00365 ReplacementOp->Common.Next = Op->Common.Next; 00366 Next = NULL; 00367 } 00368 else 00369 { 00370 Prev->Common.Next = Op->Common.Next; 00371 Next = NULL; 00372 } 00373 } 00374 Prev = Next; 00375 } 00376 } 00377 00378 00379 Cleanup: 00380 00381 /* Now we can actually delete the subtree rooted at Op */ 00382 00383 AcpiPsDeleteParseTree (Op); 00384 return_ACPI_STATUS (Status); 00385 } 00386 00387 00388 /******************************************************************************* 00389 * 00390 * FUNCTION: AcpiPsNextParseState 00391 * 00392 * PARAMETERS: WalkState - Current state 00393 * Op - Current parse op 00394 * CallbackStatus - Status from previous operation 00395 * 00396 * RETURN: Status 00397 * 00398 * DESCRIPTION: Update the parser state based upon the return exception from 00399 * the parser callback. 00400 * 00401 ******************************************************************************/ 00402 00403 ACPI_STATUS 00404 AcpiPsNextParseState ( 00405 ACPI_WALK_STATE *WalkState, 00406 ACPI_PARSE_OBJECT *Op, 00407 ACPI_STATUS CallbackStatus) 00408 { 00409 ACPI_PARSE_STATE *ParserState = &WalkState->ParserState; 00410 ACPI_STATUS Status = AE_CTRL_PENDING; 00411 00412 00413 ACPI_FUNCTION_TRACE_PTR (PsNextParseState, Op); 00414 00415 00416 switch (CallbackStatus) 00417 { 00418 case AE_CTRL_TERMINATE: 00419 /* 00420 * A control method was terminated via a RETURN statement. 00421 * The walk of this method is complete. 00422 */ 00423 ParserState->Aml = ParserState->AmlEnd; 00424 Status = AE_CTRL_TERMINATE; 00425 break; 00426 00427 00428 case AE_CTRL_BREAK: 00429 00430 ParserState->Aml = WalkState->AmlLastWhile; 00431 WalkState->ControlState->Common.Value = FALSE; 00432 Status = AE_CTRL_BREAK; 00433 break; 00434 00435 00436 case AE_CTRL_CONTINUE: 00437 00438 ParserState->Aml = WalkState->AmlLastWhile; 00439 Status = AE_CTRL_CONTINUE; 00440 break; 00441 00442 00443 case AE_CTRL_PENDING: 00444 00445 ParserState->Aml = WalkState->AmlLastWhile; 00446 break; 00447 00448 #if 0 00449 case AE_CTRL_SKIP: 00450 00451 ParserState->Aml = ParserState->Scope->ParseScope.PkgEnd; 00452 Status = AE_OK; 00453 break; 00454 #endif 00455 00456 case AE_CTRL_TRUE: 00457 /* 00458 * Predicate of an IF was true, and we are at the matching ELSE. 00459 * Just close out this package 00460 */ 00461 ParserState->Aml = AcpiPsGetNextPackageEnd (ParserState); 00462 Status = AE_CTRL_PENDING; 00463 break; 00464 00465 00466 case AE_CTRL_FALSE: 00467 /* 00468 * Either an IF/WHILE Predicate was false or we encountered a BREAK 00469 * opcode. In both cases, we do not execute the rest of the 00470 * package; We simply close out the parent (finishing the walk of 00471 * this branch of the tree) and continue execution at the parent 00472 * level. 00473 */ 00474 ParserState->Aml = ParserState->Scope->ParseScope.PkgEnd; 00475 00476 /* In the case of a BREAK, just force a predicate (if any) to FALSE */ 00477 00478 WalkState->ControlState->Common.Value = FALSE; 00479 Status = AE_CTRL_END; 00480 break; 00481 00482 00483 case AE_CTRL_TRANSFER: 00484 00485 /* A method call (invocation) -- transfer control */ 00486 00487 Status = AE_CTRL_TRANSFER; 00488 WalkState->PrevOp = Op; 00489 WalkState->MethodCallOp = Op; 00490 WalkState->MethodCallNode = (Op->Common.Value.Arg)->Common.Node; 00491 00492 /* Will return value (if any) be used by the caller? */ 00493 00494 WalkState->ReturnUsed = AcpiDsIsResultUsed (Op, WalkState); 00495 break; 00496 00497 00498 default: 00499 00500 Status = CallbackStatus; 00501 if ((CallbackStatus & AE_CODE_MASK) == AE_CODE_CONTROL) 00502 { 00503 Status = AE_OK; 00504 } 00505 break; 00506 } 00507 00508 return_ACPI_STATUS (Status); 00509 } 00510 00511 00512 /******************************************************************************* 00513 * 00514 * FUNCTION: AcpiPsParseAml 00515 * 00516 * PARAMETERS: WalkState - Current state 00517 * 00518 * 00519 * RETURN: Status 00520 * 00521 * DESCRIPTION: Parse raw AML and return a tree of ops 00522 * 00523 ******************************************************************************/ 00524 00525 ACPI_STATUS 00526 AcpiPsParseAml ( 00527 ACPI_WALK_STATE *WalkState) 00528 { 00529 ACPI_STATUS Status; 00530 ACPI_THREAD_STATE *Thread; 00531 ACPI_THREAD_STATE *PrevWalkList = AcpiGbl_CurrentWalkList; 00532 ACPI_WALK_STATE *PreviousWalkState; 00533 00534 00535 ACPI_FUNCTION_TRACE (PsParseAml); 00536 00537 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, 00538 "Entered with WalkState=%p Aml=%p size=%X\n", 00539 WalkState, WalkState->ParserState.Aml, 00540 WalkState->ParserState.AmlSize)); 00541 00542 if (!WalkState->ParserState.Aml) 00543 { 00544 return_ACPI_STATUS (AE_NULL_OBJECT); 00545 } 00546 00547 /* Create and initialize a new thread state */ 00548 00549 Thread = AcpiUtCreateThreadState (); 00550 if (!Thread) 00551 { 00552 if (WalkState->MethodDesc) 00553 { 00554 /* Executing a control method - additional cleanup */ 00555 00556 AcpiDsTerminateControlMethod (WalkState->MethodDesc, WalkState); 00557 } 00558 00559 AcpiDsDeleteWalkState (WalkState); 00560 return_ACPI_STATUS (AE_NO_MEMORY); 00561 } 00562 00563 WalkState->Thread = Thread; 00564 00565 /* 00566 * If executing a method, the starting SyncLevel is this method's 00567 * SyncLevel 00568 */ 00569 if (WalkState->MethodDesc) 00570 { 00571 WalkState->Thread->CurrentSyncLevel = WalkState->MethodDesc->Method.SyncLevel; 00572 } 00573 00574 AcpiDsPushWalkState (WalkState, Thread); 00575 00576 /* 00577 * This global allows the AML debugger to get a handle to the currently 00578 * executing control method. 00579 */ 00580 AcpiGbl_CurrentWalkList = Thread; 00581 00582 /* 00583 * Execute the walk loop as long as there is a valid Walk State. This 00584 * handles nested control method invocations without recursion. 00585 */ 00586 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "State=%p\n", WalkState)); 00587 00588 Status = AE_OK; 00589 while (WalkState) 00590 { 00591 if (ACPI_SUCCESS (Status)) 00592 { 00593 /* 00594 * The ParseLoop executes AML until the method terminates 00595 * or calls another method. 00596 */ 00597 Status = AcpiPsParseLoop (WalkState); 00598 } 00599 00600 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, 00601 "Completed one call to walk loop, %s State=%p\n", 00602 AcpiFormatException (Status), WalkState)); 00603 00604 if (Status == AE_CTRL_TRANSFER) 00605 { 00606 /* 00607 * A method call was detected. 00608 * Transfer control to the called control method 00609 */ 00610 Status = AcpiDsCallControlMethod (Thread, WalkState, NULL); 00611 if (ACPI_FAILURE (Status)) 00612 { 00613 Status = AcpiDsMethodError (Status, WalkState); 00614 } 00615 00616 /* 00617 * If the transfer to the new method method call worked, a new walk 00618 * state was created -- get it 00619 */ 00620 WalkState = AcpiDsGetCurrentWalkState (Thread); 00621 continue; 00622 } 00623 else if (Status == AE_CTRL_TERMINATE) 00624 { 00625 Status = AE_OK; 00626 } 00627 else if ((Status != AE_OK) && (WalkState->MethodDesc)) 00628 { 00629 /* Either the method parse or actual execution failed */ 00630 00631 ACPI_ERROR_METHOD ("Method parse/execution failed", 00632 WalkState->MethodNode, NULL, Status); 00633 00634 /* Check for possible multi-thread reentrancy problem */ 00635 00636 if ((Status == AE_ALREADY_EXISTS) && 00637 (!(WalkState->MethodDesc->Method.InfoFlags & ACPI_METHOD_SERIALIZED))) 00638 { 00639 /* 00640 * Method is not serialized and tried to create an object 00641 * twice. The probable cause is that the method cannot 00642 * handle reentrancy. Mark as "pending serialized" now, and 00643 * then mark "serialized" when the last thread exits. 00644 */ 00645 WalkState->MethodDesc->Method.InfoFlags |= 00646 ACPI_METHOD_SERIALIZED_PENDING; 00647 } 00648 } 00649 00650 /* We are done with this walk, move on to the parent if any */ 00651 00652 WalkState = AcpiDsPopWalkState (Thread); 00653 00654 /* Reset the current scope to the beginning of scope stack */ 00655 00656 AcpiDsScopeStackClear (WalkState); 00657 00658 /* 00659 * If we just returned from the execution of a control method or if we 00660 * encountered an error during the method parse phase, there's lots of 00661 * cleanup to do 00662 */ 00663 if (((WalkState->ParseFlags & ACPI_PARSE_MODE_MASK) == ACPI_PARSE_EXECUTE) || 00664 (ACPI_FAILURE (Status))) 00665 { 00666 AcpiDsTerminateControlMethod (WalkState->MethodDesc, WalkState); 00667 } 00668 00669 /* Delete this walk state and all linked control states */ 00670 00671 AcpiPsCleanupScope (&WalkState->ParserState); 00672 PreviousWalkState = WalkState; 00673 00674 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, 00675 "ReturnValue=%p, ImplicitValue=%p State=%p\n", 00676 WalkState->ReturnDesc, WalkState->ImplicitReturnObj, WalkState)); 00677 00678 /* Check if we have restarted a preempted walk */ 00679 00680 WalkState = AcpiDsGetCurrentWalkState (Thread); 00681 if (WalkState) 00682 { 00683 if (ACPI_SUCCESS (Status)) 00684 { 00685 /* 00686 * There is another walk state, restart it. 00687 * If the method return value is not used by the parent, 00688 * The object is deleted 00689 */ 00690 if (!PreviousWalkState->ReturnDesc) 00691 { 00692 /* 00693 * In slack mode execution, if there is no return value 00694 * we should implicitly return zero (0) as a default value. 00695 */ 00696 if (AcpiGbl_EnableInterpreterSlack && 00697 !PreviousWalkState->ImplicitReturnObj) 00698 { 00699 PreviousWalkState->ImplicitReturnObj = 00700 AcpiUtCreateIntegerObject ((UINT64) 0); 00701 if (!PreviousWalkState->ImplicitReturnObj) 00702 { 00703 return_ACPI_STATUS (AE_NO_MEMORY); 00704 } 00705 } 00706 00707 /* Restart the calling control method */ 00708 00709 Status = AcpiDsRestartControlMethod (WalkState, 00710 PreviousWalkState->ImplicitReturnObj); 00711 } 00712 else 00713 { 00714 /* 00715 * We have a valid return value, delete any implicit 00716 * return value. 00717 */ 00718 AcpiDsClearImplicitReturn (PreviousWalkState); 00719 00720 Status = AcpiDsRestartControlMethod (WalkState, 00721 PreviousWalkState->ReturnDesc); 00722 } 00723 if (ACPI_SUCCESS (Status)) 00724 { 00725 WalkState->WalkType |= ACPI_WALK_METHOD_RESTART; 00726 } 00727 } 00728 else 00729 { 00730 /* On error, delete any return object or implicit return */ 00731 00732 AcpiUtRemoveReference (PreviousWalkState->ReturnDesc); 00733 AcpiDsClearImplicitReturn (PreviousWalkState); 00734 } 00735 } 00736 00737 /* 00738 * Just completed a 1st-level method, save the final internal return 00739 * value (if any) 00740 */ 00741 else if (PreviousWalkState->CallerReturnDesc) 00742 { 00743 if (PreviousWalkState->ImplicitReturnObj) 00744 { 00745 *(PreviousWalkState->CallerReturnDesc) = 00746 PreviousWalkState->ImplicitReturnObj; 00747 } 00748 else 00749 { 00750 /* NULL if no return value */ 00751 00752 *(PreviousWalkState->CallerReturnDesc) = 00753 PreviousWalkState->ReturnDesc; 00754 } 00755 } 00756 else 00757 { 00758 if (PreviousWalkState->ReturnDesc) 00759 { 00760 /* Caller doesn't want it, must delete it */ 00761 00762 AcpiUtRemoveReference (PreviousWalkState->ReturnDesc); 00763 } 00764 if (PreviousWalkState->ImplicitReturnObj) 00765 { 00766 /* Caller doesn't want it, must delete it */ 00767 00768 AcpiUtRemoveReference (PreviousWalkState->ImplicitReturnObj); 00769 } 00770 } 00771 00772 AcpiDsDeleteWalkState (PreviousWalkState); 00773 } 00774 00775 /* Normal exit */ 00776 00777 AcpiExReleaseAllMutexes (Thread); 00778 AcpiUtDeleteGenericState (ACPI_CAST_PTR (ACPI_GENERIC_STATE, Thread)); 00779 AcpiGbl_CurrentWalkList = PrevWalkList; 00780 return_ACPI_STATUS (Status); 00781 } 00782 00783 Generated on Mon May 28 2012 04:27:09 for ReactOS by
1.7.6.1
|