Windows NT 4.0 source code leak
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.

250 lines
6.1 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. dbgkdsup.c
  5. Abstract:
  6. This module contains os specific DbgKd support routines
  7. Author:
  8. Mark Lucovsky (markl) 27-Jul-1990
  9. Revision History:
  10. Roger Lanser (O-ALEXBR) 18-Jan-1992 Removed #ifdef DECSTATION and added
  11. hack for baud rate environment variable. Unable
  12. to compile due to failure to find include files.
  13. --*/
  14. #include "ntsdp.h"
  15. #include "dbgpnt.h"
  16. #define THREAD_STACK_SIZE 16000 /* Better safe than... */
  17. #define COM_PORT_NAME "_NT_DEBUG_PORT"
  18. #define COM_PORT_BAUD "_NT_DEBUG_BAUD_RATE"
  19. HANDLE PipeRead;
  20. HANDLE PipeWrite;
  21. extern BOOLEAN KdModemControl;
  22. VOID
  23. DbgKdpStartThreads(VOID)
  24. {
  25. HANDLE PollThread;
  26. DWORD KbdPollThreadId;
  27. if( CreatePipe( &PipeRead, &PipeWrite, NULL, (1024-32)) == FALSE ) {
  28. fprintf(stderr, "Failed to create anonymous pipe in KdpStartThreads\n");
  29. fprintf(stderr, "Error code %lx\n", GetLastError());
  30. exit(1);
  31. }
  32. PollThread = CreateThread(
  33. NULL,
  34. THREAD_STACK_SIZE,
  35. (LPTHREAD_START_ROUTINE)DbgKdpKbdPollThread,
  36. NULL,
  37. THREAD_SET_INFORMATION,
  38. (LPDWORD)&KbdPollThreadId
  39. );
  40. if ( PollThread == (HANDLE)NULL ) {
  41. fprintf(stderr,"Failed to create KbdPollThread %d\n",PollThread);
  42. exit(1);
  43. }
  44. else {
  45. if (!SetThreadPriority(PollThread, THREAD_PRIORITY_ABOVE_NORMAL)) {
  46. fprintf(stderr, "Fail to raise the priority of PollThread.\n");
  47. }
  48. }
  49. }
  50. VOID
  51. DbgKdpInitComPort(
  52. ULONG ComPort
  53. )
  54. {
  55. PUCHAR ComPortName;
  56. ULONG Baud;
  57. DCB LocalDcb;
  58. COMMTIMEOUTS To;
  59. DWORD mask;
  60. //
  61. // A quick hack to remove the #ifdef DECSTATION so the mips version
  62. // is ok for DECSTATION. No other files were modified to reflect
  63. // this change.
  64. //
  65. {
  66. PUCHAR baudRateEnvValue;
  67. if (baudRateEnvValue = getenv(COM_PORT_BAUD)) {
  68. Baud = atol(baudRateEnvValue);
  69. fprintf(stderr, "KD: baud rate reset to %d\n\n", Baud);
  70. } else {
  71. Baud = 19200;
  72. }
  73. }
  74. //
  75. // Read an environment variable to decide what comport to use,
  76. // IGNORE the bogus comport argument.
  77. //
  78. ComPortName = getenv(COM_PORT_NAME);
  79. if (ComPortName == NULL) {
  80. ComPortName = "com1";
  81. }
  82. //
  83. // Open the device
  84. //
  85. DbgKdpComPort = CreateFile(
  86. (PSZ)ComPortName,
  87. GENERIC_READ | GENERIC_WRITE,
  88. 0,
  89. NULL,
  90. OPEN_ALWAYS,
  91. FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
  92. NULL
  93. );
  94. if ( DbgKdpComPort == (HANDLE)-1 ) {
  95. fprintf(stderr,"Failed to open %s\n",ComPortName);
  96. exit(1);
  97. }
  98. SetupComm(DbgKdpComPort,(DWORD)4096,(DWORD)4096);
  99. //
  100. // Create the events used by the overlapped structures for the
  101. // read and write.
  102. //
  103. ReadOverlapped.hEvent = CreateEvent(
  104. NULL,
  105. TRUE,
  106. FALSE,NULL
  107. );
  108. if (!ReadOverlapped.hEvent) {
  109. fprintf(stderr,"Failed to create read event support for %s\n",ComPortName);
  110. exit(1);
  111. }
  112. WriteOverlapped.hEvent = CreateEvent(
  113. NULL,
  114. TRUE,
  115. FALSE,NULL
  116. );
  117. if (!WriteOverlapped.hEvent) {
  118. fprintf(stderr,"Failed to create write event support for %s\n",ComPortName);
  119. exit(1);
  120. }
  121. ReadOverlapped.Offset = 0;
  122. ReadOverlapped.OffsetHigh = 0;
  123. WriteOverlapped.Offset = 0;
  124. WriteOverlapped.OffsetHigh = 0;
  125. //
  126. // Set up the Comm port....
  127. //
  128. if (!GetCommState(
  129. DbgKdpComPort,
  130. &LocalDcb
  131. )) {
  132. fprintf(stderr,"Failed to get the old comm state for %s\n",ComPort);
  133. exit(1);
  134. }
  135. LocalDcb.BaudRate = Baud;
  136. LocalDcb.ByteSize = 8;
  137. LocalDcb.Parity = NOPARITY;
  138. LocalDcb.StopBits = ONESTOPBIT;
  139. LocalDcb.fDtrControl = DTR_CONTROL_ENABLE;
  140. LocalDcb.fRtsControl = RTS_CONTROL_ENABLE;
  141. LocalDcb.fBinary = TRUE;
  142. LocalDcb.fOutxCtsFlow = FALSE;
  143. LocalDcb.fOutxDsrFlow = FALSE;
  144. LocalDcb.fOutX = FALSE;
  145. LocalDcb.fInX = FALSE;
  146. if (!SetCommState(
  147. DbgKdpComPort,
  148. &LocalDcb
  149. )) {
  150. fprintf(stderr,"Failed to set state for %s.\n",ComPortName);
  151. exit(1);
  152. }
  153. //
  154. // Set the normal read and write timeout time.
  155. // The symbols are 10 millisecond intervals.
  156. //
  157. To.ReadIntervalTimeout = 0;
  158. To.ReadTotalTimeoutMultiplier = 0;
  159. To.ReadTotalTimeoutConstant = 4 * 1000;
  160. To.WriteTotalTimeoutMultiplier = 0;
  161. To.WriteTotalTimeoutConstant = 4 * 1000;
  162. if (!SetCommTimeouts(
  163. DbgKdpComPort,
  164. &To
  165. )) {
  166. fprintf(stderr,"Failed to set timeouts for %s.\n",ComPortName);
  167. exit(1);
  168. }
  169. DbgKdpComEvent = 0;
  170. if (KdModemControl) {
  171. //
  172. // Debugger is being run over a modem. Set event to watch
  173. // carrier detect.
  174. //
  175. GetCommMask (DbgKdpComPort, &mask);
  176. if (!SetCommMask (DbgKdpComPort, mask | 0xA0)) { // set DDCD event
  177. fprintf(stderr,"Failed to set event for %s.\n", ComPortName);
  178. exit(1);
  179. }
  180. EventOverlapped.hEvent = CreateEvent(
  181. NULL,
  182. TRUE,
  183. FALSE,NULL
  184. );
  185. if (!EventOverlapped.hEvent) {
  186. fprintf(stderr,"Failed to create EventOverlapped\n");
  187. exit(1);
  188. }
  189. EventOverlapped.Offset = 0;
  190. EventOverlapped.OffsetHigh = 0;
  191. DbgKdpComEvent = 1; // Fake an event, so modem status will be checked
  192. }
  193. }