Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /*******************************************************************************
  2.  *
  3.  * Module Name: dbmethod - Debug commands for control methods
  4.  *
  5.  ******************************************************************************/
  6.  
  7. /******************************************************************************
  8.  *
  9.  * 1. Copyright Notice
  10.  *
  11.  * Some or all of this work - Copyright (c) 1999 - 2011, Intel Corp.
  12.  * All rights reserved.
  13.  *
  14.  * 2. License
  15.  *
  16.  * 2.1. This is your license from Intel Corp. under its intellectual property
  17.  * rights.  You may have additional license terms from the party that provided
  18.  * you this software, covering your right to use that party's intellectual
  19.  * property rights.
  20.  *
  21.  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
  22.  * copy of the source code appearing in this file ("Covered Code") an
  23.  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
  24.  * base code distributed originally by Intel ("Original Intel Code") to copy,
  25.  * make derivatives, distribute, use and display any portion of the Covered
  26.  * Code in any form, with the right to sublicense such rights; and
  27.  *
  28.  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
  29.  * license (with the right to sublicense), under only those claims of Intel
  30.  * patents that are infringed by the Original Intel Code, to make, use, sell,
  31.  * offer to sell, and import the Covered Code and derivative works thereof
  32.  * solely to the minimum extent necessary to exercise the above copyright
  33.  * license, and in no event shall the patent license extend to any additions
  34.  * to or modifications of the Original Intel Code.  No other license or right
  35.  * is granted directly or by implication, estoppel or otherwise;
  36.  *
  37.  * The above copyright and patent license is granted only if the following
  38.  * conditions are met:
  39.  *
  40.  * 3. Conditions
  41.  *
  42.  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
  43.  * Redistribution of source code of any substantial portion of the Covered
  44.  * Code or modification with rights to further distribute source must include
  45.  * the above Copyright Notice, the above License, this list of Conditions,
  46.  * and the following Disclaimer and Export Compliance provision.  In addition,
  47.  * Licensee must cause all Covered Code to which Licensee contributes to
  48.  * contain a file documenting the changes Licensee made to create that Covered
  49.  * Code and the date of any change.  Licensee must include in that file the
  50.  * documentation of any changes made by any predecessor Licensee.  Licensee
  51.  * must include a prominent statement that the modification is derived,
  52.  * directly or indirectly, from Original Intel Code.
  53.  *
  54.  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
  55.  * Redistribution of source code of any substantial portion of the Covered
  56.  * Code or modification without rights to further distribute source must
  57.  * include the following Disclaimer and Export Compliance provision in the
  58.  * documentation and/or other materials provided with distribution.  In
  59.  * addition, Licensee may not authorize further sublicense of source of any
  60.  * portion of the Covered Code, and must include terms to the effect that the
  61.  * license from Licensee to its licensee is limited to the intellectual
  62.  * property embodied in the software Licensee provides to its licensee, and
  63.  * not to intellectual property embodied in modifications its licensee may
  64.  * make.
  65.  *
  66.  * 3.3. Redistribution of Executable. Redistribution in executable form of any
  67.  * substantial portion of the Covered Code or modification must reproduce the
  68.  * above Copyright Notice, and the following Disclaimer and Export Compliance
  69.  * provision in the documentation and/or other materials provided with the
  70.  * distribution.
  71.  *
  72.  * 3.4. Intel retains all right, title, and interest in and to the Original
  73.  * Intel Code.
  74.  *
  75.  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
  76.  * Intel shall be used in advertising or otherwise to promote the sale, use or
  77.  * other dealings in products derived from or relating to the Covered Code
  78.  * without prior written authorization from Intel.
  79.  *
  80.  * 4. Disclaimer and Export Compliance
  81.  *
  82.  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
  83.  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
  84.  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
  85.  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
  86.  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
  87.  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
  88.  * PARTICULAR PURPOSE.
  89.  *
  90.  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
  91.  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
  92.  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
  93.  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
  94.  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
  95.  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
  96.  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
  97.  * LIMITED REMEDY.
  98.  *
  99.  * 4.3. Licensee shall not export, either directly or indirectly, any of this
  100.  * software or system incorporating such software without first obtaining any
  101.  * required license or other approval from the U. S. Department of Commerce or
  102.  * any other agency or department of the United States Government.  In the
  103.  * event Licensee exports any such software from the United States or
  104.  * re-exports any such software from a foreign destination, Licensee shall
  105.  * ensure that the distribution and export/re-export of the software is in
  106.  * compliance with all laws, regulations, orders, or other restrictions of the
  107.  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
  108.  * any of its subsidiaries will export/re-export any technical data, process,
  109.  * software, or service, directly or indirectly, to any country for which the
  110.  * United States government or any agency thereof requires an export license,
  111.  * other governmental approval, or letter of assurance, without first obtaining
  112.  * such license, approval or letter.
  113.  *
  114.  *****************************************************************************/
  115.  
  116.  
  117. #include "acpi.h"
  118. #include "accommon.h"
  119. #include "acdispat.h"
  120. #include "acnamesp.h"
  121. #include "acdebug.h"
  122. #include "acdisasm.h"
  123. #include "acparser.h"
  124.  
  125.  
  126. #ifdef ACPI_DEBUGGER
  127.  
  128. #define _COMPONENT          ACPI_CA_DEBUGGER
  129.         ACPI_MODULE_NAME    ("dbmethod")
  130.  
  131.  
  132. /* Local prototypes */
  133.  
  134. static ACPI_STATUS
  135. AcpiDbWalkForExecute (
  136.     ACPI_HANDLE             ObjHandle,
  137.     UINT32                  NestingLevel,
  138.     void                    *Context,
  139.     void                    **ReturnValue);
  140.  
  141.  
  142. /*******************************************************************************
  143.  *
  144.  * FUNCTION:    AcpiDbSetMethodBreakpoint
  145.  *
  146.  * PARAMETERS:  Location            - AML offset of breakpoint
  147.  *              WalkState           - Current walk info
  148.  *              Op                  - Current Op (from parse walk)
  149.  *
  150.  * RETURN:      None
  151.  *
  152.  * DESCRIPTION: Set a breakpoint in a control method at the specified
  153.  *              AML offset
  154.  *
  155.  ******************************************************************************/
  156.  
  157. void
  158. AcpiDbSetMethodBreakpoint (
  159.     char                    *Location,
  160.     ACPI_WALK_STATE         *WalkState,
  161.     ACPI_PARSE_OBJECT       *Op)
  162. {
  163.     UINT32                  Address;
  164.  
  165.  
  166.     if (!Op)
  167.     {
  168.         AcpiOsPrintf ("There is no method currently executing\n");
  169.         return;
  170.     }
  171.  
  172.     /* Get and verify the breakpoint address */
  173.  
  174.     Address = ACPI_STRTOUL (Location, NULL, 16);
  175.     if (Address <= Op->Common.AmlOffset)
  176.     {
  177.         AcpiOsPrintf ("Breakpoint %X is beyond current address %X\n",
  178.             Address, Op->Common.AmlOffset);
  179.     }
  180.  
  181.     /* Save breakpoint in current walk */
  182.  
  183.     WalkState->UserBreakpoint = Address;
  184.     AcpiOsPrintf ("Breakpoint set at AML offset %X\n", Address);
  185. }
  186.  
  187.  
  188. /*******************************************************************************
  189.  *
  190.  * FUNCTION:    AcpiDbSetMethodCallBreakpoint
  191.  *
  192.  * PARAMETERS:  Op                  - Current Op (from parse walk)
  193.  *
  194.  * RETURN:      None
  195.  *
  196.  * DESCRIPTION: Set a breakpoint in a control method at the specified
  197.  *              AML offset
  198.  *
  199.  ******************************************************************************/
  200.  
  201. void
  202. AcpiDbSetMethodCallBreakpoint (
  203.     ACPI_PARSE_OBJECT       *Op)
  204. {
  205.  
  206.  
  207.     if (!Op)
  208.     {
  209.         AcpiOsPrintf ("There is no method currently executing\n");
  210.         return;
  211.     }
  212.  
  213.     AcpiGbl_StepToNextCall = TRUE;
  214. }
  215.  
  216.  
  217. /*******************************************************************************
  218.  *
  219.  * FUNCTION:    AcpiDbSetMethodData
  220.  *
  221.  * PARAMETERS:  TypeArg         - L for local, A for argument
  222.  *              IndexArg        - which one
  223.  *              ValueArg        - Value to set.
  224.  *
  225.  * RETURN:      None
  226.  *
  227.  * DESCRIPTION: Set a local or argument for the running control method.
  228.  *              NOTE: only object supported is Number.
  229.  *
  230.  ******************************************************************************/
  231.  
  232. void
  233. AcpiDbSetMethodData (
  234.     char                    *TypeArg,
  235.     char                    *IndexArg,
  236.     char                    *ValueArg)
  237. {
  238.     char                    Type;
  239.     UINT32                  Index;
  240.     UINT32                  Value;
  241.     ACPI_WALK_STATE         *WalkState;
  242.     ACPI_OPERAND_OBJECT     *ObjDesc;
  243.     ACPI_STATUS             Status;
  244.     ACPI_NAMESPACE_NODE     *Node;
  245.  
  246.  
  247.     /* Validate TypeArg */
  248.  
  249.     AcpiUtStrupr (TypeArg);
  250.     Type = TypeArg[0];
  251.     if ((Type != 'L') &&
  252.         (Type != 'A') &&
  253.         (Type != 'N'))
  254.     {
  255.         AcpiOsPrintf ("Invalid SET operand: %s\n", TypeArg);
  256.         return;
  257.     }
  258.  
  259.     Value = ACPI_STRTOUL (ValueArg, NULL, 16);
  260.  
  261.     if (Type == 'N')
  262.     {
  263.         Node = AcpiDbConvertToNode (IndexArg);
  264.         if (Node->Type != ACPI_TYPE_INTEGER)
  265.         {
  266.             AcpiOsPrintf ("Can only set Integer nodes\n");
  267.             return;
  268.         }
  269.         ObjDesc = Node->Object;
  270.         ObjDesc->Integer.Value = Value;
  271.         return;
  272.     }
  273.  
  274.     /* Get the index and value */
  275.  
  276.     Index = ACPI_STRTOUL (IndexArg, NULL, 16);
  277.  
  278.     WalkState = AcpiDsGetCurrentWalkState (AcpiGbl_CurrentWalkList);
  279.     if (!WalkState)
  280.     {
  281.         AcpiOsPrintf ("There is no method currently executing\n");
  282.         return;
  283.     }
  284.  
  285.     /* Create and initialize the new object */
  286.  
  287.     ObjDesc = AcpiUtCreateIntegerObject ((UINT64) Value);
  288.     if (!ObjDesc)
  289.     {
  290.         AcpiOsPrintf ("Could not create an internal object\n");
  291.         return;
  292.     }
  293.  
  294.     /* Store the new object into the target */
  295.  
  296.     switch (Type)
  297.     {
  298.     case 'A':
  299.  
  300.         /* Set a method argument */
  301.  
  302.         if (Index > ACPI_METHOD_MAX_ARG)
  303.         {
  304.             AcpiOsPrintf ("Arg%u - Invalid argument name\n", Index);
  305.             goto Cleanup;
  306.         }
  307.  
  308.         Status = AcpiDsStoreObjectToLocal (ACPI_REFCLASS_ARG, Index, ObjDesc,
  309.                     WalkState);
  310.         if (ACPI_FAILURE (Status))
  311.         {
  312.             goto Cleanup;
  313.         }
  314.  
  315.         ObjDesc = WalkState->Arguments[Index].Object;
  316.  
  317.         AcpiOsPrintf ("Arg%u: ", Index);
  318.         AcpiDmDisplayInternalObject (ObjDesc, WalkState);
  319.         break;
  320.  
  321.     case 'L':
  322.  
  323.         /* Set a method local */
  324.  
  325.         if (Index > ACPI_METHOD_MAX_LOCAL)
  326.         {
  327.             AcpiOsPrintf ("Local%u - Invalid local variable name\n", Index);
  328.             goto Cleanup;
  329.         }
  330.  
  331.         Status = AcpiDsStoreObjectToLocal (ACPI_REFCLASS_LOCAL, Index, ObjDesc,
  332.                     WalkState);
  333.         if (ACPI_FAILURE (Status))
  334.         {
  335.             goto Cleanup;
  336.         }
  337.  
  338.         ObjDesc = WalkState->LocalVariables[Index].Object;
  339.  
  340.         AcpiOsPrintf ("Local%u: ", Index);
  341.         AcpiDmDisplayInternalObject (ObjDesc, WalkState);
  342.         break;
  343.  
  344.     default:
  345.         break;
  346.     }
  347.  
  348. Cleanup:
  349.     AcpiUtRemoveReference (ObjDesc);
  350. }
  351.  
  352.  
  353. /*******************************************************************************
  354.  *
  355.  * FUNCTION:    AcpiDbDisassembleAml
  356.  *
  357.  * PARAMETERS:  Statements          - Number of statements to disassemble
  358.  *              Op                  - Current Op (from parse walk)
  359.  *
  360.  * RETURN:      None
  361.  *
  362.  * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
  363.  *              of statements specified.
  364.  *
  365.  ******************************************************************************/
  366.  
  367. void
  368. AcpiDbDisassembleAml (
  369.     char                    *Statements,
  370.     ACPI_PARSE_OBJECT       *Op)
  371. {
  372.     UINT32                  NumStatements = 8;
  373.  
  374.  
  375.     if (!Op)
  376.     {
  377.         AcpiOsPrintf ("There is no method currently executing\n");
  378.         return;
  379.     }
  380.  
  381.     if (Statements)
  382.     {
  383.         NumStatements = ACPI_STRTOUL (Statements, NULL, 0);
  384.     }
  385.  
  386.     AcpiDmDisassemble (NULL, Op, NumStatements);
  387. }
  388.  
  389.  
  390. /*******************************************************************************
  391.  *
  392.  * FUNCTION:    AcpiDbDisassembleMethod
  393.  *
  394.  * PARAMETERS:  Name            - Name of control method
  395.  *
  396.  * RETURN:      None
  397.  *
  398.  * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
  399.  *              of statements specified.
  400.  *
  401.  ******************************************************************************/
  402.  
  403. ACPI_STATUS
  404. AcpiDbDisassembleMethod (
  405.     char                    *Name)
  406. {
  407.     ACPI_STATUS             Status;
  408.     ACPI_PARSE_OBJECT       *Op;
  409.     ACPI_WALK_STATE         *WalkState;
  410.     ACPI_OPERAND_OBJECT     *ObjDesc;
  411.     ACPI_NAMESPACE_NODE     *Method;
  412.  
  413.  
  414.     Method = AcpiDbConvertToNode (Name);
  415.     if (!Method)
  416.     {
  417.         return (AE_BAD_PARAMETER);
  418.     }
  419.  
  420.     ObjDesc = Method->Object;
  421.  
  422.     Op = AcpiPsCreateScopeOp ();
  423.     if (!Op)
  424.     {
  425.         return (AE_NO_MEMORY);
  426.     }
  427.  
  428.     /* Create and initialize a new walk state */
  429.  
  430.     WalkState = AcpiDsCreateWalkState (0, Op, NULL, NULL);
  431.     if (!WalkState)
  432.     {
  433.         return (AE_NO_MEMORY);
  434.     }
  435.  
  436.     Status = AcpiDsInitAmlWalk (WalkState, Op, NULL,
  437.                     ObjDesc->Method.AmlStart,
  438.                     ObjDesc->Method.AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
  439.     if (ACPI_FAILURE (Status))
  440.     {
  441.         return (Status);
  442.     }
  443.  
  444.     /* Parse the AML */
  445.  
  446.     WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
  447.     WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
  448.     Status = AcpiPsParseAml (WalkState);
  449.  
  450.     AcpiDmDisassemble (NULL, Op, 0);
  451.     AcpiPsDeleteParseTree (Op);
  452.     return (AE_OK);
  453. }
  454.  
  455.  
  456. /*******************************************************************************
  457.  *
  458.  * FUNCTION:    AcpiDbWalkForExecute
  459.  *
  460.  * PARAMETERS:  Callback from WalkNamespace
  461.  *
  462.  * RETURN:      Status
  463.  *
  464.  * DESCRIPTION: Batch execution module. Currently only executes predefined
  465.  *              ACPI names.
  466.  *
  467.  ******************************************************************************/
  468.  
  469. static ACPI_STATUS
  470. AcpiDbWalkForExecute (
  471.     ACPI_HANDLE             ObjHandle,
  472.     UINT32                  NestingLevel,
  473.     void                    *Context,
  474.     void                    **ReturnValue)
  475. {
  476.     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
  477.     ACPI_EXECUTE_WALK       *Info = (ACPI_EXECUTE_WALK *) Context;
  478.     ACPI_BUFFER             ReturnObj;
  479.     ACPI_STATUS             Status;
  480.     char                    *Pathname;
  481.     UINT32                  i;
  482.     ACPI_DEVICE_INFO        *ObjInfo;
  483.     ACPI_OBJECT_LIST        ParamObjects;
  484.     ACPI_OBJECT             Params[ACPI_METHOD_NUM_ARGS];
  485.     const ACPI_PREDEFINED_INFO *Predefined;
  486.  
  487.  
  488.     Predefined = AcpiNsCheckForPredefinedName (Node);
  489.     if (!Predefined)
  490.     {
  491.         return (AE_OK);
  492.     }
  493.  
  494.     if (Node->Type == ACPI_TYPE_LOCAL_SCOPE)
  495.     {
  496.         return (AE_OK);
  497.     }
  498.  
  499.     Pathname = AcpiNsGetExternalPathname (Node);
  500.     if (!Pathname)
  501.     {
  502.         return (AE_OK);
  503.     }
  504.  
  505.     /* Get the object info for number of method parameters */
  506.  
  507.     Status = AcpiGetObjectInfo (ObjHandle, &ObjInfo);
  508.     if (ACPI_FAILURE (Status))
  509.     {
  510.         return (Status);
  511.     }
  512.  
  513.     ParamObjects.Pointer = NULL;
  514.     ParamObjects.Count   = 0;
  515.  
  516.     if (ObjInfo->Type == ACPI_TYPE_METHOD)
  517.     {
  518.         /* Setup default parameters */
  519.  
  520.         for (i = 0; i < ObjInfo->ParamCount; i++)
  521.         {
  522.             Params[i].Type           = ACPI_TYPE_INTEGER;
  523.             Params[i].Integer.Value  = 1;
  524.         }
  525.  
  526.         ParamObjects.Pointer     = Params;
  527.         ParamObjects.Count       = ObjInfo->ParamCount;
  528.     }
  529.  
  530.     ACPI_FREE (ObjInfo);
  531.     ReturnObj.Pointer = NULL;
  532.     ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
  533.  
  534.     /* Do the actual method execution */
  535.  
  536.     AcpiGbl_MethodExecuting = TRUE;
  537.  
  538.     Status = AcpiEvaluateObject (Node, NULL, &ParamObjects, &ReturnObj);
  539.  
  540.     AcpiOsPrintf ("%-32s returned %s\n", Pathname, AcpiFormatException (Status));
  541.     AcpiGbl_MethodExecuting = FALSE;
  542.     ACPI_FREE (Pathname);
  543.  
  544.     /* Ignore status from method execution */
  545.  
  546.     Status = AE_OK;
  547.  
  548.     /* Update count, check if we have executed enough methods */
  549.  
  550.     Info->Count++;
  551.     if (Info->Count >= Info->MaxCount)
  552.     {
  553.         Status = AE_CTRL_TERMINATE;
  554.     }
  555.  
  556.     return (Status);
  557. }
  558.  
  559.  
  560. /*******************************************************************************
  561.  *
  562.  * FUNCTION:    AcpiDbBatchExecute
  563.  *
  564.  * PARAMETERS:  CountArg            - Max number of methods to execute
  565.  *
  566.  * RETURN:      None
  567.  *
  568.  * DESCRIPTION: Namespace batch execution. Execute predefined names in the
  569.  *              namespace, up to the max count, if specified.
  570.  *
  571.  ******************************************************************************/
  572.  
  573. void
  574. AcpiDbBatchExecute (
  575.     char                    *CountArg)
  576. {
  577.     ACPI_EXECUTE_WALK       Info;
  578.  
  579.  
  580.     Info.Count = 0;
  581.     Info.MaxCount = ACPI_UINT32_MAX;
  582.  
  583.     if (CountArg)
  584.     {
  585.         Info.MaxCount = ACPI_STRTOUL (CountArg, NULL, 0);
  586.     }
  587.  
  588.  
  589.     /* Search all nodes in namespace */
  590.  
  591.     (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
  592.                 AcpiDbWalkForExecute, NULL, (void *) &Info, NULL);
  593.  
  594.     AcpiOsPrintf ("Executed %u predefined names in the namespace\n", Info.Count);
  595. }
  596.  
  597. #endif /* ACPI_DEBUGGER */
  598.