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.

229 lines
4.1 KiB

  1. /*++
  2. Copyright (c) 1992-2001 Microsoft Corporation
  3. Module Name:
  4. kdlock.c
  5. Abstract:
  6. This module contains code to synchronize the usage of the port
  7. used by the kernel debugger.
  8. Author:
  9. Bryan M. Willman (bryanwi) 24-Sep-90
  10. Revision History:
  11. --*/
  12. #include "kdp.h"
  13. VOID
  14. KdpPortLock(
  15. VOID
  16. )
  17. /*++
  18. Routine Description:
  19. Acquire the spinlock for the debug port.
  20. Note that user must call this explicitly, the get/put routines
  21. do NOT make any use of the lock.
  22. CALLER MUST HAVE SET PROPER IRQL BEFORE CALLING US.
  23. We use KiAcquireSpinLock and NOT Ke... because our IRQL may
  24. be above DISPATCH_LEVEL.
  25. Arguments:
  26. None.
  27. Return value:
  28. None.
  29. --*/
  30. {
  31. KiAcquireSpinLock(&KdpDebuggerLock);
  32. }
  33. VOID
  34. KdpPortUnlock(
  35. VOID
  36. )
  37. /*++
  38. Routine Description:
  39. Release the spinlock for the debug port.
  40. Note that user must call this explicitly, the get/put routines
  41. do NOT make any use of the lock.
  42. CALLER MUST HAVE SET PROPER IRQL BEFORE CALLING US.
  43. We use KiReleaseSpinLock and NOT Ke... because our IRQL may
  44. be above DISPATCH_LEVEL.
  45. Arguments:
  46. None.
  47. Return value:
  48. None.
  49. --*/
  50. {
  51. KiReleaseSpinLock(&KdpDebuggerLock);
  52. }
  53. BOOLEAN
  54. KdPollBreakIn(
  55. VOID
  56. )
  57. /*++
  58. Routine Description:
  59. This procedure raises IRQL to high_level, seizes the Debug port
  60. spinlock, and checks to see if a breakin packet is pending.
  61. If a packet is present, return TRUE, else FALSE.
  62. A packet is present if:
  63. There is a valid character which matches BREAK_CHAR.
  64. N.B. Interrupts must be OFF around this call
  65. Return Value:
  66. TRUE if breakin sequence present, caller should execute int-3.
  67. FALSE if no breakin seen.
  68. --*/
  69. {
  70. BOOLEAN BreakIn;
  71. BOOLEAN Enable;
  72. KIRQL OldIrql;
  73. ULONG Status;
  74. //
  75. // If the debugger is enabled, see if a breakin by the kernel
  76. // debugger is pending.
  77. //
  78. BreakIn = FALSE;
  79. if (KdDebuggerEnabled != FALSE) {
  80. Enable = KeDisableInterrupts();
  81. #ifndef _X86_
  82. KeRaiseIrql(HIGH_LEVEL, &OldIrql);
  83. #endif
  84. if (KdpContext.KdpControlCPending != FALSE) {
  85. KdpControlCPressed = TRUE;
  86. BreakIn = TRUE;
  87. KdpContext.KdpControlCPending = FALSE;
  88. } else {
  89. if (KeTryToAcquireSpinLockAtDpcLevel(&KdpDebuggerLock) != FALSE) {
  90. Status = KdReceivePacket(PACKET_TYPE_KD_POLL_BREAKIN,
  91. NULL,
  92. NULL,
  93. NULL,
  94. NULL);
  95. if (Status == KDP_PACKET_RECEIVED) {
  96. BreakIn = TRUE;
  97. KdpControlCPressed = TRUE;
  98. }
  99. KdpPortUnlock();
  100. }
  101. }
  102. #ifndef _X86_
  103. KeLowerIrql(OldIrql);
  104. #endif
  105. KeEnableInterrupts(Enable);
  106. }
  107. return BreakIn;
  108. }
  109. BOOLEAN
  110. KdpPollBreakInWithPortLock(
  111. VOID
  112. )
  113. /*++
  114. Routine Description:
  115. This procedure same as KdPollBreakIn, but assumes the caller
  116. already holds the port lock. Returns TRUE if a breakin packet
  117. is pending.
  118. A packet is present if:
  119. There is a valid character which matches BREAK_CHAR.
  120. N.B. Interrupts must be OFF around this call
  121. Return Value:
  122. TRUE if breakin sequence present, caller should execute int-3.
  123. FALSE if no breakin seen.
  124. --*/
  125. {
  126. BOOLEAN BreakIn;
  127. BOOLEAN Enable;
  128. ULONG Status;
  129. //
  130. // If the debugger is enabled, see if a breakin by the kernel
  131. // debugger is pending.
  132. //
  133. BreakIn = FALSE;
  134. if (KdDebuggerEnabled != FALSE) {
  135. if (KdpContext.KdpControlCPending != FALSE) {
  136. BreakIn = TRUE;
  137. KdpContext.KdpControlCPending = FALSE;
  138. } else {
  139. Status = KdReceivePacket(PACKET_TYPE_KD_POLL_BREAKIN,
  140. NULL,
  141. NULL,
  142. NULL,
  143. NULL);
  144. if (Status == KDP_PACKET_RECEIVED) {
  145. BreakIn = TRUE;
  146. }
  147. }
  148. }
  149. return BreakIn;
  150. }