[FREELDR]
[reactos.git] / reactos / boot / freeldr / freeldr / windows / winldr.c
index 3218e1b..3da7eb0 100644 (file)
@@ -48,12 +48,9 @@ VOID
 AllocateAndInitLPB(PLOADER_PARAMETER_BLOCK *OutLoaderBlock)
 {
        PLOADER_PARAMETER_BLOCK LoaderBlock;
-       ULONG SystemBlockSize;
 
        /* Allocate and zero-init the LPB */
-       SystemBlockSize = sizeof(LOADER_SYSTEM_BLOCK) +
-                         reactos_disk_count * sizeof(ARC_DISK_SIGNATURE_EX);
-       WinLdrSystemBlock = MmAllocateMemoryWithType(SystemBlockSize,
+       WinLdrSystemBlock = MmAllocateMemoryWithType(sizeof(LOADER_SYSTEM_BLOCK),
                                                  LoaderSystemBlock);
        if (WinLdrSystemBlock == NULL)
        {
@@ -88,10 +85,12 @@ WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock,
        //CHAR  SystemRoot[] = "\\WINNT\\";
        //CHAR  ArcBoot[] = "multi(0)disk(0)rdisk(0)partition(1)";
 
-       CHAR    HalPath[] = "\\";
-       CHAR    ArcBoot[256];
-       CHAR    MiscFiles[256];
-       ULONG i, PathSeparator;
+       LPSTR LoadOptions, NewLoadOptions;
+       CHAR  HalPath[] = "\\";
+       CHAR  ArcBoot[256];
+       CHAR  MiscFiles[256];
+       ULONG i;
+       ULONG_PTR PathSeparator;
        PLOADER_PARAMETER_EXTENSION Extension;
 
        /* Construct SystemRoot and ArcBoot from SystemPath */
@@ -122,9 +121,18 @@ WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock,
        strncpy(LoaderBlock->NtHalPathName, HalPath, MAX_PATH);
        LoaderBlock->NtHalPathName = PaToVa(LoaderBlock->NtHalPathName);
 
-       /* Fill load options */
-       LoaderBlock->LoadOptions = WinLdrSystemBlock->LoadOptions;
+       /* Fill LoadOptions and strip the '/' commutator symbol in front of each option */
+       NewLoadOptions = LoadOptions = LoaderBlock->LoadOptions = WinLdrSystemBlock->LoadOptions;
        strncpy(LoaderBlock->LoadOptions, Options, MAX_OPTIONS_LENGTH);
+
+       do
+       {
+               while (*LoadOptions == '/')
+                       ++LoadOptions;
+
+               *NewLoadOptions++ = *LoadOptions;
+       } while (*LoadOptions++);
+
        LoaderBlock->LoadOptions = PaToVa(LoaderBlock->LoadOptions);
 
        /* Arc devices */
@@ -134,26 +142,27 @@ WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock,
        /* Convert ARC disk information from freeldr to a correct format */
        for (i = 0; i < reactos_disk_count; i++)
        {
-               PARC_DISK_SIGNATURE ArcDiskSig;
+               PARC_DISK_SIGNATURE_EX ArcDiskSig;
 
-               /* Get the ARC structure */
-               ArcDiskSig = &WinLdrSystemBlock->ArcDiskSignature[i].DiskSignature;
+               /* Allocate the ARC structure */
+               ArcDiskSig = HeapAllocate(FrLdrDefaultHeap,
+                                         sizeof(ARC_DISK_SIGNATURE_EX),
+                                         'giSD');
 
                /* Copy the data over */
-               ArcDiskSig->Signature = reactos_arc_disk_info[i].Signature;
-               ArcDiskSig->CheckSum = reactos_arc_disk_info[i].CheckSum;
+               ArcDiskSig->DiskSignature.Signature = reactos_arc_disk_info[i].Signature;
+               ArcDiskSig->DiskSignature.CheckSum = reactos_arc_disk_info[i].CheckSum;
 
                /* Copy the ARC Name */
-               ArcDiskSig->ArcName = WinLdrSystemBlock->ArcDiskSignature[i].ArcName;
                strncpy(ArcDiskSig->ArcName, reactos_arc_disk_info[i].ArcName, MAX_PATH);
-               ArcDiskSig->ArcName = PaToVa(ArcDiskSig->ArcName);
+               ArcDiskSig->DiskSignature.ArcName = PaToVa(ArcDiskSig->ArcName);
 
                /* Mark partition table as valid */
-               ArcDiskSig->ValidPartitionTable = TRUE;
+               ArcDiskSig->DiskSignature.ValidPartitionTable = TRUE;
 
                /* Insert into the list */
                InsertTailList(&LoaderBlock->ArcDiskInformation->DiskSignatureListHead,
-                       &ArcDiskSig->ListEntry);
+                              &ArcDiskSig->DiskSignature.ListEntry);
        }
 
        /* Convert all list's to Virtual address */
@@ -447,22 +456,28 @@ LoadModule(
 }
 
 VOID
-LoadAndBootWindows(PCSTR OperatingSystemName,
-                   PSTR SettingsValue,
-                   USHORT OperatingSystemVersion)
+LoadAndBootWindows(IN OperatingSystemItem* OperatingSystem,
+                   IN USHORT OperatingSystemVersion)
 {
+       ULONG_PTR SectionId;
+       PCSTR SectionName = OperatingSystem->SystemPartition;
+       CHAR  SettingsValue[80];
        BOOLEAN HasSection;
-       char  BootPath[MAX_PATH];
+       CHAR  BootPath[MAX_PATH];
        CHAR  FileName[MAX_PATH];
        CHAR  BootOptions[256];
        PCHAR File;
        BOOLEAN Status;
-       ULONG_PTR SectionId;
        PLOADER_PARAMETER_BLOCK LoaderBlock;
 
+       // Get OS setting value
+       SettingsValue[0] = ANSI_NULL;
+       IniOpenSection("Operating Systems", &SectionId);
+       IniReadSettingByName(SectionId, SectionName, SettingsValue, sizeof(SettingsValue));
+
        // Open the operating system section
        // specified in the .ini file
-       HasSection = IniOpenSection(OperatingSystemName, &SectionId);
+       HasSection = IniOpenSection(SectionName, &SectionId);
 
        UiDrawBackdrop();
        UiDrawProgressBarCenter(1, 100, "Loading NT...");
@@ -471,7 +486,7 @@ LoadAndBootWindows(PCSTR OperatingSystemName,
        if (!HasSection ||
            !IniReadSettingByName(SectionId, "SystemPath", BootPath, sizeof(BootPath)))
        {
-               strcpy(BootPath, OperatingSystemName);
+               strcpy(BootPath, SectionName);
        }
 
        /* Special case for LiveCD */
@@ -490,7 +505,7 @@ LoadAndBootWindows(PCSTR OperatingSystemName,
        if (!HasSection || !IniReadSettingByName(SectionId, "Options", BootOptions, sizeof(BootOptions)))
        {
                /* Get options after the title */
-               const CHAR*p = SettingsValue;
+               PCSTR p = SettingsValue;
                while (*p == ' ' || *p == '"')
                        p++;
                while (*p != '\0' && *p != '"')
@@ -525,7 +540,7 @@ LoadAndBootWindows(PCSTR OperatingSystemName,
        AllocateAndInitLPB(&LoaderBlock);
 
 #ifdef _M_IX86
-       /* Setup redirection support */
+       /* Setup redirection support */
        WinLdrSetupEms(BootOptions);
 #endif
 
@@ -638,7 +653,9 @@ LoadAndBootWindowsCommon(
 
        WinLdrpDumpMemoryDescriptors(LoaderBlockVA);
        WinLdrpDumpBootDriver(LoaderBlockVA);
+#ifndef _M_AMD64
        WinLdrpDumpArcDisks(LoaderBlockVA);
+#endif
 
        //FIXME: If I substitute this debugging checkpoint, GCC will "optimize away" the code below
        //while (1) {};