[winldr]
[reactos.git] / reactos / boot / freeldr / freeldr / windows / setupldr2.c
index 0853997..d449edd 100644 (file)
@@ -157,11 +157,9 @@ VOID LoadReactOSSetup2(VOID)
     CHAR  SystemPath[512], SearchPath[512];
     CHAR  FileName[512];
     CHAR  BootPath[512];
-    CHAR  LoadOptions[512];
-    LPCSTR BootOptions;
+    LPCSTR LoadOptions, DbgOptions, BootOptions;
     PVOID NtosBase = NULL, HalBase = NULL, KdComBase = NULL;
     BOOLEAN Status;
-    ULONG BootDevice;
     ULONG i, ErrorLine;
     HINF InfHandle;
     INFCONTEXT InfContext;
@@ -188,10 +186,8 @@ VOID LoadReactOSSetup2(VOID)
         NULL
     };
 
-    /* Get boot device number */
-    MachDiskGetBootDevice(&BootDevice);
-
     /* Open 'txtsetup.sif' from any of source paths */
+    MachDiskGetBootPath(SystemPath, sizeof(SystemPath));
     for (i = MachDiskBootingFromFloppy() ? 0 : 1; ; i++)
     {
         SourcePath = SourcePaths[i];
@@ -200,16 +196,15 @@ VOID LoadReactOSSetup2(VOID)
             printf("Failed to open 'txtsetup.sif'\n");
             return;
         }
-        sprintf(FileName,"%s\\txtsetup.sif", SourcePath);
+        sprintf(FileName, "%s\\txtsetup.sif", SourcePath);
         if (InfOpenFile (&InfHandle, FileName, &ErrorLine))
+        {
+            sprintf(BootPath, "%s%s\\", SystemPath, SourcePath);
             break;
+        }
     }
 
-    /* If we didn't find it anywhere, then just use root */
-    if (!*SourcePath)
-        SourcePath = "\\";
-
-    /* Load options */
+    /* Get Load options - debug and non-debug */
     if (!InfFindFirstLine(InfHandle,
                           "SetupData",
                           "OsLoadOptions",
@@ -219,14 +214,29 @@ VOID LoadReactOSSetup2(VOID)
         return;
     }
 
-    if (!InfGetDataField (&InfContext, 1, &BootOptions))
+    if (!InfGetDataField (&InfContext, 1, &LoadOptions))
     {
         printf("Failed to get load options\n");
         return;
     }
 
-    /* Save source path */
-    strcpy(BootPath, SourcePath);
+    BootOptions = LoadOptions;
+
+#if DBG
+    /* Get debug load options and use them */
+    if (InfFindFirstLine(InfHandle,
+                         "SetupData",
+                         "DbgOsLoadOptions",
+                         &InfContext))
+    {
+        if (!InfGetDataField(&InfContext, 1, &DbgOptions))
+            DbgOptions = "";
+        else
+            BootOptions = DbgOptions;
+    }
+#endif
+
+    DPRINTM(DPRINT_WINDOWS,"BootOptions: '%s'\n", BootOptions);
 
     SetupUiInitialize();
     UiDrawStatusText("");
@@ -235,20 +245,10 @@ VOID LoadReactOSSetup2(VOID)
     /* Let user know we started loading */
     UiDrawStatusText("Loading...");
 
-    /* Try to open system drive */
-    FsOpenBootVolume();
-
-    /* Append a backslash to the bootpath if needed */
-    if ((strlen(BootPath)==0) || BootPath[strlen(BootPath)] != '\\')
-    {
-        strcat(BootPath, "\\");
-    }
-
     /* Construct the system path */
-    MachDiskGetBootPath(SystemPath, sizeof(SystemPath));
-    strcat(SystemPath, SourcePath);
+    sprintf(SystemPath, "%s\\", SourcePath);
 
-    DPRINTM(DPRINT_WINDOWS,"SystemRoot: '%s', SystemPath: '%s'\n", BootPath, SystemPath);
+    DPRINTM(DPRINT_WINDOWS,"BootPath: '%s', SystemPath: '%s'\n", BootPath, SystemPath);
 
     /* Allocate and minimalistic-initialize LPB */
     AllocateAndInitLPB(&LoaderBlock);
@@ -312,8 +312,7 @@ VOID LoadReactOSSetup2(VOID)
     WinLdrSetupForNt(LoaderBlock, &GdtIdt, &PcrBasePage, &TssBasePage);
 
     /* Initialize Phase 1 - no drivers loading anymore */
-    LoadOptions[0] = 0;
-    WinLdrInitializePhase1(LoaderBlock, LoadOptions, SystemPath, BootPath, _WIN32_WINNT_WS03);
+    WinLdrInitializePhase1(LoaderBlock, (PCHAR)BootOptions, SystemPath, BootPath, _WIN32_WINNT_WS03);
 
     /* Save entry-point pointer and Loader block VAs */
     KiSystemStartup = (KERNEL_ENTRY_POINT)KernelDTE->EntryPoint;