Path: blob/main/sys/contrib/dev/acpica/components/disassembler/dmutils.c
48524 views
/*******************************************************************************1*2* Module Name: dmutils - AML disassembler utilities3*4******************************************************************************/56/******************************************************************************7*8* 1. Copyright Notice9*10* Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.11* All rights reserved.12*13* 2. License14*15* 2.1. This is your license from Intel Corp. under its intellectual property16* rights. You may have additional license terms from the party that provided17* you this software, covering your right to use that party's intellectual18* property rights.19*20* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a21* copy of the source code appearing in this file ("Covered Code") an22* irrevocable, perpetual, worldwide license under Intel's copyrights in the23* base code distributed originally by Intel ("Original Intel Code") to copy,24* make derivatives, distribute, use and display any portion of the Covered25* Code in any form, with the right to sublicense such rights; and26*27* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent28* license (with the right to sublicense), under only those claims of Intel29* patents that are infringed by the Original Intel Code, to make, use, sell,30* offer to sell, and import the Covered Code and derivative works thereof31* solely to the minimum extent necessary to exercise the above copyright32* license, and in no event shall the patent license extend to any additions33* to or modifications of the Original Intel Code. No other license or right34* is granted directly or by implication, estoppel or otherwise;35*36* The above copyright and patent license is granted only if the following37* conditions are met:38*39* 3. Conditions40*41* 3.1. Redistribution of Source with Rights to Further Distribute Source.42* Redistribution of source code of any substantial portion of the Covered43* Code or modification with rights to further distribute source must include44* the above Copyright Notice, the above License, this list of Conditions,45* and the following Disclaimer and Export Compliance provision. In addition,46* Licensee must cause all Covered Code to which Licensee contributes to47* contain a file documenting the changes Licensee made to create that Covered48* Code and the date of any change. Licensee must include in that file the49* documentation of any changes made by any predecessor Licensee. Licensee50* must include a prominent statement that the modification is derived,51* directly or indirectly, from Original Intel Code.52*53* 3.2. Redistribution of Source with no Rights to Further Distribute Source.54* Redistribution of source code of any substantial portion of the Covered55* Code or modification without rights to further distribute source must56* include the following Disclaimer and Export Compliance provision in the57* documentation and/or other materials provided with distribution. In58* addition, Licensee may not authorize further sublicense of source of any59* portion of the Covered Code, and must include terms to the effect that the60* license from Licensee to its licensee is limited to the intellectual61* property embodied in the software Licensee provides to its licensee, and62* not to intellectual property embodied in modifications its licensee may63* make.64*65* 3.3. Redistribution of Executable. Redistribution in executable form of any66* substantial portion of the Covered Code or modification must reproduce the67* above Copyright Notice, and the following Disclaimer and Export Compliance68* provision in the documentation and/or other materials provided with the69* distribution.70*71* 3.4. Intel retains all right, title, and interest in and to the Original72* Intel Code.73*74* 3.5. Neither the name Intel nor any other trademark owned or controlled by75* Intel shall be used in advertising or otherwise to promote the sale, use or76* other dealings in products derived from or relating to the Covered Code77* without prior written authorization from Intel.78*79* 4. Disclaimer and Export Compliance80*81* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED82* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE83* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,84* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY85* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY86* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A87* PARTICULAR PURPOSE.88*89* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES90* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR91* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,92* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY93* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL94* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS95* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY96* LIMITED REMEDY.97*98* 4.3. Licensee shall not export, either directly or indirectly, any of this99* software or system incorporating such software without first obtaining any100* required license or other approval from the U. S. Department of Commerce or101* any other agency or department of the United States Government. In the102* event Licensee exports any such software from the United States or103* re-exports any such software from a foreign destination, Licensee shall104* ensure that the distribution and export/re-export of the software is in105* compliance with all laws, regulations, orders, or other restrictions of the106* U.S. Export Administration Regulations. Licensee agrees that neither it nor107* any of its subsidiaries will export/re-export any technical data, process,108* software, or service, directly or indirectly, to any country for which the109* United States government or any agency thereof requires an export license,110* other governmental approval, or letter of assurance, without first obtaining111* such license, approval or letter.112*113*****************************************************************************114*115* Alternatively, you may choose to be licensed under the terms of the116* following license:117*118* Redistribution and use in source and binary forms, with or without119* modification, are permitted provided that the following conditions120* are met:121* 1. Redistributions of source code must retain the above copyright122* notice, this list of conditions, and the following disclaimer,123* without modification.124* 2. Redistributions in binary form must reproduce at minimum a disclaimer125* substantially similar to the "NO WARRANTY" disclaimer below126* ("Disclaimer") and any redistribution must be conditioned upon127* including a substantially similar Disclaimer requirement for further128* binary redistribution.129* 3. Neither the names of the above-listed copyright holders nor the names130* of any contributors may be used to endorse or promote products derived131* from this software without specific prior written permission.132*133* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS134* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT135* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR136* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT137* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,138* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT139* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,140* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY141* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT142* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE143* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.144*145* Alternatively, you may choose to be licensed under the terms of the146* GNU General Public License ("GPL") version 2 as published by the Free147* Software Foundation.148*149*****************************************************************************/150151#include <contrib/dev/acpica/include/acpi.h>152#include <contrib/dev/acpica/include/accommon.h>153#include <contrib/dev/acpica/include/amlcode.h>154#include <contrib/dev/acpica/include/acdisasm.h>155#include <contrib/dev/acpica/include/acconvert.h>156157#ifdef ACPI_ASL_COMPILER158#include <contrib/dev/acpica/include/acnamesp.h>159#endif160161162#define _COMPONENT ACPI_CA_DEBUGGER163ACPI_MODULE_NAME ("dmutils")164165166/* Data used in keeping track of fields */167#if 0168const char *AcpiGbl_FENames[] =169{170"skip",171"?access?"172}; /* FE = Field Element */173#endif174175/* Operators for Match() */176177const char *AcpiGbl_MatchOps[] =178{179"MTR",180"MEQ",181"MLE",182"MLT",183"MGE",184"MGT"185};186187/* Access type decoding */188189const char *AcpiGbl_AccessTypes[] =190{191"AnyAcc",192"ByteAcc",193"WordAcc",194"DWordAcc",195"QWordAcc",196"BufferAcc",197"InvalidAccType",198"InvalidAccType"199};200201/* Lock rule decoding */202203const char *AcpiGbl_LockRule[] =204{205"NoLock",206"Lock"207};208209/* Update rule decoding */210211const char *AcpiGbl_UpdateRules[] =212{213"Preserve",214"WriteAsOnes",215"WriteAsZeros",216"InvalidUpdateRule"217};218219/* Strings used to decode resource descriptors */220221const char *AcpiGbl_WordDecode[] =222{223"Memory",224"IO",225"BusNumber",226"UnknownResourceType"227};228229const char *AcpiGbl_IrqDecode[] =230{231"IRQNoFlags",232"IRQ"233};234235236/*******************************************************************************237*238* FUNCTION: AcpiDmDecodeAttribute239*240* PARAMETERS: Attribute - Attribute field of AccessAs keyword241*242* RETURN: None243*244* DESCRIPTION: Decode the AccessAs attribute byte. (Mostly SMBus and245* GenericSerialBus stuff.)246*247******************************************************************************/248249void250AcpiDmDecodeAttribute (251UINT8 Attribute)252{253254switch (Attribute)255{256case AML_FIELD_ATTRIB_QUICK:257258AcpiOsPrintf ("AttribQuick");259break;260261case AML_FIELD_ATTRIB_SEND_RECEIVE:262263AcpiOsPrintf ("AttribSendReceive");264break;265266case AML_FIELD_ATTRIB_BYTE:267268AcpiOsPrintf ("AttribByte");269break;270271case AML_FIELD_ATTRIB_WORD:272273AcpiOsPrintf ("AttribWord");274break;275276case AML_FIELD_ATTRIB_BLOCK:277278AcpiOsPrintf ("AttribBlock");279break;280281case AML_FIELD_ATTRIB_BYTES:282283AcpiOsPrintf ("AttribBytes");284break;285286case AML_FIELD_ATTRIB_PROCESS_CALL:287288AcpiOsPrintf ("AttribProcessCall");289break;290291case AML_FIELD_ATTRIB_BLOCK_PROCESS_CALL:292293AcpiOsPrintf ("AttribBlockProcessCall");294break;295296case AML_FIELD_ATTRIB_RAW_BYTES:297298AcpiOsPrintf ("AttribRawBytes");299break;300301case AML_FIELD_ATTRIB_RAW_PROCESS_BYTES:302303AcpiOsPrintf ("AttribRawProcessBytes");304break;305306default:307308/* A ByteConst is allowed by the grammar */309310AcpiOsPrintf ("0x%2.2X", Attribute);311break;312}313}314315316/*******************************************************************************317*318* FUNCTION: AcpiDmIndent319*320* PARAMETERS: Level - Current source code indentation level321*322* RETURN: None323*324* DESCRIPTION: Indent 4 spaces per indentation level.325*326******************************************************************************/327328void329AcpiDmIndent (330UINT32 Level)331{332333if (!Level)334{335return;336}337338AcpiOsPrintf ("%*.s", (Level * 4), " ");339}340341342/*******************************************************************************343*344* FUNCTION: AcpiDmCommaIfListMember345*346* PARAMETERS: Op - Current operator/operand347*348* RETURN: TRUE if a comma was inserted349*350* DESCRIPTION: Insert a comma if this Op is a member of an argument list.351*352******************************************************************************/353354BOOLEAN355AcpiDmCommaIfListMember (356ACPI_PARSE_OBJECT *Op)357{358359if (!Op->Common.Next)360{361ASL_CV_PRINT_ONE_COMMENT (Op, AMLCOMMENT_INLINE, NULL, 0);362return (FALSE);363}364365if (AcpiDmListType (Op->Common.Parent) & BLOCK_COMMA_LIST)366{367/* Exit if Target has been marked IGNORE */368369if (Op->Common.Next->Common.DisasmFlags & ACPI_PARSEOP_IGNORE)370{371ASL_CV_PRINT_ONE_COMMENT (Op, AMLCOMMENT_INLINE, NULL, 0);372return (FALSE);373}374375/* Check for a NULL target operand */376377if ((Op->Common.Next->Common.AmlOpcode == AML_INT_NAMEPATH_OP) &&378(!Op->Common.Next->Common.Value.String))379{380/*381* To handle the Divide() case where there are two optional382* targets, look ahead one more op. If null, this null target383* is the one and only target -- no comma needed. Otherwise,384* we need a comma to prepare for the next target.385*/386if (!Op->Common.Next->Common.Next)387{388ASL_CV_PRINT_ONE_COMMENT (Op, AMLCOMMENT_INLINE, NULL, 0);389return (FALSE);390}391}392393if ((Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMETER_LIST) &&394(!(Op->Common.Next->Common.DisasmFlags & ACPI_PARSEOP_PARAMETER_LIST)))395{396ASL_CV_PRINT_ONE_COMMENT (Op, AMLCOMMENT_INLINE, NULL, 0);397return (FALSE);398}399400/* Emit comma only if this is not a C-style operator */401402if (!Op->Common.OperatorSymbol)403{404AcpiOsPrintf (", ");405ASL_CV_PRINT_ONE_COMMENT (Op, AMLCOMMENT_INLINE, NULL, 0);406}407408return (TRUE);409}410411else if ((Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMETER_LIST) &&412(Op->Common.Next->Common.DisasmFlags & ACPI_PARSEOP_PARAMETER_LIST))413{414AcpiOsPrintf (", ");415ASL_CV_PRINT_ONE_COMMENT (Op, AMLCOMMENT_INLINE, NULL, 0);416417return (TRUE);418}419420return (FALSE);421}422423424/*******************************************************************************425*426* FUNCTION: AcpiDmCommaIfFieldMember427*428* PARAMETERS: Op - Current operator/operand429*430* RETURN: None431*432* DESCRIPTION: Insert a comma if this Op is a member of a Field argument list.433*434******************************************************************************/435436void437AcpiDmCommaIfFieldMember (438ACPI_PARSE_OBJECT *Op)439{440441if (Op->Common.Next)442{443AcpiOsPrintf (", ");444}445}446447448