mirror of
https://github.com/reactos/reactos.git
synced 2024-11-04 22:00:55 +00:00
[NTOS:KD] Merge KdInitDebugger with kd64 version + move variable declarations to kd64/kddata.c
Remove now unused file kd/kdinit.c
This commit is contained in:
parent
777a2d94da
commit
4d84c856ad
4 changed files with 41 additions and 293 deletions
|
@ -1,289 +0,0 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS Kernel
|
||||
* FILE: ntoskrnl/kd/kdinit.c
|
||||
* PURPOSE: Kernel Debugger Initializtion
|
||||
*
|
||||
* PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
|
||||
*/
|
||||
|
||||
#include <ntoskrnl.h>
|
||||
#include <reactos/buildno.h>
|
||||
#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
||||
/* Make bochs debug output in the very early boot phase available */
|
||||
//#define AUTO_ENABLE_BOCHS
|
||||
|
||||
/* VARIABLES ***************************************************************/
|
||||
|
||||
ULONG PortNumber = DEFAULT_DEBUG_PORT;
|
||||
CPPORT PortInfo = {0, DEFAULT_DEBUG_BAUD_RATE, 0};
|
||||
ULONG KdpPortIrq;
|
||||
#ifdef AUTO_ENABLE_BOCHS
|
||||
KDP_DEBUG_MODE KdpDebugMode = {{{.Bochs=TRUE}}};
|
||||
#else
|
||||
KDP_DEBUG_MODE KdpDebugMode;
|
||||
#endif
|
||||
PKDP_INIT_ROUTINE WrapperInitRoutine;
|
||||
KD_DISPATCH_TABLE WrapperTable;
|
||||
LIST_ENTRY KdProviders = {&KdProviders, &KdProviders};
|
||||
KD_DISPATCH_TABLE DispatchTable[KdMax];
|
||||
|
||||
PKDP_INIT_ROUTINE InitRoutines[KdMax] = {KdpScreenInit,
|
||||
KdpSerialInit,
|
||||
KdpDebugLogInit,
|
||||
KdpBochsInit,
|
||||
KdpKdbgInit};
|
||||
|
||||
extern ANSI_STRING KdpLogFileName;
|
||||
|
||||
/* PRIVATE FUNCTIONS *********************************************************/
|
||||
|
||||
/*
|
||||
* Get the total size of the memory before
|
||||
* Mm is initialized, by counting the number
|
||||
* of physical pages. Useful for debug logging.
|
||||
*
|
||||
* Strongly inspired by:
|
||||
* mm\ARM3\mminit.c : MiScanMemoryDescriptors(...)
|
||||
*
|
||||
* See also: kd\kdio.c
|
||||
*/
|
||||
static CODE_SEG("INIT")
|
||||
SIZE_T
|
||||
KdpGetMemorySizeInMBs(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
|
||||
{
|
||||
PLIST_ENTRY ListEntry;
|
||||
PMEMORY_ALLOCATION_DESCRIPTOR Descriptor;
|
||||
SIZE_T NumberOfPhysicalPages = 0;
|
||||
|
||||
/* Loop the memory descriptors */
|
||||
for (ListEntry = LoaderBlock->MemoryDescriptorListHead.Flink;
|
||||
ListEntry != &LoaderBlock->MemoryDescriptorListHead;
|
||||
ListEntry = ListEntry->Flink)
|
||||
{
|
||||
/* Get the descriptor */
|
||||
Descriptor = CONTAINING_RECORD(ListEntry,
|
||||
MEMORY_ALLOCATION_DESCRIPTOR,
|
||||
ListEntry);
|
||||
|
||||
/* Check if this is invisible memory */
|
||||
if ((Descriptor->MemoryType == LoaderFirmwarePermanent) ||
|
||||
(Descriptor->MemoryType == LoaderSpecialMemory) ||
|
||||
(Descriptor->MemoryType == LoaderHALCachedMemory) ||
|
||||
(Descriptor->MemoryType == LoaderBBTMemory))
|
||||
{
|
||||
/* Skip this descriptor */
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Check if this is bad memory */
|
||||
if (Descriptor->MemoryType != LoaderBad)
|
||||
{
|
||||
/* Count this in the total of pages */
|
||||
NumberOfPhysicalPages += Descriptor->PageCount;
|
||||
}
|
||||
}
|
||||
|
||||
/* Round size up. Assumed to better match actual physical RAM size */
|
||||
return ALIGN_UP_BY(NumberOfPhysicalPages * PAGE_SIZE, 1024 * 1024) / (1024 * 1024);
|
||||
}
|
||||
|
||||
/* See also: kd\kdio.c */
|
||||
static CODE_SEG("INIT")
|
||||
VOID
|
||||
KdpPrintBanner(IN SIZE_T MemSizeMBs)
|
||||
{
|
||||
DPRINT1("-----------------------------------------------------\n");
|
||||
DPRINT1("ReactOS " KERNEL_VERSION_STR " (Build " KERNEL_VERSION_BUILD_STR ") (Commit " KERNEL_VERSION_COMMIT_HASH ")\n");
|
||||
DPRINT1("%u System Processor [%u MB Memory]\n", KeNumberProcessors, MemSizeMBs);
|
||||
|
||||
if (KeLoaderBlock)
|
||||
{
|
||||
DPRINT1("Command Line: %s\n", KeLoaderBlock->LoadOptions);
|
||||
DPRINT1("ARC Paths: %s %s %s %s\n", KeLoaderBlock->ArcBootDeviceName, KeLoaderBlock->NtHalPathName, KeLoaderBlock->ArcHalDeviceName, KeLoaderBlock->NtBootPathName);
|
||||
}
|
||||
}
|
||||
BOOLEAN
|
||||
NTAPI
|
||||
KdRegisterDebuggerDataBlock(IN ULONG Tag,
|
||||
IN PDBGKD_DEBUG_DATA_HEADER64 DataHeader,
|
||||
IN ULONG Size);
|
||||
|
||||
BOOLEAN
|
||||
NTAPI
|
||||
KdInitSystem(IN ULONG BootPhase,
|
||||
IN PLOADER_PARAMETER_BLOCK LoaderBlock)
|
||||
{
|
||||
BOOLEAN EnableKd;
|
||||
LPSTR DebugLine;
|
||||
PLDR_DATA_TABLE_ENTRY LdrEntry;
|
||||
ULONG i;
|
||||
PCHAR CommandLine;
|
||||
SIZE_T MemSizeMBs;
|
||||
|
||||
/* Check if this is Phase 1 */
|
||||
if (BootPhase)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Check if we already initialized once */
|
||||
if (KdDebuggerEnabled) return TRUE;
|
||||
|
||||
/* Disable break after symbol load for now */
|
||||
KdBreakAfterSymbolLoad = FALSE;
|
||||
|
||||
/* Check if the Debugger Data Block was already initialized */
|
||||
if (!KdpDebuggerDataListHead.Flink)
|
||||
{
|
||||
/* It wasn't...Initialize the KD Data Listhead */
|
||||
InitializeListHead(&KdpDebuggerDataListHead);
|
||||
|
||||
/* Register the Debugger Data Block */
|
||||
KdRegisterDebuggerDataBlock(KDBG_TAG,
|
||||
&KdDebuggerDataBlock.Header,
|
||||
sizeof(KdDebuggerDataBlock));
|
||||
|
||||
/* Fill out the KD Version Block */
|
||||
KdVersionBlock.MajorVersion = (USHORT)((DBGKD_MAJOR_NT << 8) | (NtBuildNumber >> 28));
|
||||
KdVersionBlock.MinorVersion = (USHORT)(NtBuildNumber & 0xFFFF);
|
||||
|
||||
#ifdef CONFIG_SMP
|
||||
/* This is an MP Build */
|
||||
KdVersionBlock.Flags |= DBGKD_VERS_FLAG_MP;
|
||||
#endif
|
||||
|
||||
/* Save Pointers to Loaded Module List and Debugger Data */
|
||||
KdVersionBlock.PsLoadedModuleList = (ULONG64)(LONG_PTR)&PsLoadedModuleList;
|
||||
KdVersionBlock.DebuggerDataList = (ULONG64)(LONG_PTR)&KdpDebuggerDataListHead;
|
||||
|
||||
/* Set protocol limits */
|
||||
KdVersionBlock.MaxStateChange = DbgKdMaximumStateChange -
|
||||
DbgKdMinimumStateChange;
|
||||
KdVersionBlock.MaxManipulate = DbgKdMaximumManipulate -
|
||||
DbgKdMinimumManipulate;
|
||||
KdVersionBlock.Unused[0] = 0;
|
||||
|
||||
/* Link us in the KPCR */
|
||||
KeGetPcr()->KdVersionBlock = &KdVersionBlock;
|
||||
}
|
||||
|
||||
/* Check if we have a loader block */
|
||||
if (LoaderBlock)
|
||||
{
|
||||
/* Get the image entry */
|
||||
LdrEntry = CONTAINING_RECORD(LoaderBlock->LoadOrderListHead.Flink,
|
||||
LDR_DATA_TABLE_ENTRY,
|
||||
InLoadOrderLinks);
|
||||
|
||||
/* Save the Kernel Base */
|
||||
PsNtosImageBase = (ULONG_PTR)LdrEntry->DllBase;
|
||||
KdVersionBlock.KernBase = (ULONG64)(LONG_PTR)LdrEntry->DllBase;
|
||||
|
||||
/* Check if we have a command line */
|
||||
CommandLine = LoaderBlock->LoadOptions;
|
||||
if (CommandLine)
|
||||
{
|
||||
/* Upcase it */
|
||||
_strupr(CommandLine);
|
||||
|
||||
/* Assume we'll disable KD */
|
||||
EnableKd = FALSE;
|
||||
|
||||
/* Check for CRASHDEBUG, NODEBUG and just DEBUG */
|
||||
if (strstr(CommandLine, "CRASHDEBUG"))
|
||||
{
|
||||
/* Don't enable KD now, but allow it to be enabled later */
|
||||
KdPitchDebugger = FALSE;
|
||||
}
|
||||
else if (strstr(CommandLine, "NODEBUG"))
|
||||
{
|
||||
/* Don't enable KD and don't let it be enabled later */
|
||||
KdPitchDebugger = TRUE;
|
||||
}
|
||||
else if ((DebugLine = strstr(CommandLine, "DEBUG")) != NULL)
|
||||
{
|
||||
/* Enable KD */
|
||||
EnableKd = TRUE;
|
||||
KdDebuggerNotPresent = FALSE;
|
||||
#ifdef KDBG
|
||||
/* Get the KDBG Settings */
|
||||
KdbpGetCommandLineSettings(LoaderBlock->LoadOptions);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* No command line options? Disable debugger by default */
|
||||
KdPitchDebugger = TRUE;
|
||||
EnableKd = FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Called from a bugcheck or a re-enable. Save the Kernel Base. */
|
||||
KdVersionBlock.KernBase = (ULONG64)(LONG_PTR)PsNtosImageBase;
|
||||
|
||||
/* Unconditionally enable KD */
|
||||
EnableKd = TRUE;
|
||||
}
|
||||
|
||||
/* Set the Kernel Base in the Data Block */
|
||||
KdDebuggerDataBlock.KernBase = (ULONG_PTR)KdVersionBlock.KernBase;
|
||||
|
||||
/* Initialize the debugger if requested */
|
||||
if (EnableKd && (NT_SUCCESS(KdDebuggerInitialize0(LoaderBlock))))
|
||||
{
|
||||
/* Check if we've already initialized our structures */
|
||||
if (!KdpDebuggerStructuresInitialized)
|
||||
{
|
||||
/* Set the Debug Switch Routine and Retries */
|
||||
KdpContext.KdpDefaultRetries = 20;
|
||||
KiDebugSwitchRoutine = KdpSwitchProcessor;
|
||||
|
||||
/* Initialize breakpoints owed flag and table */
|
||||
KdpOweBreakpoint = FALSE;
|
||||
for (i = 0; i < KD_BREAKPOINT_MAX; i++)
|
||||
{
|
||||
KdpBreakpointTable[i].Flags = 0;
|
||||
KdpBreakpointTable[i].DirectoryTableBase = 0;
|
||||
KdpBreakpointTable[i].Address = NULL;
|
||||
}
|
||||
|
||||
/* Initialize the Time Slip DPC */
|
||||
KeInitializeDpc(&KdpTimeSlipDpc, KdpTimeSlipDpcRoutine, NULL);
|
||||
KeInitializeTimer(&KdpTimeSlipTimer);
|
||||
ExInitializeWorkItem(&KdpTimeSlipWorkItem, KdpTimeSlipWork, NULL);
|
||||
|
||||
/* First-time initialization done! */
|
||||
KdpDebuggerStructuresInitialized = TRUE;
|
||||
}
|
||||
|
||||
/* Initialize the timer */
|
||||
KdTimerStart.QuadPart = 0;
|
||||
|
||||
/* Officially enable KD */
|
||||
KdPitchDebugger = FALSE;
|
||||
KdDebuggerEnabled = TRUE;
|
||||
|
||||
/* Let user-mode know that it's enabled as well */
|
||||
SharedUserData->KdDebuggerEnabled = TRUE;
|
||||
|
||||
/* Display separator + ReactOS version at start of the debug log */
|
||||
MemSizeMBs = KdpGetMemorySizeInMBs(KeLoaderBlock);
|
||||
KdpPrintBanner(MemSizeMBs);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable debugger */
|
||||
KdDebuggerNotPresent = TRUE;
|
||||
}
|
||||
|
||||
/* Return initialized */
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* EOF */
|
|
@ -139,6 +139,29 @@ PCHAR KdPrintCircularBuffer = KdPrintDefaultCircularBuffer;
|
|||
ULONG KdPrintBufferSize = sizeof(KdPrintDefaultCircularBuffer);
|
||||
ULONG KdPrintBufferChanges = 0;
|
||||
|
||||
#ifndef _WINKD_
|
||||
/* Make bochs debug output in the very early boot phase available */
|
||||
//#define AUTO_ENABLE_BOCHS
|
||||
ULONG PortNumber = DEFAULT_DEBUG_PORT;
|
||||
CPPORT PortInfo = {0, DEFAULT_DEBUG_BAUD_RATE, 0};
|
||||
ULONG KdpPortIrq;
|
||||
#ifdef AUTO_ENABLE_BOCHS
|
||||
KDP_DEBUG_MODE KdpDebugMode = {{{.Bochs=TRUE}}};
|
||||
#else
|
||||
KDP_DEBUG_MODE KdpDebugMode;
|
||||
#endif
|
||||
PKDP_INIT_ROUTINE WrapperInitRoutine;
|
||||
KD_DISPATCH_TABLE WrapperTable;
|
||||
LIST_ENTRY KdProviders = {&KdProviders, &KdProviders};
|
||||
KD_DISPATCH_TABLE DispatchTable[KdMax];
|
||||
|
||||
PKDP_INIT_ROUTINE InitRoutines[KdMax] = {KdpScreenInit,
|
||||
KdpSerialInit,
|
||||
KdpDebugLogInit,
|
||||
KdpBochsInit,
|
||||
KdpKdbgInit};
|
||||
#endif
|
||||
|
||||
//
|
||||
// Debug Filter Masks
|
||||
//
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
/* UTILITY FUNCTIONS *********************************************************/
|
||||
|
||||
#ifdef _WINKD_
|
||||
/*
|
||||
* Get the total size of the memory before
|
||||
* Mm is initialized, by counting the number
|
||||
|
@ -85,6 +84,7 @@ KdpPrintBanner(IN SIZE_T MemSizeMBs)
|
|||
|
||||
/* FUNCTIONS *****************************************************************/
|
||||
|
||||
#ifdef _WINKD_
|
||||
VOID
|
||||
NTAPI
|
||||
KdUpdateDataBlock(VOID)
|
||||
|
@ -139,7 +139,6 @@ KdRegisterDebuggerDataBlock(IN ULONG Tag,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
#ifdef _WINKD_
|
||||
BOOLEAN
|
||||
NTAPI
|
||||
KdInitSystem(IN ULONG BootPhase,
|
||||
|
@ -172,8 +171,10 @@ KdInitSystem(IN ULONG BootPhase,
|
|||
/* Check if we already initialized once */
|
||||
if (KdDebuggerEnabled) return TRUE;
|
||||
|
||||
#ifdef _WINKD_
|
||||
/* Set the Debug Routine as the Stub for now */
|
||||
KiDebugRoutine = KdpStub;
|
||||
#endif
|
||||
|
||||
/* Disable break after symbol load for now */
|
||||
KdBreakAfterSymbolLoad = FALSE;
|
||||
|
@ -251,6 +252,7 @@ KdInitSystem(IN ULONG BootPhase,
|
|||
/* Enable KD */
|
||||
EnableKd = TRUE;
|
||||
|
||||
#ifdef _WINKD_
|
||||
/* Check if there are any options */
|
||||
if (DebugLine[5] == '=')
|
||||
{
|
||||
|
@ -332,6 +334,16 @@ KdInitSystem(IN ULONG BootPhase,
|
|||
DebugOptionStart = DebugOptionEnd;
|
||||
}
|
||||
}
|
||||
#else
|
||||
(VOID)DebugOptionStart;
|
||||
(VOID)DebugOptionEnd;
|
||||
(VOID)DebugOptionLength;
|
||||
KdDebuggerNotPresent = FALSE;
|
||||
#ifdef KDBG
|
||||
/* Get the KDBG Settings */
|
||||
KdbpGetCommandLineSettings(LoaderBlock->LoadOptions);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -356,8 +368,10 @@ KdInitSystem(IN ULONG BootPhase,
|
|||
/* Initialize the debugger if requested */
|
||||
if (EnableKd && (NT_SUCCESS(KdDebuggerInitialize0(LoaderBlock))))
|
||||
{
|
||||
#ifdef _WINKD_
|
||||
/* Now set our real KD routine */
|
||||
KiDebugRoutine = KdpTrap;
|
||||
#endif
|
||||
|
||||
/* Check if we've already initialized our structures */
|
||||
if (!KdpDebuggerStructuresInitialized)
|
||||
|
@ -440,9 +454,11 @@ KdInitSystem(IN ULONG BootPhase,
|
|||
|
||||
/* Load symbols for image */
|
||||
RtlInitString(&ImageName, NameBuffer);
|
||||
#ifdef _WINKD_
|
||||
DbgLoadImageSymbols(&ImageName,
|
||||
LdrEntry->DllBase,
|
||||
(ULONG_PTR)PsGetCurrentProcessId());
|
||||
#endif
|
||||
|
||||
/* Go to the next entry */
|
||||
NextEntry = NextEntry->Flink;
|
||||
|
@ -462,4 +478,3 @@ KdInitSystem(IN ULONG BootPhase,
|
|||
/* Return initialized */
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -396,7 +396,6 @@ if(NOT _WINKD_)
|
|||
list(APPEND SOURCE
|
||||
${REACTOS_SOURCE_DIR}/ntoskrnl/kd/wrappers/bochs.c
|
||||
${REACTOS_SOURCE_DIR}/ntoskrnl/kd/wrappers/kdbg.c
|
||||
${REACTOS_SOURCE_DIR}/ntoskrnl/kd/kdinit.c
|
||||
${REACTOS_SOURCE_DIR}/ntoskrnl/kd/kdio.c
|
||||
${REACTOS_SOURCE_DIR}/ntoskrnl/kd/kdmain.c
|
||||
${REACTOS_SOURCE_DIR}/ntoskrnl/kd64/kdapi.c
|
||||
|
|
Loading…
Reference in a new issue