Home | History | Annotate | Line # | Download | only in debugger
dbmethod.c revision 1.13
      1 /*******************************************************************************
      2  *
      3  * Module Name: dbmethod - Debug commands for control methods
      4  *
      5  ******************************************************************************/
      6 
      7 /*
      8  * Copyright (C) 2000 - 2019, Intel Corp.
      9  * All rights reserved.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions, and the following disclaimer,
     16  *    without modification.
     17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  *    including a substantially similar Disclaimer requirement for further
     21  *    binary redistribution.
     22  * 3. Neither the names of the above-listed copyright holders nor the names
     23  *    of any contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * Alternatively, this software may be distributed under the terms of the
     27  * GNU General Public License ("GPL") version 2 as published by the Free
     28  * Software Foundation.
     29  *
     30  * NO WARRANTY
     31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  * POSSIBILITY OF SUCH DAMAGES.
     42  */
     43 
     44 #include "acpi.h"
     45 #include "accommon.h"
     46 #include "acdispat.h"
     47 #include "acnamesp.h"
     48 #include "acdebug.h"
     49 #include "acparser.h"
     50 #include "acpredef.h"
     51 
     52 
     53 #define _COMPONENT          ACPI_CA_DEBUGGER
     54         ACPI_MODULE_NAME    ("dbmethod")
     55 
     56 /* Local prototypes */
     57 
     58 static ACPI_STATUS
     59 AcpiDbWalkForExecute (
     60     ACPI_HANDLE             ObjHandle,
     61     UINT32                  NestingLevel,
     62     void                    *Context,
     63     void                    **ReturnValue);
     64 
     65 
     66 /*******************************************************************************
     67  *
     68  * FUNCTION:    AcpiDbSetMethodBreakpoint
     69  *
     70  * PARAMETERS:  Location            - AML offset of breakpoint
     71  *              WalkState           - Current walk info
     72  *              Op                  - Current Op (from parse walk)
     73  *
     74  * RETURN:      None
     75  *
     76  * DESCRIPTION: Set a breakpoint in a control method at the specified
     77  *              AML offset
     78  *
     79  ******************************************************************************/
     80 
     81 void
     82 AcpiDbSetMethodBreakpoint (
     83     char                    *Location,
     84     ACPI_WALK_STATE         *WalkState,
     85     ACPI_PARSE_OBJECT       *Op)
     86 {
     87     UINT32                  Address;
     88     UINT32                  AmlOffset;
     89 
     90 
     91     if (!Op)
     92     {
     93         AcpiOsPrintf ("There is no method currently executing\n");
     94         return;
     95     }
     96 
     97     /* Get and verify the breakpoint address */
     98 
     99     Address = strtoul (Location, NULL, 16);
    100     AmlOffset = (UINT32) ACPI_PTR_DIFF (Op->Common.Aml,
    101         WalkState->ParserState.AmlStart);
    102     if (Address <= AmlOffset)
    103     {
    104         AcpiOsPrintf ("Breakpoint %X is beyond current address %X\n",
    105             Address, AmlOffset);
    106     }
    107 
    108     /* Save breakpoint in current walk */
    109 
    110     WalkState->UserBreakpoint = Address;
    111     AcpiOsPrintf ("Breakpoint set at AML offset %X\n", Address);
    112 }
    113 
    114 
    115 /*******************************************************************************
    116  *
    117  * FUNCTION:    AcpiDbSetMethodCallBreakpoint
    118  *
    119  * PARAMETERS:  Op                  - Current Op (from parse walk)
    120  *
    121  * RETURN:      None
    122  *
    123  * DESCRIPTION: Set a breakpoint in a control method at the specified
    124  *              AML offset
    125  *
    126  ******************************************************************************/
    127 
    128 void
    129 AcpiDbSetMethodCallBreakpoint (
    130     ACPI_PARSE_OBJECT       *Op)
    131 {
    132 
    133 
    134     if (!Op)
    135     {
    136         AcpiOsPrintf ("There is no method currently executing\n");
    137         return;
    138     }
    139 
    140     AcpiGbl_StepToNextCall = TRUE;
    141 }
    142 
    143 
    144 /*******************************************************************************
    145  *
    146  * FUNCTION:    AcpiDbSetMethodData
    147  *
    148  * PARAMETERS:  TypeArg         - L for local, A for argument
    149  *              IndexArg        - which one
    150  *              ValueArg        - Value to set.
    151  *
    152  * RETURN:      None
    153  *
    154  * DESCRIPTION: Set a local or argument for the running control method.
    155  *              NOTE: only object supported is Number.
    156  *
    157  ******************************************************************************/
    158 
    159 void
    160 AcpiDbSetMethodData (
    161     char                    *TypeArg,
    162     char                    *IndexArg,
    163     char                    *ValueArg)
    164 {
    165     char                    Type;
    166     UINT32                  Index;
    167     UINT32                  Value;
    168     ACPI_WALK_STATE         *WalkState;
    169     ACPI_OPERAND_OBJECT     *ObjDesc;
    170     ACPI_STATUS             Status;
    171     ACPI_NAMESPACE_NODE     *Node;
    172 
    173 
    174     /* Validate TypeArg */
    175 
    176     AcpiUtStrupr (TypeArg);
    177     Type = TypeArg[0];
    178     if ((Type != 'L') &&
    179         (Type != 'A') &&
    180         (Type != 'N'))
    181     {
    182         AcpiOsPrintf ("Invalid SET operand: %s\n", TypeArg);
    183         return;
    184     }
    185 
    186     Value = strtoul (ValueArg, NULL, 16);
    187 
    188     if (Type == 'N')
    189     {
    190         Node = AcpiDbConvertToNode (IndexArg);
    191         if (!Node)
    192         {
    193             return;
    194         }
    195 
    196         if (Node->Type != ACPI_TYPE_INTEGER)
    197         {
    198             AcpiOsPrintf ("Can only set Integer nodes\n");
    199             return;
    200         }
    201         ObjDesc = Node->Object;
    202         ObjDesc->Integer.Value = Value;
    203         return;
    204     }
    205 
    206     /* Get the index and value */
    207 
    208     Index = strtoul (IndexArg, NULL, 16);
    209 
    210     WalkState = AcpiDsGetCurrentWalkState (AcpiGbl_CurrentWalkList);
    211     if (!WalkState)
    212     {
    213         AcpiOsPrintf ("There is no method currently executing\n");
    214         return;
    215     }
    216 
    217     /* Create and initialize the new object */
    218 
    219     ObjDesc = AcpiUtCreateIntegerObject ((UINT64) Value);
    220     if (!ObjDesc)
    221     {
    222         AcpiOsPrintf ("Could not create an internal object\n");
    223         return;
    224     }
    225 
    226     /* Store the new object into the target */
    227 
    228     switch (Type)
    229     {
    230     case 'A':
    231 
    232         /* Set a method argument */
    233 
    234         if (Index > ACPI_METHOD_MAX_ARG)
    235         {
    236             AcpiOsPrintf ("Arg%u - Invalid argument name\n",
    237                 Index);
    238             goto Cleanup;
    239         }
    240 
    241         Status = AcpiDsStoreObjectToLocal (ACPI_REFCLASS_ARG,
    242             Index, ObjDesc, WalkState);
    243         if (ACPI_FAILURE (Status))
    244         {
    245             goto Cleanup;
    246         }
    247 
    248         ObjDesc = WalkState->Arguments[Index].Object;
    249 
    250         AcpiOsPrintf ("Arg%u: ", Index);
    251         AcpiDbDisplayInternalObject (ObjDesc, WalkState);
    252         break;
    253 
    254     case 'L':
    255 
    256         /* Set a method local */
    257 
    258         if (Index > ACPI_METHOD_MAX_LOCAL)
    259         {
    260             AcpiOsPrintf ("Local%u - Invalid local variable name\n",
    261                 Index);
    262             goto Cleanup;
    263         }
    264 
    265         Status = AcpiDsStoreObjectToLocal (ACPI_REFCLASS_LOCAL,
    266             Index, ObjDesc, WalkState);
    267         if (ACPI_FAILURE (Status))
    268         {
    269             goto Cleanup;
    270         }
    271 
    272         ObjDesc = WalkState->LocalVariables[Index].Object;
    273 
    274         AcpiOsPrintf ("Local%u: ", Index);
    275         AcpiDbDisplayInternalObject (ObjDesc, WalkState);
    276         break;
    277 
    278     default:
    279 
    280         break;
    281     }
    282 
    283 Cleanup:
    284     AcpiUtRemoveReference (ObjDesc);
    285 }
    286 
    287 
    288 #ifdef ACPI_DISASSEMBLER
    289 /*******************************************************************************
    290  *
    291  * FUNCTION:    AcpiDbDisassembleAml
    292  *
    293  * PARAMETERS:  Statements          - Number of statements to disassemble
    294  *              Op                  - Current Op (from parse walk)
    295  *
    296  * RETURN:      None
    297  *
    298  * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
    299  *              of statements specified.
    300  *
    301  ******************************************************************************/
    302 
    303 void
    304 AcpiDbDisassembleAml (
    305     char                    *Statements,
    306     ACPI_PARSE_OBJECT       *Op)
    307 {
    308     UINT32                  NumStatements = 8;
    309 
    310 
    311     if (!Op)
    312     {
    313         AcpiOsPrintf ("There is no method currently executing\n");
    314         return;
    315     }
    316 
    317     if (Statements)
    318     {
    319         NumStatements = strtoul (Statements, NULL, 0);
    320     }
    321 
    322     AcpiDmDisassemble (NULL, Op, NumStatements);
    323 }
    324 
    325 
    326 /*******************************************************************************
    327  *
    328  * FUNCTION:    AcpiDbDisassembleMethod
    329  *
    330  * PARAMETERS:  Name            - Name of control method
    331  *
    332  * RETURN:      None
    333  *
    334  * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
    335  *              of statements specified.
    336  *
    337  ******************************************************************************/
    338 
    339 ACPI_STATUS
    340 AcpiDbDisassembleMethod (
    341     char                    *Name)
    342 {
    343     ACPI_STATUS             Status;
    344     ACPI_PARSE_OBJECT       *Op;
    345     ACPI_WALK_STATE         *WalkState;
    346     ACPI_OPERAND_OBJECT     *ObjDesc;
    347     ACPI_NAMESPACE_NODE     *Method;
    348 
    349 
    350     Method = AcpiDbConvertToNode (Name);
    351     if (!Method)
    352     {
    353         return (AE_BAD_PARAMETER);
    354     }
    355 
    356     if (Method->Type != ACPI_TYPE_METHOD)
    357     {
    358         ACPI_ERROR ((AE_INFO, "%s (%s): Object must be a control method",
    359             Name, AcpiUtGetTypeName (Method->Type)));
    360         return (AE_BAD_PARAMETER);
    361     }
    362 
    363     ObjDesc = Method->Object;
    364 
    365     Op = AcpiPsCreateScopeOp (ObjDesc->Method.AmlStart);
    366     if (!Op)
    367     {
    368         return (AE_NO_MEMORY);
    369     }
    370 
    371     /* Create and initialize a new walk state */
    372 
    373     WalkState = AcpiDsCreateWalkState (0, Op, NULL, NULL);
    374     if (!WalkState)
    375     {
    376         return (AE_NO_MEMORY);
    377     }
    378 
    379     Status = AcpiDsInitAmlWalk (WalkState, Op, NULL,
    380         ObjDesc->Method.AmlStart,
    381         ObjDesc->Method.AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
    382     if (ACPI_FAILURE (Status))
    383     {
    384         return (Status);
    385     }
    386 
    387     Status = AcpiUtAllocateOwnerId (&ObjDesc->Method.OwnerId);
    388     if (ACPI_FAILURE(Status))
    389     {
    390         return (Status);
    391     }
    392 
    393     WalkState->OwnerId = ObjDesc->Method.OwnerId;
    394 
    395     /* Push start scope on scope stack and make it current */
    396 
    397     Status = AcpiDsScopeStackPush (Method,
    398         Method->Type, WalkState);
    399     if (ACPI_FAILURE (Status))
    400     {
    401         return (Status);
    402     }
    403 
    404     /* Parse the entire method AML including deferred operators */
    405 
    406     WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
    407     WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
    408 
    409     Status = AcpiPsParseAml (WalkState);
    410     (void) AcpiDmParseDeferredOps (Op);
    411 
    412     /* Now we can disassemble the method */
    413 
    414     AcpiGbl_DmOpt_Verbose = FALSE;
    415     AcpiDmDisassemble (NULL, Op, 0);
    416     AcpiGbl_DmOpt_Verbose = TRUE;
    417 
    418     AcpiPsDeleteParseTree (Op);
    419 
    420     /* Method cleanup */
    421 
    422     AcpiNsDeleteNamespaceSubtree (Method);
    423     AcpiNsDeleteNamespaceByOwner (ObjDesc->Method.OwnerId);
    424     AcpiUtReleaseOwnerId (&ObjDesc->Method.OwnerId);
    425     return (AE_OK);
    426 }
    427 #endif
    428 
    429 
    430 /*******************************************************************************
    431  *
    432  * FUNCTION:    AcpiDbWalkForExecute
    433  *
    434  * PARAMETERS:  Callback from WalkNamespace
    435  *
    436  * RETURN:      Status
    437  *
    438  * DESCRIPTION: Batch execution module. Currently only executes predefined
    439  *              ACPI names.
    440  *
    441  ******************************************************************************/
    442 
    443 static ACPI_STATUS
    444 AcpiDbWalkForExecute (
    445     ACPI_HANDLE             ObjHandle,
    446     UINT32                  NestingLevel,
    447     void                    *Context,
    448     void                    **ReturnValue)
    449 {
    450     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
    451     ACPI_DB_EXECUTE_WALK    *Info = (ACPI_DB_EXECUTE_WALK *) Context;
    452     ACPI_BUFFER             ReturnObj;
    453     ACPI_STATUS             Status;
    454     char                    *Pathname;
    455     UINT32                  i;
    456     ACPI_DEVICE_INFO        *ObjInfo;
    457     ACPI_OBJECT_LIST        ParamObjects;
    458     ACPI_OBJECT             Params[ACPI_METHOD_NUM_ARGS];
    459     const ACPI_PREDEFINED_INFO *Predefined;
    460 
    461 
    462     Predefined = AcpiUtMatchPredefinedMethod (Node->Name.Ascii);
    463     if (!Predefined)
    464     {
    465         return (AE_OK);
    466     }
    467 
    468     if (Node->Type == ACPI_TYPE_LOCAL_SCOPE)
    469     {
    470         return (AE_OK);
    471     }
    472 
    473     Pathname = AcpiNsGetExternalPathname (Node);
    474     if (!Pathname)
    475     {
    476         return (AE_OK);
    477     }
    478 
    479     /* Get the object info for number of method parameters */
    480 
    481     Status = AcpiGetObjectInfo (ObjHandle, &ObjInfo);
    482     if (ACPI_FAILURE (Status))
    483     {
    484         ACPI_FREE (Pathname);
    485         return (Status);
    486     }
    487 
    488     ParamObjects.Pointer = NULL;
    489     ParamObjects.Count   = 0;
    490 
    491     if (ObjInfo->Type == ACPI_TYPE_METHOD)
    492     {
    493         /* Setup default parameters */
    494 
    495         for (i = 0; i < ObjInfo->ParamCount; i++)
    496         {
    497             Params[i].Type           = ACPI_TYPE_INTEGER;
    498             Params[i].Integer.Value  = 1;
    499         }
    500 
    501         ParamObjects.Pointer     = Params;
    502         ParamObjects.Count       = ObjInfo->ParamCount;
    503     }
    504 
    505     ACPI_FREE (ObjInfo);
    506     ReturnObj.Pointer = NULL;
    507     ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
    508 
    509     /* Do the actual method execution */
    510 
    511     AcpiGbl_MethodExecuting = TRUE;
    512 
    513     Status = AcpiEvaluateObject (Node, NULL, &ParamObjects, &ReturnObj);
    514 
    515     AcpiOsPrintf ("%-32s returned %s\n", Pathname, AcpiFormatException (Status));
    516     AcpiGbl_MethodExecuting = FALSE;
    517     ACPI_FREE (Pathname);
    518 
    519     /* Ignore status from method execution */
    520 
    521     Status = AE_OK;
    522 
    523     /* Update count, check if we have executed enough methods */
    524 
    525     Info->Count++;
    526     if (Info->Count >= Info->MaxCount)
    527     {
    528         Status = AE_CTRL_TERMINATE;
    529     }
    530 
    531     return (Status);
    532 }
    533 
    534 
    535 /*******************************************************************************
    536  *
    537  * FUNCTION:    AcpiDbEvaluatePredefinedNames
    538  *
    539  * PARAMETERS:  None
    540  *
    541  * RETURN:      None
    542  *
    543  * DESCRIPTION: Namespace batch execution. Execute predefined names in the
    544  *              namespace, up to the max count, if specified.
    545  *
    546  ******************************************************************************/
    547 
    548 void
    549 AcpiDbEvaluatePredefinedNames (
    550     void)
    551 {
    552     ACPI_DB_EXECUTE_WALK    Info;
    553 
    554 
    555     Info.Count = 0;
    556     Info.MaxCount = ACPI_UINT32_MAX;
    557 
    558     /* Search all nodes in namespace */
    559 
    560     (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
    561                 AcpiDbWalkForExecute, NULL, (void *) &Info, NULL);
    562 
    563     AcpiOsPrintf ("Evaluated %u predefined names in the namespace\n", Info.Count);
    564 }
    565