1ae115bc7Smrj /******************************************************************************* 2ae115bc7Smrj * 3ae115bc7Smrj * Module Name: dmutils - AML disassembler utilities 4ae115bc7Smrj * 5ae115bc7Smrj ******************************************************************************/ 6ae115bc7Smrj 726f3cdf0SGordon Ross /* 8*385cc6b4SJerry Jelinek * Copyright (C) 2000 - 2016, Intel Corp. 9ae115bc7Smrj * All rights reserved. 10ae115bc7Smrj * 1126f3cdf0SGordon Ross * Redistribution and use in source and binary forms, with or without 1226f3cdf0SGordon Ross * modification, are permitted provided that the following conditions 1326f3cdf0SGordon Ross * are met: 1426f3cdf0SGordon Ross * 1. Redistributions of source code must retain the above copyright 1526f3cdf0SGordon Ross * notice, this list of conditions, and the following disclaimer, 1626f3cdf0SGordon Ross * without modification. 1726f3cdf0SGordon Ross * 2. Redistributions in binary form must reproduce at minimum a disclaimer 1826f3cdf0SGordon Ross * substantially similar to the "NO WARRANTY" disclaimer below 1926f3cdf0SGordon Ross * ("Disclaimer") and any redistribution must be conditioned upon 2026f3cdf0SGordon Ross * including a substantially similar Disclaimer requirement for further 2126f3cdf0SGordon Ross * binary redistribution. 2226f3cdf0SGordon Ross * 3. Neither the names of the above-listed copyright holders nor the names 2326f3cdf0SGordon Ross * of any contributors may be used to endorse or promote products derived 2426f3cdf0SGordon Ross * from this software without specific prior written permission. 25ae115bc7Smrj * 2626f3cdf0SGordon Ross * Alternatively, this software may be distributed under the terms of the 2726f3cdf0SGordon Ross * GNU General Public License ("GPL") version 2 as published by the Free 2826f3cdf0SGordon Ross * Software Foundation. 29ae115bc7Smrj * 3026f3cdf0SGordon Ross * NO WARRANTY 3126f3cdf0SGordon Ross * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 3226f3cdf0SGordon Ross * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 3326f3cdf0SGordon Ross * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 3426f3cdf0SGordon Ross * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 3526f3cdf0SGordon Ross * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3626f3cdf0SGordon Ross * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3726f3cdf0SGordon Ross * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3826f3cdf0SGordon Ross * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 3926f3cdf0SGordon Ross * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 4026f3cdf0SGordon Ross * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 4126f3cdf0SGordon Ross * POSSIBILITY OF SUCH DAMAGES. 4226f3cdf0SGordon Ross */ 43ae115bc7Smrj 44ae115bc7Smrj #include "acpi.h" 45aa2aa9a6SDana Myers #include "accommon.h" 46ae115bc7Smrj #include "amlcode.h" 47ae115bc7Smrj #include "acdisasm.h" 48ae115bc7Smrj 49ae115bc7Smrj #ifdef ACPI_ASL_COMPILER 50ae115bc7Smrj #include <acnamesp.h> 51ae115bc7Smrj #endif 52ae115bc7Smrj 53ae115bc7Smrj 54ae115bc7Smrj #define _COMPONENT ACPI_CA_DEBUGGER 55ae115bc7Smrj ACPI_MODULE_NAME ("dmutils") 56ae115bc7Smrj 57ae115bc7Smrj 58ae115bc7Smrj /* Data used in keeping track of fields */ 59ae115bc7Smrj #if 0 60ae115bc7Smrj const char *AcpiGbl_FENames[] = 61ae115bc7Smrj { 62ae115bc7Smrj "skip", 63ae115bc7Smrj "?access?" 64ae115bc7Smrj }; /* FE = Field Element */ 65ae115bc7Smrj #endif 66ae115bc7Smrj 67ae115bc7Smrj /* Operators for Match() */ 68ae115bc7Smrj 69ae115bc7Smrj const char *AcpiGbl_MatchOps[] = 70ae115bc7Smrj { 71ae115bc7Smrj "MTR", 72ae115bc7Smrj "MEQ", 73ae115bc7Smrj "MLE", 74ae115bc7Smrj "MLT", 75ae115bc7Smrj "MGE", 76ae115bc7Smrj "MGT" 77ae115bc7Smrj }; 78ae115bc7Smrj 79ae115bc7Smrj /* Access type decoding */ 80ae115bc7Smrj 81ae115bc7Smrj const char *AcpiGbl_AccessTypes[] = 82ae115bc7Smrj { 83ae115bc7Smrj "AnyAcc", 84ae115bc7Smrj "ByteAcc", 85ae115bc7Smrj "WordAcc", 86ae115bc7Smrj "DWordAcc", 87ae115bc7Smrj "QWordAcc", 88ae115bc7Smrj "BufferAcc", 89ae115bc7Smrj "InvalidAccType", 90ae115bc7Smrj "InvalidAccType" 91ae115bc7Smrj }; 92ae115bc7Smrj 93ae115bc7Smrj /* Lock rule decoding */ 94ae115bc7Smrj 95ae115bc7Smrj const char *AcpiGbl_LockRule[] = 96ae115bc7Smrj { 97ae115bc7Smrj "NoLock", 98ae115bc7Smrj "Lock" 99ae115bc7Smrj }; 100ae115bc7Smrj 101ae115bc7Smrj /* Update rule decoding */ 102ae115bc7Smrj 103ae115bc7Smrj const char *AcpiGbl_UpdateRules[] = 104ae115bc7Smrj { 105ae115bc7Smrj "Preserve", 106ae115bc7Smrj "WriteAsOnes", 107ae115bc7Smrj "WriteAsZeros", 108ae115bc7Smrj "InvalidUpdateRule" 109ae115bc7Smrj }; 110ae115bc7Smrj 111ae115bc7Smrj /* Strings used to decode resource descriptors */ 112ae115bc7Smrj 113ae115bc7Smrj const char *AcpiGbl_WordDecode[] = 114ae115bc7Smrj { 115ae115bc7Smrj "Memory", 116ae115bc7Smrj "IO", 117ae115bc7Smrj "BusNumber", 118ae115bc7Smrj "UnknownResourceType" 119ae115bc7Smrj }; 120ae115bc7Smrj 121ae115bc7Smrj const char *AcpiGbl_IrqDecode[] = 122ae115bc7Smrj { 123ae115bc7Smrj "IRQNoFlags", 124ae115bc7Smrj "IRQ" 125ae115bc7Smrj }; 126ae115bc7Smrj 127ae115bc7Smrj 128ae115bc7Smrj /******************************************************************************* 129ae115bc7Smrj * 130ae115bc7Smrj * FUNCTION: AcpiDmDecodeAttribute 131ae115bc7Smrj * 132ae115bc7Smrj * PARAMETERS: Attribute - Attribute field of AccessAs keyword 133ae115bc7Smrj * 134ae115bc7Smrj * RETURN: None 135ae115bc7Smrj * 136*385cc6b4SJerry Jelinek * DESCRIPTION: Decode the AccessAs attribute byte. (Mostly SMBus and 137*385cc6b4SJerry Jelinek * GenericSerialBus stuff.) 138ae115bc7Smrj * 139ae115bc7Smrj ******************************************************************************/ 140ae115bc7Smrj 141ae115bc7Smrj void 142ae115bc7Smrj AcpiDmDecodeAttribute ( 143ae115bc7Smrj UINT8 Attribute) 144ae115bc7Smrj { 145ae115bc7Smrj 146ae115bc7Smrj switch (Attribute) 147ae115bc7Smrj { 148*385cc6b4SJerry Jelinek case AML_FIELD_ATTRIB_QUICK: 149ae115bc7Smrj 150*385cc6b4SJerry Jelinek AcpiOsPrintf ("AttribQuick"); 151ae115bc7Smrj break; 152ae115bc7Smrj 153*385cc6b4SJerry Jelinek case AML_FIELD_ATTRIB_SEND_RCV: 154ae115bc7Smrj 155*385cc6b4SJerry Jelinek AcpiOsPrintf ("AttribSendReceive"); 156ae115bc7Smrj break; 157ae115bc7Smrj 158*385cc6b4SJerry Jelinek case AML_FIELD_ATTRIB_BYTE: 159ae115bc7Smrj 160*385cc6b4SJerry Jelinek AcpiOsPrintf ("AttribByte"); 161ae115bc7Smrj break; 162ae115bc7Smrj 163*385cc6b4SJerry Jelinek case AML_FIELD_ATTRIB_WORD: 164ae115bc7Smrj 165*385cc6b4SJerry Jelinek AcpiOsPrintf ("AttribWord"); 166ae115bc7Smrj break; 167ae115bc7Smrj 168*385cc6b4SJerry Jelinek case AML_FIELD_ATTRIB_BLOCK: 169ae115bc7Smrj 170*385cc6b4SJerry Jelinek AcpiOsPrintf ("AttribBlock"); 171ae115bc7Smrj break; 172ae115bc7Smrj 173*385cc6b4SJerry Jelinek case AML_FIELD_ATTRIB_MULTIBYTE: 174ae115bc7Smrj 175*385cc6b4SJerry Jelinek AcpiOsPrintf ("AttribBytes"); 176ae115bc7Smrj break; 177ae115bc7Smrj 178*385cc6b4SJerry Jelinek case AML_FIELD_ATTRIB_WORD_CALL: 179ae115bc7Smrj 180*385cc6b4SJerry Jelinek AcpiOsPrintf ("AttribProcessCall"); 181*385cc6b4SJerry Jelinek break; 182*385cc6b4SJerry Jelinek 183*385cc6b4SJerry Jelinek case AML_FIELD_ATTRIB_BLOCK_CALL: 184*385cc6b4SJerry Jelinek 185*385cc6b4SJerry Jelinek AcpiOsPrintf ("AttribBlockProcessCall"); 186*385cc6b4SJerry Jelinek break; 187*385cc6b4SJerry Jelinek 188*385cc6b4SJerry Jelinek case AML_FIELD_ATTRIB_RAW_BYTES: 189*385cc6b4SJerry Jelinek 190*385cc6b4SJerry Jelinek AcpiOsPrintf ("AttribRawBytes"); 191*385cc6b4SJerry Jelinek break; 192*385cc6b4SJerry Jelinek 193*385cc6b4SJerry Jelinek case AML_FIELD_ATTRIB_RAW_PROCESS: 194*385cc6b4SJerry Jelinek 195*385cc6b4SJerry Jelinek AcpiOsPrintf ("AttribRawProcessBytes"); 196ae115bc7Smrj break; 197ae115bc7Smrj 198ae115bc7Smrj default: 199ae115bc7Smrj 200*385cc6b4SJerry Jelinek /* A ByteConst is allowed by the grammar */ 201*385cc6b4SJerry Jelinek 202*385cc6b4SJerry Jelinek AcpiOsPrintf ("0x%2.2X", Attribute); 203ae115bc7Smrj break; 204ae115bc7Smrj } 205ae115bc7Smrj } 206ae115bc7Smrj 207ae115bc7Smrj 208ae115bc7Smrj /******************************************************************************* 209ae115bc7Smrj * 210ae115bc7Smrj * FUNCTION: AcpiDmIndent 211ae115bc7Smrj * 212ae115bc7Smrj * PARAMETERS: Level - Current source code indentation level 213ae115bc7Smrj * 214ae115bc7Smrj * RETURN: None 215ae115bc7Smrj * 216ae115bc7Smrj * DESCRIPTION: Indent 4 spaces per indentation level. 217ae115bc7Smrj * 218ae115bc7Smrj ******************************************************************************/ 219ae115bc7Smrj 220ae115bc7Smrj void 221ae115bc7Smrj AcpiDmIndent ( 222ae115bc7Smrj UINT32 Level) 223ae115bc7Smrj { 224ae115bc7Smrj 225ae115bc7Smrj if (!Level) 226ae115bc7Smrj { 227ae115bc7Smrj return; 228ae115bc7Smrj } 229ae115bc7Smrj 230*385cc6b4SJerry Jelinek AcpiOsPrintf ("%*.s", (Level * 4), " "); 231ae115bc7Smrj } 232ae115bc7Smrj 233ae115bc7Smrj 234ae115bc7Smrj /******************************************************************************* 235ae115bc7Smrj * 236ae115bc7Smrj * FUNCTION: AcpiDmCommaIfListMember 237ae115bc7Smrj * 238ae115bc7Smrj * PARAMETERS: Op - Current operator/operand 239ae115bc7Smrj * 240ae115bc7Smrj * RETURN: TRUE if a comma was inserted 241ae115bc7Smrj * 242ae115bc7Smrj * DESCRIPTION: Insert a comma if this Op is a member of an argument list. 243ae115bc7Smrj * 244ae115bc7Smrj ******************************************************************************/ 245ae115bc7Smrj 246ae115bc7Smrj BOOLEAN 247ae115bc7Smrj AcpiDmCommaIfListMember ( 248ae115bc7Smrj ACPI_PARSE_OBJECT *Op) 249ae115bc7Smrj { 250ae115bc7Smrj 251ae115bc7Smrj if (!Op->Common.Next) 252ae115bc7Smrj { 253*385cc6b4SJerry Jelinek return (FALSE); 254ae115bc7Smrj } 255ae115bc7Smrj 256ae115bc7Smrj if (AcpiDmListType (Op->Common.Parent) & BLOCK_COMMA_LIST) 257ae115bc7Smrj { 258*385cc6b4SJerry Jelinek /* Exit if Target has been marked IGNORE */ 259*385cc6b4SJerry Jelinek 260*385cc6b4SJerry Jelinek if (Op->Common.Next->Common.DisasmFlags & ACPI_PARSEOP_IGNORE) 261*385cc6b4SJerry Jelinek { 262*385cc6b4SJerry Jelinek return (FALSE); 263*385cc6b4SJerry Jelinek } 264*385cc6b4SJerry Jelinek 265ae115bc7Smrj /* Check for a NULL target operand */ 266ae115bc7Smrj 267ae115bc7Smrj if ((Op->Common.Next->Common.AmlOpcode == AML_INT_NAMEPATH_OP) && 268ae115bc7Smrj (!Op->Common.Next->Common.Value.String)) 269ae115bc7Smrj { 270ae115bc7Smrj /* 271ae115bc7Smrj * To handle the Divide() case where there are two optional 272ae115bc7Smrj * targets, look ahead one more op. If null, this null target 273ae115bc7Smrj * is the one and only target -- no comma needed. Otherwise, 274ae115bc7Smrj * we need a comma to prepare for the next target. 275ae115bc7Smrj */ 276ae115bc7Smrj if (!Op->Common.Next->Common.Next) 277ae115bc7Smrj { 278*385cc6b4SJerry Jelinek return (FALSE); 279ae115bc7Smrj } 280ae115bc7Smrj } 281ae115bc7Smrj 282*385cc6b4SJerry Jelinek if ((Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMETER_LIST) && 283*385cc6b4SJerry Jelinek (!(Op->Common.Next->Common.DisasmFlags & ACPI_PARSEOP_PARAMETER_LIST))) 284ae115bc7Smrj { 285*385cc6b4SJerry Jelinek return (FALSE); 286ae115bc7Smrj } 287ae115bc7Smrj 288*385cc6b4SJerry Jelinek /* Emit comma only if this is not a C-style operator */ 289*385cc6b4SJerry Jelinek 290*385cc6b4SJerry Jelinek if (!Op->Common.OperatorSymbol) 291*385cc6b4SJerry Jelinek { 292ae115bc7Smrj AcpiOsPrintf (", "); 293*385cc6b4SJerry Jelinek } 294*385cc6b4SJerry Jelinek 295ae115bc7Smrj return (TRUE); 296ae115bc7Smrj } 297ae115bc7Smrj 298*385cc6b4SJerry Jelinek else if ((Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMETER_LIST) && 299*385cc6b4SJerry Jelinek (Op->Common.Next->Common.DisasmFlags & ACPI_PARSEOP_PARAMETER_LIST)) 300ae115bc7Smrj { 301ae115bc7Smrj AcpiOsPrintf (", "); 302ae115bc7Smrj return (TRUE); 303ae115bc7Smrj } 304ae115bc7Smrj 305ae115bc7Smrj return (FALSE); 306ae115bc7Smrj } 307ae115bc7Smrj 308ae115bc7Smrj 309ae115bc7Smrj /******************************************************************************* 310ae115bc7Smrj * 311ae115bc7Smrj * FUNCTION: AcpiDmCommaIfFieldMember 312ae115bc7Smrj * 313ae115bc7Smrj * PARAMETERS: Op - Current operator/operand 314ae115bc7Smrj * 315ae115bc7Smrj * RETURN: None 316ae115bc7Smrj * 317ae115bc7Smrj * DESCRIPTION: Insert a comma if this Op is a member of a Field argument list. 318ae115bc7Smrj * 319ae115bc7Smrj ******************************************************************************/ 320ae115bc7Smrj 321ae115bc7Smrj void 322ae115bc7Smrj AcpiDmCommaIfFieldMember ( 323ae115bc7Smrj ACPI_PARSE_OBJECT *Op) 324ae115bc7Smrj { 325ae115bc7Smrj 326ae115bc7Smrj if (Op->Common.Next) 327ae115bc7Smrj { 328ae115bc7Smrj AcpiOsPrintf (", "); 329ae115bc7Smrj } 330ae115bc7Smrj } 331