Fixed compatibility of output.
[AROS.git] / arch / all-pc / acpica / source / components / utilities / utdebug.c
blob87dbf53866859a7ac6cb003430ad41ef8ea36eea
1 /******************************************************************************
3 * Module Name: utdebug - Debug print/trace routines
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2013, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
30 * NO WARRANTY
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.
44 #define __UTDEBUG_C__
45 #define EXPORT_ACPI_INTERFACES
47 #include "acpi.h"
48 #include "accommon.h"
50 #define _COMPONENT ACPI_UTILITIES
51 ACPI_MODULE_NAME ("utdebug")
54 #ifdef ACPI_DEBUG_OUTPUT
56 static ACPI_THREAD_ID AcpiGbl_PrevThreadId = (ACPI_THREAD_ID) 0xFFFFFFFF;
57 static char *AcpiGbl_FnEntryStr = "----Entry";
58 static char *AcpiGbl_FnExitStr = "----Exit-";
60 /* Local prototypes */
62 static const char *
63 AcpiUtTrimFunctionName (
64 const char *FunctionName);
67 /*******************************************************************************
69 * FUNCTION: AcpiUtInitStackPtrTrace
71 * PARAMETERS: None
73 * RETURN: None
75 * DESCRIPTION: Save the current CPU stack pointer at subsystem startup
77 ******************************************************************************/
79 void
80 AcpiUtInitStackPtrTrace (
81 void)
83 ACPI_SIZE CurrentSp;
86 AcpiGbl_EntryStackPointer = &CurrentSp;
90 /*******************************************************************************
92 * FUNCTION: AcpiUtTrackStackPtr
94 * PARAMETERS: None
96 * RETURN: None
98 * DESCRIPTION: Save the current CPU stack pointer
100 ******************************************************************************/
102 void
103 AcpiUtTrackStackPtr (
104 void)
106 ACPI_SIZE CurrentSp;
109 if (&CurrentSp < AcpiGbl_LowestStackPointer)
111 AcpiGbl_LowestStackPointer = &CurrentSp;
114 if (AcpiGbl_NestingLevel > AcpiGbl_DeepestNesting)
116 AcpiGbl_DeepestNesting = AcpiGbl_NestingLevel;
121 /*******************************************************************************
123 * FUNCTION: AcpiUtTrimFunctionName
125 * PARAMETERS: FunctionName - Ascii string containing a procedure name
127 * RETURN: Updated pointer to the function name
129 * DESCRIPTION: Remove the "Acpi" prefix from the function name, if present.
130 * This allows compiler macros such as __FUNCTION__ to be used
131 * with no change to the debug output.
133 ******************************************************************************/
135 static const char *
136 AcpiUtTrimFunctionName (
137 const char *FunctionName)
140 /* All Function names are longer than 4 chars, check is safe */
142 if (*(ACPI_CAST_PTR (UINT32, FunctionName)) == ACPI_PREFIX_MIXED)
144 /* This is the case where the original source has not been modified */
146 return (FunctionName + 4);
149 if (*(ACPI_CAST_PTR (UINT32, FunctionName)) == ACPI_PREFIX_LOWER)
151 /* This is the case where the source has been 'linuxized' */
153 return (FunctionName + 5);
156 return (FunctionName);
160 /*******************************************************************************
162 * FUNCTION: AcpiDebugPrint
164 * PARAMETERS: RequestedDebugLevel - Requested debug print level
165 * LineNumber - Caller's line number (for error output)
166 * FunctionName - Caller's procedure name
167 * ModuleName - Caller's module name
168 * ComponentId - Caller's component ID
169 * Format - Printf format field
170 * ... - Optional printf arguments
172 * RETURN: None
174 * DESCRIPTION: Print error message with prefix consisting of the module name,
175 * line number, and component ID.
177 ******************************************************************************/
179 void ACPI_INTERNAL_VAR_XFACE
180 AcpiDebugPrint (
181 UINT32 RequestedDebugLevel,
182 UINT32 LineNumber,
183 const char *FunctionName,
184 const char *ModuleName,
185 UINT32 ComponentId,
186 const char *Format,
187 ...)
189 ACPI_THREAD_ID ThreadId;
190 va_list args;
193 /* Check if debug output enabled */
195 if (!ACPI_IS_DEBUG_ENABLED (RequestedDebugLevel, ComponentId))
197 return;
201 * Thread tracking and context switch notification
203 ThreadId = AcpiOsGetThreadId ();
204 if (ThreadId != AcpiGbl_PrevThreadId)
206 if (ACPI_LV_THREADS & AcpiDbgLevel)
208 AcpiOsPrintf (
209 "\n**** Context Switch from TID %u to TID %u ****\n\n",
210 (UINT32) AcpiGbl_PrevThreadId, (UINT32) ThreadId);
213 AcpiGbl_PrevThreadId = ThreadId;
214 AcpiGbl_NestingLevel = 0;
218 * Display the module name, current line number, thread ID (if requested),
219 * current procedure nesting level, and the current procedure name
221 AcpiOsPrintf ("%9s-%04ld ", ModuleName, LineNumber);
223 #ifdef ACPI_EXEC_APP
225 * For AcpiExec only, emit the thread ID and nesting level.
226 * Note: nesting level is really only useful during a single-thread
227 * execution. Otherwise, multiple threads will keep resetting the
228 * level.
230 if (ACPI_LV_THREADS & AcpiDbgLevel)
232 AcpiOsPrintf ("[%u] ", (UINT32) ThreadId);
235 AcpiOsPrintf ("[%02ld] ", AcpiGbl_NestingLevel);
236 #endif
238 AcpiOsPrintf ("%-22.22s: ", AcpiUtTrimFunctionName (FunctionName));
240 va_start (args, Format);
241 AcpiOsVprintf (Format, args);
242 va_end (args);
245 ACPI_EXPORT_SYMBOL (AcpiDebugPrint)
248 /*******************************************************************************
250 * FUNCTION: AcpiDebugPrintRaw
252 * PARAMETERS: RequestedDebugLevel - Requested debug print level
253 * LineNumber - Caller's line number
254 * FunctionName - Caller's procedure name
255 * ModuleName - Caller's module name
256 * ComponentId - Caller's component ID
257 * Format - Printf format field
258 * ... - Optional printf arguments
260 * RETURN: None
262 * DESCRIPTION: Print message with no headers. Has same interface as
263 * DebugPrint so that the same macros can be used.
265 ******************************************************************************/
267 void ACPI_INTERNAL_VAR_XFACE
268 AcpiDebugPrintRaw (
269 UINT32 RequestedDebugLevel,
270 UINT32 LineNumber,
271 const char *FunctionName,
272 const char *ModuleName,
273 UINT32 ComponentId,
274 const char *Format,
275 ...)
277 va_list args;
280 /* Check if debug output enabled */
282 if (!ACPI_IS_DEBUG_ENABLED (RequestedDebugLevel, ComponentId))
284 return;
287 va_start (args, Format);
288 AcpiOsVprintf (Format, args);
289 va_end (args);
292 ACPI_EXPORT_SYMBOL (AcpiDebugPrintRaw)
295 /*******************************************************************************
297 * FUNCTION: AcpiUtTrace
299 * PARAMETERS: LineNumber - Caller's line number
300 * FunctionName - Caller's procedure name
301 * ModuleName - Caller's module name
302 * ComponentId - Caller's component ID
304 * RETURN: None
306 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
307 * set in DebugLevel
309 ******************************************************************************/
311 void
312 AcpiUtTrace (
313 UINT32 LineNumber,
314 const char *FunctionName,
315 const char *ModuleName,
316 UINT32 ComponentId)
319 AcpiGbl_NestingLevel++;
320 AcpiUtTrackStackPtr ();
322 /* Check if enabled up-front for performance */
324 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
326 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
327 LineNumber, FunctionName, ModuleName, ComponentId,
328 "%s\n", AcpiGbl_FnEntryStr);
332 ACPI_EXPORT_SYMBOL (AcpiUtTrace)
335 /*******************************************************************************
337 * FUNCTION: AcpiUtTracePtr
339 * PARAMETERS: LineNumber - Caller's line number
340 * FunctionName - Caller's procedure name
341 * ModuleName - Caller's module name
342 * ComponentId - Caller's component ID
343 * Pointer - Pointer to display
345 * RETURN: None
347 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
348 * set in DebugLevel
350 ******************************************************************************/
352 void
353 AcpiUtTracePtr (
354 UINT32 LineNumber,
355 const char *FunctionName,
356 const char *ModuleName,
357 UINT32 ComponentId,
358 void *Pointer)
361 AcpiGbl_NestingLevel++;
362 AcpiUtTrackStackPtr ();
364 /* Check if enabled up-front for performance */
366 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
368 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
369 LineNumber, FunctionName, ModuleName, ComponentId,
370 "%s %p\n", AcpiGbl_FnEntryStr, Pointer);
375 /*******************************************************************************
377 * FUNCTION: AcpiUtTraceStr
379 * PARAMETERS: LineNumber - Caller's line number
380 * FunctionName - Caller's procedure name
381 * ModuleName - Caller's module name
382 * ComponentId - Caller's component ID
383 * String - Additional string to display
385 * RETURN: None
387 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
388 * set in DebugLevel
390 ******************************************************************************/
392 void
393 AcpiUtTraceStr (
394 UINT32 LineNumber,
395 const char *FunctionName,
396 const char *ModuleName,
397 UINT32 ComponentId,
398 char *String)
401 AcpiGbl_NestingLevel++;
402 AcpiUtTrackStackPtr ();
404 /* Check if enabled up-front for performance */
406 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
408 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
409 LineNumber, FunctionName, ModuleName, ComponentId,
410 "%s %s\n", AcpiGbl_FnEntryStr, String);
415 /*******************************************************************************
417 * FUNCTION: AcpiUtTraceU32
419 * PARAMETERS: LineNumber - Caller's line number
420 * FunctionName - Caller's procedure name
421 * ModuleName - Caller's module name
422 * ComponentId - Caller's component ID
423 * Integer - Integer to display
425 * RETURN: None
427 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
428 * set in DebugLevel
430 ******************************************************************************/
432 void
433 AcpiUtTraceU32 (
434 UINT32 LineNumber,
435 const char *FunctionName,
436 const char *ModuleName,
437 UINT32 ComponentId,
438 UINT32 Integer)
441 AcpiGbl_NestingLevel++;
442 AcpiUtTrackStackPtr ();
444 /* Check if enabled up-front for performance */
446 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
448 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
449 LineNumber, FunctionName, ModuleName, ComponentId,
450 "%s %08X\n", AcpiGbl_FnEntryStr, Integer);
455 /*******************************************************************************
457 * FUNCTION: AcpiUtExit
459 * PARAMETERS: LineNumber - Caller's line number
460 * FunctionName - Caller's procedure name
461 * ModuleName - Caller's module name
462 * ComponentId - Caller's component ID
464 * RETURN: None
466 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
467 * set in DebugLevel
469 ******************************************************************************/
471 void
472 AcpiUtExit (
473 UINT32 LineNumber,
474 const char *FunctionName,
475 const char *ModuleName,
476 UINT32 ComponentId)
479 /* Check if enabled up-front for performance */
481 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
483 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
484 LineNumber, FunctionName, ModuleName, ComponentId,
485 "%s\n", AcpiGbl_FnExitStr);
488 if (AcpiGbl_NestingLevel)
490 AcpiGbl_NestingLevel--;
494 ACPI_EXPORT_SYMBOL (AcpiUtExit)
497 /*******************************************************************************
499 * FUNCTION: AcpiUtStatusExit
501 * PARAMETERS: LineNumber - Caller's line number
502 * FunctionName - Caller's procedure name
503 * ModuleName - Caller's module name
504 * ComponentId - Caller's component ID
505 * Status - Exit status code
507 * RETURN: None
509 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
510 * set in DebugLevel. Prints exit status also.
512 ******************************************************************************/
514 void
515 AcpiUtStatusExit (
516 UINT32 LineNumber,
517 const char *FunctionName,
518 const char *ModuleName,
519 UINT32 ComponentId,
520 ACPI_STATUS Status)
523 /* Check if enabled up-front for performance */
525 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
527 if (ACPI_SUCCESS (Status))
529 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
530 LineNumber, FunctionName, ModuleName, ComponentId,
531 "%s %s\n", AcpiGbl_FnExitStr,
532 AcpiFormatException (Status));
534 else
536 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
537 LineNumber, FunctionName, ModuleName, ComponentId,
538 "%s ****Exception****: %s\n", AcpiGbl_FnExitStr,
539 AcpiFormatException (Status));
543 if (AcpiGbl_NestingLevel)
545 AcpiGbl_NestingLevel--;
549 ACPI_EXPORT_SYMBOL (AcpiUtStatusExit)
552 /*******************************************************************************
554 * FUNCTION: AcpiUtValueExit
556 * PARAMETERS: LineNumber - Caller's line number
557 * FunctionName - Caller's procedure name
558 * ModuleName - Caller's module name
559 * ComponentId - Caller's component ID
560 * Value - Value to be printed with exit msg
562 * RETURN: None
564 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
565 * set in DebugLevel. Prints exit value also.
567 ******************************************************************************/
569 void
570 AcpiUtValueExit (
571 UINT32 LineNumber,
572 const char *FunctionName,
573 const char *ModuleName,
574 UINT32 ComponentId,
575 UINT64 Value)
578 /* Check if enabled up-front for performance */
580 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
582 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
583 LineNumber, FunctionName, ModuleName, ComponentId,
584 "%s %8.8X%8.8X\n", AcpiGbl_FnExitStr,
585 ACPI_FORMAT_UINT64 (Value));
588 if (AcpiGbl_NestingLevel)
590 AcpiGbl_NestingLevel--;
594 ACPI_EXPORT_SYMBOL (AcpiUtValueExit)
597 /*******************************************************************************
599 * FUNCTION: AcpiUtPtrExit
601 * PARAMETERS: LineNumber - Caller's line number
602 * FunctionName - Caller's procedure name
603 * ModuleName - Caller's module name
604 * ComponentId - Caller's component ID
605 * Ptr - Pointer to display
607 * RETURN: None
609 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
610 * set in DebugLevel. Prints exit value also.
612 ******************************************************************************/
614 void
615 AcpiUtPtrExit (
616 UINT32 LineNumber,
617 const char *FunctionName,
618 const char *ModuleName,
619 UINT32 ComponentId,
620 UINT8 *Ptr)
623 /* Check if enabled up-front for performance */
625 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
627 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
628 LineNumber, FunctionName, ModuleName, ComponentId,
629 "%s %p\n", AcpiGbl_FnExitStr, Ptr);
632 if (AcpiGbl_NestingLevel)
634 AcpiGbl_NestingLevel--;
638 #endif