1310450Sjkim/****************************************************************************** 2310450Sjkim * 3327557Sjkim * Module Name: osgendbg - Generic debugger command signalling 4310450Sjkim * 5310450Sjkim *****************************************************************************/ 6310450Sjkim 7316303Sjkim/****************************************************************************** 8316303Sjkim * 9316303Sjkim * 1. Copyright Notice 10316303Sjkim * 11316303Sjkim * Some or all of this work - Copyright (c) 1999 - 2015, Intel Corp. 12310450Sjkim * All rights reserved. 13310450Sjkim * 14316303Sjkim * 2. License 15316303Sjkim * 16316303Sjkim * 2.1. This is your license from Intel Corp. under its intellectual property 17316303Sjkim * rights. You may have additional license terms from the party that provided 18316303Sjkim * you this software, covering your right to use that party's intellectual 19316303Sjkim * property rights. 20316303Sjkim * 21316303Sjkim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 22316303Sjkim * copy of the source code appearing in this file ("Covered Code") an 23316303Sjkim * irrevocable, perpetual, worldwide license under Intel's copyrights in the 24316303Sjkim * base code distributed originally by Intel ("Original Intel Code") to copy, 25316303Sjkim * make derivatives, distribute, use and display any portion of the Covered 26316303Sjkim * Code in any form, with the right to sublicense such rights; and 27316303Sjkim * 28316303Sjkim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 29316303Sjkim * license (with the right to sublicense), under only those claims of Intel 30316303Sjkim * patents that are infringed by the Original Intel Code, to make, use, sell, 31316303Sjkim * offer to sell, and import the Covered Code and derivative works thereof 32316303Sjkim * solely to the minimum extent necessary to exercise the above copyright 33316303Sjkim * license, and in no event shall the patent license extend to any additions 34316303Sjkim * to or modifications of the Original Intel Code. No other license or right 35316303Sjkim * is granted directly or by implication, estoppel or otherwise; 36316303Sjkim * 37316303Sjkim * The above copyright and patent license is granted only if the following 38316303Sjkim * conditions are met: 39316303Sjkim * 40316303Sjkim * 3. Conditions 41316303Sjkim * 42316303Sjkim * 3.1. Redistribution of Source with Rights to Further Distribute Source. 43316303Sjkim * Redistribution of source code of any substantial portion of the Covered 44316303Sjkim * Code or modification with rights to further distribute source must include 45316303Sjkim * the above Copyright Notice, the above License, this list of Conditions, 46316303Sjkim * and the following Disclaimer and Export Compliance provision. In addition, 47316303Sjkim * Licensee must cause all Covered Code to which Licensee contributes to 48316303Sjkim * contain a file documenting the changes Licensee made to create that Covered 49316303Sjkim * Code and the date of any change. Licensee must include in that file the 50316303Sjkim * documentation of any changes made by any predecessor Licensee. Licensee 51316303Sjkim * must include a prominent statement that the modification is derived, 52316303Sjkim * directly or indirectly, from Original Intel Code. 53316303Sjkim * 54316303Sjkim * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 55316303Sjkim * Redistribution of source code of any substantial portion of the Covered 56316303Sjkim * Code or modification without rights to further distribute source must 57316303Sjkim * include the following Disclaimer and Export Compliance provision in the 58316303Sjkim * documentation and/or other materials provided with distribution. In 59316303Sjkim * addition, Licensee may not authorize further sublicense of source of any 60316303Sjkim * portion of the Covered Code, and must include terms to the effect that the 61316303Sjkim * license from Licensee to its licensee is limited to the intellectual 62316303Sjkim * property embodied in the software Licensee provides to its licensee, and 63316303Sjkim * not to intellectual property embodied in modifications its licensee may 64316303Sjkim * make. 65316303Sjkim * 66316303Sjkim * 3.3. Redistribution of Executable. Redistribution in executable form of any 67316303Sjkim * substantial portion of the Covered Code or modification must reproduce the 68316303Sjkim * above Copyright Notice, and the following Disclaimer and Export Compliance 69316303Sjkim * provision in the documentation and/or other materials provided with the 70316303Sjkim * distribution. 71316303Sjkim * 72316303Sjkim * 3.4. Intel retains all right, title, and interest in and to the Original 73316303Sjkim * Intel Code. 74316303Sjkim * 75316303Sjkim * 3.5. Neither the name Intel nor any other trademark owned or controlled by 76316303Sjkim * Intel shall be used in advertising or otherwise to promote the sale, use or 77316303Sjkim * other dealings in products derived from or relating to the Covered Code 78316303Sjkim * without prior written authorization from Intel. 79316303Sjkim * 80316303Sjkim * 4. Disclaimer and Export Compliance 81316303Sjkim * 82316303Sjkim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 83316303Sjkim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 84316303Sjkim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 85316303Sjkim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 86316303Sjkim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 87316303Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 88316303Sjkim * PARTICULAR PURPOSE. 89316303Sjkim * 90316303Sjkim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 91316303Sjkim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 92316303Sjkim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 93316303Sjkim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 94316303Sjkim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 95316303Sjkim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 96316303Sjkim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 97316303Sjkim * LIMITED REMEDY. 98316303Sjkim * 99316303Sjkim * 4.3. Licensee shall not export, either directly or indirectly, any of this 100316303Sjkim * software or system incorporating such software without first obtaining any 101316303Sjkim * required license or other approval from the U. S. Department of Commerce or 102316303Sjkim * any other agency or department of the United States Government. In the 103316303Sjkim * event Licensee exports any such software from the United States or 104316303Sjkim * re-exports any such software from a foreign destination, Licensee shall 105316303Sjkim * ensure that the distribution and export/re-export of the software is in 106316303Sjkim * compliance with all laws, regulations, orders, or other restrictions of the 107316303Sjkim * U.S. Export Administration Regulations. Licensee agrees that neither it nor 108316303Sjkim * any of its subsidiaries will export/re-export any technical data, process, 109316303Sjkim * software, or service, directly or indirectly, to any country for which the 110316303Sjkim * United States government or any agency thereof requires an export license, 111316303Sjkim * other governmental approval, or letter of assurance, without first obtaining 112316303Sjkim * such license, approval or letter. 113316303Sjkim * 114316303Sjkim ***************************************************************************** 115316303Sjkim * 116316303Sjkim * Alternatively, you may choose to be licensed under the terms of the 117316303Sjkim * following license: 118316303Sjkim * 119310450Sjkim * Redistribution and use in source and binary forms, with or without 120310450Sjkim * modification, are permitted provided that the following conditions 121310450Sjkim * are met: 122310450Sjkim * 1. Redistributions of source code must retain the above copyright 123310450Sjkim * notice, this list of conditions, and the following disclaimer, 124310450Sjkim * without modification. 125310450Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer 126310450Sjkim * substantially similar to the "NO WARRANTY" disclaimer below 127310450Sjkim * ("Disclaimer") and any redistribution must be conditioned upon 128310450Sjkim * including a substantially similar Disclaimer requirement for further 129310450Sjkim * binary redistribution. 130310450Sjkim * 3. Neither the names of the above-listed copyright holders nor the names 131310450Sjkim * of any contributors may be used to endorse or promote products derived 132310450Sjkim * from this software without specific prior written permission. 133310450Sjkim * 134316303Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 135316303Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 136316303Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 137316303Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 138316303Sjkim * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 139316303Sjkim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 140316303Sjkim * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 141316303Sjkim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 142316303Sjkim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 143316303Sjkim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 144316303Sjkim * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 145316303Sjkim * 146316303Sjkim * Alternatively, you may choose to be licensed under the terms of the 147310450Sjkim * GNU General Public License ("GPL") version 2 as published by the Free 148310450Sjkim * Software Foundation. 149310450Sjkim * 150316303Sjkim *****************************************************************************/ 151310450Sjkim 152311462Sjkim#include <contrib/dev/acpica/include/acpi.h> 153311462Sjkim#include <contrib/dev/acpica/include/accommon.h> 154311462Sjkim#include <contrib/dev/acpica/include/acdebug.h> 155310450Sjkim 156310450Sjkim 157310450Sjkim#define _COMPONENT ACPI_CA_DEBUGGER 158310450Sjkim ACPI_MODULE_NAME ("osgendbg") 159310450Sjkim 160310450Sjkim 161310450Sjkim/* Local prototypes */ 162310450Sjkim 163310450Sjkimstatic void 164310450SjkimAcpiDbRunRemoteDebugger ( 165310450Sjkim char *BatchBuffer); 166310450Sjkim 167310450Sjkim 168310450Sjkimstatic ACPI_MUTEX AcpiGbl_DbCommandReady; 169310450Sjkimstatic ACPI_MUTEX AcpiGbl_DbCommandComplete; 170310450Sjkimstatic BOOLEAN AcpiGbl_DbCommandSignalsInitialized = FALSE; 171310450Sjkim 172327557Sjkim 173310450Sjkim/****************************************************************************** 174310450Sjkim * 175310450Sjkim * FUNCTION: AcpiDbRunRemoteDebugger 176310450Sjkim * 177310450Sjkim * PARAMETERS: BatchBuffer - Buffer containing commands running in 178310450Sjkim * the batch mode 179310450Sjkim * 180310450Sjkim * RETURN: None 181310450Sjkim * 182310450Sjkim * DESCRIPTION: Run multi-threading debugger remotely 183310450Sjkim * 184310450Sjkim *****************************************************************************/ 185310450Sjkim 186310450Sjkimstatic void 187310450SjkimAcpiDbRunRemoteDebugger ( 188310450Sjkim char *BatchBuffer) 189310450Sjkim{ 190310450Sjkim ACPI_STATUS Status; 191310450Sjkim char *Ptr = BatchBuffer; 192310450Sjkim char *Cmd = Ptr; 193310450Sjkim 194310450Sjkim 195310450Sjkim while (!AcpiGbl_DbTerminateLoop) 196310450Sjkim { 197310450Sjkim if (BatchBuffer) 198310450Sjkim { 199310450Sjkim if (*Ptr) 200310450Sjkim { 201310450Sjkim while (*Ptr) 202310450Sjkim { 203310450Sjkim if (*Ptr == ',') 204310450Sjkim { 205310450Sjkim /* Convert commas to spaces */ 206310450Sjkim *Ptr = ' '; 207310450Sjkim } 208310450Sjkim else if (*Ptr == ';') 209310450Sjkim { 210310450Sjkim *Ptr = '\0'; 211310450Sjkim continue; 212310450Sjkim } 213310450Sjkim 214310450Sjkim Ptr++; 215310450Sjkim } 216310450Sjkim 217327557Sjkim AcpiUtSafeStrncpy (AcpiGbl_DbLineBuf, Cmd, ACPI_DB_LINE_BUFFER_SIZE); 218310450Sjkim Ptr++; 219310450Sjkim Cmd = Ptr; 220310450Sjkim } 221310450Sjkim else 222310450Sjkim { 223310450Sjkim return; 224310450Sjkim } 225310450Sjkim } 226310450Sjkim else 227310450Sjkim { 228310450Sjkim /* Force output to console until a command is entered */ 229310450Sjkim 230310450Sjkim AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT); 231310450Sjkim 232310450Sjkim /* Different prompt if method is executing */ 233310450Sjkim 234310450Sjkim if (!AcpiGbl_MethodExecuting) 235310450Sjkim { 236310450Sjkim AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_COMMAND_PROMPT); 237310450Sjkim } 238310450Sjkim else 239310450Sjkim { 240310450Sjkim AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_EXECUTE_PROMPT); 241310450Sjkim } 242310450Sjkim 243310450Sjkim /* Get the user input line */ 244310450Sjkim 245310450Sjkim Status = AcpiOsGetLine (AcpiGbl_DbLineBuf, 246310450Sjkim ACPI_DB_LINE_BUFFER_SIZE, NULL); 247310450Sjkim if (ACPI_FAILURE (Status)) 248310450Sjkim { 249310450Sjkim return; 250310450Sjkim } 251310450Sjkim } 252310450Sjkim 253310450Sjkim /* 254310450Sjkim * Signal the debug thread that we have a command to execute, 255310450Sjkim * and wait for the command to complete. 256310450Sjkim */ 257310450Sjkim AcpiOsReleaseMutex (AcpiGbl_DbCommandReady); 258310450Sjkim 259310450Sjkim Status = AcpiOsAcquireMutex (AcpiGbl_DbCommandComplete, 260310450Sjkim ACPI_WAIT_FOREVER); 261310450Sjkim if (ACPI_FAILURE (Status)) 262310450Sjkim { 263310450Sjkim return; 264310450Sjkim } 265310450Sjkim } 266310450Sjkim} 267310450Sjkim 268310450Sjkim 269310450Sjkim/****************************************************************************** 270310450Sjkim * 271310450Sjkim * FUNCTION: AcpiOsWaitCommandReady 272310450Sjkim * 273310450Sjkim * PARAMETERS: None 274310450Sjkim * 275310450Sjkim * RETURN: Status 276310450Sjkim * 277310450Sjkim * DESCRIPTION: Negotiate with the debugger foreground thread (the user 278310450Sjkim * thread) to wait the readiness of a command. 279310450Sjkim * 280310450Sjkim *****************************************************************************/ 281310450Sjkim 282310450SjkimACPI_STATUS 283310450SjkimAcpiOsWaitCommandReady ( 284310450Sjkim void) 285310450Sjkim{ 286310450Sjkim ACPI_STATUS Status = AE_OK; 287310450Sjkim 288310450Sjkim 289310450Sjkim if (AcpiGbl_DebuggerConfiguration == DEBUGGER_MULTI_THREADED) 290310450Sjkim { 291310450Sjkim Status = AE_TIME; 292310450Sjkim 293310450Sjkim while (Status == AE_TIME) 294310450Sjkim { 295310450Sjkim if (AcpiGbl_DbTerminateLoop) 296310450Sjkim { 297310450Sjkim Status = AE_CTRL_TERMINATE; 298310450Sjkim } 299310450Sjkim else 300310450Sjkim { 301310450Sjkim Status = AcpiOsAcquireMutex (AcpiGbl_DbCommandReady, 1000); 302310450Sjkim } 303310450Sjkim } 304310450Sjkim } 305310450Sjkim else 306310450Sjkim { 307310450Sjkim /* Force output to console until a command is entered */ 308310450Sjkim 309310450Sjkim AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT); 310310450Sjkim 311310450Sjkim /* Different prompt if method is executing */ 312310450Sjkim 313310450Sjkim if (!AcpiGbl_MethodExecuting) 314310450Sjkim { 315310450Sjkim AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_COMMAND_PROMPT); 316310450Sjkim } 317310450Sjkim else 318310450Sjkim { 319310450Sjkim AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_EXECUTE_PROMPT); 320310450Sjkim } 321310450Sjkim 322310450Sjkim /* Get the user input line */ 323310450Sjkim 324310450Sjkim Status = AcpiOsGetLine (AcpiGbl_DbLineBuf, 325310450Sjkim ACPI_DB_LINE_BUFFER_SIZE, NULL); 326310450Sjkim } 327310450Sjkim 328310450Sjkim if (ACPI_FAILURE (Status) && Status != AE_CTRL_TERMINATE) 329310450Sjkim { 330310450Sjkim ACPI_EXCEPTION ((AE_INFO, Status, 331310450Sjkim "While parsing/handling command line")); 332310450Sjkim } 333310450Sjkim return (Status); 334310450Sjkim} 335310450Sjkim 336310450Sjkim 337310450Sjkim/****************************************************************************** 338310450Sjkim * 339310450Sjkim * FUNCTION: AcpiOsNotifyCommandComplete 340310450Sjkim * 341310450Sjkim * PARAMETERS: void 342310450Sjkim * 343310450Sjkim * RETURN: Status 344310450Sjkim * 345310450Sjkim * DESCRIPTION: Negotiate with the debugger foreground thread (the user 346310450Sjkim * thread) to notify the completion of a command. 347310450Sjkim * 348310450Sjkim *****************************************************************************/ 349310450Sjkim 350310450SjkimACPI_STATUS 351310450SjkimAcpiOsNotifyCommandComplete ( 352310450Sjkim void) 353310450Sjkim{ 354310450Sjkim 355310450Sjkim if (AcpiGbl_DebuggerConfiguration == DEBUGGER_MULTI_THREADED) 356310450Sjkim { 357310450Sjkim AcpiOsReleaseMutex (AcpiGbl_DbCommandComplete); 358310450Sjkim } 359310450Sjkim return (AE_OK); 360310450Sjkim} 361310450Sjkim 362310450Sjkim 363310450Sjkim/****************************************************************************** 364310450Sjkim * 365310450Sjkim * FUNCTION: AcpiOsInitializeDebugger 366310450Sjkim * 367310450Sjkim * PARAMETERS: None 368310450Sjkim * 369310450Sjkim * RETURN: Status 370310450Sjkim * 371310450Sjkim * DESCRIPTION: Initialize OSPM specific part of the debugger 372310450Sjkim * 373310450Sjkim *****************************************************************************/ 374310450Sjkim 375310450SjkimACPI_STATUS 376310450SjkimAcpiOsInitializeDebugger ( 377310450Sjkim void) 378310450Sjkim{ 379310450Sjkim ACPI_STATUS Status; 380310450Sjkim 381310450Sjkim 382310450Sjkim /* Create command signals */ 383310450Sjkim 384310450Sjkim Status = AcpiOsCreateMutex (&AcpiGbl_DbCommandReady); 385310450Sjkim if (ACPI_FAILURE (Status)) 386310450Sjkim { 387310450Sjkim return (Status); 388310450Sjkim } 389310450Sjkim Status = AcpiOsCreateMutex (&AcpiGbl_DbCommandComplete); 390310450Sjkim if (ACPI_FAILURE (Status)) 391310450Sjkim { 392310450Sjkim goto ErrorReady; 393310450Sjkim } 394310450Sjkim 395310450Sjkim /* Initialize the states of the command signals */ 396310450Sjkim 397310450Sjkim Status = AcpiOsAcquireMutex (AcpiGbl_DbCommandComplete, 398310450Sjkim ACPI_WAIT_FOREVER); 399310450Sjkim if (ACPI_FAILURE (Status)) 400310450Sjkim { 401310450Sjkim goto ErrorComplete; 402310450Sjkim } 403310450Sjkim Status = AcpiOsAcquireMutex (AcpiGbl_DbCommandReady, 404310450Sjkim ACPI_WAIT_FOREVER); 405310450Sjkim if (ACPI_FAILURE (Status)) 406310450Sjkim { 407310450Sjkim goto ErrorComplete; 408310450Sjkim } 409310450Sjkim 410310450Sjkim AcpiGbl_DbCommandSignalsInitialized = TRUE; 411310450Sjkim return (Status); 412310450Sjkim 413310450SjkimErrorComplete: 414310450Sjkim AcpiOsDeleteMutex (AcpiGbl_DbCommandComplete); 415310450SjkimErrorReady: 416310450Sjkim AcpiOsDeleteMutex (AcpiGbl_DbCommandReady); 417310450Sjkim return (Status); 418310450Sjkim} 419310450Sjkim 420310450Sjkim 421310450Sjkim/****************************************************************************** 422310450Sjkim * 423310450Sjkim * FUNCTION: AcpiOsTerminateDebugger 424310450Sjkim * 425310450Sjkim * PARAMETERS: None 426310450Sjkim * 427310450Sjkim * RETURN: None 428310450Sjkim * 429310450Sjkim * DESCRIPTION: Terminate signals used by the multi-threading debugger 430310450Sjkim * 431310450Sjkim *****************************************************************************/ 432310450Sjkim 433310450Sjkimvoid 434310450SjkimAcpiOsTerminateDebugger ( 435310450Sjkim void) 436310450Sjkim{ 437310450Sjkim 438310450Sjkim if (AcpiGbl_DbCommandSignalsInitialized) 439310450Sjkim { 440310450Sjkim AcpiOsDeleteMutex (AcpiGbl_DbCommandReady); 441310450Sjkim AcpiOsDeleteMutex (AcpiGbl_DbCommandComplete); 442310450Sjkim } 443310450Sjkim} 444310450Sjkim 445310450Sjkim 446310450Sjkim/****************************************************************************** 447310450Sjkim * 448310450Sjkim * FUNCTION: AcpiRunDebugger 449310450Sjkim * 450310450Sjkim * PARAMETERS: BatchBuffer - Buffer containing commands running in 451310450Sjkim * the batch mode 452310450Sjkim * 453310450Sjkim * RETURN: None 454310450Sjkim * 455310450Sjkim * DESCRIPTION: Run a local/remote debugger 456310450Sjkim * 457310450Sjkim *****************************************************************************/ 458310450Sjkim 459310450Sjkimvoid 460310450SjkimAcpiRunDebugger ( 461310450Sjkim char *BatchBuffer) 462310450Sjkim{ 463310450Sjkim /* Check for single or multithreaded debug */ 464310450Sjkim 465310450Sjkim if (AcpiGbl_DebuggerConfiguration & DEBUGGER_MULTI_THREADED) 466310450Sjkim { 467310450Sjkim AcpiDbRunRemoteDebugger (BatchBuffer); 468310450Sjkim } 469310450Sjkim else 470310450Sjkim { 471310450Sjkim AcpiDbUserCommands (); 472310450Sjkim } 473310450Sjkim} 474310450Sjkim 475310450SjkimACPI_EXPORT_SYMBOL (AcpiRunDebugger) 476