[FREELDR]
[reactos.git] / reactos / boot / freeldr / freeldr / windows / winldr.c
index 84ccc6e..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 */
@@ -217,8 +226,8 @@ WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock,
     TRACE("WinLdrInitializePhase1() completed\n");
 }
 
-BOOLEAN
-WinLdrLoadDeviceDriver(PLOADER_PARAMETER_BLOCK LoaderBlock,
+static BOOLEAN
+WinLdrLoadDeviceDriver(PLIST_ENTRY LoadOrderListHead,
                        LPSTR BootPath,
                        PUNICODE_STRING FilePath,
                        ULONG Flags,
@@ -249,11 +258,11 @@ WinLdrLoadDeviceDriver(PLOADER_PARAMETER_BLOCK LoaderBlock,
                DriverPath[0] = 0;
        }
 
-       TRACE("DriverPath: %s, DllName: %s, LPB %p\n", DriverPath, DllName, LoaderBlock);
+       TRACE("DriverPath: %s, DllName: %s, LPB\n", DriverPath, DllName);
 
 
        // Check if driver is already loaded
-       Status = WinLdrCheckForLoadedDll(&LoaderBlock->LoadOrderListHead, DllName, DriverDTE);
+       Status = WinLdrCheckForLoadedDll(LoadOrderListHead, DllName, DriverDTE);
        if (Status)
        {
                // We've got the pointer to its DTE, just return success
@@ -267,7 +276,7 @@ WinLdrLoadDeviceDriver(PLOADER_PARAMETER_BLOCK LoaderBlock,
                return FALSE;
 
        // Allocate a DTE for it
-       Status = WinLdrAllocateDataTableEntry(&LoaderBlock->LoadOrderListHead, DllName, DllName, DriverBase, DriverDTE);
+       Status = WinLdrAllocateDataTableEntry(LoadOrderListHead, DllName, DllName, DriverBase, DriverDTE);
        if (!Status)
        {
                ERR("WinLdrAllocateDataTableEntry() failed\n");
@@ -279,7 +288,7 @@ WinLdrLoadDeviceDriver(PLOADER_PARAMETER_BLOCK LoaderBlock,
 
        // Look for any dependencies it may have, and load them too
        sprintf(FullPath,"%s%s", BootPath, DriverPath);
-       Status = WinLdrScanImportDescriptorTable(&LoaderBlock->LoadOrderListHead, FullPath, *DriverDTE);
+       Status = WinLdrScanImportDescriptorTable(LoadOrderListHead, FullPath, *DriverDTE);
        if (!Status)
        {
                ERR("WinLdrScanImportDescriptorTable() failed for %s\n", FullPath);
@@ -310,7 +319,7 @@ WinLdrLoadBootDrivers(PLOADER_PARAMETER_BLOCK LoaderBlock,
                // Paths are relative (FIXME: Are they always relative?)
 
                // Load it
-               Status = WinLdrLoadDeviceDriver(LoaderBlock, BootPath, &BootDriver->FilePath,
+               Status = WinLdrLoadDeviceDriver(&LoaderBlock->LoadOrderListHead, BootPath, &BootDriver->FilePath,
                        0, &BootDriver->LdrEntry);
 
                // If loading failed - cry loudly
@@ -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) {};