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.

282 lines
7.0 KiB

  1. /*++
  2. Copyright(c) 1998 Microsoft Corporation
  3. Module Name:
  4. dbgsys.c
  5. Abstract:
  6. Debug routines
  7. Author:
  8. Todd Carpenter
  9. Environment:
  10. kernel mode
  11. Revision History:
  12. 08-24-98 : created, toddcar
  13. --*/
  14. #if DBG
  15. #include <ntddk.h>
  16. #include <stdio.h>
  17. #include <stdarg.h>
  18. #include "dbgsys.h"
  19. #pragma alloc_text (PAGELK, PnPMinorFunctionString)
  20. #pragma alloc_text (PAGELK, PowerMinorFunctionString)
  21. #pragma alloc_text (PAGELK, DbgSystemPowerString)
  22. #pragma alloc_text (PAGELK, DbgDevicePowerString)
  23. #define DEBUG_BUFFER_SIZE 256
  24. extern PUCHAR DebugName;
  25. VOID
  26. _cdecl
  27. DebugPrintX(
  28. ULONG DebugLevel,
  29. PUCHAR Format,
  30. ...
  31. )
  32. /*++
  33. Routine Description:
  34. Arguments:
  35. Return Value:
  36. --*/
  37. {
  38. va_list list;
  39. UCHAR debugString[DEBUG_BUFFER_SIZE+1];
  40. va_start(list, Format);
  41. debugString[DEBUG_BUFFER_SIZE]=0;
  42. _vsnprintf(debugString, DEBUG_BUFFER_SIZE, Format, list);
  43. DbgPrintEx(DPFLTR_PROCESSOR_ID,
  44. DebugLevel,
  45. "%s: %s",
  46. DebugName,
  47. debugString);
  48. return;
  49. }
  50. PUCHAR
  51. PnPMinorFunctionString (
  52. UCHAR MinorFunction
  53. )
  54. {
  55. #define IRP_MN_QUERY_LEGACY_BUS_INFORMATION 0x18
  56. switch (MinorFunction)
  57. {
  58. case IRP_MN_START_DEVICE:
  59. return "IRP_MN_START_DEVICE";
  60. case IRP_MN_QUERY_REMOVE_DEVICE:
  61. return "IRP_MN_QUERY_REMOVE_DEVICE";
  62. case IRP_MN_REMOVE_DEVICE:
  63. return "IRP_MN_REMOVE_DEVICE";
  64. case IRP_MN_CANCEL_REMOVE_DEVICE:
  65. return "IRP_MN_CANCEL_REMOVE_DEVICE";
  66. case IRP_MN_STOP_DEVICE:
  67. return "IRP_MN_STOP_DEVICE";
  68. case IRP_MN_QUERY_STOP_DEVICE:
  69. return "IRP_MN_QUERY_STOP_DEVICE";
  70. case IRP_MN_CANCEL_STOP_DEVICE:
  71. return "IRP_MN_CANCEL_STOP_DEVICE";
  72. case IRP_MN_QUERY_DEVICE_RELATIONS:
  73. return "IRP_MN_QUERY_DEVICE_RELATIONS";
  74. case IRP_MN_QUERY_INTERFACE:
  75. return "IRP_MN_QUERY_INTERFACE";
  76. case IRP_MN_QUERY_CAPABILITIES:
  77. return "IRP_MN_QUERY_CAPABILITIES";
  78. case IRP_MN_QUERY_RESOURCES:
  79. return "IRP_MN_QUERY_RESOURCES";
  80. case IRP_MN_QUERY_RESOURCE_REQUIREMENTS:
  81. return "IRP_MN_QUERY_RESOURCE_REQUIREMENTS";
  82. case IRP_MN_QUERY_DEVICE_TEXT:
  83. return "IRP_MN_QUERY_DEVICE_TEXT";
  84. case IRP_MN_FILTER_RESOURCE_REQUIREMENTS:
  85. return "IRP_MN_FILTER_RESOURCE_REQUIREMENTS";
  86. case IRP_MN_READ_CONFIG:
  87. return "IRP_MN_READ_CONFIG";
  88. case IRP_MN_WRITE_CONFIG:
  89. return "IRP_MN_WRITE_CONFIG";
  90. case IRP_MN_EJECT:
  91. return "IRP_MN_EJECT";
  92. case IRP_MN_SET_LOCK:
  93. return "IRP_MN_SET_LOCK";
  94. case IRP_MN_QUERY_ID:
  95. return "IRP_MN_QUERY_ID";
  96. case IRP_MN_QUERY_PNP_DEVICE_STATE:
  97. return "IRP_MN_QUERY_PNP_DEVICE_STATE";
  98. case IRP_MN_QUERY_BUS_INFORMATION:
  99. return "IRP_MN_QUERY_BUS_INFORMATION";
  100. case IRP_MN_DEVICE_USAGE_NOTIFICATION:
  101. return "IRP_MN_DEVICE_USAGE_NOTIFICATION";
  102. case IRP_MN_SURPRISE_REMOVAL:
  103. return "IRP_MN_SURPRISE_REMOVAL";
  104. case IRP_MN_QUERY_LEGACY_BUS_INFORMATION:
  105. return "IRP_MN_QUERY_LEGACY_BUS_INFORMATION";
  106. default:
  107. return "IRP_MN_UNKNOWN";
  108. }
  109. }
  110. PUCHAR
  111. PowerMinorFunctionString (
  112. UCHAR MinorFunction
  113. )
  114. {
  115. switch (MinorFunction)
  116. {
  117. case IRP_MN_SET_POWER:
  118. return "IRP_MN_SET_POWER";
  119. case IRP_MN_QUERY_POWER:
  120. return "IRP_MN_QUERY_POWER";
  121. case IRP_MN_POWER_SEQUENCE:
  122. return "IRP_MN_POWER_SEQUENCE";
  123. case IRP_MN_WAIT_WAKE:
  124. return "IRP_MN_WAIT_WAKE";
  125. default:
  126. return "IRP_MN_?????";
  127. }
  128. }
  129. PUCHAR
  130. DbgSystemPowerString(
  131. IN SYSTEM_POWER_STATE Type
  132. )
  133. {
  134. switch (Type)
  135. {
  136. case PowerSystemUnspecified:
  137. return "PowerSystemUnspecified";
  138. case PowerSystemWorking:
  139. return "PowerSystemWorking";
  140. case PowerSystemSleeping1:
  141. return "PowerSystemSleeping1";
  142. case PowerSystemSleeping2:
  143. return "PowerSystemSleeping2";
  144. case PowerSystemSleeping3:
  145. return "PowerSystemSleeping3";
  146. case PowerSystemHibernate:
  147. return "PowerSystemHibernate";
  148. case PowerSystemShutdown:
  149. return "PowerSystemShutdown";
  150. case PowerSystemMaximum:
  151. return "PowerSystemMaximum";
  152. default:
  153. return "UnKnown System Power State";
  154. }
  155. }
  156. PUCHAR
  157. DbgPowerStateHandlerType(
  158. IN POWER_STATE_HANDLER_TYPE Type
  159. )
  160. {
  161. switch (Type)
  162. {
  163. case PowerStateSleeping1:
  164. return "PowerStateSleeping1";
  165. case PowerStateSleeping2:
  166. return "PowerStateSleeping2";
  167. case PowerStateSleeping3:
  168. return "PowerStateSleeping3";
  169. case PowerStateSleeping4:
  170. return "PowerStateSleeping4";
  171. case PowerStateSleeping4Firmware:
  172. return "PowerStateSleeping4Firware";
  173. case PowerStateShutdownReset:
  174. return "PowerStateShutdownReset";
  175. case PowerStateShutdownOff:
  176. return "PowerStateShutdownOff";
  177. case PowerStateMaximum:
  178. return "PowerStateMaximum";
  179. default:
  180. return "UnKnown Power State Handler Type";
  181. }
  182. }
  183. PUCHAR
  184. DbgDevicePowerString(
  185. IN DEVICE_POWER_STATE Type
  186. )
  187. {
  188. switch (Type)
  189. {
  190. case PowerDeviceUnspecified:
  191. return "PowerDeviceUnspecified";
  192. case PowerDeviceD0:
  193. return "PowerDeviceD0";
  194. case PowerDeviceD1:
  195. return "PowerDeviceD1";
  196. case PowerDeviceD2:
  197. return "PowerDeviceD2";
  198. case PowerDeviceD3:
  199. return "PowerDeviceD3";
  200. case PowerDeviceMaximum:
  201. return "PowerDeviceMaximum";
  202. default:
  203. return "UnKnown Device Power State";
  204. }
  205. }
  206. VOID
  207. DisplayPowerStateInfo(
  208. IN ULONG_PTR Arg1,
  209. IN ULONG_PTR Arg2
  210. )
  211. {
  212. switch (Arg1) {
  213. case PO_CB_SYSTEM_POWER_POLICY:
  214. DebugPrint((TRACE, " Power Policy Changed.\n"));
  215. break;
  216. case PO_CB_AC_STATUS:
  217. DebugPrint((TRACE, " AC/DC Transition. Now on %s\n", Arg2 ? "AC" : "DC"));
  218. break;
  219. case PO_CB_BUTTON_COLLISION:
  220. DebugPrint((ERROR, "PO_CB_BUTTON_COLLISION\n"));
  221. break;
  222. case PO_CB_SYSTEM_STATE_LOCK:
  223. DebugPrint((TRACE, " %sLock memory.\n", Arg2 ? "Un" : ""));
  224. break;
  225. case PO_CB_LID_SWITCH_STATE:
  226. DebugPrint((TRACE, " Lid is now %s\n", Arg2 ? "Open" : "Closed"));
  227. break;
  228. case PO_CB_PROCESSOR_POWER_POLICY:
  229. DebugPrint((TRACE, " Processor Power Policy Changed.\n"));
  230. break;
  231. default:
  232. DebugPrint((TRACE, " Unknown PowerState value 0x%x\n", Arg1));
  233. }
  234. }
  235. #endif