Leaked source code of windows server 2003
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.

355 lines
7.7 KiB

  1. //
  2. // No Check-in Source Code.
  3. //
  4. // Do not make this code available to non-Microsoft personnel
  5. // without Intel's express permission
  6. //
  7. /**
  8. *** Copyright (C) 1996-97 Intel Corporation. All rights reserved.
  9. ***
  10. *** The information and source code contained herein is the exclusive
  11. *** property of Intel Corporation and may not be disclosed, examined
  12. *** or reproduced in whole or in part without explicit written authorization
  13. *** from the company.
  14. **/
  15. /*++
  16. Copyright (c) 1995 Intel Corporation
  17. Module Name:
  18. simkd.c
  19. Abstract:
  20. Kernel debug com support.
  21. Author:
  22. 14-Apr-1995
  23. Environment:
  24. Kernel mode
  25. Revision History:
  26. --*/
  27. #include "halp.h"
  28. extern int sprintf(char *, const char *, ...);
  29. // #define KDDBG 1
  30. #define TIMEOUT_COUNT 100 // 1024 * 200
  31. #define GET_RETRY_COUNT 1024
  32. #define MSG_DEBUG_ENABLE "Kernel Debugger Using: COM%x (Port %p, Baud Rate %d)\n"
  33. #define MSG2_DEBUG_ENABLE "Kernel Debugger Using named pipe: COM%x (Port %p, Baud Rate %d)\n"
  34. PUCHAR KdComPortInUse=NULL;
  35. BOOLEAN
  36. KdPortInitialize(
  37. PDEBUG_PARAMETERS DebugParameters,
  38. PLOADER_PARAMETER_BLOCK LoaderBlock,
  39. BOOLEAN Initialize
  40. )
  41. /*++
  42. Routine Description:
  43. This routine initialize a com port to support kernel debug.
  44. Arguments:
  45. DebugParameters - Supplies a pointer a structure which optionally
  46. sepcified the debugging port information.
  47. LoaderBlock - supplies a pointer to the loader parameter block.
  48. Initialize - Specifies a boolean value that determines whether the
  49. debug port is initialized or just the debug port parameters
  50. are captured.
  51. Returned Value:
  52. TRUE - If a debug port is found.
  53. --*/
  54. {
  55. PUCHAR PortAddress = NULL;
  56. ULONG Com = 0;
  57. UCHAR DebugMessage[80];
  58. PHYSICAL_ADDRESS LPDebugParameters;
  59. if (Initialize) {
  60. LPDebugParameters = MmGetPhysicalAddress (DebugParameters);
  61. if ( !SscKdInitialize( (PVOID)LPDebugParameters.QuadPart, (SSC_BOOL)Initialize )) {
  62. // SscKd initialized sucessfully
  63. Com = DebugParameters->CommunicationPort;
  64. if ( Com != 0 ) { // initialize port struct if not named-pipe
  65. //
  66. // set port address to default value.
  67. //
  68. if (PortAddress == NULL) {
  69. switch (Com) {
  70. case 1:
  71. PortAddress = (PUCHAR)(ULONG_PTR)0x3f8;
  72. break;
  73. case 2:
  74. PortAddress = (PUCHAR)(ULONG_PTR)0x2f8;
  75. break;
  76. case 3:
  77. PortAddress = (PUCHAR)(ULONG_PTR)0x3e8;
  78. break;
  79. case 4:
  80. PortAddress = (PUCHAR)(ULONG_PTR)0x2e8;
  81. }
  82. }
  83. KdComPortInUse= PortAddress;
  84. sprintf(DebugMessage, MSG_DEBUG_ENABLE,
  85. Com, PortAddress, DebugParameters->BaudRate);
  86. HalDisplayString("\n");
  87. HalDisplayString(DebugMessage);
  88. }
  89. else { // port=0, named-pipe
  90. sprintf(DebugMessage, MSG2_DEBUG_ENABLE,
  91. Com, PortAddress, DebugParameters->BaudRate);
  92. HalDisplayString("\n");
  93. HalDisplayString(DebugMessage);
  94. }
  95. return(TRUE);
  96. }
  97. else {
  98. // SscKdinitialize() failed
  99. return(FALSE);
  100. }
  101. }
  102. else { // By pass. do not initialize
  103. return(FALSE);
  104. }
  105. }
  106. ULONG
  107. KdPortGetByte (
  108. OUT PUCHAR Input
  109. )
  110. /*++
  111. Routine Description:
  112. Fetch a byte from the debug port and return it.
  113. This routine does nothing in the simulation environment.
  114. N.B. It is assumed that the IRQL has been raised to the highest level, and
  115. necessary multiprocessor synchronization has been performed before this
  116. routine is called.
  117. Arguments:
  118. Input - Returns the data byte.
  119. Return Value:
  120. CP_GET_SUCCESS is returned if a byte is successfully read from the
  121. kernel debugger line.
  122. CP_GET_ERROR is returned if error encountered during reading.
  123. CP_GET_NODATA is returned if timeout.
  124. --*/
  125. {
  126. PHYSICAL_ADDRESS LPInput;
  127. UCHAR DebugMessage[80];
  128. ULONG limitcount, status;
  129. LPInput = MmGetPhysicalAddress (Input);
  130. limitcount = GET_RETRY_COUNT;
  131. while (limitcount != 0) {
  132. limitcount--;
  133. status = SscKdPortGetByte((PVOID)LPInput.QuadPart);
  134. if (status == CP_GET_SUCCESS) {
  135. #ifdef KDDBG
  136. sprintf(DebugMessage,"%02x ", *Input);
  137. HalDisplayString(DebugMessage);
  138. #endif
  139. return(CP_GET_SUCCESS);
  140. }
  141. #ifdef KDDBG
  142. else {
  143. HalDisplayString(".");
  144. }
  145. #endif
  146. }
  147. return status;
  148. }
  149. ULONG
  150. KdPortPollByte (
  151. OUT PUCHAR Input
  152. )
  153. /*++
  154. Routine Description:
  155. Fetch a byte from the debug port and return it if one is available.
  156. This routine does nothing in the simulation environment.
  157. N.B. It is assumed that the IRQL has been raised to the highest level, and
  158. necessary multiprocessor synchronization has been performed before this
  159. routine is called.
  160. Arguments:
  161. Input - Returns the data byte.
  162. Return Value:
  163. CP_GET_SUCCESS is returned if a byte is successfully read from the
  164. kernel debugger line.
  165. CP_GET_ERROR is returned if error encountered during reading.
  166. CP_GET_NODATA is returned if timeout.
  167. --*/
  168. {
  169. PHYSICAL_ADDRESS LPInput;
  170. UCHAR DebugMessage[80];
  171. ULONG limitcount, status;
  172. LPInput = MmGetPhysicalAddress (Input);
  173. limitcount = TIMEOUT_COUNT;
  174. while (limitcount != 0) {
  175. limitcount--;
  176. status = SscKdPortGetByte((PVOID)LPInput.QuadPart);
  177. if (status == CP_GET_ERROR)
  178. return(CP_GET_ERROR);
  179. if (status == CP_GET_SUCCESS) {
  180. #ifdef KDDBG
  181. sprintf(DebugMessage, "%02x ", *Input);
  182. HalDisplayString(DebugMessage);
  183. #endif
  184. return(CP_GET_SUCCESS);
  185. }
  186. #ifdef KDDBG
  187. HalDisplayString(".");
  188. #endif
  189. }
  190. return (CP_GET_NODATA);
  191. }
  192. VOID
  193. KdPortPutByte (
  194. IN UCHAR Output
  195. )
  196. /*++
  197. Routine Description:
  198. Write a byte to the debug port.
  199. This routine does nothing in the simulation environment.
  200. N.B. It is assumed that the IRQL has been raised to the highest level, and
  201. necessary multiprocessor synchronization has been performed before this
  202. routine is called.
  203. Arguments:
  204. Output - Supplies the output data byte.
  205. Return Value:
  206. None.
  207. --*/
  208. {
  209. #ifdef KDDBG
  210. UCHAR DebugMessage[80];
  211. sprintf(DebugMessage, "%02x-", Output);
  212. HalDisplayString(DebugMessage);
  213. #endif
  214. SscKdPortPutByte(Output);
  215. }
  216. VOID
  217. KdPortRestore (
  218. VOID
  219. )
  220. /*++
  221. Routine Description:
  222. This routine does nothing in the simulation environment.
  223. N.B. It is assumed that the IRQL has been raised to the highest level, and
  224. necessary multiprocessor synchronization has been performed before this
  225. routine is called.
  226. Arguments:
  227. None.
  228. Return Value:
  229. None.
  230. --*/
  231. {
  232. }
  233. VOID
  234. KdPortSave (
  235. VOID
  236. )
  237. /*++
  238. Routine Description:
  239. This routine does nothing in the simulation environment.
  240. N.B. It is assumed that the IRQL has been raised to the highest level, and
  241. necessary multiprocessor synchronization has been performed before this
  242. routine is called.
  243. Arguments:
  244. None.
  245. Return Value:
  246. None.
  247. --*/
  248. {
  249. }