Path: blob/main/sys/contrib/dev/acpica/components/debugger/dbxface.c
48406 views
/*******************************************************************************1*2* Module Name: dbxface - AML Debugger external interfaces3*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/acdebug.h>155#include <contrib/dev/acpica/include/acinterp.h>156#include <contrib/dev/acpica/include/acparser.h>157158159#define _COMPONENT ACPI_CA_DEBUGGER160ACPI_MODULE_NAME ("dbxface")161162163/* Local prototypes */164165static ACPI_STATUS166AcpiDbStartCommand (167ACPI_WALK_STATE *WalkState,168ACPI_PARSE_OBJECT *Op);169170#ifdef ACPI_OBSOLETE_FUNCTIONS171void172AcpiDbMethodEnd (173ACPI_WALK_STATE *WalkState);174#endif175176#ifdef ACPI_DISASSEMBLER177static ACPI_PARSE_OBJECT *178AcpiDbGetDisplayOp (179ACPI_WALK_STATE *WalkState,180ACPI_PARSE_OBJECT *Op);181#endif182183/*******************************************************************************184*185* FUNCTION: AcpiDbStartCommand186*187* PARAMETERS: WalkState - Current walk188* Op - Current executing Op, from AML interpreter189*190* RETURN: Status191*192* DESCRIPTION: Enter debugger command loop193*194******************************************************************************/195196static ACPI_STATUS197AcpiDbStartCommand (198ACPI_WALK_STATE *WalkState,199ACPI_PARSE_OBJECT *Op)200{201ACPI_STATUS Status;202203204/* TBD: [Investigate] are there namespace locking issues here? */205206/* AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); */207208/* Go into the command loop and await next user command */209210211AcpiGbl_MethodExecuting = TRUE;212Status = AE_CTRL_TRUE;213214while (Status == AE_CTRL_TRUE)215{216/* Notify the completion of the command */217218Status = AcpiOsNotifyCommandComplete ();219if (ACPI_FAILURE (Status))220{221goto ErrorExit;222}223224/* Wait the readiness of the command */225226Status = AcpiOsWaitCommandReady ();227if (ACPI_FAILURE (Status))228{229goto ErrorExit;230}231232Status = AcpiDbCommandDispatch (AcpiGbl_DbLineBuf, WalkState, Op);233}234235/* AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); */236237ErrorExit:238if (ACPI_FAILURE (Status) && Status != AE_CTRL_TERMINATE)239{240ACPI_EXCEPTION ((AE_INFO, Status,241"While parsing/handling command line"));242}243return (Status);244}245246247/*******************************************************************************248*249* FUNCTION: AcpiDbSignalBreakPoint250*251* PARAMETERS: WalkState - Current walk252*253* RETURN: Status254*255* DESCRIPTION: Called for AML_BREAKPOINT_OP256*257******************************************************************************/258259void260AcpiDbSignalBreakPoint (261ACPI_WALK_STATE *WalkState)262{263264#ifndef ACPI_APPLICATION265if (AcpiGbl_DbThreadId != AcpiOsGetThreadId ())266{267return;268}269#endif270271/*272* Set the single-step flag. This will cause the debugger (if present)273* to break to the console within the AML debugger at the start of the274* next AML instruction.275*/276AcpiGbl_CmSingleStep = TRUE;277AcpiOsPrintf ("**break** Executed AML BreakPoint opcode\n");278}279280281#ifdef ACPI_DISASSEMBLER282/*******************************************************************************283*284* FUNCTION: AcpiDbGetDisplayOp285*286* PARAMETERS: WalkState - Current walk287* Op - Current executing op (from aml interpreter)288*289* RETURN: Opcode to display290*291* DESCRIPTION: Find the opcode to display during single stepping292*293******************************************************************************/294295static ACPI_PARSE_OBJECT *296AcpiDbGetDisplayOp (297ACPI_WALK_STATE *WalkState,298ACPI_PARSE_OBJECT *Op)299{300ACPI_PARSE_OBJECT *DisplayOp;301ACPI_PARSE_OBJECT *ParentOp;302303DisplayOp = Op;304ParentOp = Op->Common.Parent;305if (ParentOp)306{307if ((WalkState->ControlState) &&308(WalkState->ControlState->Common.State ==309ACPI_CONTROL_PREDICATE_EXECUTING))310{311/*312* We are executing the predicate of an IF or WHILE statement313* Search upwards for the containing IF or WHILE so that the314* entire predicate can be displayed.315*/316while (ParentOp)317{318if ((ParentOp->Common.AmlOpcode == AML_IF_OP) ||319(ParentOp->Common.AmlOpcode == AML_WHILE_OP))320{321DisplayOp = ParentOp;322break;323}324ParentOp = ParentOp->Common.Parent;325}326}327else328{329while (ParentOp)330{331if ((ParentOp->Common.AmlOpcode == AML_IF_OP) ||332(ParentOp->Common.AmlOpcode == AML_ELSE_OP) ||333(ParentOp->Common.AmlOpcode == AML_SCOPE_OP) ||334(ParentOp->Common.AmlOpcode == AML_METHOD_OP) ||335(ParentOp->Common.AmlOpcode == AML_WHILE_OP))336{337break;338}339DisplayOp = ParentOp;340ParentOp = ParentOp->Common.Parent;341}342}343}344return DisplayOp;345}346#endif347348349/*******************************************************************************350*351* FUNCTION: AcpiDbSingleStep352*353* PARAMETERS: WalkState - Current walk354* Op - Current executing op (from aml interpreter)355* OpcodeClass - Class of the current AML Opcode356*357* RETURN: Status358*359* DESCRIPTION: Called just before execution of an AML opcode.360*361******************************************************************************/362363ACPI_STATUS364AcpiDbSingleStep (365ACPI_WALK_STATE *WalkState,366ACPI_PARSE_OBJECT *Op,367UINT32 OpcodeClass)368{369ACPI_PARSE_OBJECT *Next;370ACPI_STATUS Status = AE_OK;371UINT32 OriginalDebugLevel;372UINT32 AmlOffset;373374375ACPI_FUNCTION_ENTRY ();376377378#ifndef ACPI_APPLICATION379if (AcpiGbl_DbThreadId != AcpiOsGetThreadId ())380{381return (AE_OK);382}383#endif384385/* Check the abort flag */386387if (AcpiGbl_AbortMethod)388{389AcpiGbl_AbortMethod = FALSE;390return (AE_ABORT_METHOD);391}392393AmlOffset = (UINT32) ACPI_PTR_DIFF (Op->Common.Aml,394WalkState->ParserState.AmlStart);395396/* Check for single-step breakpoint */397398if (WalkState->MethodBreakpoint &&399(WalkState->MethodBreakpoint <= AmlOffset))400{401/* Check if the breakpoint has been reached or passed */402/* Hit the breakpoint, resume single step, reset breakpoint */403404AcpiOsPrintf ("***Break*** at AML offset %X\n", AmlOffset);405AcpiGbl_CmSingleStep = TRUE;406AcpiGbl_StepToNextCall = FALSE;407WalkState->MethodBreakpoint = 0;408}409410/* Check for user breakpoint (Must be on exact Aml offset) */411412else if (WalkState->UserBreakpoint &&413(WalkState->UserBreakpoint == AmlOffset))414{415AcpiOsPrintf ("***UserBreakpoint*** at AML offset %X\n",416AmlOffset);417AcpiGbl_CmSingleStep = TRUE;418AcpiGbl_StepToNextCall = FALSE;419WalkState->MethodBreakpoint = 0;420}421422/*423* Check if this is an opcode that we are interested in --424* namely, opcodes that have arguments425*/426if (Op->Common.AmlOpcode == AML_INT_NAMEDFIELD_OP)427{428return (AE_OK);429}430431switch (OpcodeClass)432{433case AML_CLASS_UNKNOWN:434case AML_CLASS_ARGUMENT: /* constants, literals, etc. do nothing */435436return (AE_OK);437438default:439440/* All other opcodes -- continue */441break;442}443444/*445* Under certain debug conditions, display this opcode and its operands446*/447if ((AcpiGbl_DbOutputToFile) ||448(AcpiGbl_CmSingleStep) ||449(AcpiDbgLevel & ACPI_LV_PARSE))450{451if ((AcpiGbl_DbOutputToFile) ||452(AcpiDbgLevel & ACPI_LV_PARSE))453{454AcpiOsPrintf ("\nAML Debug: Next AML Opcode to execute:\n");455}456457/*458* Display this op (and only this op - zero out the NEXT field459* temporarily, and disable parser trace output for the duration of460* the display because we don't want the extraneous debug output)461*/462OriginalDebugLevel = AcpiDbgLevel;463AcpiDbgLevel &= ~(ACPI_LV_PARSE | ACPI_LV_FUNCTIONS);464Next = Op->Common.Next;465Op->Common.Next = NULL;466467/* Now we can disassemble and display it */468469#ifdef ACPI_DISASSEMBLER470AcpiDmDisassemble (WalkState, AcpiDbGetDisplayOp (WalkState, Op),471ACPI_UINT32_MAX);472#else473/*474* The AML Disassembler is not configured - at least we can475* display the opcode value and name476*/477AcpiOsPrintf ("AML Opcode: %4.4X %s\n", Op->Common.AmlOpcode,478AcpiPsGetOpcodeName (Op->Common.AmlOpcode));479#endif480481if ((Op->Common.AmlOpcode == AML_IF_OP) ||482(Op->Common.AmlOpcode == AML_WHILE_OP))483{484if (WalkState->ControlState->Common.Value)485{486AcpiOsPrintf ("Predicate = [True], IF block was executed\n");487}488else489{490AcpiOsPrintf ("Predicate = [False], Skipping IF block\n");491}492}493else if (Op->Common.AmlOpcode == AML_ELSE_OP)494{495AcpiOsPrintf ("Predicate = [False], ELSE block was executed\n");496}497498/* Restore everything */499500Op->Common.Next = Next;501AcpiOsPrintf ("\n");502if ((AcpiGbl_DbOutputToFile) ||503(AcpiDbgLevel & ACPI_LV_PARSE))504{505AcpiOsPrintf ("\n");506}507AcpiDbgLevel = OriginalDebugLevel;508}509510/* If we are not single stepping, just continue executing the method */511512if (!AcpiGbl_CmSingleStep)513{514return (AE_OK);515}516517/*518* If we are executing a step-to-call command,519* Check if this is a method call.520*/521if (AcpiGbl_StepToNextCall)522{523if (Op->Common.AmlOpcode != AML_INT_METHODCALL_OP)524{525/* Not a method call, just keep executing */526527return (AE_OK);528}529530/* Found a method call, stop executing */531532AcpiGbl_StepToNextCall = FALSE;533}534535/*536* If the next opcode is a method call, we will "step over" it537* by default.538*/539if (Op->Common.AmlOpcode == AML_INT_METHODCALL_OP)540{541/* Force no more single stepping while executing called method */542543AcpiGbl_CmSingleStep = FALSE;544545/*546* Set the breakpoint on/before the call, it will stop execution547* as soon as we return548*/549WalkState->MethodBreakpoint = 1; /* Must be non-zero! */550}551552553AcpiExExitInterpreter ();554Status = AcpiDbStartCommand (WalkState, Op);555AcpiExEnterInterpreter ();556557/* User commands complete, continue execution of the interrupted method */558559return (Status);560}561562563/*******************************************************************************564*565* FUNCTION: AcpiInitializeDebugger566*567* PARAMETERS: None568*569* RETURN: Status570*571* DESCRIPTION: Init and start debugger572*573******************************************************************************/574575ACPI_STATUS576AcpiInitializeDebugger (577void)578{579ACPI_STATUS Status;580581582ACPI_FUNCTION_TRACE (AcpiInitializeDebugger);583584585/* Init globals */586587AcpiGbl_DbBuffer = NULL;588AcpiGbl_DbFilename = NULL;589AcpiGbl_DbOutputToFile = FALSE;590591AcpiGbl_DbDebugLevel = ACPI_LV_VERBOSITY2;592AcpiGbl_DbConsoleDebugLevel = ACPI_NORMAL_DEFAULT | ACPI_LV_TABLES;593AcpiGbl_DbOutputFlags = ACPI_DB_CONSOLE_OUTPUT;594595AcpiGbl_DbOpt_NoIniMethods = FALSE;596AcpiGbl_DbOpt_NoRegionSupport = FALSE;597598AcpiGbl_DbBuffer = AcpiOsAllocate (ACPI_DEBUG_BUFFER_SIZE);599if (!AcpiGbl_DbBuffer)600{601return_ACPI_STATUS (AE_NO_MEMORY);602}603memset (AcpiGbl_DbBuffer, 0, ACPI_DEBUG_BUFFER_SIZE);604605/* Initial scope is the root */606607AcpiGbl_DbScopeBuf [0] = AML_ROOT_PREFIX;608AcpiGbl_DbScopeBuf [1] = 0;609AcpiGbl_DbScopeNode = AcpiGbl_RootNode;610611/* Initialize user commands loop */612613AcpiGbl_DbTerminateLoop = FALSE;614615/*616* If configured for multi-thread support, the debug executor runs in617* a separate thread so that the front end can be in another address618* space, environment, or even another machine.619*/620if (AcpiGbl_DebuggerConfiguration & DEBUGGER_MULTI_THREADED)621{622/* These were created with one unit, grab it */623624Status = AcpiOsInitializeDebugger ();625if (ACPI_FAILURE (Status))626{627AcpiOsPrintf ("Could not get debugger mutex\n");628return_ACPI_STATUS (Status);629}630631/* Create the debug execution thread to execute commands */632633AcpiGbl_DbThreadsTerminated = FALSE;634Status = AcpiOsExecute (OSL_DEBUGGER_MAIN_THREAD,635AcpiDbExecuteThread, NULL);636if (ACPI_FAILURE (Status))637{638ACPI_EXCEPTION ((AE_INFO, Status,639"Could not start debugger thread"));640AcpiGbl_DbThreadsTerminated = TRUE;641return_ACPI_STATUS (Status);642}643}644else645{646AcpiGbl_DbThreadId = AcpiOsGetThreadId ();647}648649return_ACPI_STATUS (AE_OK);650}651652ACPI_EXPORT_SYMBOL (AcpiInitializeDebugger)653654655/*******************************************************************************656*657* FUNCTION: AcpiTerminateDebugger658*659* PARAMETERS: None660*661* RETURN: None662*663* DESCRIPTION: Stop debugger664*665******************************************************************************/666667void668AcpiTerminateDebugger (669void)670{671672/* Terminate the AML Debugger */673674AcpiGbl_DbTerminateLoop = TRUE;675676if (AcpiGbl_DebuggerConfiguration & DEBUGGER_MULTI_THREADED)677{678/* Wait the AML Debugger threads */679680while (!AcpiGbl_DbThreadsTerminated)681{682AcpiOsSleep (100);683}684685AcpiOsTerminateDebugger ();686}687688if (AcpiGbl_DbBuffer)689{690AcpiOsFree (AcpiGbl_DbBuffer);691AcpiGbl_DbBuffer = NULL;692}693694/* Ensure that debug output is now disabled */695696AcpiGbl_DbOutputFlags = ACPI_DB_DISABLE_OUTPUT;697}698699ACPI_EXPORT_SYMBOL (AcpiTerminateDebugger)700701702/*******************************************************************************703*704* FUNCTION: AcpiSetDebuggerThreadId705*706* PARAMETERS: ThreadId - Debugger thread ID707*708* RETURN: None709*710* DESCRIPTION: Set debugger thread ID711*712******************************************************************************/713714void715AcpiSetDebuggerThreadId (716ACPI_THREAD_ID ThreadId)717{718AcpiGbl_DbThreadId = ThreadId;719}720721ACPI_EXPORT_SYMBOL (AcpiSetDebuggerThreadId)722723724