2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/kd64/kdprint.c
5 * PURPOSE: KD64 Trap Handler Routines
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
9 /* INCLUDES ******************************************************************/
15 /* FUNCTIONS *****************************************************************/
19 KdpPrintString(IN PSTRING Output
)
22 DBGKD_DEBUG_IO DebugIo
;
23 ULONG Length
= Output
->Length
;
26 RtlMoveMemory(KdpMessageBuffer
, Output
->Buffer
, Length
);
28 /* Make sure we don't exceed the KD Packet size */
29 if ((sizeof(DBGKD_DEBUG_IO
) + Length
) > PACKET_MAX_SIZE
)
31 /* Normalize length */
32 Length
= PACKET_MAX_SIZE
- sizeof(DBGKD_DEBUG_IO
);
35 /* Build the packet header */
36 DebugIo
.ApiNumber
= DbgKdPrintStringApi
;
37 DebugIo
.ProcessorLevel
= KeProcessorLevel
;
38 DebugIo
.Processor
= KeGetCurrentPrcb()->Number
;
39 DebugIo
.u
.PrintString
.LengthOfString
= Length
;
40 Header
.Length
= sizeof(DBGKD_DEBUG_IO
);
41 Header
.Buffer
= (PCHAR
)&DebugIo
;
45 Data
.Buffer
= KdpMessageBuffer
;
48 KdSendPacket(PACKET_TYPE_KD_DEBUG_IO
, &Header
, &Data
, &KdpContext
);
50 /* Check if the user pressed CTRL+C */
51 return KdpPollBreakInWithPortLock();
56 KdpCommandString(IN ULONG Length
,
58 IN KPROCESSOR_MODE PreviousMode
,
59 IN PCONTEXT ContextRecord
,
60 IN PKTRAP_FRAME TrapFrame
,
61 IN PKEXCEPTION_FRAME ExceptionFrame
)
69 KdpSymbol(IN PSTRING DllPath
,
70 IN PKD_SYMBOLS_INFO DllBase
,
72 IN KPROCESSOR_MODE PreviousMode
,
73 IN PCONTEXT ContextRecord
,
74 IN PKTRAP_FRAME TrapFrame
,
75 IN PKEXCEPTION_FRAME ExceptionFrame
)
78 PKPRCB Prcb
= KeGetCurrentPrcb();
81 /* Check if we need to do anything */
82 if ((PreviousMode
!= KernelMode
) || (KdDebuggerNotPresent
)) return 0;
84 /* Enter the debugger */
85 Entered
= KdEnterDebugger(TrapFrame
, ExceptionFrame
);
87 /* Save the CPU Control State and save the context */
88 KiSaveProcessorControlState(&Prcb
->ProcessorState
);
89 RtlCopyMemory(&Prcb
->ProcessorState
.ContextFrame
,
93 /* Report the new state */
94 Status
= KdpReportLoadSymbolsStateChange(DllPath
,
97 &Prcb
->ProcessorState
.
100 /* Now restore the processor state, manually again. */
101 RtlCopyMemory(ContextRecord
,
102 &Prcb
->ProcessorState
.ContextFrame
,
104 //KiRestoreProcessorControlState(&Prcb->ProcessorState);
106 /* Exit the debugger and clear the CTRL-C state */
107 KdExitDebugger(Entered
);
113 KdpPrompt(IN LPSTR InString
,
114 IN ULONG InStringLength
,
116 IN ULONG OutStringLength
,
117 IN KPROCESSOR_MODE PreviousMode
,
118 IN PKTRAP_FRAME TrapFrame
,
119 IN PKEXCEPTION_FRAME ExceptionFrame
)
127 KdpPrint(IN ULONG ComponentId
,
128 IN ULONG ComponentMask
,
131 IN KPROCESSOR_MODE PreviousMode
,
132 IN PKTRAP_FRAME TrapFrame
,
133 IN PKEXCEPTION_FRAME ExceptionFrame
,
136 NTSTATUS ReturnValue
;
138 ANSI_STRING AnsiString
;
143 /* Validate the mask */
144 if (ComponentMask
<= 0x1F) ComponentMask
= 1 << ComponentMask
;
145 if (!(Kd_WIN2000_Mask
& ComponentMask
) ||
146 ((ComponentId
< KdComponentTableSize
) &&
147 !(*KdComponentTable
[ComponentId
] & ComponentMask
)))
149 /* Mask validation failed */
154 /* Normalize the length */
155 Length
= min(Length
, 512);
157 /* Check if we need to verify the buffer */
158 if (PreviousMode
!= KernelMode
)
160 /* FIXME: Support user-mode */
163 /* Setup the ANSI string */
164 AnsiString
.Buffer
= String
;
165 AnsiString
.Length
= (USHORT
)Length
;
168 //KdLogDbgPrint(&AnsiString);
170 /* Check for a debugger */
171 if (KdDebuggerNotPresent
)
175 return (ULONG
)STATUS_DEVICE_NOT_CONNECTED
;
178 /* Enter the debugger */
179 Entered
= KdEnterDebugger(TrapFrame
, ExceptionFrame
);
181 /* Print the string */
182 if (KdpPrintString(&AnsiString
))
184 /* User pressed CTRL-C, breakpoint on return */
185 ReturnValue
= STATUS_BREAKPOINT
;
189 /* String was printed */
190 ReturnValue
= STATUS_SUCCESS
;
193 /* Exit the debugger and return */
194 KdExitDebugger(Entered
);