Path: blob/main/sys/contrib/dev/acpica/components/debugger/dbobject.c
48406 views
/*******************************************************************************1*2* Module Name: dbobject - ACPI object decode and display3*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/acnamesp.h>154#include <contrib/dev/acpica/include/acdebug.h>155156157#define _COMPONENT ACPI_CA_DEBUGGER158ACPI_MODULE_NAME ("dbobject")159160161/* Local prototypes */162163static void164AcpiDbDecodeNode (165ACPI_NAMESPACE_NODE *Node);166167168/*******************************************************************************169*170* FUNCTION: AcpiDbDumpMethodInfo171*172* PARAMETERS: Status - Method execution status173* WalkState - Current state of the parse tree walk174*175* RETURN: None176*177* DESCRIPTION: Called when a method has been aborted because of an error.178* Dumps the method execution stack, and the method locals/args,179* and disassembles the AML opcode that failed.180*181******************************************************************************/182183void184AcpiDbDumpMethodInfo (185ACPI_STATUS Status,186ACPI_WALK_STATE *WalkState)187{188ACPI_THREAD_STATE *Thread;189ACPI_NAMESPACE_NODE *Node;190191192Node = WalkState->MethodNode;193194/* There are no locals or arguments for the module-level code case */195196if (Node == AcpiGbl_RootNode)197{198return;199}200201/* Ignore control codes, they are not errors */202203if (ACPI_CNTL_EXCEPTION (Status))204{205return;206}207208/* We may be executing a deferred opcode */209210if (WalkState->DeferredNode)211{212AcpiOsPrintf ("Executing subtree for Buffer/Package/Region\n");213return;214}215216/*217* If there is no Thread, we are not actually executing a method.218* This can happen when the iASL compiler calls the interpreter219* to perform constant folding.220*/221Thread = WalkState->Thread;222if (!Thread)223{224return;225}226227/* Display the method locals and arguments */228229AcpiOsPrintf ("\n");230AcpiDbDecodeLocals (WalkState);231AcpiOsPrintf ("\n");232AcpiDbDecodeArguments (WalkState);233AcpiOsPrintf ("\n");234}235236237/*******************************************************************************238*239* FUNCTION: AcpiDbDecodeInternalObject240*241* PARAMETERS: ObjDesc - Object to be displayed242*243* RETURN: None244*245* DESCRIPTION: Short display of an internal object. Numbers/Strings/Buffers.246*247******************************************************************************/248249void250AcpiDbDecodeInternalObject (251ACPI_OPERAND_OBJECT *ObjDesc)252{253UINT32 i;254255256if (!ObjDesc)257{258AcpiOsPrintf (" Uninitialized");259return;260}261262if (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) != ACPI_DESC_TYPE_OPERAND)263{264AcpiOsPrintf (" %p [%s]", ObjDesc,265AcpiUtGetDescriptorName (ObjDesc));266return;267}268269AcpiOsPrintf (" %s", AcpiUtGetObjectTypeName (ObjDesc));270271switch (ObjDesc->Common.Type)272{273case ACPI_TYPE_INTEGER:274275AcpiOsPrintf (" %8.8X%8.8X",276ACPI_FORMAT_UINT64 (ObjDesc->Integer.Value));277break;278279case ACPI_TYPE_STRING:280281AcpiOsPrintf ("(%u) \"%.60s",282ObjDesc->String.Length, ObjDesc->String.Pointer);283284if (ObjDesc->String.Length > 60)285{286AcpiOsPrintf ("...");287}288else289{290AcpiOsPrintf ("\"");291}292break;293294case ACPI_TYPE_BUFFER:295296AcpiOsPrintf ("(%u)", ObjDesc->Buffer.Length);297for (i = 0; (i < 8) && (i < ObjDesc->Buffer.Length); i++)298{299AcpiOsPrintf (" %2.2X", ObjDesc->Buffer.Pointer[i]);300}301break;302303default:304305AcpiOsPrintf (" %p", ObjDesc);306break;307}308}309310311/*******************************************************************************312*313* FUNCTION: AcpiDbDecodeNode314*315* PARAMETERS: Node - Object to be displayed316*317* RETURN: None318*319* DESCRIPTION: Short display of a namespace node320*321******************************************************************************/322323static void324AcpiDbDecodeNode (325ACPI_NAMESPACE_NODE *Node)326{327328AcpiOsPrintf ("<Node> Name %4.4s",329AcpiUtGetNodeName (Node));330331if (Node->Flags & ANOBJ_METHOD_ARG)332{333AcpiOsPrintf (" [Method Arg]");334}335if (Node->Flags & ANOBJ_METHOD_LOCAL)336{337AcpiOsPrintf (" [Method Local]");338}339340switch (Node->Type)341{342/* These types have no attached object */343344case ACPI_TYPE_DEVICE:345346AcpiOsPrintf (" Device");347break;348349case ACPI_TYPE_THERMAL:350351AcpiOsPrintf (" Thermal Zone");352break;353354default:355356AcpiDbDecodeInternalObject (AcpiNsGetAttachedObject (Node));357break;358}359}360361362/*******************************************************************************363*364* FUNCTION: AcpiDbDisplayInternalObject365*366* PARAMETERS: ObjDesc - Object to be displayed367* WalkState - Current walk state368*369* RETURN: None370*371* DESCRIPTION: Short display of an internal object372*373******************************************************************************/374375void376AcpiDbDisplayInternalObject (377ACPI_OPERAND_OBJECT *ObjDesc,378ACPI_WALK_STATE *WalkState)379{380UINT8 Type;381382383AcpiOsPrintf ("%p ", ObjDesc);384385if (!ObjDesc)386{387AcpiOsPrintf ("<Null Object>\n");388return;389}390391/* Decode the object type */392393switch (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc))394{395case ACPI_DESC_TYPE_PARSER:396397AcpiOsPrintf ("<Parser> ");398break;399400case ACPI_DESC_TYPE_NAMED:401402AcpiDbDecodeNode ((ACPI_NAMESPACE_NODE *) ObjDesc);403break;404405case ACPI_DESC_TYPE_OPERAND:406407Type = ObjDesc->Common.Type;408if (Type > ACPI_TYPE_LOCAL_MAX)409{410AcpiOsPrintf (" Type %X [Invalid Type]", (UINT32) Type);411return;412}413414/* Decode the ACPI object type */415416switch (ObjDesc->Common.Type)417{418case ACPI_TYPE_LOCAL_REFERENCE:419420AcpiOsPrintf ("[%s] ", AcpiUtGetReferenceName (ObjDesc));421422/* Decode the reference */423424switch (ObjDesc->Reference.Class)425{426case ACPI_REFCLASS_LOCAL:427428AcpiOsPrintf ("%X ", ObjDesc->Reference.Value);429if (WalkState)430{431ObjDesc = WalkState->LocalVariables432[ObjDesc->Reference.Value].Object;433AcpiOsPrintf ("%p", ObjDesc);434AcpiDbDecodeInternalObject (ObjDesc);435}436break;437438case ACPI_REFCLASS_ARG:439440AcpiOsPrintf ("%X ", ObjDesc->Reference.Value);441if (WalkState)442{443ObjDesc = WalkState->Arguments444[ObjDesc->Reference.Value].Object;445AcpiOsPrintf ("%p", ObjDesc);446AcpiDbDecodeInternalObject (ObjDesc);447}448break;449450case ACPI_REFCLASS_INDEX:451452switch (ObjDesc->Reference.TargetType)453{454case ACPI_TYPE_BUFFER_FIELD:455456AcpiOsPrintf ("%p", ObjDesc->Reference.Object);457AcpiDbDecodeInternalObject (ObjDesc->Reference.Object);458break;459460case ACPI_TYPE_PACKAGE:461462AcpiOsPrintf ("%p", ObjDesc->Reference.Where);463if (!ObjDesc->Reference.Where)464{465AcpiOsPrintf (" Uninitialized WHERE pointer");466}467else468{469AcpiDbDecodeInternalObject (470*(ObjDesc->Reference.Where));471}472break;473474default:475476AcpiOsPrintf ("Unknown index target type");477break;478}479break;480481case ACPI_REFCLASS_REFOF:482483if (!ObjDesc->Reference.Object)484{485AcpiOsPrintf (486"Uninitialized reference subobject pointer");487break;488}489490/* Reference can be to a Node or an Operand object */491492switch (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc->Reference.Object))493{494case ACPI_DESC_TYPE_NAMED:495496AcpiDbDecodeNode (ObjDesc->Reference.Object);497break;498499case ACPI_DESC_TYPE_OPERAND:500501AcpiDbDecodeInternalObject (ObjDesc->Reference.Object);502break;503504default:505break;506}507break;508509case ACPI_REFCLASS_NAME:510511AcpiDbDecodeNode (ObjDesc->Reference.Node);512break;513514case ACPI_REFCLASS_DEBUG:515case ACPI_REFCLASS_TABLE:516517AcpiOsPrintf ("\n");518break;519520default: /* Unknown reference class */521522AcpiOsPrintf ("%2.2X\n", ObjDesc->Reference.Class);523break;524}525break;526527default:528529AcpiOsPrintf ("<Obj> ");530AcpiDbDecodeInternalObject (ObjDesc);531break;532}533break;534535default:536537AcpiOsPrintf ("<Not a valid ACPI Object Descriptor> [%s]",538AcpiUtGetDescriptorName (ObjDesc));539break;540}541542AcpiOsPrintf ("\n");543}544545546/*******************************************************************************547*548* FUNCTION: AcpiDbDecodeLocals549*550* PARAMETERS: WalkState - State for current method551*552* RETURN: None553*554* DESCRIPTION: Display all locals for the currently running control method555*556******************************************************************************/557558void559AcpiDbDecodeLocals (560ACPI_WALK_STATE *WalkState)561{562UINT32 i;563ACPI_OPERAND_OBJECT *ObjDesc;564ACPI_NAMESPACE_NODE *Node;565BOOLEAN DisplayLocals = FALSE;566567568Node = WalkState->MethodNode;569570/* There are no locals for the module-level code case */571572if (Node == AcpiGbl_RootNode)573{574return;575}576577if (!Node)578{579AcpiOsPrintf (580"No method node (Executing subtree for buffer or opregion)\n");581return;582}583584if (Node->Type != ACPI_TYPE_METHOD)585{586AcpiOsPrintf ("Executing subtree for Buffer/Package/Region\n");587return;588}589590/* Are any locals actually set? */591592for (i = 0; i < ACPI_METHOD_NUM_LOCALS; i++)593{594ObjDesc = WalkState->LocalVariables[i].Object;595if (ObjDesc)596{597DisplayLocals = TRUE;598break;599}600}601602/* If any are set, only display the ones that are set */603604if (DisplayLocals)605{606AcpiOsPrintf ("\nInitialized Local Variables for Method [%4.4s]:\n",607AcpiUtGetNodeName (Node));608609for (i = 0; i < ACPI_METHOD_NUM_LOCALS; i++)610{611ObjDesc = WalkState->LocalVariables[i].Object;612if (ObjDesc)613{614AcpiOsPrintf (" Local%X: ", i);615AcpiDbDisplayInternalObject (ObjDesc, WalkState);616}617}618}619else620{621AcpiOsPrintf (622"No Local Variables are initialized for Method [%4.4s]\n",623AcpiUtGetNodeName (Node));624}625}626627628/*******************************************************************************629*630* FUNCTION: AcpiDbDecodeArguments631*632* PARAMETERS: WalkState - State for current method633*634* RETURN: None635*636* DESCRIPTION: Display all arguments for the currently running control method637*638******************************************************************************/639640void641AcpiDbDecodeArguments (642ACPI_WALK_STATE *WalkState)643{644UINT32 i;645ACPI_OPERAND_OBJECT *ObjDesc;646ACPI_NAMESPACE_NODE *Node;647BOOLEAN DisplayArgs = FALSE;648649650Node = WalkState->MethodNode;651652/* There are no arguments for the module-level code case */653654if (Node == AcpiGbl_RootNode)655{656return;657}658659if (!Node)660{661AcpiOsPrintf (662"No method node (Executing subtree for buffer or opregion)\n");663return;664}665666if (Node->Type != ACPI_TYPE_METHOD)667{668AcpiOsPrintf ("Executing subtree for Buffer/Package/Region\n");669return;670}671672/* Are any arguments actually set? */673674for (i = 0; i < ACPI_METHOD_NUM_ARGS; i++)675{676ObjDesc = WalkState->Arguments[i].Object;677if (ObjDesc)678{679DisplayArgs = TRUE;680break;681}682}683684/* If any are set, only display the ones that are set */685686if (DisplayArgs)687{688AcpiOsPrintf (689"Initialized Arguments for Method [%4.4s]: "690"(%X arguments defined for method invocation)\n",691AcpiUtGetNodeName (Node), Node->Object->Method.ParamCount);692693for (i = 0; i < ACPI_METHOD_NUM_ARGS; i++)694{695ObjDesc = WalkState->Arguments[i].Object;696if (ObjDesc)697{698AcpiOsPrintf (" Arg%u: ", i);699AcpiDbDisplayInternalObject (ObjDesc, WalkState);700}701}702}703else704{705AcpiOsPrintf (706"No Arguments are initialized for method [%4.4s]\n",707AcpiUtGetNodeName (Node));708}709}710711712