- Add kd64 folder for KD64 6.0 implementation.
[reactos.git] / reactos / ntoskrnl / kd64 / kdlock.c
1 /*
2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/kd64/kdlock.c
5 * PURPOSE: KD64 Port Lock and Breakin Support
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7 */
8
9 /* INCLUDES ******************************************************************/
10
11 #include <ntoskrnl.h>
12 #define NDEBUG
13 #include <debug.h>
14
15 /* PRIVATE FUNCTIONS *********************************************************/
16
17 VOID
18 NTAPI
19 KdpPortLock(VOID)
20 {
21 /* Acquire the lock */
22 KiAcquireSpinLock(&KdpDebuggerLock);
23 }
24
25 VOID
26 NTAPI
27 KdpPortUnlock(VOID)
28 {
29 /* Release the lock */
30 KiReleaseSpinLock(&KdpDebuggerLock);
31 }
32
33 /* PUBLIC FUNCTIONS **********************************************************/
34
35 /*
36 * @implemented
37 */
38 BOOLEAN
39 NTAPI
40 KdPollBreakIn(VOID)
41 {
42 BOOLEAN DoBreak = FALSE;
43 ULONG Flags;
44
45 /* First make sure that KD is enabled */
46 if (KdDebuggerEnabled)
47 {
48 /* Disable interrupts */
49 Ke386SaveFlags(Flags);
50 //Flags = __getcallerseflags();
51 _disable();
52
53 /* Check if a CTRL-C is in the queue */
54 if (KdpControlCWaiting)
55 {
56 /* Set it and prepare for break */
57 KdpControlCPressed = TRUE;
58 DoBreak = TRUE;
59 KdpControlCWaiting = FALSE;
60 }
61 else
62 {
63 /* Try to acquire the lock */
64 if (KeTryToAcquireSpinLockAtDpcLevel(&KdpDebuggerLock))
65 {
66 /* Now get a packet */
67 if (!KdReceivePacket(PACKET_TYPE_KD_POLL_BREAKIN,
68 NULL,
69 NULL,
70 NULL,
71 NULL))
72 {
73 /* Successful breakin */
74 DoBreak = TRUE;
75 KdpControlCPressed = TRUE;
76 }
77
78 /* Let go of the port */
79 KdpPortUnlock();
80 }
81 }
82
83 /* Re-enable interrupts if they were disabled */
84 if (Flags & EFLAGS_INTERRUPT_MASK) _enable();
85 }
86
87 /* Tell the caller to do a break */
88 return DoBreak;
89 }
90