ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

dscontrol.c
Go to the documentation of this file.
00001 /******************************************************************************
00002  *
00003  * Module Name: dscontrol - Support for execution control opcodes -
00004  *                          if/else/while/return
00005  *
00006  *****************************************************************************/
00007 
00008 /******************************************************************************
00009  *
00010  * 1. Copyright Notice
00011  *
00012  * Some or all of this work - Copyright (c) 1999 - 2011, Intel Corp.
00013  * All rights reserved.
00014  *
00015  * 2. License
00016  *
00017  * 2.1. This is your license from Intel Corp. under its intellectual property
00018  * rights.  You may have additional license terms from the party that provided
00019  * you this software, covering your right to use that party's intellectual
00020  * property rights.
00021  *
00022  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
00023  * copy of the source code appearing in this file ("Covered Code") an
00024  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
00025  * base code distributed originally by Intel ("Original Intel Code") to copy,
00026  * make derivatives, distribute, use and display any portion of the Covered
00027  * Code in any form, with the right to sublicense such rights; and
00028  *
00029  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
00030  * license (with the right to sublicense), under only those claims of Intel
00031  * patents that are infringed by the Original Intel Code, to make, use, sell,
00032  * offer to sell, and import the Covered Code and derivative works thereof
00033  * solely to the minimum extent necessary to exercise the above copyright
00034  * license, and in no event shall the patent license extend to any additions
00035  * to or modifications of the Original Intel Code.  No other license or right
00036  * is granted directly or by implication, estoppel or otherwise;
00037  *
00038  * The above copyright and patent license is granted only if the following
00039  * conditions are met:
00040  *
00041  * 3. Conditions
00042  *
00043  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
00044  * Redistribution of source code of any substantial portion of the Covered
00045  * Code or modification with rights to further distribute source must include
00046  * the above Copyright Notice, the above License, this list of Conditions,
00047  * and the following Disclaimer and Export Compliance provision.  In addition,
00048  * Licensee must cause all Covered Code to which Licensee contributes to
00049  * contain a file documenting the changes Licensee made to create that Covered
00050  * Code and the date of any change.  Licensee must include in that file the
00051  * documentation of any changes made by any predecessor Licensee.  Licensee
00052  * must include a prominent statement that the modification is derived,
00053  * directly or indirectly, from Original Intel Code.
00054  *
00055  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
00056  * Redistribution of source code of any substantial portion of the Covered
00057  * Code or modification without rights to further distribute source must
00058  * include the following Disclaimer and Export Compliance provision in the
00059  * documentation and/or other materials provided with distribution.  In
00060  * addition, Licensee may not authorize further sublicense of source of any
00061  * portion of the Covered Code, and must include terms to the effect that the
00062  * license from Licensee to its licensee is limited to the intellectual
00063  * property embodied in the software Licensee provides to its licensee, and
00064  * not to intellectual property embodied in modifications its licensee may
00065  * make.
00066  *
00067  * 3.3. Redistribution of Executable. Redistribution in executable form of any
00068  * substantial portion of the Covered Code or modification must reproduce the
00069  * above Copyright Notice, and the following Disclaimer and Export Compliance
00070  * provision in the documentation and/or other materials provided with the
00071  * distribution.
00072  *
00073  * 3.4. Intel retains all right, title, and interest in and to the Original
00074  * Intel Code.
00075  *
00076  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
00077  * Intel shall be used in advertising or otherwise to promote the sale, use or
00078  * other dealings in products derived from or relating to the Covered Code
00079  * without prior written authorization from Intel.
00080  *
00081  * 4. Disclaimer and Export Compliance
00082  *
00083  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
00084  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
00085  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
00086  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
00087  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
00088  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
00089  * PARTICULAR PURPOSE.
00090  *
00091  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
00092  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
00093  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
00094  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
00095  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
00096  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
00097  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
00098  * LIMITED REMEDY.
00099  *
00100  * 4.3. Licensee shall not export, either directly or indirectly, any of this
00101  * software or system incorporating such software without first obtaining any
00102  * required license or other approval from the U. S. Department of Commerce or
00103  * any other agency or department of the United States Government.  In the
00104  * event Licensee exports any such software from the United States or
00105  * re-exports any such software from a foreign destination, Licensee shall
00106  * ensure that the distribution and export/re-export of the software is in
00107  * compliance with all laws, regulations, orders, or other restrictions of the
00108  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
00109  * any of its subsidiaries will export/re-export any technical data, process,
00110  * software, or service, directly or indirectly, to any country for which the
00111  * United States government or any agency thereof requires an export license,
00112  * other governmental approval, or letter of assurance, without first obtaining
00113  * such license, approval or letter.
00114  *
00115  *****************************************************************************/
00116 
00117 #define __DSCONTROL_C__
00118 
00119 #include "acpi.h"
00120 #include "accommon.h"
00121 #include "amlcode.h"
00122 #include "acdispat.h"
00123 #include "acinterp.h"
00124 
00125 #define _COMPONENT          ACPI_DISPATCHER
00126         ACPI_MODULE_NAME    ("dscontrol")
00127 
00128 
00129 /*******************************************************************************
00130  *
00131  * FUNCTION:    AcpiDsExecBeginControlOp
00132  *
00133  * PARAMETERS:  WalkList        - The list that owns the walk stack
00134  *              Op              - The control Op
00135  *
00136  * RETURN:      Status
00137  *
00138  * DESCRIPTION: Handles all control ops encountered during control method
00139  *              execution.
00140  *
00141  ******************************************************************************/
00142 
00143 ACPI_STATUS
00144 AcpiDsExecBeginControlOp (
00145     ACPI_WALK_STATE         *WalkState,
00146     ACPI_PARSE_OBJECT       *Op)
00147 {
00148     ACPI_STATUS             Status = AE_OK;
00149     ACPI_GENERIC_STATE      *ControlState;
00150 
00151 
00152     ACPI_FUNCTION_NAME (DsExecBeginControlOp);
00153 
00154 
00155     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p Opcode=%2.2X State=%p\n",
00156         Op, Op->Common.AmlOpcode, WalkState));
00157 
00158     switch (Op->Common.AmlOpcode)
00159     {
00160     case AML_WHILE_OP:
00161 
00162         /*
00163          * If this is an additional iteration of a while loop, continue.
00164          * There is no need to allocate a new control state.
00165          */
00166         if (WalkState->ControlState)
00167         {
00168             if (WalkState->ControlState->Control.AmlPredicateStart ==
00169                 (WalkState->ParserState.Aml - 1))
00170             {
00171                 /* Reset the state to start-of-loop */
00172 
00173                 WalkState->ControlState->Common.State =
00174                     ACPI_CONTROL_CONDITIONAL_EXECUTING;
00175                 break;
00176             }
00177         }
00178 
00179         /*lint -fallthrough */
00180 
00181     case AML_IF_OP:
00182 
00183         /*
00184          * IF/WHILE: Create a new control state to manage these
00185          * constructs. We need to manage these as a stack, in order
00186          * to handle nesting.
00187          */
00188         ControlState = AcpiUtCreateControlState ();
00189         if (!ControlState)
00190         {
00191             Status = AE_NO_MEMORY;
00192             break;
00193         }
00194         /*
00195          * Save a pointer to the predicate for multiple executions
00196          * of a loop
00197          */
00198         ControlState->Control.AmlPredicateStart = WalkState->ParserState.Aml - 1;
00199         ControlState->Control.PackageEnd = WalkState->ParserState.PkgEnd;
00200         ControlState->Control.Opcode = Op->Common.AmlOpcode;
00201 
00202 
00203         /* Push the control state on this walk's control stack */
00204 
00205         AcpiUtPushGenericState (&WalkState->ControlState, ControlState);
00206         break;
00207 
00208     case AML_ELSE_OP:
00209 
00210         /* Predicate is in the state object */
00211         /* If predicate is true, the IF was executed, ignore ELSE part */
00212 
00213         if (WalkState->LastPredicate)
00214         {
00215             Status = AE_CTRL_TRUE;
00216         }
00217 
00218         break;
00219 
00220     case AML_RETURN_OP:
00221 
00222         break;
00223 
00224     default:
00225         break;
00226     }
00227 
00228     return (Status);
00229 }
00230 
00231 
00232 /*******************************************************************************
00233  *
00234  * FUNCTION:    AcpiDsExecEndControlOp
00235  *
00236  * PARAMETERS:  WalkList        - The list that owns the walk stack
00237  *              Op              - The control Op
00238  *
00239  * RETURN:      Status
00240  *
00241  * DESCRIPTION: Handles all control ops encountered during control method
00242  *              execution.
00243  *
00244  ******************************************************************************/
00245 
00246 ACPI_STATUS
00247 AcpiDsExecEndControlOp (
00248     ACPI_WALK_STATE         *WalkState,
00249     ACPI_PARSE_OBJECT       *Op)
00250 {
00251     ACPI_STATUS             Status = AE_OK;
00252     ACPI_GENERIC_STATE      *ControlState;
00253 
00254 
00255     ACPI_FUNCTION_NAME (DsExecEndControlOp);
00256 
00257 
00258     switch (Op->Common.AmlOpcode)
00259     {
00260     case AML_IF_OP:
00261 
00262         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[IF_OP] Op=%p\n", Op));
00263 
00264         /*
00265          * Save the result of the predicate in case there is an
00266          * ELSE to come
00267          */
00268         WalkState->LastPredicate =
00269             (BOOLEAN) WalkState->ControlState->Common.Value;
00270 
00271         /*
00272          * Pop the control state that was created at the start
00273          * of the IF and free it
00274          */
00275         ControlState = AcpiUtPopGenericState (&WalkState->ControlState);
00276         AcpiUtDeleteGenericState (ControlState);
00277         break;
00278 
00279 
00280     case AML_ELSE_OP:
00281 
00282         break;
00283 
00284 
00285     case AML_WHILE_OP:
00286 
00287         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[WHILE_OP] Op=%p\n", Op));
00288 
00289         ControlState = WalkState->ControlState;
00290         if (ControlState->Common.Value)
00291         {
00292             /* Predicate was true, the body of the loop was just executed */
00293 
00294             /*
00295              * This loop counter mechanism allows the interpreter to escape
00296              * possibly infinite loops. This can occur in poorly written AML
00297              * when the hardware does not respond within a while loop and the
00298              * loop does not implement a timeout.
00299              */
00300             ControlState->Control.LoopCount++;
00301             if (ControlState->Control.LoopCount > ACPI_MAX_LOOP_ITERATIONS)
00302             {
00303                 Status = AE_AML_INFINITE_LOOP;
00304                 break;
00305             }
00306 
00307             /*
00308              * Go back and evaluate the predicate and maybe execute the loop
00309              * another time
00310              */
00311             Status = AE_CTRL_PENDING;
00312             WalkState->AmlLastWhile = ControlState->Control.AmlPredicateStart;
00313             break;
00314         }
00315 
00316         /* Predicate was false, terminate this while loop */
00317 
00318         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
00319             "[WHILE_OP] termination! Op=%p\n",Op));
00320 
00321         /* Pop this control state and free it */
00322 
00323         ControlState = AcpiUtPopGenericState (&WalkState->ControlState);
00324         AcpiUtDeleteGenericState (ControlState);
00325         break;
00326 
00327 
00328     case AML_RETURN_OP:
00329 
00330         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
00331             "[RETURN_OP] Op=%p Arg=%p\n",Op, Op->Common.Value.Arg));
00332 
00333         /*
00334          * One optional operand -- the return value
00335          * It can be either an immediate operand or a result that
00336          * has been bubbled up the tree
00337          */
00338         if (Op->Common.Value.Arg)
00339         {
00340             /* Since we have a real Return(), delete any implicit return */
00341 
00342             AcpiDsClearImplicitReturn (WalkState);
00343 
00344             /* Return statement has an immediate operand */
00345 
00346             Status = AcpiDsCreateOperands (WalkState, Op->Common.Value.Arg);
00347             if (ACPI_FAILURE (Status))
00348             {
00349                 return (Status);
00350             }
00351 
00352             /*
00353              * If value being returned is a Reference (such as
00354              * an arg or local), resolve it now because it may
00355              * cease to exist at the end of the method.
00356              */
00357             Status = AcpiExResolveToValue (&WalkState->Operands [0], WalkState);
00358             if (ACPI_FAILURE (Status))
00359             {
00360                 return (Status);
00361             }
00362 
00363             /*
00364              * Get the return value and save as the last result
00365              * value.  This is the only place where WalkState->ReturnDesc
00366              * is set to anything other than zero!
00367              */
00368             WalkState->ReturnDesc = WalkState->Operands[0];
00369         }
00370         else if (WalkState->ResultCount)
00371         {
00372             /* Since we have a real Return(), delete any implicit return */
00373 
00374             AcpiDsClearImplicitReturn (WalkState);
00375 
00376             /*
00377              * The return value has come from a previous calculation.
00378              *
00379              * If value being returned is a Reference (such as
00380              * an arg or local), resolve it now because it may
00381              * cease to exist at the end of the method.
00382              *
00383              * Allow references created by the Index operator to return
00384              * unchanged.
00385              */
00386             if ((ACPI_GET_DESCRIPTOR_TYPE (WalkState->Results->Results.ObjDesc[0]) == ACPI_DESC_TYPE_OPERAND) &&
00387                 ((WalkState->Results->Results.ObjDesc [0])->Common.Type == ACPI_TYPE_LOCAL_REFERENCE) &&
00388                 ((WalkState->Results->Results.ObjDesc [0])->Reference.Class != ACPI_REFCLASS_INDEX))
00389             {
00390                 Status = AcpiExResolveToValue (&WalkState->Results->Results.ObjDesc [0], WalkState);
00391                 if (ACPI_FAILURE (Status))
00392                 {
00393                     return (Status);
00394                 }
00395             }
00396 
00397             WalkState->ReturnDesc = WalkState->Results->Results.ObjDesc [0];
00398         }
00399         else
00400         {
00401             /* No return operand */
00402 
00403             if (WalkState->NumOperands)
00404             {
00405                 AcpiUtRemoveReference (WalkState->Operands [0]);
00406             }
00407 
00408             WalkState->Operands [0]     = NULL;
00409             WalkState->NumOperands      = 0;
00410             WalkState->ReturnDesc       = NULL;
00411         }
00412 
00413 
00414         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
00415             "Completed RETURN_OP State=%p, RetVal=%p\n",
00416             WalkState, WalkState->ReturnDesc));
00417 
00418         /* End the control method execution right now */
00419 
00420         Status = AE_CTRL_TERMINATE;
00421         break;
00422 
00423 
00424     case AML_NOOP_OP:
00425 
00426         /* Just do nothing! */
00427         break;
00428 
00429 
00430     case AML_BREAK_POINT_OP:
00431 
00432         /*
00433          * Set the single-step flag. This will cause the debugger (if present)
00434          * to break to the console within the AML debugger at the start of the
00435          * next AML instruction.
00436          */
00437         ACPI_DEBUGGER_EXEC (
00438             AcpiGbl_CmSingleStep = TRUE);
00439         ACPI_DEBUGGER_EXEC (
00440             AcpiOsPrintf ("**break** Executed AML BreakPoint opcode\n"));
00441 
00442         /* Call to the OSL in case OS wants a piece of the action */
00443 
00444         Status = AcpiOsSignal (ACPI_SIGNAL_BREAKPOINT,
00445                     "Executed AML Breakpoint opcode");
00446         break;
00447 
00448 
00449     case AML_BREAK_OP:
00450     case AML_CONTINUE_OP: /* ACPI 2.0 */
00451 
00452 
00453         /* Pop and delete control states until we find a while */
00454 
00455         while (WalkState->ControlState &&
00456                 (WalkState->ControlState->Control.Opcode != AML_WHILE_OP))
00457         {
00458             ControlState = AcpiUtPopGenericState (&WalkState->ControlState);
00459             AcpiUtDeleteGenericState (ControlState);
00460         }
00461 
00462         /* No while found? */
00463 
00464         if (!WalkState->ControlState)
00465         {
00466             return (AE_AML_NO_WHILE);
00467         }
00468 
00469         /* Was: WalkState->AmlLastWhile = WalkState->ControlState->Control.AmlPredicateStart; */
00470 
00471         WalkState->AmlLastWhile = WalkState->ControlState->Control.PackageEnd;
00472 
00473         /* Return status depending on opcode */
00474 
00475         if (Op->Common.AmlOpcode == AML_BREAK_OP)
00476         {
00477             Status = AE_CTRL_BREAK;
00478         }
00479         else
00480         {
00481             Status = AE_CTRL_CONTINUE;
00482         }
00483         break;
00484 
00485 
00486     default:
00487 
00488         ACPI_ERROR ((AE_INFO, "Unknown control opcode=0x%X Op=%p",
00489             Op->Common.AmlOpcode, Op));
00490 
00491         Status = AE_AML_BAD_OPCODE;
00492         break;
00493     }
00494 
00495     return (Status);
00496 }

Generated on Sun May 27 2012 04:27:14 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.