utdebug.c revision 87031
1/****************************************************************************** 2 * 3 * Module Name: utdebug - Debug print routines 4 * $Revision: 91 $ 5 * 6 *****************************************************************************/ 7 8/****************************************************************************** 9 * 10 * 1. Copyright Notice 11 * 12 * Some or all of this work - Copyright (c) 1999, 2000, 2001, Intel Corp. 13 * All rights reserved. 14 * 15 * 2. License 16 * 17 * 2.1. This is your license from Intel Corp. under its intellectual property 18 * rights. You may have additional license terms from the party that provided 19 * you this software, covering your right to use that party's intellectual 20 * property rights. 21 * 22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 23 * copy of the source code appearing in this file ("Covered Code") an 24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 25 * base code distributed originally by Intel ("Original Intel Code") to copy, 26 * make derivatives, distribute, use and display any portion of the Covered 27 * Code in any form, with the right to sublicense such rights; and 28 * 29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 30 * license (with the right to sublicense), under only those claims of Intel 31 * patents that are infringed by the Original Intel Code, to make, use, sell, 32 * offer to sell, and import the Covered Code and derivative works thereof 33 * solely to the minimum extent necessary to exercise the above copyright 34 * license, and in no event shall the patent license extend to any additions 35 * to or modifications of the Original Intel Code. No other license or right 36 * is granted directly or by implication, estoppel or otherwise; 37 * 38 * The above copyright and patent license is granted only if the following 39 * conditions are met: 40 * 41 * 3. Conditions 42 * 43 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 44 * Redistribution of source code of any substantial portion of the Covered 45 * Code or modification with rights to further distribute source must include 46 * the above Copyright Notice, the above License, this list of Conditions, 47 * and the following Disclaimer and Export Compliance provision. In addition, 48 * Licensee must cause all Covered Code to which Licensee contributes to 49 * contain a file documenting the changes Licensee made to create that Covered 50 * Code and the date of any change. Licensee must include in that file the 51 * documentation of any changes made by any predecessor Licensee. Licensee 52 * must include a prominent statement that the modification is derived, 53 * directly or indirectly, from Original Intel Code. 54 * 55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 56 * Redistribution of source code of any substantial portion of the Covered 57 * Code or modification without rights to further distribute source must 58 * include the following Disclaimer and Export Compliance provision in the 59 * documentation and/or other materials provided with distribution. In 60 * addition, Licensee may not authorize further sublicense of source of any 61 * portion of the Covered Code, and must include terms to the effect that the 62 * license from Licensee to its licensee is limited to the intellectual 63 * property embodied in the software Licensee provides to its licensee, and 64 * not to intellectual property embodied in modifications its licensee may 65 * make. 66 * 67 * 3.3. Redistribution of Executable. Redistribution in executable form of any 68 * substantial portion of the Covered Code or modification must reproduce the 69 * above Copyright Notice, and the following Disclaimer and Export Compliance 70 * provision in the documentation and/or other materials provided with the 71 * distribution. 72 * 73 * 3.4. Intel retains all right, title, and interest in and to the Original 74 * Intel Code. 75 * 76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 77 * Intel shall be used in advertising or otherwise to promote the sale, use or 78 * other dealings in products derived from or relating to the Covered Code 79 * without prior written authorization from Intel. 80 * 81 * 4. Disclaimer and Export Compliance 82 * 83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 89 * PARTICULAR PURPOSE. 90 * 91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 98 * LIMITED REMEDY. 99 * 100 * 4.3. Licensee shall not export, either directly or indirectly, any of this 101 * software or system incorporating such software without first obtaining any 102 * required license or other approval from the U. S. Department of Commerce or 103 * any other agency or department of the United States Government. In the 104 * event Licensee exports any such software from the United States or 105 * re-exports any such software from a foreign destination, Licensee shall 106 * ensure that the distribution and export/re-export of the software is in 107 * compliance with all laws, regulations, orders, or other restrictions of the 108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 109 * any of its subsidiaries will export/re-export any technical data, process, 110 * software, or service, directly or indirectly, to any country for which the 111 * United States government or any agency thereof requires an export license, 112 * other governmental approval, or letter of assurance, without first obtaining 113 * such license, approval or letter. 114 * 115 *****************************************************************************/ 116 117#define __UTDEBUG_C__ 118 119#include "acpi.h" 120 121#define _COMPONENT ACPI_UTILITIES 122 MODULE_NAME ("utdebug") 123 124 125UINT32 AcpiGbl_PrevThreadId = 0xFFFFFFFF; 126char *AcpiGbl_FnEntryStr = "----Entry"; 127char *AcpiGbl_FnExitStr = "----Exit-"; 128 129 130#ifdef ACPI_DEBUG 131 132 133/***************************************************************************** 134 * 135 * FUNCTION: AcpiUtInitStackPtrTrace 136 * 137 * PARAMETERS: None 138 * 139 * RETURN: None 140 * 141 * DESCRIPTION: Save the current stack pointer 142 * 143 ****************************************************************************/ 144 145void 146AcpiUtInitStackPtrTrace ( 147 void) 148{ 149 UINT32 CurrentSp; 150 151 152 AcpiGbl_EntryStackPointer = (UINT32) &CurrentSp; 153} 154 155 156/***************************************************************************** 157 * 158 * FUNCTION: AcpiUtTrackStackPtr 159 * 160 * PARAMETERS: None 161 * 162 * RETURN: None 163 * 164 * DESCRIPTION: Save the current stack pointer 165 * 166 ****************************************************************************/ 167 168void 169AcpiUtTrackStackPtr ( 170 void) 171{ 172 UINT32 CurrentSp; 173 174 CurrentSp = (UINT32) &CurrentSp; 175 176 if (CurrentSp < AcpiGbl_LowestStackPointer) 177 { 178 AcpiGbl_LowestStackPointer = CurrentSp; 179 } 180 181 if (AcpiGbl_NestingLevel > AcpiGbl_DeepestNesting) 182 { 183 AcpiGbl_DeepestNesting = AcpiGbl_NestingLevel; 184 } 185} 186 187 188/***************************************************************************** 189 * 190 * FUNCTION: AcpiUtDebugPrint 191 * 192 * PARAMETERS: DebugLevel - Requested debug print level 193 * ProcName - Caller's procedure name 194 * ModuleName - Caller's module name (for error output) 195 * LineNumber - Caller's line number (for error output) 196 * ComponentId - Caller's component ID (for error output) 197 * 198 * Format - Printf format field 199 * ... - Optional printf arguments 200 * 201 * RETURN: None 202 * 203 * DESCRIPTION: Print error message with prefix consisting of the module name, 204 * line number, and component ID. 205 * 206 ****************************************************************************/ 207 208void 209AcpiUtDebugPrint ( 210 UINT32 RequestedDebugLevel, 211 UINT32 LineNumber, 212 ACPI_DEBUG_PRINT_INFO *DbgInfo, 213 char *Format, 214 ...) 215{ 216 UINT32 ThreadId; 217 va_list args; 218 219 220 /* 221 * Stay silent if the debug level or component ID is disabled 222 */ 223 if (!(RequestedDebugLevel & AcpiDbgLevel) || 224 !(DbgInfo->ComponentId & AcpiDbgLayer)) 225 { 226 return; 227 } 228 229 230 /* 231 * Thread tracking and context switch notification 232 */ 233 ThreadId = AcpiOsGetThreadId (); 234 235 if (ThreadId != AcpiGbl_PrevThreadId) 236 { 237 if (ACPI_LV_THREADS & AcpiDbgLevel) 238 { 239 AcpiOsPrintf ("\n**** Context Switch from TID %X to TID %X ****\n\n", 240 AcpiGbl_PrevThreadId, ThreadId); 241 } 242 243 AcpiGbl_PrevThreadId = ThreadId; 244 } 245 246 /* 247 * Display the module name, current line number, thread ID (if requested), 248 * current procedure nesting level, and the current procedure name 249 */ 250 AcpiOsPrintf ("%8s-%04d ", DbgInfo->ModuleName, LineNumber); 251 252 if (ACPI_LV_THREADS & AcpiDbgLevel) 253 { 254 AcpiOsPrintf ("[%04X] ", ThreadId, AcpiGbl_NestingLevel, DbgInfo->ProcName); 255 } 256 257 AcpiOsPrintf ("[%02d] %-22.22s: ", AcpiGbl_NestingLevel, DbgInfo->ProcName); 258 259 260 va_start (args, Format); 261 AcpiOsVprintf (Format, args); 262} 263 264 265/***************************************************************************** 266 * 267 * FUNCTION: AcpiUtDebugPrintRaw 268 * 269 * PARAMETERS: RequestedDebugLevel - Requested debug print level 270 * LineNumber - Caller's line number 271 * DbgInfo - Contains: 272 * ProcName - Caller's procedure name 273 * ModuleName - Caller's module name 274 * ComponentId - Caller's component ID 275 * Format - Printf format field 276 * ... - Optional printf arguments 277 * 278 * RETURN: None 279 * 280 * DESCRIPTION: Print message with no headers. Has same interface as 281 * DebugPrint so that the same macros can be used. 282 * 283 ****************************************************************************/ 284 285void 286AcpiUtDebugPrintRaw ( 287 UINT32 RequestedDebugLevel, 288 UINT32 LineNumber, 289 ACPI_DEBUG_PRINT_INFO *DbgInfo, 290 char *Format, 291 ...) 292{ 293 va_list args; 294 295 296 if (!(RequestedDebugLevel & AcpiDbgLevel) || 297 !(DbgInfo->ComponentId & AcpiDbgLayer)) 298 { 299 return; 300 } 301 302 va_start (args, Format); 303 304 AcpiOsVprintf (Format, args); 305} 306 307 308/***************************************************************************** 309 * 310 * FUNCTION: AcpiUtTrace 311 * 312 * PARAMETERS: LineNumber - Caller's line number 313 * DbgInfo - Contains: 314 * ProcName - Caller's procedure name 315 * ModuleName - Caller's module name 316 * ComponentId - Caller's component ID 317 * 318 * RETURN: None 319 * 320 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is 321 * set in DebugLevel 322 * 323 ****************************************************************************/ 324 325void 326AcpiUtTrace ( 327 UINT32 LineNumber, 328 ACPI_DEBUG_PRINT_INFO *DbgInfo) 329{ 330 331 AcpiGbl_NestingLevel++; 332 AcpiUtTrackStackPtr (); 333 334 AcpiUtDebugPrint (ACPI_LV_FUNCTIONS, LineNumber, DbgInfo, 335 "%s\n", AcpiGbl_FnEntryStr); 336} 337 338 339/***************************************************************************** 340 * 341 * FUNCTION: AcpiUtTracePtr 342 * 343 * PARAMETERS: LineNumber - Caller's line number 344 * DbgInfo - Contains: 345 * ProcName - Caller's procedure name 346 * ModuleName - Caller's module name 347 * ComponentId - Caller's component ID 348 * Pointer - Pointer to display 349 * 350 * RETURN: None 351 * 352 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is 353 * set in DebugLevel 354 * 355 ****************************************************************************/ 356 357void 358AcpiUtTracePtr ( 359 UINT32 LineNumber, 360 ACPI_DEBUG_PRINT_INFO *DbgInfo, 361 void *Pointer) 362{ 363 AcpiGbl_NestingLevel++; 364 AcpiUtTrackStackPtr (); 365 366 AcpiUtDebugPrint (ACPI_LV_FUNCTIONS, LineNumber, DbgInfo, 367 "%s %p\n", AcpiGbl_FnEntryStr, Pointer); 368} 369 370 371/***************************************************************************** 372 * 373 * FUNCTION: AcpiUtTraceStr 374 * 375 * PARAMETERS: LineNumber - Caller's line number 376 * DbgInfo - Contains: 377 * ProcName - Caller's procedure name 378 * ModuleName - Caller's module name 379 * ComponentId - Caller's component ID 380 * String - Additional string to display 381 * 382 * RETURN: None 383 * 384 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is 385 * set in DebugLevel 386 * 387 ****************************************************************************/ 388 389void 390AcpiUtTraceStr ( 391 UINT32 LineNumber, 392 ACPI_DEBUG_PRINT_INFO *DbgInfo, 393 NATIVE_CHAR *String) 394{ 395 396 AcpiGbl_NestingLevel++; 397 AcpiUtTrackStackPtr (); 398 399 AcpiUtDebugPrint (ACPI_LV_FUNCTIONS, LineNumber, DbgInfo, 400 "%s %s\n", AcpiGbl_FnEntryStr, String); 401} 402 403 404/***************************************************************************** 405 * 406 * FUNCTION: AcpiUtTraceU32 407 * 408 * PARAMETERS: LineNumber - Caller's line number 409 * DbgInfo - Contains: 410 * ProcName - Caller's procedure name 411 * ModuleName - Caller's module name 412 * ComponentId - Caller's component ID 413 * Integer - Integer to display 414 * 415 * RETURN: None 416 * 417 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is 418 * set in DebugLevel 419 * 420 ****************************************************************************/ 421 422void 423AcpiUtTraceU32 ( 424 UINT32 LineNumber, 425 ACPI_DEBUG_PRINT_INFO *DbgInfo, 426 UINT32 Integer) 427{ 428 429 AcpiGbl_NestingLevel++; 430 AcpiUtTrackStackPtr (); 431 432 AcpiUtDebugPrint (ACPI_LV_FUNCTIONS, LineNumber, DbgInfo, 433 "%s %08X\n", AcpiGbl_FnEntryStr, Integer); 434} 435 436 437/***************************************************************************** 438 * 439 * FUNCTION: AcpiUtExit 440 * 441 * PARAMETERS: LineNumber - Caller's line number 442 * DbgInfo - Contains: 443 * ProcName - Caller's procedure name 444 * ModuleName - Caller's module name 445 * ComponentId - Caller's component ID 446 * 447 * RETURN: None 448 * 449 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is 450 * set in DebugLevel 451 * 452 ****************************************************************************/ 453 454void 455AcpiUtExit ( 456 UINT32 LineNumber, 457 ACPI_DEBUG_PRINT_INFO *DbgInfo) 458{ 459 460 AcpiUtDebugPrint (ACPI_LV_FUNCTIONS, LineNumber, DbgInfo, 461 "%s\n", AcpiGbl_FnExitStr); 462 463 AcpiGbl_NestingLevel--; 464} 465 466 467/***************************************************************************** 468 * 469 * FUNCTION: AcpiUtStatusExit 470 * 471 * PARAMETERS: LineNumber - Caller's line number 472 * DbgInfo - Contains: 473 * ProcName - Caller's procedure name 474 * ModuleName - Caller's module name 475 * ComponentId - Caller's component ID 476 * Status - Exit status code 477 * 478 * RETURN: None 479 * 480 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is 481 * set in DebugLevel. Prints exit status also. 482 * 483 ****************************************************************************/ 484 485void 486AcpiUtStatusExit ( 487 UINT32 LineNumber, 488 ACPI_DEBUG_PRINT_INFO *DbgInfo, 489 ACPI_STATUS Status) 490{ 491 492 if (ACPI_SUCCESS (Status)) 493 { 494 AcpiUtDebugPrint (ACPI_LV_FUNCTIONS, LineNumber, DbgInfo, 495 "%s %s\n", AcpiGbl_FnExitStr, 496 AcpiFormatException (Status)); 497 } 498 else 499 { 500 AcpiUtDebugPrint (ACPI_LV_FUNCTIONS, LineNumber, DbgInfo, 501 "%s ****Exception****: %s\n", AcpiGbl_FnExitStr, 502 AcpiFormatException (Status)); 503 } 504 505 AcpiGbl_NestingLevel--; 506} 507 508 509/***************************************************************************** 510 * 511 * FUNCTION: AcpiUtValueExit 512 * 513 * PARAMETERS: LineNumber - Caller's line number 514 * DbgInfo - Contains: 515 * ProcName - Caller's procedure name 516 * ModuleName - Caller's module name 517 * ComponentId - Caller's component ID 518 * Value - Value to be printed with exit msg 519 * 520 * RETURN: None 521 * 522 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is 523 * set in DebugLevel. Prints exit value also. 524 * 525 ****************************************************************************/ 526 527void 528AcpiUtValueExit ( 529 UINT32 LineNumber, 530 ACPI_DEBUG_PRINT_INFO *DbgInfo, 531 ACPI_INTEGER Value) 532{ 533 534 AcpiUtDebugPrint (ACPI_LV_FUNCTIONS, LineNumber, DbgInfo, 535 "%s %8.8X%8.8X\n", AcpiGbl_FnExitStr, HIDWORD(Value), LODWORD(Value)); 536 537 AcpiGbl_NestingLevel--; 538} 539 540 541/***************************************************************************** 542 * 543 * FUNCTION: AcpiUtPtrExit 544 * 545 * PARAMETERS: LineNumber - Caller's line number 546 * DbgInfo - Contains: 547 * ProcName - Caller's procedure name 548 * ModuleName - Caller's module name 549 * ComponentId - Caller's component ID 550 * Value - Value to be printed with exit msg 551 * 552 * RETURN: None 553 * 554 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is 555 * set in DebugLevel. Prints exit value also. 556 * 557 ****************************************************************************/ 558 559void 560AcpiUtPtrExit ( 561 UINT32 LineNumber, 562 ACPI_DEBUG_PRINT_INFO *DbgInfo, 563 UINT8 *Ptr) 564{ 565 566 AcpiUtDebugPrint (ACPI_LV_FUNCTIONS, LineNumber, DbgInfo, 567 "%s %p\n", AcpiGbl_FnExitStr, Ptr); 568 569 AcpiGbl_NestingLevel--; 570} 571 572#endif 573 574 575/***************************************************************************** 576 * 577 * FUNCTION: AcpiUtDumpBuffer 578 * 579 * PARAMETERS: Buffer - Buffer to dump 580 * Count - Amount to dump, in bytes 581 * Display - BYTE, WORD, DWORD, or QWORD display 582 * ComponentID - Caller's component ID 583 * 584 * RETURN: None 585 * 586 * DESCRIPTION: Generic dump buffer in both hex and ascii. 587 * 588 ****************************************************************************/ 589 590void 591AcpiUtDumpBuffer ( 592 UINT8 *Buffer, 593 UINT32 Count, 594 UINT32 Display, 595 UINT32 ComponentId) 596{ 597 UINT32 i = 0; 598 UINT32 j; 599 UINT32 Temp32; 600 UINT8 BufChar; 601 602 603 /* Only dump the buffer if tracing is enabled */ 604 605 if (!((ACPI_LV_TABLES & AcpiDbgLevel) && 606 (ComponentId & AcpiDbgLayer))) 607 { 608 return; 609 } 610 611 612 /* 613 * Nasty little dump buffer routine! 614 */ 615 while (i < Count) 616 { 617 /* Print current offset */ 618 619 AcpiOsPrintf ("%05X ", i); 620 621 622 /* Print 16 hex chars */ 623 624 for (j = 0; j < 16;) 625 { 626 if (i + j >= Count) 627 { 628 AcpiOsPrintf ("\n"); 629 return; 630 } 631 632 /* Make sure that the INT8 doesn't get sign-extended! */ 633 634 switch (Display) 635 { 636 /* Default is BYTE display */ 637 638 default: 639 640 AcpiOsPrintf ("%02X ", 641 *((UINT8 *) &Buffer[i + j])); 642 j += 1; 643 break; 644 645 646 case DB_WORD_DISPLAY: 647 648 MOVE_UNALIGNED16_TO_32 (&Temp32, 649 &Buffer[i + j]); 650 AcpiOsPrintf ("%04X ", Temp32); 651 j += 2; 652 break; 653 654 655 case DB_DWORD_DISPLAY: 656 657 MOVE_UNALIGNED32_TO_32 (&Temp32, 658 &Buffer[i + j]); 659 AcpiOsPrintf ("%08X ", Temp32); 660 j += 4; 661 break; 662 663 664 case DB_QWORD_DISPLAY: 665 666 MOVE_UNALIGNED32_TO_32 (&Temp32, 667 &Buffer[i + j]); 668 AcpiOsPrintf ("%08X", Temp32); 669 670 MOVE_UNALIGNED32_TO_32 (&Temp32, 671 &Buffer[i + j + 4]); 672 AcpiOsPrintf ("%08X ", Temp32); 673 j += 8; 674 break; 675 } 676 } 677 678 679 /* 680 * Print the ASCII equivalent characters 681 * But watch out for the bad unprintable ones... 682 */ 683 684 for (j = 0; j < 16; j++) 685 { 686 if (i + j >= Count) 687 { 688 AcpiOsPrintf ("\n"); 689 return; 690 } 691 692 BufChar = Buffer[i + j]; 693 if ((BufChar > 0x1F && BufChar < 0x2E) || 694 (BufChar > 0x2F && BufChar < 0x61) || 695 (BufChar > 0x60 && BufChar < 0x7F)) 696 { 697 AcpiOsPrintf ("%c", BufChar); 698 } 699 else 700 { 701 AcpiOsPrintf ("."); 702 } 703 } 704 705 /* Done with that line. */ 706 707 AcpiOsPrintf ("\n"); 708 i += 16; 709 } 710 711 return; 712} 713 714