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.

306 lines
6.5 KiB

  1. /*++
  2. Copyright (c) 1993 Microsoft Corporation
  3. :ts=4
  4. Module Name:
  5. dbg.h
  6. Abstract:
  7. debug macros
  8. Environment:
  9. Kernel & user mode
  10. Revision History:
  11. 10-27-95 : created
  12. --*/
  13. #ifndef __DBG_H__
  14. #define __DBG_H__
  15. //
  16. // Structure signatures
  17. //
  18. #define UHCD_TAG 0x44434855 //"UHCD"
  19. #define SIG_QH 0x68714851 //"QHqh" signature for queue head
  20. #define SIG_TD 0x64744454 //"TDtd" signature for transfer descriptor
  21. #define SIG_EP 0x70655045 //"EPep" signature for endpoint
  22. #define SIG_MD 0x646D444D //"MDmd" signature for memory descriptor
  23. #define SIG_RH 0x68724852 //"RHrh" signature for root hub
  24. #define UHCD_FREE_TAG 0xFFFFFFFF //"" signature free memory
  25. #define LOG_MISC 0x00000001 //debug log entries
  26. #define LOG_PROFILE 0x00000002 //profile log entries
  27. #define LOG_ISO 0x00000004
  28. #define LOG_IO 0x00000008 // Log all I/O access
  29. //
  30. // Assert Macros
  31. //
  32. #if DBG
  33. //
  34. // Assert Macros
  35. //
  36. // We define our own assert function because ntkern will
  37. // not stop in the debugger on assert failures in our own
  38. // code.
  39. //
  40. VOID
  41. UHCD_Assert(
  42. PVOID FailedAssertion,
  43. PVOID FileName,
  44. ULONG LineNumber,
  45. PCHAR Message
  46. );
  47. #define UHCD_ASSERT( exp ) \
  48. if (!(exp)) \
  49. UHCD_Assert( #exp, __FILE__, __LINE__, NULL )
  50. #define UHCD_ASSERTMSG( msg, exp ) \
  51. if (!(exp)) \
  52. UHCD_Assert( #exp, __FILE__, __LINE__, msg )
  53. #define ASSERT_TRANFSER_DESCRIPTOR(td) UHCD_ASSERT(td->Sig == SIG_TD)
  54. #define ASSERT_QUEUE_HEAD(qh) UHCD_ASSERT(qh->Sig == SIG_QH)
  55. #define ASSERT_ENDPOINT(ep) UHCD_ASSERT(ep->Sig == SIG_EP)
  56. #define ASSERT_MD(md) UHCD_ASSERT(md->Sig == SIG_MD)
  57. #define ASSERT_RH(rh) UHCD_ASSERT(rh->Sig == SIG_RH)
  58. VOID
  59. UHCD_CheckSystemBuffer(
  60. IN PUCHAR VirtualAddress,
  61. IN ULONG Length
  62. );
  63. //#define ASSERT_BUFFER(buf, len) UHCD_CheckSystemBuffer(buf, len)
  64. #define ASSERT_BUFFER(buf, len)
  65. //
  66. // Heap Macros for debug heap services
  67. //
  68. extern LONG UHCD_TotalAllocatedHeapSpace;
  69. #define GETHEAP(pooltype, numbytes) UHCD_Debug_GetHeap(pooltype, numbytes, UHCD_TAG, &UHCD_TotalAllocatedHeapSpace)
  70. #define RETHEAP(p) UHCD_Debug_RetHeap(p, UHCD_TAG, &UHCD_TotalAllocatedHeapSpace);
  71. VOID
  72. UHCD_PrintPnPMessage(
  73. PUCHAR Label,
  74. UCHAR MinorFunction
  75. );
  76. VOID
  77. UHCD_PrintPowerMessage(
  78. PUCHAR Label,
  79. UCHAR MinorFunction
  80. );
  81. ULONG
  82. _cdecl
  83. UHCD_KdPrintX(
  84. ULONG l,
  85. PCH Format,
  86. ...
  87. );
  88. #define UHCD_KdPrint(_x_) UHCD_KdPrintX _x_
  89. //
  90. // ** DEBUG TRAPS
  91. //
  92. // Ntkern currently implements DebugBreak with a global int 3,
  93. // we really would like the int 3 in our own code.
  94. // TEST_TRAP() is a code coverage trap these should be removed
  95. // if you are able to 'g' past them OK
  96. //
  97. // KdTrap() breaks in the debugger on the debugger build
  98. // these indicate bugs in client drivers or fatal error
  99. // conditions that should be debugged. also used to mark
  100. // code for features not implemented yet.
  101. //
  102. // KdBreak() breaks in the debugger when in MAX_DEBUG mode
  103. // ie debug trace info is turned on, these are intended to help
  104. // debug drivers devices and special conditions on the
  105. // bus.
  106. #ifdef NTKERN
  107. #pragma message ("warning: ntkern debug enabled")
  108. #define TRAP() _asm { int 3 }
  109. #define TEST_TRAP() _asm { int 3 }
  110. #else
  111. #define TRAP() DbgBreakPoint()
  112. #define TEST_TRAP() { \
  113. DbgPrint ("'UHCD.SYS: Code Coverage %s, %d\n", __FILE__, __LINE__);\
  114. TRAP(); \
  115. }
  116. #endif
  117. #ifdef MAX_DEBUG
  118. #define UHCD_KdBreak(_s_) {UHCD_KdPrintX _s_ ; TRAP();}
  119. #else
  120. //#define UHCD_KdBreak(_s_) {DbgPrint("'UHCD: "); DbgPrint _s_; }
  121. #define UHCD_KdBreak(_s_)
  122. #endif
  123. #define UHCD_KdTrap(_s_) {DbgPrint("UHCD: "); DbgPrint _s_; TRAP();}
  124. VOID
  125. UHCD_Debug_DumpTD(
  126. IN struct _HW_TRANSFER_DESCRIPTOR *Transfer
  127. );
  128. PVOID
  129. UHCD_Debug_GetHeap(
  130. IN POOL_TYPE PoolType,
  131. IN ULONG NumberOfBytes,
  132. IN ULONG Signature,
  133. IN PLONG TotalAllocatedHeapSpace
  134. );
  135. VOID
  136. UHCD_Debug_RetHeap(
  137. IN PVOID P,
  138. IN ULONG Signature,
  139. IN PLONG TotalAllocatedHeapSpace
  140. );
  141. #define UHCD_ASSERT_QSTOPPED(devobj, ep, qtd)
  142. #ifdef PROFILE2
  143. #define DEBUG_LOG
  144. #define STARTPROC(tag) LONG start, stop; \
  145. LONG delta; \
  146. start = ; \
  147. LOGENTRY(LOG_PROFILE, tag, start, 0, 0);
  148. #define ENDPROC(tag) stop = ; \
  149. delta = stop - start; \
  150. LOGENTRY(LOG_PROFILE, tag, stop, start, delta);
  151. #else
  152. #define STARTPROC(tag)
  153. #define ENDPROC(tag)
  154. #endif /* PROFILE */
  155. #else /* NOT DBG */
  156. #define UHCD_KdTrap(_s_)
  157. #define UHCD_KdBreak(_s_)
  158. #define ASSERT_TRANFSER_DESCRIPTOR(td)
  159. #define ASSERT_QUEUE_HEAD(qh)
  160. #define ASSERT_ENDPOINT(ep)
  161. #define ASSERT_MD(md)
  162. #define ASSERT_RH(rh)
  163. #define UHCD_KdPrint(_x_)
  164. #define TRAP()
  165. #define TEST_TRAP();
  166. #define UHCD_ASSERT_QSTOPPED(devobj, ep, qtd)
  167. #define UHCD_ASSERT( exp )
  168. #define ASSERT_BUFFER(buf, len)
  169. #define UHCD_Debug_DumpTD(transfer)
  170. #define GETHEAP(pooltype, numbytes) ExAllocatePoolWithTag(pooltype, numbytes, UHCD_TAG)
  171. #define RETHEAP(p) ExFreePool(p);
  172. #define STARTPROC(tag)
  173. #define ENDPROC(tag)
  174. #define UHCD_PrintPnPMessage(Label, MinorFunction)
  175. #define UHCD_PrintPowerMessage(Label, MinorFunction)
  176. #endif /* DBG */
  177. #ifdef DEBUG_LOG
  178. VOID
  179. UHCD_LogTD(
  180. IN ULONG s,
  181. IN PULONG p
  182. );
  183. #define LOGENTRY(mask, sig, info1, info2, info3) \
  184. UHCD_Debug_LogEntry(mask, sig, (ULONG_PTR)info1, \
  185. (ULONG_PTR)info2, \
  186. (ULONG_PTR)info3)
  187. #define LOG_TD(sig, td) UHCD_LogTD(sig, (PULONG)td)
  188. #ifdef DEBUG_LOG_IO
  189. #define WRITE_PORT_USHORT(P, V) UhcdLogIoUshort((P), (V), 1)
  190. #define WRITE_PORT_ULONG(P, V) UhcdLogIoUlong((P), (V), 1)
  191. #define WRITE_PORT_UCHAR(P, V) UhcdLogIoUchar((P), (V), 1)
  192. #define READ_PORT_USHORT(P) UhcdLogIoUshort((P), 0, 0)
  193. #define READ_PORT_ULONG(P) UhcdLogIoUlong((P), 0, 0)
  194. #define READ_PORT_UCHAR(P) UhcdLogIoUchar((P), 0, 0)
  195. USHORT
  196. UhcdLogIoUshort(PUSHORT Port, USHORT Val, BOOLEAN Write);
  197. ULONG
  198. UhcdLogIoUlong(PULONG Port, ULONG Val, BOOLEAN Write);
  199. UCHAR
  200. UhcdLogIoUchar(PUCHAR Port, UCHAR Val, BOOLEAN Write);
  201. #endif // DEBUG_LOG_IO
  202. VOID
  203. UHCD_Debug_LogEntry(
  204. IN ULONG Mask,
  205. IN ULONG Sig,
  206. IN ULONG_PTR Info1,
  207. IN ULONG_PTR Info2,
  208. IN ULONG_PTR Info3
  209. );
  210. VOID
  211. UHCD_LogInit(
  212. );
  213. VOID
  214. UHCD_LogFree(
  215. );
  216. #else
  217. #define LOGENTRY(mask, sig, info1, info2, info3)
  218. #define LOG_TD(sig, td)
  219. #endif
  220. #endif /* __DBG_H__ */