[NTOS:MM] Fix ViewSize parameter passed to MiInsertVadEx() from MiCreatePebOrTeb()
[reactos.git] / ntoskrnl / kd64 / kdinit.c
index 89d57fb..64a7c7b 100644 (file)
 /* INCLUDES ******************************************************************/
 
 #include <ntoskrnl.h>
+#include <reactos/buildno.h>
 #define NDEBUG
 #include <debug.h>
 
+/* UTILITY 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 SIZE_T
+INIT_FUNCTION
+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;
+        }
+    }
+
+    return NumberOfPhysicalPages * PAGE_SIZE / 1024 / 1024;
+}
+
+/* See also: kd\kdio.c */
+static VOID
+INIT_FUNCTION
+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);
+    }
+}
+
 /* FUNCTIONS *****************************************************************/
 
 VOID
@@ -80,6 +148,7 @@ KdInitSystem(IN ULONG BootPhase,
     PLIST_ENTRY NextEntry;
     ULONG i, j, Length;
     SIZE_T DebugOptionLength;
+    SIZE_T MemSizeMBs;
     CHAR NameBuffer[256];
     PWCHAR Name;
 
@@ -281,7 +350,7 @@ KdInitSystem(IN ULONG BootPhase,
     KdDebuggerDataBlock.KernBase = (ULONG_PTR)KdVersionBlock.KernBase;
 
     /* Initialize the debugger if requested */
-    if ((EnableKd) && (NT_SUCCESS(KdDebuggerInitialize0(LoaderBlock))))
+    if (EnableKd && (NT_SUCCESS(KdDebuggerInitialize0(LoaderBlock))))
     {
         /* Now set our real KD routine */
         KiDebugRoutine = KdpTrap;
@@ -289,10 +358,19 @@ KdInitSystem(IN ULONG BootPhase,
         /* Check if we've already initialized our structures */
         if (!KdpDebuggerStructuresInitialized)
         {
-            /* Set the Debug Switch Routine and Retries*/
+            /* 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);
@@ -310,9 +388,11 @@ KdInitSystem(IN ULONG BootPhase,
         KdDebuggerEnabled = TRUE;
 
         /* Let user-mode know that it's enabled as well */
-#undef KdDebuggerEnabled
         SharedUserData->KdDebuggerEnabled = TRUE;
-#define KdDebuggerEnabled _KdDebuggerEnabled
+
+        /* Display separator + ReactOS version at start of the debug log */
+        MemSizeMBs = KdpGetMemorySizeInMBs(KeLoaderBlock);
+        KdpPrintBanner(MemSizeMBs);
 
         /* Check if the debugger should be disabled initially */
         if (DisableKdAfterInit)
@@ -358,7 +438,7 @@ KdInitSystem(IN ULONG BootPhase,
                 RtlInitString(&ImageName, NameBuffer);
                 DbgLoadImageSymbols(&ImageName,
                                     LdrEntry->DllBase,
-                                    (ULONG_PTR)ZwCurrentProcess());
+                                    (ULONG_PTR)PsGetCurrentProcessId());
 
                 /* Go to the next entry */
                 NextEntry = NextEntry->Flink;