Home | History | Annotate | Line # | Download | only in disassembler
dmutils.c revision 1.1.1.13.6.1
      1 /*******************************************************************************
      2  *
      3  * Module Name: dmutils - AML disassembler utilities
      4  *
      5  ******************************************************************************/
      6 
      7 /*
      8  * Copyright (C) 2000 - 2021, 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 MERCHANTABILITY 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 "amlcode.h"
     47 #include "acdisasm.h"
     48 #include "acconvert.h"
     49 
     50 #ifdef ACPI_ASL_COMPILER
     51 #include <acnamesp.h>
     52 #endif
     53 
     54 
     55 #define _COMPONENT          ACPI_CA_DEBUGGER
     56         ACPI_MODULE_NAME    ("dmutils")
     57 
     58 
     59 /* Data used in keeping track of fields */
     60 #if 0
     61 const char                      *AcpiGbl_FENames[] =
     62 {
     63     "skip",
     64     "?access?"
     65 };              /* FE = Field Element */
     66 #endif
     67 
     68 /* Operators for Match() */
     69 
     70 const char                      *AcpiGbl_MatchOps[] =
     71 {
     72     "MTR",
     73     "MEQ",
     74     "MLE",
     75     "MLT",
     76     "MGE",
     77     "MGT"
     78 };
     79 
     80 /* Access type decoding */
     81 
     82 const char                      *AcpiGbl_AccessTypes[] =
     83 {
     84     "AnyAcc",
     85     "ByteAcc",
     86     "WordAcc",
     87     "DWordAcc",
     88     "QWordAcc",
     89     "BufferAcc",
     90     "InvalidAccType",
     91     "InvalidAccType"
     92 };
     93 
     94 /* Lock rule decoding */
     95 
     96 const char                      *AcpiGbl_LockRule[] =
     97 {
     98     "NoLock",
     99     "Lock"
    100 };
    101 
    102 /* Update rule decoding */
    103 
    104 const char                      *AcpiGbl_UpdateRules[] =
    105 {
    106     "Preserve",
    107     "WriteAsOnes",
    108     "WriteAsZeros",
    109     "InvalidUpdateRule"
    110 };
    111 
    112 /* Strings used to decode resource descriptors */
    113 
    114 const char                      *AcpiGbl_WordDecode[] =
    115 {
    116     "Memory",
    117     "IO",
    118     "BusNumber",
    119     "UnknownResourceType"
    120 };
    121 
    122 const char                      *AcpiGbl_IrqDecode[] =
    123 {
    124     "IRQNoFlags",
    125     "IRQ"
    126 };
    127 
    128 
    129 /*******************************************************************************
    130  *
    131  * FUNCTION:    AcpiDmDecodeAttribute
    132  *
    133  * PARAMETERS:  Attribute       - Attribute field of AccessAs keyword
    134  *
    135  * RETURN:      None
    136  *
    137  * DESCRIPTION: Decode the AccessAs attribute byte. (Mostly SMBus and
    138  *              GenericSerialBus stuff.)
    139  *
    140  ******************************************************************************/
    141 
    142 void
    143 AcpiDmDecodeAttribute (
    144     UINT8                   Attribute)
    145 {
    146 
    147     switch (Attribute)
    148     {
    149     case AML_FIELD_ATTRIB_QUICK:
    150 
    151         AcpiOsPrintf ("AttribQuick");
    152         break;
    153 
    154     case AML_FIELD_ATTRIB_SEND_RECEIVE:
    155 
    156         AcpiOsPrintf ("AttribSendReceive");
    157         break;
    158 
    159     case AML_FIELD_ATTRIB_BYTE:
    160 
    161         AcpiOsPrintf ("AttribByte");
    162         break;
    163 
    164     case AML_FIELD_ATTRIB_WORD:
    165 
    166         AcpiOsPrintf ("AttribWord");
    167         break;
    168 
    169     case AML_FIELD_ATTRIB_BLOCK:
    170 
    171         AcpiOsPrintf ("AttribBlock");
    172         break;
    173 
    174     case AML_FIELD_ATTRIB_BYTES:
    175 
    176         AcpiOsPrintf ("AttribBytes");
    177         break;
    178 
    179     case AML_FIELD_ATTRIB_PROCESS_CALL:
    180 
    181         AcpiOsPrintf ("AttribProcessCall");
    182         break;
    183 
    184     case AML_FIELD_ATTRIB_BLOCK_PROCESS_CALL:
    185 
    186         AcpiOsPrintf ("AttribBlockProcessCall");
    187         break;
    188 
    189     case AML_FIELD_ATTRIB_RAW_BYTES:
    190 
    191         AcpiOsPrintf ("AttribRawBytes");
    192         break;
    193 
    194     case AML_FIELD_ATTRIB_RAW_PROCESS_BYTES:
    195 
    196         AcpiOsPrintf ("AttribRawProcessBytes");
    197         break;
    198 
    199     default:
    200 
    201         /* A ByteConst is allowed by the grammar */
    202 
    203         AcpiOsPrintf ("0x%2.2X", Attribute);
    204         break;
    205     }
    206 }
    207 
    208 
    209 /*******************************************************************************
    210  *
    211  * FUNCTION:    AcpiDmIndent
    212  *
    213  * PARAMETERS:  Level               - Current source code indentation level
    214  *
    215  * RETURN:      None
    216  *
    217  * DESCRIPTION: Indent 4 spaces per indentation level.
    218  *
    219  ******************************************************************************/
    220 
    221 void
    222 AcpiDmIndent (
    223     UINT32                  Level)
    224 {
    225 
    226     if (!Level)
    227     {
    228         return;
    229     }
    230 
    231     AcpiOsPrintf ("%*.s", (Level * 4), " ");
    232 }
    233 
    234 
    235 /*******************************************************************************
    236  *
    237  * FUNCTION:    AcpiDmCommaIfListMember
    238  *
    239  * PARAMETERS:  Op              - Current operator/operand
    240  *
    241  * RETURN:      TRUE if a comma was inserted
    242  *
    243  * DESCRIPTION: Insert a comma if this Op is a member of an argument list.
    244  *
    245  ******************************************************************************/
    246 
    247 BOOLEAN
    248 AcpiDmCommaIfListMember (
    249     ACPI_PARSE_OBJECT       *Op)
    250 {
    251 
    252     if (!Op->Common.Next)
    253     {
    254         ASL_CV_PRINT_ONE_COMMENT (Op, AMLCOMMENT_INLINE, NULL, 0);
    255         return (FALSE);
    256     }
    257 
    258     if (AcpiDmListType (Op->Common.Parent) & BLOCK_COMMA_LIST)
    259     {
    260         /* Exit if Target has been marked IGNORE */
    261 
    262         if (Op->Common.Next->Common.DisasmFlags & ACPI_PARSEOP_IGNORE)
    263         {
    264             ASL_CV_PRINT_ONE_COMMENT (Op, AMLCOMMENT_INLINE, NULL, 0);
    265             return (FALSE);
    266         }
    267 
    268         /* Check for a NULL target operand */
    269 
    270         if ((Op->Common.Next->Common.AmlOpcode == AML_INT_NAMEPATH_OP) &&
    271             (!Op->Common.Next->Common.Value.String))
    272         {
    273             /*
    274              * To handle the Divide() case where there are two optional
    275              * targets, look ahead one more op. If null, this null target
    276              * is the one and only target -- no comma needed. Otherwise,
    277              * we need a comma to prepare for the next target.
    278              */
    279             if (!Op->Common.Next->Common.Next)
    280             {
    281                 ASL_CV_PRINT_ONE_COMMENT (Op, AMLCOMMENT_INLINE, NULL, 0);
    282                 return (FALSE);
    283             }
    284         }
    285 
    286         if ((Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMETER_LIST) &&
    287             (!(Op->Common.Next->Common.DisasmFlags & ACPI_PARSEOP_PARAMETER_LIST)))
    288         {
    289             ASL_CV_PRINT_ONE_COMMENT (Op, AMLCOMMENT_INLINE, NULL, 0);
    290             return (FALSE);
    291         }
    292 
    293         /* Emit comma only if this is not a C-style operator */
    294 
    295         if (!Op->Common.OperatorSymbol)
    296         {
    297             AcpiOsPrintf (", ");
    298             ASL_CV_PRINT_ONE_COMMENT (Op, AMLCOMMENT_INLINE, NULL, 0);
    299         }
    300 
    301         return (TRUE);
    302     }
    303 
    304     else if ((Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMETER_LIST) &&
    305              (Op->Common.Next->Common.DisasmFlags & ACPI_PARSEOP_PARAMETER_LIST))
    306     {
    307         AcpiOsPrintf (", ");
    308         ASL_CV_PRINT_ONE_COMMENT (Op, AMLCOMMENT_INLINE, NULL, 0);
    309 
    310         return (TRUE);
    311     }
    312 
    313     return (FALSE);
    314 }
    315 
    316 
    317 /*******************************************************************************
    318  *
    319  * FUNCTION:    AcpiDmCommaIfFieldMember
    320  *
    321  * PARAMETERS:  Op              - Current operator/operand
    322  *
    323  * RETURN:      None
    324  *
    325  * DESCRIPTION: Insert a comma if this Op is a member of a Field argument list.
    326  *
    327  ******************************************************************************/
    328 
    329 void
    330 AcpiDmCommaIfFieldMember (
    331     ACPI_PARSE_OBJECT       *Op)
    332 {
    333 
    334     if (Op->Common.Next)
    335     {
    336         AcpiOsPrintf (", ");
    337     }
    338 }
    339