Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

kdinit.c File Reference

#include "kdp.h"

Go to the source code of this file.

Defines

#define BAUD_OPTION   "BAUDRATE"
#define PORT_OPTION   "DEBUGPORT"

Functions

BOOLEAN KdInitSystem (IN PLOADER_PARAMETER_BLOCK LoaderBlock OPTIONAL, BOOLEAN StopInDebugger)
BOOLEAN KdRegisterDebuggerDataBlock (IN ULONG Tag, IN PDBGKD_DEBUG_DATA_HEADER DataHeader, IN ULONG Size)
VOID KdDeregisterDebuggerDataBlock (IN PDBGKD_DEBUG_DATA_HEADER DataHeader)
VOID KdLogDbgPrint (IN PSTRING String)


Define Documentation

#define BAUD_OPTION   "BAUDRATE"
 

Definition at line 27 of file kdinit.c.

Referenced by KdInitSystem().

#define PORT_OPTION   "DEBUGPORT"
 

Definition at line 28 of file kdinit.c.

Referenced by KdInitSystem().


Function Documentation

VOID KdDeregisterDebuggerDataBlock IN PDBGKD_DEBUG_DATA_HEADER  DataHeader  ) 
 

Definition at line 328 of file kdinit.c.

References Header, KdpDataSpinLock, KdpDebuggerDataListHead, KeAcquireSpinLock, KeReleaseSpinLock(), and List.

00333 : 00334 00335 This routine is called to deregister a data block previously 00336 registered with KdRegisterDebuggerDataBlock. If the block is 00337 found in the list, it is removed. 00338 00339 Arguments: 00340 00341 DataHeader - Supplies the address of the data block which is 00342 to be removed from the list. 00343 00344 Return Value: 00345 00346 None 00347 00348 --*/ 00349 00350 { 00351 KIRQL OldIrql; 00352 PLIST_ENTRY List; 00353 PDBGKD_DEBUG_DATA_HEADER Header; 00354 00355 KeAcquireSpinLock(&KdpDataSpinLock, &OldIrql); 00356 00357 // 00358 // Make sure the data block is on our list before removing it. 00359 // 00360 00361 List = KdpDebuggerDataListHead.Flink; 00362 00363 while (List != &KdpDebuggerDataListHead) { 00364 00365 Header = CONTAINING_RECORD(List, DBGKD_DEBUG_DATA_HEADER, List); 00366 List = List->Flink; 00367 00368 if (DataHeader == Header) { 00369 RemoveEntryList(&DataHeader->List); 00370 break; 00371 } 00372 } 00373 00374 KeReleaseSpinLock(&KdpDataSpinLock, OldIrql); 00375 }

BOOLEAN KdInitSystem IN PLOADER_PARAMETER_BLOCK LoaderBlock  OPTIONAL,
BOOLEAN  StopInDebugger
 

Definition at line 36 of file kdinit.c.

References _BREAKPOINT_ENTRY::Address, BAUD_OPTION, _DEBUG_PARAMETERS::BaudRate, _DEBUG_PARAMETERS::CommunicationPort, _BREAKPOINT_ENTRY::DirectoryTableBase, ExInitializeWorkItem, FALSE, _BREAKPOINT_ENTRY::Flags, Index, KdDebuggerDataBlock, KdDebuggerEnabled, KdDebugParameters, KDP_BREAKPOINT_VALUE, KdpBreakpointInstruction, KdpBreakpointTable, KdpDebuggerDataListHead, KdpDebuggerStructuresInitialized, KdPerformanceCounterRate, KdPitchDebugger, KdpNextPacketIdToSend, KdpNtosImageBase, KdPortInitialize(), KdpOweBreakpoint, KdpPacketIdExpected, KdpStub(), KdpSwitchProcessor(), KdpTimeSlipDpc, KdpTimeSlipDpcRoutine(), KdpTimeSlipTimer, KdpTimeSlipWork(), KdpTimeSlipWorkItem, KdpTrap(), KdRegisterDebuggerDataBlock(), KdTimerStart, KeInitializeDpc(), KeInitializeTimer(), KeQueryPerformanceCounter(), KeUserCallbackDispatcher, KiDebugRoutine, KiDebugSwitchRoutine, L, NULL, PORT_OPTION, strlen(), and TRUE.

00043 : 00044 00045 This routine initializes the portable kernel debugger. 00046 00047 Arguments: 00048 00049 LoaderBlock - Supplies a pointer to the LOADER_PARAMETER_BLOCK passed 00050 in from the OS Loader. 00051 00052 StopInDebugger - Supplies a boolean value that determines whether a 00053 debug message and breakpoint are generated. 00054 00055 Return Value: 00056 00057 None. 00058 00059 --*/ 00060 00061 { 00062 00063 ULONG Index; 00064 BOOLEAN Initialize; 00065 PCHAR Options; 00066 PCHAR BaudOption; 00067 PCHAR PortOption; 00068 00069 // 00070 // If kernel debugger is already initialized, then return. 00071 // 00072 00073 if (KdDebuggerEnabled != FALSE) { 00074 return TRUE; 00075 } 00076 00077 KiDebugRoutine = KdpStub; 00078 00079 // 00080 // Determine whether or not the debugger should be enabled. 00081 // 00082 // Note that if LoaderBlock == NULL, then KdInitSystem was called 00083 // from BugCheck code. For this case the debugger is always enabled 00084 // to report the bugcheck if possible. 00085 // 00086 00087 if (LoaderBlock != NULL) { 00088 00089 KdpNtosImageBase = CONTAINING_RECORD( 00090 (LoaderBlock->LoadOrderListHead.Flink), 00091 LDR_DATA_TABLE_ENTRY, 00092 InLoadOrderLinks)->DllBase; 00093 00094 // 00095 // Initialize the debugger data block list when called at startup time. 00096 // 00097 00098 InitializeListHead(&KdpDebuggerDataListHead); 00099 00100 // 00101 // Fill in and register the debugger's debugger data block. 00102 // Most fields are already initialized, some fields will not be 00103 // filled in until later. 00104 // 00105 00106 KdDebuggerDataBlock.KernBase = (ULONG_PTR) KdpNtosImageBase; 00107 KdDebuggerDataBlock.KeUserCallbackDispatcher = (ULONG_PTR) KeUserCallbackDispatcher; 00108 00109 KdRegisterDebuggerDataBlock(KDBG_TAG, 00110 &KdDebuggerDataBlock.Header, 00111 sizeof(KdDebuggerDataBlock)); 00112 00113 if (LoaderBlock->LoadOptions != NULL) { 00114 Options = LoaderBlock->LoadOptions; 00115 _strupr(Options); 00116 00117 // 00118 // If any of the port option, baud option, or debug is specified, 00119 // then enable the debugger unless it is explictly disabled. 00120 // 00121 00122 Initialize = TRUE; 00123 PortOption = strstr(Options, PORT_OPTION); 00124 BaudOption = strstr(Options, BAUD_OPTION); 00125 if ((PortOption == NULL) && (BaudOption == NULL)) { 00126 if (strstr(Options, "DEBUG") == NULL) { 00127 Initialize = FALSE; 00128 } 00129 00130 } else { 00131 if (PortOption) { 00132 PortOption = strstr(PortOption, "COM"); 00133 if (PortOption) { 00134 KdDebugParameters.CommunicationPort = 00135 atol(PortOption + 3); 00136 } 00137 } 00138 00139 if (BaudOption) { 00140 BaudOption += strlen(BAUD_OPTION); 00141 while (*BaudOption == ' ') { 00142 BaudOption++; 00143 } 00144 00145 if (*BaudOption != '\0') { 00146 KdDebugParameters.BaudRate = atol(BaudOption + 1); 00147 } 00148 } 00149 } 00150 00151 // 00152 // If the debugger is explicitly disabled, then set to NODEBUG. 00153 // 00154 00155 if (strstr(Options, "NODEBUG")) { 00156 Initialize = FALSE; 00157 KdPitchDebugger = TRUE; 00158 } 00159 00160 if (strstr(Options, "CRASHDEBUG")) { 00161 Initialize = FALSE; 00162 KdPitchDebugger = FALSE; 00163 } 00164 00165 } else { 00166 00167 // 00168 // If the load options are not specified, then set to NODEBUG. 00169 // 00170 00171 KdPitchDebugger = TRUE; 00172 Initialize = FALSE; 00173 } 00174 00175 } else { 00176 Initialize = TRUE; 00177 } 00178 00179 if ((KdPortInitialize(&KdDebugParameters, LoaderBlock, Initialize) == FALSE) || 00180 (Initialize == FALSE)) { 00181 return(TRUE); 00182 } 00183 00184 // 00185 // Set address of kernel debugger trap routine. 00186 // 00187 00188 KiDebugRoutine = KdpTrap; 00189 00190 if (!KdpDebuggerStructuresInitialized) { 00191 00192 KiDebugSwitchRoutine = KdpSwitchProcessor; 00193 KdpBreakpointInstruction = KDP_BREAKPOINT_VALUE; 00194 KdpOweBreakpoint = FALSE; 00195 00196 // 00197 // Initialize the breakpoint table. 00198 // 00199 00200 for (Index = 0; Index < BREAKPOINT_TABLE_SIZE; Index += 1) { 00201 KdpBreakpointTable[Index].Flags = 0; 00202 KdpBreakpointTable[Index].Address = NULL; 00203 KdpBreakpointTable[Index].DirectoryTableBase = 0L; 00204 } 00205 00206 // 00207 // Initialize TimeSlip 00208 // 00209 KeInitializeDpc(&KdpTimeSlipDpc, KdpTimeSlipDpcRoutine, NULL); 00210 KeInitializeTimer(&KdpTimeSlipTimer); 00211 ExInitializeWorkItem(&KdpTimeSlipWorkItem, KdpTimeSlipWork, NULL); 00212 00213 KdpDebuggerStructuresInitialized = TRUE ; 00214 } 00215 00216 // 00217 // Initialize timer facility - HACKHACK 00218 // 00219 00220 KeQueryPerformanceCounter(&KdPerformanceCounterRate); 00221 KdTimerStart.HighPart = 0L; 00222 KdTimerStart.LowPart = 0L; 00223 00224 // 00225 // Initialize ID for NEXT packet to send and Expect ID of next incoming 00226 // packet. 00227 // 00228 00229 KdpNextPacketIdToSend = INITIAL_PACKET_ID | SYNC_PACKET_ID; 00230 KdpPacketIdExpected = INITIAL_PACKET_ID; 00231 00232 // 00233 // Mark debugger enabled. 00234 // 00235 KdPitchDebugger = FALSE; 00236 KdDebuggerEnabled = TRUE; 00237 SharedUserData->KdDebuggerEnabled = TRUE; 00238 00239 // 00240 // If requested, stop in the kernel debugger. 00241 // 00242 00243 if (StopInDebugger) { 00244 DbgBreakPoint(); 00245 } 00246 00247 return TRUE; 00248 }

VOID KdLogDbgPrint IN PSTRING  String  ) 
 

Definition at line 379 of file kdinit.c.

References HIGH_LEVEL, KdpMoveMemory(), KdpPrintSpinLock, KDPRINTBUFFERSIZE, KdPrintCircularBuffer, KdPrintRolloverCount, KdPrintWritePointer, KeLowerIrql(), KeRaiseIrql(), KiTryToAcquireSpinLock(), and String.

00382 { 00383 KIRQL OldIrql; 00384 ULONG Length; 00385 ULONG LengthCopied; 00386 00387 for (; ;) { 00388 if (KeTestSpinLock (&KdpPrintSpinLock)) { 00389 KeRaiseIrql (HIGH_LEVEL, &OldIrql); 00390 if (KiTryToAcquireSpinLock(&KdpPrintSpinLock)) { 00391 break; // got the lock 00392 } 00393 KeLowerIrql(OldIrql); 00394 } 00395 } 00396 00397 if (KdPrintCircularBuffer) { 00398 Length = String->Length; 00399 // 00400 // truncate ridiculous strings 00401 // 00402 if (Length > KDPRINTBUFFERSIZE) { 00403 Length = KDPRINTBUFFERSIZE; 00404 } 00405 00406 if (KdPrintWritePointer + Length <= KdPrintCircularBuffer+KDPRINTBUFFERSIZE) { 00407 LengthCopied = KdpMoveMemory(KdPrintWritePointer, String->Buffer, Length); 00408 KdPrintWritePointer += LengthCopied; 00409 if (KdPrintWritePointer >= KdPrintCircularBuffer+KDPRINTBUFFERSIZE) { 00410 KdPrintWritePointer = KdPrintCircularBuffer; 00411 KdPrintRolloverCount++; 00412 } 00413 } else { 00414 ULONG First = (ULONG)(KdPrintCircularBuffer + KDPRINTBUFFERSIZE - KdPrintWritePointer); 00415 LengthCopied = KdpMoveMemory(KdPrintWritePointer, 00416 String->Buffer, 00417 First); 00418 if (LengthCopied == First) { 00419 LengthCopied += KdpMoveMemory(KdPrintCircularBuffer, 00420 String->Buffer + First, 00421 Length - First); 00422 } 00423 if (LengthCopied > First) { 00424 KdPrintWritePointer = KdPrintCircularBuffer + LengthCopied - First; 00425 KdPrintRolloverCount++; 00426 } else { 00427 KdPrintWritePointer += LengthCopied; 00428 if (KdPrintWritePointer >= KdPrintCircularBuffer+KDPRINTBUFFERSIZE) { 00429 KdPrintWritePointer = KdPrintCircularBuffer; 00430 KdPrintRolloverCount++; 00431 } 00432 } 00433 } 00434 } 00435 00436 KiReleaseSpinLock(&KdpPrintSpinLock); 00437 KeLowerIrql(OldIrql); 00438 }

BOOLEAN KdRegisterDebuggerDataBlock IN ULONG  Tag,
IN PDBGKD_DEBUG_DATA_HEADER  DataHeader,
IN ULONG  Size
 

Definition at line 252 of file kdinit.c.

References FALSE, Header, KdpDataSpinLock, KdpDebuggerDataListHead, KeAcquireSpinLock, KeReleaseSpinLock(), List, Size, and TRUE.

00259 : 00260 00261 This routine is called by a component or driver to register a 00262 debugger data block. The data block is made accessible to the 00263 kernel debugger, thus providing a reliable method of exposing 00264 random data to debugger extensions. 00265 00266 Arguments: 00267 00268 Tag - Supplies a unique 4 byte tag which is used to identify the 00269 data block. 00270 00271 DataHeader - Supplies the address of the debugger data block header. 00272 The OwnerTag field must contain a unique value, and the Size 00273 field must contain the size of the data block, including the 00274 header. If this block is already present, or there is 00275 already a block with the same value for OwnerTag, this one 00276 will not be inserted. If Size is incorrect, this code will 00277 not notice, but the usermode side of the debugger might not 00278 function correctly. 00279 00280 Size - Supplies the size of the data block, including the header. 00281 00282 Return Value: 00283 00284 TRUE if the block was added to the list, FALSE if not. 00285 00286 --*/ 00287 { 00288 KIRQL OldIrql; 00289 PLIST_ENTRY List; 00290 PDBGKD_DEBUG_DATA_HEADER Header; 00291 00292 KeAcquireSpinLock(&KdpDataSpinLock, &OldIrql); 00293 00294 // 00295 // Look for a record with the same tag or address 00296 // 00297 00298 List = KdpDebuggerDataListHead.Flink; 00299 00300 while (List != &KdpDebuggerDataListHead) { 00301 00302 Header = CONTAINING_RECORD(List, DBGKD_DEBUG_DATA_HEADER, List); 00303 00304 List = List->Flink; 00305 00306 if ((Header == DataHeader) || (Header->OwnerTag == Tag)) { 00307 KeReleaseSpinLock(&KdpDataSpinLock, OldIrql); 00308 return FALSE; 00309 } 00310 } 00311 00312 // 00313 // It wasn't already there, so add it. 00314 // 00315 00316 DataHeader->OwnerTag = Tag; 00317 DataHeader->Size = Size; 00318 00319 InsertTailList(&KdpDebuggerDataListHead, &DataHeader->List); 00320 00321 KeReleaseSpinLock(&KdpDataSpinLock, OldIrql); 00322 00323 return TRUE; 00324 }


Generated on Sat May 15 19:44:26 2004 for test by doxygen 1.3.7