Detect hardware before ntoskrnl.exe will be loaded.
[reactos.git] / freeldr / freeldr / reactos / reactos.c
index 25d8b7c..498a79e 100644 (file)
@@ -31,7 +31,6 @@
 #include <inifile.h>
 
 #include "registry.h"
-#include "hwdetect.h"
 
 
 #define NDEBUG
@@ -452,6 +451,7 @@ LoadAndBootReactOS(PUCHAR OperatingSystemName)
 
         PARTITION_TABLE_ENTRY PartitionTableEntry;
         U32 rosPartition;
+       BOOL TextHive = FALSE;
 
        //
        // Open the operating system section
@@ -493,6 +493,11 @@ LoadAndBootReactOS(PUCHAR OperatingSystemName)
        DbgPrint((DPRINT_REACTOS, "low_mem = %d\n", mb_info.mem_lower));
        DbgPrint((DPRINT_REACTOS, "high_mem = %d\n", mb_info.mem_upper));
 
+       /*
+        * Initialize the registry
+        */
+       RegInitializeRegistry();
+
        /*
         * Make sure the system path is set in the .ini file
         */
@@ -516,17 +521,17 @@ LoadAndBootReactOS(PUCHAR OperatingSystemName)
        ((char *)(&mb_info.boot_device))[0] = (char)BootDrive;
        ((char *)(&mb_info.boot_device))[1] = (char)BootPartition;
 
-        /* recalculate the boot partition for freeldr */
+       /* recalculate the boot partition for freeldr */
        i = 0;
-        rosPartition = 0;
-        while (1)
+       rosPartition = 0;
+       while (1)
        {
-           if (!DiskGetPartitionEntry(BootDrive, ++i, &PartitionTableEntry))
+          if (!DiskGetPartitionEntry(BootDrive, ++i, &PartitionTableEntry))
           {
              BootPartition = 0;
              break;
           }
-           if (IsRecognizedPartition(PartitionTableEntry.SystemIndicator))
+          if (IsRecognizedPartition(PartitionTableEntry.SystemIndicator))
           {
              if (++rosPartition == BootPartition)
              {
@@ -541,7 +546,7 @@ LoadAndBootReactOS(PUCHAR OperatingSystemName)
                UiMessageBox(MsgBuffer);
                return;
        }
-          
+
        /* copy ARC path into kernel command line */
        strcpy(multiboot_kernel_cmdline, value);
 
@@ -561,7 +566,16 @@ LoadAndBootReactOS(PUCHAR OperatingSystemName)
 
        DbgPrint((DPRINT_REACTOS,"SystemRoot: '%s'\n", szBootPath));
 
+
        UiDrawBackdrop();
+       UiDrawStatusText("Detecting Hardware...");
+
+       /*
+        * Detect hardware
+        */
+       DetectHardware();
+
+
        UiDrawStatusText("Loading...");
        UiDrawProgressBarCenter(0, 100, "Loading ReactOS...");
 
@@ -637,41 +651,31 @@ LoadAndBootReactOS(PUCHAR OperatingSystemName)
                return;
 
        /*
-        * Find the System hive image name
-        * and try to load it off the disk
+        * Load the System hive from disk
         */
-       if(IniReadSettingByName(SectionId, "SystemHive", value, 1024))
-       {
-               /*
-                * Set the name and
-                */
-               if (value[0] == '\\')
-               {
-                       strcpy(szFileName, value);
-               }
-               else
-               {
-                       strcpy(szFileName, szBootPath);
-                       strcat(szFileName, "SYSTEM32\\CONFIG\\");
-                       strcat(szFileName, value);
-               }
-       }
-       else
-       {
-               strcpy(value, "SYSTEM.HIV");
-               strcpy(szFileName, szBootPath);
-               strcat(szFileName, "SYSTEM32\\CONFIG\\");
-               strcat(szFileName, value);
-       }
+       strcpy(szFileName, szBootPath);
+       strcat(szFileName, "SYSTEM32\\CONFIG\\SYSTEM");
 
        DbgPrint((DPRINT_REACTOS, "SystemHive: '%s'", szFileName));
 
        FilePointer = FsOpenFile(szFileName);
        if (FilePointer == NULL)
        {
-               strcat(value, " not found.");
-               UiMessageBox(value);
-               return;
+               strcpy(szFileName, szBootPath);
+               strcat(szFileName, "SYSTEM32\\CONFIG\\SYSTEM.HIV");
+
+               DbgPrint((DPRINT_REACTOS, "SystemHive: '%s'", szFileName));
+
+               FilePointer = FsOpenFile(szFileName);
+               if (FilePointer == NULL)
+               {
+                       UiMessageBox("Could not find the System hive!");
+                       return;
+               }
+               else
+               {
+                       TextHive = TRUE;
+               }
        }
 
        /*
@@ -684,44 +688,57 @@ LoadAndBootReactOS(PUCHAR OperatingSystemName)
        UiDrawStatusText(name);
 
        /*
-        * Load the system hive
+        * Load the System hive
         */
        Base = MultiBootLoadModule(FilePointer, szFileName, &Size);
-       RegInitializeRegistry();
-       RegImportHive(Base, Size);
-
-       UiDrawProgressBarCenter(15, 100, "Loading ReactOS...");
+       if (Base == NULL || Size == 0)
+       {
+               UiMessageBox("Could not load the System hive!\n");
+               return;
+       }
        DbgPrint((DPRINT_REACTOS, "SystemHive loaded at 0x%x size %u", (unsigned)Base, (unsigned)Size));
 
        /*
-        * Retrieve hardware information and create the hardware hive
+        * Import the loaded system hive
         */
-       DetectHardware();
-#if 0
-       Base = MultiBootCreateModule(HARDWARE.HIV);
-       RegExportHive("\\Registry\\Machine\\HARDWARE", Base, &Size);
-       MultiBootCloseModule(Base, Size);
-#endif
-       UiDrawProgressBarCenter(20, 100, "Loading ReactOS...");
+       if (TextHive)
+       {
+               RegImportTextHive(Base, Size);
+       }
+       else
+       {
+               RegImportBinaryHive(Base, Size);
+       }
 
        /*
-        * Initialize the 'currentControlSet' link
+        * Initialize the 'CurrentControlSet' link
         */
        RegInitCurrentControlSet(FALSE);
 
+       UiDrawProgressBarCenter(15, 100, "Loading ReactOS...");
+
+       /*
+        * Export the hardware hive
+        */
+       Base = MultiBootCreateModule ("HARDWARE");
+       RegExportBinaryHive ("\\Registry\\Machine\\HARDWARE", Base, &Size);
+       MultiBootCloseModule (Base, Size);
+
+       UiDrawProgressBarCenter(20, 100, "Loading ReactOS...");
+
        /*
         * Load NLS files
         */
 #if 0
        if (!LoadNlsFiles(szBootPath))
        {
-               MessageBox("Failed to load NLS files\n");
+               UiMessageBox("Failed to load NLS files\n");
                return;
        }
 #endif
 
-  LoadSymbolFile(szBootPath, szKernelName, 25);
-  LoadSymbolFile(szBootPath, szHalName, 25);
+       LoadSymbolFile(szBootPath, szKernelName, 25);
+       LoadSymbolFile(szBootPath, szHalName, 25);
 
        UiDrawProgressBarCenter(25, 100, "Loading ReactOS...");
 
@@ -737,14 +754,15 @@ LoadAndBootReactOS(PUCHAR OperatingSystemName)
        UiDrawBackdrop();
        UiDrawStatusText("Press any key to boot");
 
+#if 0
        /*
         * Wait for user
         */
        strcpy(name, "Kernel and Drivers loaded.\nPress any key to boot ");
        strcat(name, OperatingSystemName);
        strcat(name, ".");
-       //MessageBox(name);
-
+       MessageBox(name);
+#endif
 
        UiUnInitialize("Booting ReactOS...");