utdebug.c revision 83174
1/****************************************************************************** 2 * 3 * Module Name: utdebug - Debug print routines 4 * $Revision: 87 $ 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 131#ifdef ACPI_DEBUG 132 133 134/***************************************************************************** 135 * 136 * FUNCTION: AcpiUtInitStackPtrTrace 137 * 138 * PARAMETERS: None 139 * 140 * RETURN: None 141 * 142 * DESCRIPTION: Save the current stack pointer 143 * 144 ****************************************************************************/ 145 146void 147AcpiUtInitStackPtrTrace ( 148 void) 149{ 150 UINT32 CurrentSp; 151 152 153 AcpiGbl_EntryStackPointer = (UINT32) &CurrentSp; 154} 155 156 157/***************************************************************************** 158 * 159 * FUNCTION: AcpiUtTrackStackPtr 160 * 161 * PARAMETERS: None 162 * 163 * RETURN: None 164 * 165 * DESCRIPTION: Save the current stack pointer 166 * 167 ****************************************************************************/ 168 169void 170AcpiUtTrackStackPtr ( 171 void) 172{ 173 UINT32 CurrentSp; 174 175 CurrentSp = (UINT32) &CurrentSp; 176 177 if (CurrentSp < AcpiGbl_LowestStackPointer) 178 { 179 AcpiGbl_LowestStackPointer = CurrentSp; 180 } 181 182 if (AcpiGbl_NestingLevel > AcpiGbl_DeepestNesting) 183 { 184 AcpiGbl_DeepestNesting = AcpiGbl_NestingLevel; 185 186 if (AcpiGbl_DeepestNesting == 34) 187 { 188 AcpiOsPrintf ("hit deepest nesting\n"); 189 } 190 } 191} 192 193 194/***************************************************************************** 195 * 196 * FUNCTION: AcpiUtDebugPrint 197 * 198 * PARAMETERS: DebugLevel - Requested debug print level 199 * ProcName - Caller's procedure name 200 * ModuleName - Caller's module name (for error output) 201 * LineNumber - Caller's line number (for error output) 202 * ComponentId - Caller's component ID (for error output) 203 * 204 * Format - Printf format field 205 * ... - Optional printf arguments 206 * 207 * RETURN: None 208 * 209 * DESCRIPTION: Print error message with prefix consisting of the module name, 210 * line number, and component ID. 211 * 212 ****************************************************************************/ 213 214void 215AcpiUtDebugPrint ( 216 UINT32 RequestedDebugLevel, 217 UINT32 LineNumber, 218 ACPI_DEBUG_PRINT_INFO *DbgInfo, 219 char *Format, 220 ...) 221{ 222 UINT32 ThreadId; 223 va_list args; 224 225 226 /* 227 * Stay silent if the debug level or component ID is disabled 228 */ 229 if (!(RequestedDebugLevel & AcpiDbgLevel) || 230 !(DbgInfo->ComponentId & AcpiDbgLayer)) 231 { 232 return; 233 } 234 235 236 /* 237 * Thread tracking and context switch notification 238 */ 239 ThreadId = AcpiOsGetThreadId (); 240 241 if (ThreadId != AcpiGbl_PrevThreadId) 242 { 243 if (ACPI_LV_THREADS & AcpiDbgLevel) 244 { 245 AcpiOsPrintf ("\n**** Context Switch from TID %X to TID %X ****\n\n", 246 AcpiGbl_PrevThreadId, ThreadId); 247 } 248 249 AcpiGbl_PrevThreadId = ThreadId; 250 } 251 252 /* 253 * Display the module name, current line number, thread ID (if requested), 254 * current procedure nesting level, and the current procedure name 255 */ 256 AcpiOsPrintf ("%8s-%04d ", DbgInfo->ModuleName, LineNumber); 257 258 if (ACPI_LV_THREADS & AcpiDbgLevel) 259 { 260 AcpiOsPrintf ("[%04X] ", ThreadId, AcpiGbl_NestingLevel, DbgInfo->ProcName); 261 } 262 263 AcpiOsPrintf ("[%02d] %-22.22s: ", AcpiGbl_NestingLevel, DbgInfo->ProcName); 264 265 266 va_start (args, Format); 267 AcpiOsVprintf (Format, args); 268} 269 270 271/***************************************************************************** 272 * 273 * FUNCTION: AcpiUtDebugPrintRaw 274 * 275 * PARAMETERS: RequestedDebugLevel - Requested debug print level 276 * LineNumber - Caller's line number 277 * DbgInfo - Contains: 278 * ProcName - Caller's procedure name 279 * ModuleName - Caller's module name 280 * ComponentId - Caller's component ID 281 * Format - Printf format field 282 * ... - Optional printf arguments 283 * 284 * RETURN: None 285 * 286 * DESCRIPTION: Print message with no headers. Has same interface as 287 * DebugPrint so that the same macros can be used. 288 * 289 ****************************************************************************/ 290 291void 292AcpiUtDebugPrintRaw ( 293 UINT32 RequestedDebugLevel, 294 UINT32 LineNumber, 295 ACPI_DEBUG_PRINT_INFO *DbgInfo, 296 char *Format, 297 ...) 298{ 299 va_list args; 300 301 302 if (!(RequestedDebugLevel & AcpiDbgLevel) || 303 !(DbgInfo->ComponentId & AcpiDbgLayer)) 304 { 305 return; 306 } 307 308 va_start (args, Format); 309 310 AcpiOsVprintf (Format, args); 311} 312 313 314/***************************************************************************** 315 * 316 * FUNCTION: AcpiUtTrace 317 * 318 * PARAMETERS: LineNumber - Caller's line number 319 * DbgInfo - Contains: 320 * ProcName - Caller's procedure name 321 * ModuleName - Caller's module name 322 * ComponentId - Caller's component ID 323 * 324 * RETURN: None 325 * 326 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is 327 * set in DebugLevel 328 * 329 ****************************************************************************/ 330 331void 332AcpiUtTrace ( 333 UINT32 LineNumber, 334 ACPI_DEBUG_PRINT_INFO *DbgInfo) 335{ 336 337 AcpiGbl_NestingLevel++; 338 AcpiUtTrackStackPtr (); 339 340 AcpiUtDebugPrint (ACPI_LV_FUNCTIONS, LineNumber, DbgInfo, 341 "%s\n", AcpiGbl_FnEntryStr); 342} 343 344 345/***************************************************************************** 346 * 347 * FUNCTION: AcpiUtTracePtr 348 * 349 * PARAMETERS: LineNumber - Caller's line number 350 * DbgInfo - Contains: 351 * ProcName - Caller's procedure name 352 * ModuleName - Caller's module name 353 * ComponentId - Caller's component ID 354 * Pointer - Pointer to display 355 * 356 * RETURN: None 357 * 358 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is 359 * set in DebugLevel 360 * 361 ****************************************************************************/ 362 363void 364AcpiUtTracePtr ( 365 UINT32 LineNumber, 366 ACPI_DEBUG_PRINT_INFO *DbgInfo, 367 void *Pointer) 368{ 369 AcpiGbl_NestingLevel++; 370 AcpiUtTrackStackPtr (); 371 372 AcpiUtDebugPrint (ACPI_LV_FUNCTIONS, LineNumber, DbgInfo, 373 "%s %p\n", AcpiGbl_FnEntryStr, Pointer); 374} 375 376 377/***************************************************************************** 378 * 379 * FUNCTION: AcpiUtTraceStr 380 * 381 * PARAMETERS: LineNumber - Caller's line number 382 * DbgInfo - Contains: 383 * ProcName - Caller's procedure name 384 * ModuleName - Caller's module name 385 * ComponentId - Caller's component ID 386 * String - Additional string to display 387 * 388 * RETURN: None 389 * 390 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is 391 * set in DebugLevel 392 * 393 ****************************************************************************/ 394 395void 396AcpiUtTraceStr ( 397 UINT32 LineNumber, 398 ACPI_DEBUG_PRINT_INFO *DbgInfo, 399 NATIVE_CHAR *String) 400{ 401 402 AcpiGbl_NestingLevel++; 403 AcpiUtTrackStackPtr (); 404 405 AcpiUtDebugPrint (ACPI_LV_FUNCTIONS, LineNumber, DbgInfo, 406 "%s %s\n", AcpiGbl_FnEntryStr, String); 407} 408 409 410/***************************************************************************** 411 * 412 * FUNCTION: AcpiUtTraceU32 413 * 414 * PARAMETERS: LineNumber - Caller's line number 415 * DbgInfo - Contains: 416 * ProcName - Caller's procedure name 417 * ModuleName - Caller's module name 418 * ComponentId - Caller's component ID 419 * Integer - Integer to display 420 * 421 * RETURN: None 422 * 423 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is 424 * set in DebugLevel 425 * 426 ****************************************************************************/ 427 428void 429AcpiUtTraceU32 ( 430 UINT32 LineNumber, 431 ACPI_DEBUG_PRINT_INFO *DbgInfo, 432 UINT32 Integer) 433{ 434 435 AcpiGbl_NestingLevel++; 436 AcpiUtTrackStackPtr (); 437 438 AcpiUtDebugPrint (ACPI_LV_FUNCTIONS, LineNumber, DbgInfo, 439 "%s %08X\n", AcpiGbl_FnEntryStr, Integer); 440} 441 442 443/***************************************************************************** 444 * 445 * FUNCTION: AcpiUtExit 446 * 447 * PARAMETERS: LineNumber - Caller's line number 448 * DbgInfo - Contains: 449 * ProcName - Caller's procedure name 450 * ModuleName - Caller's module name 451 * ComponentId - Caller's component ID 452 * 453 * RETURN: None 454 * 455 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is 456 * set in DebugLevel 457 * 458 ****************************************************************************/ 459 460void 461AcpiUtExit ( 462 UINT32 LineNumber, 463 ACPI_DEBUG_PRINT_INFO *DbgInfo) 464{ 465 466 AcpiUtDebugPrint (ACPI_LV_FUNCTIONS, LineNumber, DbgInfo, 467 "%s\n", AcpiGbl_FnExitStr); 468 469 AcpiGbl_NestingLevel--; 470} 471 472 473/***************************************************************************** 474 * 475 * FUNCTION: AcpiUtStatusExit 476 * 477 * PARAMETERS: LineNumber - Caller's line number 478 * DbgInfo - Contains: 479 * ProcName - Caller's procedure name 480 * ModuleName - Caller's module name 481 * ComponentId - Caller's component ID 482 * Status - Exit status code 483 * 484 * RETURN: None 485 * 486 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is 487 * set in DebugLevel. Prints exit status also. 488 * 489 ****************************************************************************/ 490 491void 492AcpiUtStatusExit ( 493 UINT32 LineNumber, 494 ACPI_DEBUG_PRINT_INFO *DbgInfo, 495 ACPI_STATUS Status) 496{ 497 498 if (ACPI_SUCCESS (Status)) 499 { 500 AcpiUtDebugPrint (ACPI_LV_FUNCTIONS, LineNumber, DbgInfo, 501 "%s %s\n", AcpiGbl_FnExitStr, 502 AcpiFormatException (Status)); 503 } 504 else 505 { 506 AcpiUtDebugPrint (ACPI_LV_FUNCTIONS, LineNumber, DbgInfo, 507 "%s ****Exception****: %s\n", AcpiGbl_FnExitStr, 508 AcpiFormatException (Status)); 509 } 510 511 AcpiGbl_NestingLevel--; 512} 513 514 515/***************************************************************************** 516 * 517 * FUNCTION: AcpiUtValueExit 518 * 519 * PARAMETERS: LineNumber - Caller's line number 520 * DbgInfo - Contains: 521 * ProcName - Caller's procedure name 522 * ModuleName - Caller's module name 523 * ComponentId - Caller's component ID 524 * Value - Value to be printed with exit msg 525 * 526 * RETURN: None 527 * 528 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is 529 * set in DebugLevel. Prints exit value also. 530 * 531 ****************************************************************************/ 532 533void 534AcpiUtValueExit ( 535 UINT32 LineNumber, 536 ACPI_DEBUG_PRINT_INFO *DbgInfo, 537 ACPI_INTEGER Value) 538{ 539 540 AcpiUtDebugPrint (ACPI_LV_FUNCTIONS, LineNumber, DbgInfo, 541 "%s %08X\n", AcpiGbl_FnExitStr, Value); 542 543 AcpiGbl_NestingLevel--; 544} 545 546 547/***************************************************************************** 548 * 549 * FUNCTION: AcpiUtPtrExit 550 * 551 * PARAMETERS: LineNumber - Caller's line number 552 * DbgInfo - Contains: 553 * ProcName - Caller's procedure name 554 * ModuleName - Caller's module name 555 * ComponentId - Caller's component ID 556 * Value - Value to be printed with exit msg 557 * 558 * RETURN: None 559 * 560 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is 561 * set in DebugLevel. Prints exit value also. 562 * 563 ****************************************************************************/ 564 565void 566AcpiUtPtrExit ( 567 UINT32 LineNumber, 568 ACPI_DEBUG_PRINT_INFO *DbgInfo, 569 UINT8 *Ptr) 570{ 571 572 AcpiUtDebugPrint (ACPI_LV_FUNCTIONS, LineNumber, DbgInfo, 573 "%s %p\n", AcpiGbl_FnExitStr, Ptr); 574 575 AcpiGbl_NestingLevel--; 576} 577 578#endif 579 580 581 582 583/***************************************************************************** 584 * 585 * FUNCTION: AcpiUtDumpBuffer 586 * 587 * PARAMETERS: Buffer - Buffer to dump 588 * Count - Amount to dump, in bytes 589 * Display - BYTE, WORD, DWORD, or QWORD display 590 * ComponentID - Caller's component ID 591 * 592 * RETURN: None 593 * 594 * DESCRIPTION: Generic dump buffer in both hex and ascii. 595 * 596 ****************************************************************************/ 597 598void 599AcpiUtDumpBuffer ( 600 UINT8 *Buffer, 601 UINT32 Count, 602 UINT32 Display, 603 UINT32 ComponentId) 604{ 605 UINT32 i = 0; 606 UINT32 j; 607 UINT32 Temp32; 608 UINT8 BufChar; 609 610 611 /* Only dump the buffer if tracing is enabled */ 612 613 if (!((ACPI_LV_TABLES & AcpiDbgLevel) && 614 (ComponentId & AcpiDbgLayer))) 615 { 616 return; 617 } 618 619 620 /* 621 * Nasty little dump buffer routine! 622 */ 623 while (i < Count) 624 { 625 /* Print current offset */ 626 627 AcpiOsPrintf ("%05X ", i); 628 629 630 /* Print 16 hex chars */ 631 632 for (j = 0; j < 16;) 633 { 634 if (i + j >= Count) 635 { 636 AcpiOsPrintf ("\n"); 637 return; 638 } 639 640 /* Make sure that the INT8 doesn't get sign-extended! */ 641 642 switch (Display) 643 { 644 /* Default is BYTE display */ 645 646 default: 647 648 AcpiOsPrintf ("%02X ", 649 *((UINT8 *) &Buffer[i + j])); 650 j += 1; 651 break; 652 653 654 case DB_WORD_DISPLAY: 655 656 MOVE_UNALIGNED16_TO_32 (&Temp32, 657 &Buffer[i + j]); 658 AcpiOsPrintf ("%04X ", Temp32); 659 j += 2; 660 break; 661 662 663 case DB_DWORD_DISPLAY: 664 665 MOVE_UNALIGNED32_TO_32 (&Temp32, 666 &Buffer[i + j]); 667 AcpiOsPrintf ("%08X ", Temp32); 668 j += 4; 669 break; 670 671 672 case DB_QWORD_DISPLAY: 673 674 MOVE_UNALIGNED32_TO_32 (&Temp32, 675 &Buffer[i + j]); 676 AcpiOsPrintf ("%08X", Temp32); 677 678 MOVE_UNALIGNED32_TO_32 (&Temp32, 679 &Buffer[i + j + 4]); 680 AcpiOsPrintf ("%08X ", Temp32); 681 j += 8; 682 break; 683 } 684 } 685 686 687 /* 688 * Print the ASCII equivalent characters 689 * But watch out for the bad unprintable ones... 690 */ 691 692 for (j = 0; j < 16; j++) 693 { 694 if (i + j >= Count) 695 { 696 AcpiOsPrintf ("\n"); 697 return; 698 } 699 700 BufChar = Buffer[i + j]; 701 if ((BufChar > 0x1F && BufChar < 0x2E) || 702 (BufChar > 0x2F && BufChar < 0x61) || 703 (BufChar > 0x60 && BufChar < 0x7F)) 704 { 705 AcpiOsPrintf ("%c", BufChar); 706 } 707 else 708 { 709 AcpiOsPrintf ("."); 710 } 711 } 712 713 /* Done with that line. */ 714 715 AcpiOsPrintf ("\n"); 716 i += 16; 717 } 718 719 return; 720} 721 722