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.

412 lines
6.8 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. dbg.c
  5. Abstract:
  6. Debug logging code and other debug services
  7. Environment:
  8. kernel mode only
  9. Notes:
  10. THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  11. KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  12. IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  13. PURPOSE.
  14. Copyright (c) 1996 Microsoft Corporation. All Rights Reserved.
  15. Revision History:
  16. 5-4-96 : created jdunn
  17. --*/
  18. #include "openhci.h"
  19. //
  20. // other debug functions
  21. //
  22. #if DBG
  23. VOID
  24. OpenHCI_Assert(
  25. IN PVOID FailedAssertion,
  26. IN PVOID FileName,
  27. IN ULONG LineNumber,
  28. IN PCHAR Message
  29. )
  30. /*++
  31. Routine Description:
  32. Debug Assert function.
  33. Arguments:
  34. DeviceObject - pointer to a device object
  35. Irp - pointer to an I/O Request Packet
  36. Return Value:
  37. --*/
  38. {
  39. #ifdef NTKERN
  40. // this makes the compiler generate a ret
  41. ULONG stop = 1;
  42. assert_loop:
  43. #endif
  44. // just call the NT assert function and stop
  45. // in the debugger.
  46. RtlAssert( FailedAssertion, FileName, LineNumber, Message );
  47. // loop here to prevent users from going past
  48. // are assert before we can look at it
  49. #ifdef NTKERN
  50. TRAP();
  51. if (stop) {
  52. goto assert_loop;
  53. }
  54. #endif
  55. return;
  56. }
  57. ULONG
  58. _cdecl
  59. OHCI_KdPrint2(
  60. PCH Format,
  61. ...
  62. )
  63. {
  64. va_list list;
  65. int i;
  66. int arg[5];
  67. ULONG l=2;
  68. if (OHCI_Debug_Trace_Level >= l) {
  69. if (l <= 1) {
  70. DbgPrint("OPENHCI.SYS: ");
  71. *Format = ' ';
  72. } else {
  73. DbgPrint("'OPENHCI.SYS: ");
  74. }
  75. va_start(list, Format);
  76. for (i=0; i<4; i++) {
  77. arg[i] = va_arg(list, int);
  78. }
  79. DbgPrint(Format, arg[0], arg[1], arg[2], arg[3]);
  80. }
  81. return 0;
  82. }
  83. ULONG
  84. _cdecl
  85. OHCI_KdPrintX(
  86. ULONG l,
  87. PCH Format,
  88. ...
  89. )
  90. {
  91. va_list list;
  92. int i;
  93. int arg[5];
  94. if (OHCI_Debug_Trace_Level >= l) {
  95. if (l <= 1) {
  96. DbgPrint("OPENHCI.SYS: ");
  97. #ifdef NTKERN
  98. *Format = ' ';
  99. #endif
  100. } else {
  101. DbgPrint("'OPENHCI.SYS: ");
  102. }
  103. va_start(list, Format);
  104. for (i=0; i<4; i++) {
  105. arg[i] = va_arg(list, int);
  106. }
  107. DbgPrint(Format, arg[0], arg[1], arg[2], arg[3]);
  108. }
  109. return 0;
  110. }
  111. #endif // DBG
  112. #ifdef DEBUG_LOG
  113. KSPIN_LOCK OHCILogSpinLock;
  114. struct UHCD_LOG_ENTRY {
  115. ULONG le_sig; // Identifying string
  116. ULONG_PTR le_info1; // entry specific info
  117. ULONG_PTR le_info2; // entry specific info
  118. ULONG_PTR le_info3; // entry specific info
  119. }; /* USBD_LOG_ENTRY */
  120. struct UHCD_LOG_ENTRY *OHCILStart = NULL; // No log yet
  121. struct UHCD_LOG_ENTRY *OHCILPtr;
  122. struct UHCD_LOG_ENTRY *OHCILEnd;
  123. #ifdef IRP_LOG
  124. ULONG IrpLogSize = 4096*4; //4 page of log entries
  125. #endif
  126. #ifdef IRP_LOG
  127. PULONG OHCIIrpLog;
  128. #endif
  129. ULONG OHCI_LogMask = 0xffffffff;
  130. VOID
  131. OHCI_Debug_LogEntry(
  132. IN ULONG Mask,
  133. IN ULONG Sig,
  134. IN ULONG_PTR Info1,
  135. IN ULONG_PTR Info2,
  136. IN ULONG_PTR Info3
  137. )
  138. /*++
  139. Routine Description:
  140. Adds an Entry to USBD log.
  141. Arguments:
  142. Return Value:
  143. None.
  144. --*/
  145. {
  146. KIRQL irql;
  147. typedef union _SIG {
  148. struct {
  149. UCHAR Byte0;
  150. UCHAR Byte1;
  151. UCHAR Byte2;
  152. UCHAR Byte3;
  153. } b;
  154. ULONG l;
  155. } SIG, *PSIG;
  156. SIG sig, rsig;
  157. if (OHCILStart == NULL) {
  158. return;
  159. }
  160. if ((OHCI_LogMask & Mask) == 0) {
  161. return;
  162. }
  163. irql = KeGetCurrentIrql();
  164. if (irql < DISPATCH_LEVEL) {
  165. KeAcquireSpinLock(&OHCILogSpinLock, &irql);
  166. } else {
  167. KeAcquireSpinLockAtDpcLevel(&OHCILogSpinLock);
  168. }
  169. if (OHCILPtr > OHCILStart) {
  170. OHCILPtr -= 1; // Decrement to next entry
  171. } else {
  172. OHCILPtr = OHCILEnd;
  173. }
  174. // RtlCopyMemory(OHCILPtr->le_name, Name, 4);
  175. // LPtr->le_ret = (stk[1] & 0x00ffffff) | (CurVMID()<<24);
  176. sig.l = Sig;
  177. rsig.b.Byte0 = sig.b.Byte3;
  178. rsig.b.Byte1 = sig.b.Byte2;
  179. rsig.b.Byte2 = sig.b.Byte1;
  180. rsig.b.Byte3 = sig.b.Byte0;
  181. OHCILPtr->le_sig = rsig.l;
  182. OHCILPtr->le_info1 = Info1;
  183. OHCILPtr->le_info2 = Info2;
  184. OHCILPtr->le_info3 = Info3;
  185. ASSERT(OHCILPtr >= OHCILStart);
  186. if (irql < DISPATCH_LEVEL) {
  187. KeReleaseSpinLock(&OHCILogSpinLock, irql);
  188. } else {
  189. KeReleaseSpinLockFromDpcLevel(&OHCILogSpinLock);
  190. }
  191. return;
  192. }
  193. VOID
  194. OHCI_LogInit(
  195. VOID
  196. )
  197. /*++
  198. Routine Description:
  199. Init the debug log - remember interesting information in a circular
  200. buffer
  201. Arguments:
  202. Return Value:
  203. None.
  204. --*/
  205. {
  206. #ifdef MAX_DEBUG
  207. ULONG logSize = 4096*4; //4 page of log entries
  208. #else
  209. ULONG logSize = 4096*8;
  210. #endif
  211. if (OHCILStart != NULL) {
  212. return;
  213. }
  214. #ifdef IRP_LOG
  215. if (OHCIIrpLog == NULL) {
  216. OHCIIrpLog = ExAllocatePoolWithTag(NonPagedPool,
  217. IrpLogSize,
  218. OpenHCI_TAG);
  219. if (OHCIIrpLog) {
  220. RtlZeroMemory(OHCIIrpLog, IrpLogSize);
  221. }
  222. }
  223. #endif
  224. KeInitializeSpinLock(&OHCILogSpinLock);
  225. OHCILStart = ExAllocatePoolWithTag(NonPagedPool,
  226. logSize,
  227. OpenHCI_TAG);
  228. if (OHCILStart) {
  229. OHCILPtr = OHCILStart;
  230. // Point the end (and first entry) 1 entry from the end of
  231. // the segment
  232. OHCILEnd = OHCILStart + (logSize / sizeof(struct UHCD_LOG_ENTRY)) - 1;
  233. } else {
  234. TRAP();
  235. }
  236. return;
  237. }
  238. VOID
  239. OHCI_LogFree(
  240. VOID
  241. )
  242. /*++
  243. Routine Description:
  244. Init the debug log - remember interesting information in a circular
  245. buffer
  246. Arguments:
  247. Return Value:
  248. None.
  249. --*/
  250. {
  251. if (OHCILStart) {
  252. ExFreePool(OHCILStart);
  253. OHCILStart = NULL;
  254. }
  255. #ifdef IRP_LOG
  256. if (OHCIIrpLog) {
  257. ExFreePool(OHCIIrpLog);
  258. OHCIIrpLog = NULL;
  259. }
  260. #endif
  261. return;
  262. }
  263. #ifdef IRP_LOG
  264. VOID
  265. OHCI_LogIrp(
  266. PIRP Irp,
  267. ULONG Add
  268. )
  269. /*++
  270. Routine Description:
  271. Arguments:
  272. Return Value:
  273. None.
  274. --*/
  275. {
  276. PULONG p;
  277. PUCHAR end;
  278. p = OHCIIrpLog;
  279. end = (PUCHAR) OHCIIrpLog;
  280. end+=IrpLogSize;
  281. if (Add) {
  282. while (*p) {
  283. p++;
  284. }
  285. if ((PUCHAR) p > end) {
  286. // no room
  287. TEST_TRAP();
  288. } else {
  289. *p = (ULONG) Irp;
  290. }
  291. } else {
  292. while (*p != (ULONG) Irp) {
  293. p++;
  294. }
  295. if ((PUCHAR) p > end) {
  296. // no room
  297. TEST_TRAP();
  298. } else {
  299. *p = 0;
  300. }
  301. }
  302. return;
  303. }
  304. #endif
  305. #endif /* DEBUG_LOG */