1 /******************************************************************************
3 * Module Name: osgendbg - Generic debugger command singalling
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2016, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
49 #define _COMPONENT ACPI_CA_DEBUGGER
50 ACPI_MODULE_NAME ("osgendbg")
53 /* Local prototypes */
56 AcpiDbRunRemoteDebugger (
60 static ACPI_MUTEX AcpiGbl_DbCommandReady
;
61 static ACPI_MUTEX AcpiGbl_DbCommandComplete
;
62 static BOOLEAN AcpiGbl_DbCommandSignalsInitialized
= FALSE
;
64 /******************************************************************************
66 * FUNCTION: AcpiDbRunRemoteDebugger
68 * PARAMETERS: BatchBuffer - Buffer containing commands running in
73 * DESCRIPTION: Run multi-threading debugger remotely
75 *****************************************************************************/
78 AcpiDbRunRemoteDebugger (
82 char *Ptr
= BatchBuffer
;
86 while (!AcpiGbl_DbTerminateLoop
)
96 /* Convert commas to spaces */
108 strncpy (AcpiGbl_DbLineBuf
, Cmd
, ACPI_DB_LINE_BUFFER_SIZE
);
119 /* Force output to console until a command is entered */
121 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT
);
123 /* Different prompt if method is executing */
125 if (!AcpiGbl_MethodExecuting
)
127 AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_COMMAND_PROMPT
);
131 AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_EXECUTE_PROMPT
);
134 /* Get the user input line */
136 Status
= AcpiOsGetLine (AcpiGbl_DbLineBuf
,
137 ACPI_DB_LINE_BUFFER_SIZE
, NULL
);
138 if (ACPI_FAILURE (Status
))
145 * Signal the debug thread that we have a command to execute,
146 * and wait for the command to complete.
148 AcpiOsReleaseMutex (AcpiGbl_DbCommandReady
);
150 Status
= AcpiOsAcquireMutex (AcpiGbl_DbCommandComplete
,
152 if (ACPI_FAILURE (Status
))
160 /******************************************************************************
162 * FUNCTION: AcpiOsWaitCommandReady
168 * DESCRIPTION: Negotiate with the debugger foreground thread (the user
169 * thread) to wait the readiness of a command.
171 *****************************************************************************/
174 AcpiOsWaitCommandReady (
177 ACPI_STATUS Status
= AE_OK
;
180 if (AcpiGbl_DebuggerConfiguration
== DEBUGGER_MULTI_THREADED
)
184 while (Status
== AE_TIME
)
186 if (AcpiGbl_DbTerminateLoop
)
188 Status
= AE_CTRL_TERMINATE
;
192 Status
= AcpiOsAcquireMutex (AcpiGbl_DbCommandReady
, 1000);
198 /* Force output to console until a command is entered */
200 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT
);
202 /* Different prompt if method is executing */
204 if (!AcpiGbl_MethodExecuting
)
206 AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_COMMAND_PROMPT
);
210 AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_EXECUTE_PROMPT
);
213 /* Get the user input line */
215 Status
= AcpiOsGetLine (AcpiGbl_DbLineBuf
,
216 ACPI_DB_LINE_BUFFER_SIZE
, NULL
);
219 if (ACPI_FAILURE (Status
) && Status
!= AE_CTRL_TERMINATE
)
221 ACPI_EXCEPTION ((AE_INFO
, Status
,
222 "While parsing/handling command line"));
228 /******************************************************************************
230 * FUNCTION: AcpiOsNotifyCommandComplete
236 * DESCRIPTION: Negotiate with the debugger foreground thread (the user
237 * thread) to notify the completion of a command.
239 *****************************************************************************/
242 AcpiOsNotifyCommandComplete (
246 if (AcpiGbl_DebuggerConfiguration
== DEBUGGER_MULTI_THREADED
)
248 AcpiOsReleaseMutex (AcpiGbl_DbCommandComplete
);
254 /******************************************************************************
256 * FUNCTION: AcpiOsInitializeDebugger
262 * DESCRIPTION: Initialize OSPM specific part of the debugger
264 *****************************************************************************/
267 AcpiOsInitializeDebugger (
273 /* Create command signals */
275 Status
= AcpiOsCreateMutex (&AcpiGbl_DbCommandReady
);
276 if (ACPI_FAILURE (Status
))
280 Status
= AcpiOsCreateMutex (&AcpiGbl_DbCommandComplete
);
281 if (ACPI_FAILURE (Status
))
286 /* Initialize the states of the command signals */
288 Status
= AcpiOsAcquireMutex (AcpiGbl_DbCommandComplete
,
290 if (ACPI_FAILURE (Status
))
294 Status
= AcpiOsAcquireMutex (AcpiGbl_DbCommandReady
,
296 if (ACPI_FAILURE (Status
))
301 AcpiGbl_DbCommandSignalsInitialized
= TRUE
;
305 AcpiOsDeleteMutex (AcpiGbl_DbCommandComplete
);
307 AcpiOsDeleteMutex (AcpiGbl_DbCommandReady
);
312 /******************************************************************************
314 * FUNCTION: AcpiOsTerminateDebugger
320 * DESCRIPTION: Terminate signals used by the multi-threading debugger
322 *****************************************************************************/
325 AcpiOsTerminateDebugger (
329 if (AcpiGbl_DbCommandSignalsInitialized
)
331 AcpiOsDeleteMutex (AcpiGbl_DbCommandReady
);
332 AcpiOsDeleteMutex (AcpiGbl_DbCommandComplete
);
337 /******************************************************************************
339 * FUNCTION: AcpiRunDebugger
341 * PARAMETERS: BatchBuffer - Buffer containing commands running in
346 * DESCRIPTION: Run a local/remote debugger
348 *****************************************************************************/
354 /* Check for single or multithreaded debug */
356 if (AcpiGbl_DebuggerConfiguration
& DEBUGGER_MULTI_THREADED
)
358 AcpiDbRunRemoteDebugger (BatchBuffer
);
362 AcpiDbUserCommands ();
366 ACPI_EXPORT_SYMBOL (AcpiRunDebugger
)