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.

371 lines
7.7 KiB

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