Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

228 lines
5.9 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: debug.c
  3. *
  4. * Debug helper routines.
  5. *
  6. * Copyright (c) 1992-1995 Microsoft Corporation
  7. *
  8. \**************************************************************************/
  9. #include "precomp.h"
  10. #if DBG
  11. ////////////////////////////////////////////////////////////////////////////
  12. // DEBUGGING INITIALIZATION CODE
  13. //
  14. // When you're bringing up your display for the first time, you can
  15. // recompile with 'DebugLevel' set to 100. That will cause absolutely
  16. // all DISPDBG messages to be displayed on the kernel debugger (this
  17. // is known as the "PrintF Approach to Debugging" and is about the only
  18. // viable method for debugging driver initialization code).
  19. LONG DebugLevel = 0; // Set to '100' to debug initialization code
  20. // (the default is '0')
  21. ////////////////////////////////////////////////////////////////////////////
  22. LONG gcFifo = 0; // Number of currently free FIFO entries
  23. #define LARGE_LOOP_COUNT 10000000
  24. ////////////////////////////////////////////////////////////////////////////
  25. // Miscellaneous Driver Debug Routines
  26. ////////////////////////////////////////////////////////////////////////////
  27. /*****************************************************************************
  28. *
  29. * Routine Description:
  30. *
  31. * This function is variable-argument, level-sensitive debug print
  32. * routine.
  33. * If the specified debug level for the print statement is lower or equal
  34. * to the current debug level, the message will be printed.
  35. *
  36. * Arguments:
  37. *
  38. * DebugPrintLevel - Specifies at which debugging level the string should
  39. * be printed
  40. *
  41. * DebugMessage - Variable argument ascii c string
  42. *
  43. * Return Value:
  44. *
  45. * None.
  46. *
  47. ***************************************************************************/
  48. VOID
  49. DebugPrint(
  50. LONG DebugPrintLevel,
  51. PCHAR DebugMessage,
  52. ...
  53. )
  54. {
  55. va_list ap;
  56. #if TARGET_BUILD <= 351
  57. char buffer[128];
  58. #endif
  59. va_start(ap, DebugMessage);
  60. if (DebugPrintLevel <= DebugLevel)
  61. {
  62. #if TARGET_BUILD > 351
  63. EngDebugPrint(STANDARD_DEBUG_PREFIX, DebugMessage, ap);
  64. EngDebugPrint("", "\n", ap);
  65. #else
  66. vsprintf( buffer, DebugMessage, ap );
  67. OutputDebugString( buffer );
  68. OutputDebugString("\n");
  69. #endif
  70. }
  71. va_end(ap);
  72. } // DebugPrint()
  73. /******************************Public*Routine******************************\
  74. * VOID vCheckFifoWrite
  75. \**************************************************************************/
  76. VOID vCheckFifoWrite()
  77. {
  78. gcFifo--;
  79. if (gcFifo < 0)
  80. {
  81. gcFifo = 0;
  82. RIP("Incorrect FIFO wait count");
  83. }
  84. }
  85. /******************************Public*Routine******************************\
  86. * VOID vI32CheckFifoSpace
  87. \**************************************************************************/
  88. VOID vI32CheckFifoSpace(
  89. PDEV* ppdev,
  90. VOID* pbase,
  91. LONG level)
  92. {
  93. LONG i;
  94. ASSERTDD((level > 0) && (level <= 16), "Illegal wait level");
  95. ASSERTDD((ppdev->iMachType == MACH_IO_32) || (ppdev->iMachType == MACH_MM_32),
  96. "Wrong Mach type!");
  97. gcFifo = level;
  98. for (i = LARGE_LOOP_COUNT; i != 0; i--)
  99. {
  100. if (!(I32_IW(pbase, EXT_FIFO_STATUS) & (0x10000L >> (level))))
  101. return; // There are 'level' entries free
  102. }
  103. RIP("vI32CheckFifoSpace timeout -- The hardware is in a funky state.");
  104. }
  105. /******************************Public*Routine******************************\
  106. * VOID vM32CheckFifoSpace
  107. \**************************************************************************/
  108. VOID vM32CheckFifoSpace(
  109. PDEV* ppdev,
  110. VOID* pbase,
  111. LONG level)
  112. {
  113. LONG i;
  114. ASSERTDD((level > 0) && (level <= 16), "Illegal wait level");
  115. ASSERTDD(ppdev->iMachType == MACH_MM_32, "Wrong Mach type!");
  116. gcFifo = level;
  117. for (i = LARGE_LOOP_COUNT; i != 0; i--)
  118. {
  119. if (!(M32_IW(pbase, EXT_FIFO_STATUS) & (0x10000L >> (level))))
  120. return; // There are 'level' entries free
  121. }
  122. RIP("vM32CheckFifoSpace timeout -- The hardware is in a funky state.");
  123. }
  124. /******************************Public*Routine******************************\
  125. * VOID vM64CheckFifoSpace
  126. \**************************************************************************/
  127. VOID vM64CheckFifoSpace(
  128. PDEV* ppdev,
  129. VOID* pbase,
  130. LONG level)
  131. {
  132. LONG i;
  133. ASSERTDD((level > 0) && (level <= 16), "Illegal wait level");
  134. ASSERTDD(ppdev->iMachType == MACH_MM_64, "Wrong Mach type!");
  135. gcFifo = level;
  136. for (i = LARGE_LOOP_COUNT; i != 0; i--)
  137. {
  138. if (!(M64_ID((pbase), FIFO_STAT) & (0x10000L >> (level))))
  139. return; // There are 'level' entries free
  140. }
  141. RIP("vM64CheckFifoSpace timeout -- The hardware is in a funky state.");
  142. }
  143. /******************************Public*Routine******************************\
  144. * ULONG ulM64FastFifoCheck
  145. \**************************************************************************/
  146. ULONG ulM64FastFifoCheck(
  147. PDEV* ppdev,
  148. VOID* pbase,
  149. LONG level,
  150. ULONG ulFifo)
  151. {
  152. LONG i;
  153. ULONG ulFree;
  154. LONG cFree;
  155. ASSERTDD((level > 0) && (level <= 16), "Illegal wait level");
  156. ASSERTDD(ppdev->iMachType == MACH_MM_64, "Wrong Mach type!");
  157. i = LARGE_LOOP_COUNT;
  158. do {
  159. ulFifo = ~M64_ID((pbase), FIFO_STAT); // Invert bits
  160. // Count the number of empty slots:
  161. ulFree = ulFifo;
  162. cFree = 0;
  163. while (ulFree & 0x8000)
  164. {
  165. cFree++;
  166. ulFree <<= 1;
  167. }
  168. // Break if we've been looping a zillion times:
  169. if (--i == 0)
  170. {
  171. RIP("vM64CheckFifoSpace timeout -- The hardware is in a funky state.");
  172. break;
  173. }
  174. } while (cFree < level);
  175. gcFifo = cFree;
  176. // Account for the slots we're about to use:
  177. return(ulFifo << level);
  178. }
  179. ////////////////////////////////////////////////////////////////////////////
  180. #endif // DBG
  181.