[freeldr] Rework the ramdisk driver to let it be a full device, instead of a deprecat...
[reactos.git] / reactos / boot / freeldr / freeldr / reactos / reactos.c
index 432b7cd..7db4d0e 100644 (file)
  */
 
 #include <freeldr.h>
  */
 
 #include <freeldr.h>
-
-#define NDEBUG
 #include <debug.h>
 
 #include <debug.h>
 
+extern ULONG PageDirectoryStart;
+extern ULONG PageDirectoryEnd;
+
 ROS_LOADER_PARAMETER_BLOCK LoaderBlock;
 char                                   reactos_kernel_cmdline[255];    // Command line passed to kernel
 LOADER_MODULE                  reactos_modules[64];            // Array to hold boot module info loaded for the kernel
 char                                   reactos_module_strings[64][256];        // Array to hold module names
 ROS_LOADER_PARAMETER_BLOCK LoaderBlock;
 char                                   reactos_kernel_cmdline[255];    // Command line passed to kernel
 LOADER_MODULE                  reactos_modules[64];            // Array to hold boot module info loaded for the kernel
 char                                   reactos_module_strings[64][256];        // Array to hold module names
-unsigned long                  reactos_memory_map_descriptor_size;
-memory_map_t                   reactos_memory_map[32];         // Memory map
+// Make this a single struct to guarantee that these elements are nearby in
+// memory.  
+reactos_mem_data_t reactos_mem_data;
 ARC_DISK_SIGNATURE      reactos_arc_disk_info[32]; // ARC Disk Information
 char                    reactos_arc_strings[32][256];
 unsigned long           reactos_disk_count = 0;
 ARC_DISK_SIGNATURE      reactos_arc_disk_info[32]; // ARC Disk Information
 char                    reactos_arc_strings[32][256];
 unsigned long           reactos_disk_count = 0;
+char reactos_arc_hardware_data[HW_MAX_ARC_HEAP_SIZE] = {0};
+
 CHAR szHalName[255];
 CHAR szBootPath[255];
 CHAR szHalName[255];
 CHAR szBootPath[255];
-static CHAR szLoadingMsg[] = "Loading ReactOS...";
+CHAR SystemRoot[255];
+static CHAR szLoadingMsg[] = "ReactOS is loading files...";
 BOOLEAN FrLdrBootType;
 BOOLEAN FrLdrBootType;
-extern ULONG_PTR KernelBase, KernelEntry;
+ULONG_PTR KernelBase;
+ROS_KERNEL_ENTRY_POINT KernelEntryPoint;
+
+BOOLEAN
+FrLdrLoadDriver(PCHAR szFileName,
+                INT nPos)
+{
+    PFILE FilePointer;
+    CHAR value[256], *FinalSlash;
+    LPSTR p;
+
+    if (!_stricmp(szFileName, "hal.dll"))
+    {
+        /* Use the boot.ini name instead */
+        szFileName = szHalName;
+    }
+
+    FinalSlash = strrchr(szFileName, '\\');
+    if(FinalSlash)
+    szFileName = FinalSlash + 1;
+
+    /* Open the Driver */
+    FilePointer = FsOpenFile(szFileName);
+
+    /* Try under the system root in the main dir and drivers */
+    if (!FilePointer)
+    {
+    strcpy(value, SystemRoot);
+    if(value[strlen(value)-1] != '\\')
+        strcat(value, "\\");
+    strcat(value, szFileName);
+    FilePointer = FsOpenFile(value);
+    }
+
+    if (!FilePointer)
+    {
+    strcpy(value, SystemRoot);
+    if(value[strlen(value)-1] != '\\')
+        strcat(value, "\\");
+    strcat(value, "SYSTEM32\\");
+    strcat(value, szFileName);
+    FilePointer = FsOpenFile(value);
+    }
+
+    if (!FilePointer)
+    {
+    strcpy(value, SystemRoot);
+    if(value[strlen(value)-1] != '\\')
+        strcat(value, "\\");
+    strcat(value, "SYSTEM32\\DRIVERS\\");
+    strcat(value, szFileName);
+    FilePointer = FsOpenFile(value);
+    }
+
+    /* Make sure we did */
+    if (!FilePointer) {
+
+        /* Fail if file wasn't opened */
+        strcpy(value, szFileName);
+        strcat(value, " not found.");
+        return(FALSE);
+    }
+
+    /* Update the status bar with the current file */
+    strcpy(value, "Reading ");
+    p = strrchr(szFileName, '\\');
+    if (p == NULL) {
+
+        strcat(value, szFileName);
+
+    } else {
+
+        strcat(value, p + 1);
+
+    }
+    UiDrawStatusText(value);
+
+    /* Load the driver */
+    FrLdrReadAndMapImage(FilePointer, szFileName, 0);
+
+    /* Update status and return */
+    UiDrawProgressBarCenter(nPos, 100, szLoadingMsg);
+    return(TRUE);
+}
 
 PVOID
 NTAPI
 
 PVOID
 NTAPI
@@ -50,13 +138,6 @@ FrLdrLoadImage(IN PCHAR szFileName,
     CHAR szBuffer[256], szFullPath[256];
     PVOID LoadBase;
 
     CHAR szBuffer[256], szFullPath[256];
     PVOID LoadBase;
 
-    /* Check if this the HAL being loaded */
-    if (!_stricmp(szFileName, "hal.dll"))
-    {
-        /* Use the boot.ini name instead */
-        szFileName = szHalName;
-    }
-
     /* Extract filename without path */
     szShortName = strrchr(szFileName, '\\');
     if (!szShortName)
     /* Extract filename without path */
     szShortName = strrchr(szFileName, '\\');
     if (!szShortName)
@@ -101,14 +182,14 @@ FrLdrLoadImage(IN PCHAR szFileName,
     UiDrawStatusText(szBuffer);
 
     /* Do the actual loading */
     UiDrawStatusText(szBuffer);
 
     /* Do the actual loading */
-    LoadBase = FrLdrMapImage(FilePointer, szShortName, ImageType);
+    LoadBase = FrLdrReadAndMapImage(FilePointer, szShortName, ImageType);
 
     /* Update Processbar and return success */
     if (!FrLdrBootType) UiDrawProgressBarCenter(nPos, 100, szLoadingMsg);
     return LoadBase;
 }
 
 
     /* Update Processbar and return success */
     if (!FrLdrBootType) UiDrawProgressBarCenter(nPos, 100, szLoadingMsg);
     return LoadBase;
 }
 
-static BOOLEAN
+BOOLEAN
 FrLdrLoadNlsFile(PCSTR szFileName,
                  PCSTR szModuleName)
 {
 FrLdrLoadNlsFile(PCSTR szFileName,
                  PCSTR szModuleName)
 {
@@ -120,7 +201,7 @@ FrLdrLoadNlsFile(PCSTR szFileName,
     FilePointer = FsOpenFile(szFileName);
 
     /* Make sure we did */
     FilePointer = FsOpenFile(szFileName);
 
     /* Make sure we did */
-    if (FilePointer == NULL) {
+    if (!FilePointer) {
 
         /* Fail if file wasn't opened */
         strcpy(value, szFileName);
 
         /* Fail if file wasn't opened */
         strcpy(value, szFileName);
@@ -181,13 +262,16 @@ FrLdrLoadNlsFiles(PCHAR szSystemRoot,
     rc = RegQueryValue(hKey, szIdBuffer, NULL, (PUCHAR)szNameBuffer, &BufferSize);
     if (rc != ERROR_SUCCESS) {
 
     rc = RegQueryValue(hKey, szIdBuffer, NULL, (PUCHAR)szNameBuffer, &BufferSize);
     if (rc != ERROR_SUCCESS) {
 
-        strcpy(szErrorOut, "ACP NLS Setting exists, but isn't readable");
-        return(FALSE);
+        //strcpy(szErrorOut, "ACP NLS Setting exists, but isn't readable");
+        //return(FALSE);
+
+        /* HACK */
+        wcscpy(szNameBuffer, L"c_1252.nls");
     }
 
     /* load ANSI codepage table */
     sprintf(szFileName,"%ssystem32\\%S", szSystemRoot, szNameBuffer);
     }
 
     /* load ANSI codepage table */
     sprintf(szFileName,"%ssystem32\\%S", szSystemRoot, szNameBuffer);
-    DbgPrint((DPRINT_REACTOS, "ANSI file: %s\n", szFileName));
+    DPRINTM(DPRINT_REACTOS, "ANSI file: %s\n", szFileName);
     if (!FrLdrLoadNlsFile(szFileName, "ansi.nls")) {
 
         strcpy(szErrorOut, "Couldn't load ansi.nls");
     if (!FrLdrLoadNlsFile(szFileName, "ansi.nls")) {
 
         strcpy(szErrorOut, "Couldn't load ansi.nls");
@@ -207,13 +291,16 @@ FrLdrLoadNlsFiles(PCHAR szSystemRoot,
     rc = RegQueryValue(hKey, szIdBuffer, NULL, (PUCHAR)szNameBuffer, &BufferSize);
     if (rc != ERROR_SUCCESS) {
 
     rc = RegQueryValue(hKey, szIdBuffer, NULL, (PUCHAR)szNameBuffer, &BufferSize);
     if (rc != ERROR_SUCCESS) {
 
-        strcpy(szErrorOut, "OEMCP NLS setting exists, but isn't readable");
-        return(FALSE);
+        //strcpy(szErrorOut, "OEMCP NLS setting exists, but isn't readable");
+        //return(FALSE);
+
+        /* HACK */
+        wcscpy(szNameBuffer, L"c_437.nls");
     }
 
     /* load OEM codepage table */
     sprintf(szFileName, "%ssystem32\\%S", szSystemRoot, szNameBuffer);
     }
 
     /* load OEM codepage table */
     sprintf(szFileName, "%ssystem32\\%S", szSystemRoot, szNameBuffer);
-    DbgPrint((DPRINT_REACTOS, "Oem file: %s\n", szFileName));
+    DPRINTM(DPRINT_REACTOS, "Oem file: %s\n", szFileName);
     if (!FrLdrLoadNlsFile(szFileName, "oem.nls")) {
 
         strcpy(szErrorOut, "Couldn't load oem.nls");
     if (!FrLdrLoadNlsFile(szFileName, "oem.nls")) {
 
         strcpy(szErrorOut, "Couldn't load oem.nls");
@@ -243,13 +330,13 @@ FrLdrLoadNlsFiles(PCHAR szSystemRoot,
     rc = RegQueryValue(hKey, szIdBuffer, NULL, (PUCHAR)szNameBuffer, &BufferSize);
     if (rc != ERROR_SUCCESS) {
 
     rc = RegQueryValue(hKey, szIdBuffer, NULL, (PUCHAR)szNameBuffer, &BufferSize);
     if (rc != ERROR_SUCCESS) {
 
-        strcpy(szErrorOut, "Language Default setting exists, but isn't readable");
+        sprintf(szErrorOut, "Language Default setting exists, but isn't readable (%S)", szIdBuffer);
         return(FALSE);
     }
 
     /* load Unicode case table */
     sprintf(szFileName, "%ssystem32\\%S", szSystemRoot, szNameBuffer);
         return(FALSE);
     }
 
     /* load Unicode case table */
     sprintf(szFileName, "%ssystem32\\%S", szSystemRoot, szNameBuffer);
-    DbgPrint((DPRINT_REACTOS, "Casemap file: %s\n", szFileName));
+    DPRINTM(DPRINT_REACTOS, "Casemap file: %s\n", szFileName);
     if (!FrLdrLoadNlsFile(szFileName, "casemap.nls")) {
 
         strcpy(szErrorOut, "casemap.nls");
     if (!FrLdrLoadNlsFile(szFileName, "casemap.nls")) {
 
         strcpy(szErrorOut, "casemap.nls");
@@ -289,7 +376,7 @@ FrLdrLoadBootDrivers(PCHAR szSystemRoot,
                     &hGroupKey);
     if (rc != ERROR_SUCCESS) {
 
                     &hGroupKey);
     if (rc != ERROR_SUCCESS) {
 
-        DbgPrint((DPRINT_REACTOS, "Failed to open the 'ServiceGroupOrder' key (rc %d)\n", (int)rc));
+        DPRINTM(DPRINT_REACTOS, "Failed to open the 'ServiceGroupOrder' key (rc %d)\n", (int)rc);
         return;
     }
 
         return;
     }
 
@@ -299,7 +386,7 @@ FrLdrLoadBootDrivers(PCHAR szSystemRoot,
                     &hOrderKey);
     if (rc != ERROR_SUCCESS) {
 
                     &hOrderKey);
     if (rc != ERROR_SUCCESS) {
 
-        DbgPrint((DPRINT_REACTOS, "Failed to open the 'GroupOrderList' key (rc %d)\n", (int)rc));
+        DPRINTM(DPRINT_REACTOS, "Failed to open the 'GroupOrderList' key (rc %d)\n", (int)rc);
         return;
     }
 
         return;
     }
 
@@ -309,22 +396,22 @@ FrLdrLoadBootDrivers(PCHAR szSystemRoot,
                     &hServiceKey);
     if (rc != ERROR_SUCCESS)  {
 
                     &hServiceKey);
     if (rc != ERROR_SUCCESS)  {
 
-        DbgPrint((DPRINT_REACTOS, "Failed to open the 'Services' key (rc %d)\n", (int)rc));
+        DPRINTM(DPRINT_REACTOS, "Failed to open the 'Services' key (rc %d)\n", (int)rc);
         return;
     }
 
     /* Get the Name Group */
     BufferSize = sizeof(GroupNameBuffer);
     rc = RegQueryValue(hGroupKey, L"List", NULL, (PUCHAR)GroupNameBuffer, &BufferSize);
         return;
     }
 
     /* Get the Name Group */
     BufferSize = sizeof(GroupNameBuffer);
     rc = RegQueryValue(hGroupKey, L"List", NULL, (PUCHAR)GroupNameBuffer, &BufferSize);
-    DbgPrint((DPRINT_REACTOS, "RegQueryValue(): rc %d\n", (int)rc));
+    DPRINTM(DPRINT_REACTOS, "RegQueryValue(): rc %d\n", (int)rc);
     if (rc != ERROR_SUCCESS) return;
     if (rc != ERROR_SUCCESS) return;
-    DbgPrint((DPRINT_REACTOS, "BufferSize: %d \n", (int)BufferSize));
-    DbgPrint((DPRINT_REACTOS, "GroupNameBuffer: '%S' \n", GroupNameBuffer));
+    DPRINTM(DPRINT_REACTOS, "BufferSize: %d \n", (int)BufferSize);
+    DPRINTM(DPRINT_REACTOS, "GroupNameBuffer: '%S' \n", GroupNameBuffer);
 
     /* Loop through each group */
     GroupName = GroupNameBuffer;
     while (*GroupName) {
 
     /* Loop through each group */
     GroupName = GroupNameBuffer;
     while (*GroupName) {
-        DbgPrint((DPRINT_REACTOS, "Driver group: '%S'\n", GroupName));
+        DPRINTM(DPRINT_REACTOS, "Driver group: '%S'\n", GroupName);
 
         /* Query the Order */
         BufferSize = sizeof(OrderList);
 
         /* Query the Order */
         BufferSize = sizeof(OrderList);
@@ -332,7 +419,7 @@ FrLdrLoadBootDrivers(PCHAR szSystemRoot,
         if (rc != ERROR_SUCCESS) OrderList[0] = 0;
 
         /* enumerate all drivers */
         if (rc != ERROR_SUCCESS) OrderList[0] = 0;
 
         /* enumerate all drivers */
-        for (TagIndex = 1; TagIndex <= OrderList[0]; TagIndex++) {
+        for (TagIndex = 1; TagIndex <= SWAPD(OrderList[0]); TagIndex++) {
 
             Index = 0;
 
 
             Index = 0;
 
@@ -341,33 +428,33 @@ FrLdrLoadBootDrivers(PCHAR szSystemRoot,
                 /* Get the Driver's Name */
                 ValueSize = sizeof(ServiceName);
                 rc = RegEnumKey(hServiceKey, Index, ServiceName, &ValueSize);
                 /* Get the Driver's Name */
                 ValueSize = sizeof(ServiceName);
                 rc = RegEnumKey(hServiceKey, Index, ServiceName, &ValueSize);
-                DbgPrint((DPRINT_REACTOS, "RegEnumKey(): rc %d\n", (int)rc));
+                DPRINTM(DPRINT_REACTOS, "RegEnumKey(): rc %d\n", (int)rc);
 
                 /* Makre sure it's valid, and check if we're done */
                 if (rc == ERROR_NO_MORE_ITEMS) break;
                 if (rc != ERROR_SUCCESS) return;
 
                 /* Makre sure it's valid, and check if we're done */
                 if (rc == ERROR_NO_MORE_ITEMS) break;
                 if (rc != ERROR_SUCCESS) return;
-                DbgPrint((DPRINT_REACTOS, "Service %d: '%S'\n", (int)Index, ServiceName));
+                DPRINTM(DPRINT_REACTOS, "Service %d: '%S'\n", (int)Index, ServiceName);
 
                 /* open driver Key */
                 rc = RegOpenKey(hServiceKey, ServiceName, &hDriverKey);
                 if (rc == ERROR_SUCCESS)
 
                 /* open driver Key */
                 rc = RegOpenKey(hServiceKey, ServiceName, &hDriverKey);
                 if (rc == ERROR_SUCCESS)
-                               {
+                {
                     /* Read the Start Value */
                     ValueSize = sizeof(ULONG);
                     rc = RegQueryValue(hDriverKey, L"Start", &ValueType, (PUCHAR)&StartValue, &ValueSize);
                     if (rc != ERROR_SUCCESS) StartValue = (ULONG)-1;
                     /* Read the Start Value */
                     ValueSize = sizeof(ULONG);
                     rc = RegQueryValue(hDriverKey, L"Start", &ValueType, (PUCHAR)&StartValue, &ValueSize);
                     if (rc != ERROR_SUCCESS) StartValue = (ULONG)-1;
-                    DbgPrint((DPRINT_REACTOS, "  Start: %x  \n", (int)StartValue));
+                    DPRINTM(DPRINT_REACTOS, "  Start: %x  \n", (int)StartValue);
 
                     /* Read the Tag */
                     ValueSize = sizeof(ULONG);
                     rc = RegQueryValue(hDriverKey, L"Tag", &ValueType, (PUCHAR)&TagValue, &ValueSize);
                     if (rc != ERROR_SUCCESS) TagValue = (ULONG)-1;
 
                     /* Read the Tag */
                     ValueSize = sizeof(ULONG);
                     rc = RegQueryValue(hDriverKey, L"Tag", &ValueType, (PUCHAR)&TagValue, &ValueSize);
                     if (rc != ERROR_SUCCESS) TagValue = (ULONG)-1;
-                    DbgPrint((DPRINT_REACTOS, "  Tag:   %x  \n", (int)TagValue));
+                    DPRINTM(DPRINT_REACTOS, "  Tag:   %x  \n", (int)TagValue);
 
                     /* Read the driver's group */
                     DriverGroupSize = sizeof(DriverGroup);
                     rc = RegQueryValue(hDriverKey, L"Group", NULL, (PUCHAR)DriverGroup, &DriverGroupSize);
 
                     /* Read the driver's group */
                     DriverGroupSize = sizeof(DriverGroup);
                     rc = RegQueryValue(hDriverKey, L"Group", NULL, (PUCHAR)DriverGroup, &DriverGroupSize);
-                    DbgPrint((DPRINT_REACTOS, "  Group: '%S'  \n", DriverGroup));
+                    DPRINTM(DPRINT_REACTOS, "  Group: '%S'  \n", DriverGroup);
 
                     /* Make sure it should be started */
                     if ((StartValue == 0) &&
 
                     /* Make sure it should be started */
                     if ((StartValue == 0) &&
@@ -380,16 +467,16 @@ FrLdrLoadBootDrivers(PCHAR szSystemRoot,
 
                         /* Write the whole path if it suceeded, else prepare to fail */
                         if (rc != ERROR_SUCCESS) {
 
                         /* Write the whole path if it suceeded, else prepare to fail */
                         if (rc != ERROR_SUCCESS) {
-                            DbgPrint((DPRINT_REACTOS, "  ImagePath: not found\n"));
+                            DPRINTM(DPRINT_REACTOS, "  ImagePath: not found\n");
                             sprintf(ImagePath, "%s\\system32\\drivers\\%S.sys", szSystemRoot, ServiceName);
                         } else if (TempImagePath[0] != L'\\') {
                             sprintf(ImagePath, "%s%S", szSystemRoot, TempImagePath);
                         } else {
                             sprintf(ImagePath, "%S", TempImagePath);
                             sprintf(ImagePath, "%s\\system32\\drivers\\%S.sys", szSystemRoot, ServiceName);
                         } else if (TempImagePath[0] != L'\\') {
                             sprintf(ImagePath, "%s%S", szSystemRoot, TempImagePath);
                         } else {
                             sprintf(ImagePath, "%S", TempImagePath);
-                            DbgPrint((DPRINT_REACTOS, "  ImagePath: '%s'\n", ImagePath));
+                            DPRINTM(DPRINT_REACTOS, "  ImagePath: '%s'\n", ImagePath);
                         }
 
                         }
 
-                        DbgPrint((DPRINT_REACTOS, "  Loading driver: '%s'\n", ImagePath));
+                        DPRINTM(DPRINT_REACTOS, "  Loading driver: '%s'\n", ImagePath);
 
                         /* Update the position if needed */
                         if (nPos < 100) nPos += 5;
 
                         /* Update the position if needed */
                         if (nPos < 100) nPos += 5;
@@ -398,8 +485,8 @@ FrLdrLoadBootDrivers(PCHAR szSystemRoot,
 
                     } else {
 
 
                     } else {
 
-                        DbgPrint((DPRINT_REACTOS, "  Skipping driver '%S' with Start %d, Tag %d and Group '%S' (Current Tag %d, current group '%S')\n",
-                                 ServiceName, StartValue, TagValue, DriverGroup, OrderList[TagIndex], GroupName));
+                        DPRINTM(DPRINT_REACTOS, "  Skipping driver '%S' with Start %d, Tag %d and Group '%S' (Current Tag %d, current group '%S')\n",
+                                 ServiceName, StartValue, TagValue, DriverGroup, OrderList[TagIndex], GroupName);
                     }
                 }
 
                     }
                 }
 
@@ -414,10 +501,10 @@ FrLdrLoadBootDrivers(PCHAR szSystemRoot,
             ValueSize = sizeof(ServiceName);
             rc = RegEnumKey(hServiceKey, Index, ServiceName, &ValueSize);
 
             ValueSize = sizeof(ServiceName);
             rc = RegEnumKey(hServiceKey, Index, ServiceName, &ValueSize);
 
-            DbgPrint((DPRINT_REACTOS, "RegEnumKey(): rc %d\n", (int)rc));
+            DPRINTM(DPRINT_REACTOS, "RegEnumKey(): rc %d\n", (int)rc);
             if (rc == ERROR_NO_MORE_ITEMS) break;
             if (rc != ERROR_SUCCESS) return;
             if (rc == ERROR_NO_MORE_ITEMS) break;
             if (rc != ERROR_SUCCESS) return;
-            DbgPrint((DPRINT_REACTOS, "Service %d: '%S'\n", (int)Index, ServiceName));
+            DPRINTM(DPRINT_REACTOS, "Service %d: '%S'\n", (int)Index, ServiceName);
 
             /* open driver Key */
             rc = RegOpenKey(hServiceKey, ServiceName, &hDriverKey);
 
             /* open driver Key */
             rc = RegOpenKey(hServiceKey, ServiceName, &hDriverKey);
@@ -427,18 +514,18 @@ FrLdrLoadBootDrivers(PCHAR szSystemRoot,
                 ValueSize = sizeof(ULONG);
                 rc = RegQueryValue(hDriverKey, L"Start", &ValueType, (PUCHAR)&StartValue, &ValueSize);
                 if (rc != ERROR_SUCCESS) StartValue = (ULONG)-1;
                 ValueSize = sizeof(ULONG);
                 rc = RegQueryValue(hDriverKey, L"Start", &ValueType, (PUCHAR)&StartValue, &ValueSize);
                 if (rc != ERROR_SUCCESS) StartValue = (ULONG)-1;
-                DbgPrint((DPRINT_REACTOS, "  Start: %x  \n", (int)StartValue));
+                DPRINTM(DPRINT_REACTOS, "  Start: %x  \n", (int)StartValue);
 
                 /* Read the Tag */
                 ValueSize = sizeof(ULONG);
                 rc = RegQueryValue(hDriverKey, L"Tag", &ValueType, (PUCHAR)&TagValue, &ValueSize);
                 if (rc != ERROR_SUCCESS) TagValue = (ULONG)-1;
 
                 /* Read the Tag */
                 ValueSize = sizeof(ULONG);
                 rc = RegQueryValue(hDriverKey, L"Tag", &ValueType, (PUCHAR)&TagValue, &ValueSize);
                 if (rc != ERROR_SUCCESS) TagValue = (ULONG)-1;
-                DbgPrint((DPRINT_REACTOS, "  Tag:   %x  \n", (int)TagValue));
+                DPRINTM(DPRINT_REACTOS, "  Tag:   %x  \n", (int)TagValue);
 
                 /* Read the driver's group */
                 DriverGroupSize = sizeof(DriverGroup);
                 rc = RegQueryValue(hDriverKey, L"Group", NULL, (PUCHAR)DriverGroup, &DriverGroupSize);
 
                 /* Read the driver's group */
                 DriverGroupSize = sizeof(DriverGroup);
                 rc = RegQueryValue(hDriverKey, L"Group", NULL, (PUCHAR)DriverGroup, &DriverGroupSize);
-                DbgPrint((DPRINT_REACTOS, "  Group: '%S'  \n", DriverGroup));
+                DPRINTM(DPRINT_REACTOS, "  Group: '%S'  \n", DriverGroup);
 
                 for (TagIndex = 1; TagIndex <= OrderList[0]; TagIndex++) {
                     if (TagValue == OrderList[TagIndex]) break;
 
                 for (TagIndex = 1; TagIndex <= OrderList[0]; TagIndex++) {
                     if (TagValue == OrderList[TagIndex]) break;
@@ -451,15 +538,15 @@ FrLdrLoadBootDrivers(PCHAR szSystemRoot,
                         ValueSize = sizeof(TempImagePath);
                         rc = RegQueryValue(hDriverKey, L"ImagePath", NULL, (PUCHAR)TempImagePath, &ValueSize);
                         if (rc != ERROR_SUCCESS) {
                         ValueSize = sizeof(TempImagePath);
                         rc = RegQueryValue(hDriverKey, L"ImagePath", NULL, (PUCHAR)TempImagePath, &ValueSize);
                         if (rc != ERROR_SUCCESS) {
-                            DbgPrint((DPRINT_REACTOS, "  ImagePath: not found\n"));
+                            DPRINTM(DPRINT_REACTOS, "  ImagePath: not found\n");
                             sprintf(ImagePath, "%ssystem32\\drivers\\%S.sys", szSystemRoot, ServiceName);
                         } else if (TempImagePath[0] != L'\\') {
                             sprintf(ImagePath, "%s%S", szSystemRoot, TempImagePath);
                         } else {
                             sprintf(ImagePath, "%S", TempImagePath);
                             sprintf(ImagePath, "%ssystem32\\drivers\\%S.sys", szSystemRoot, ServiceName);
                         } else if (TempImagePath[0] != L'\\') {
                             sprintf(ImagePath, "%s%S", szSystemRoot, TempImagePath);
                         } else {
                             sprintf(ImagePath, "%S", TempImagePath);
-                            DbgPrint((DPRINT_REACTOS, "  ImagePath: '%s'\n", ImagePath));
+                            DPRINTM(DPRINT_REACTOS, "  ImagePath: '%s'\n", ImagePath);
                         }
                         }
-                    DbgPrint((DPRINT_REACTOS, "  Loading driver: '%s'\n", ImagePath));
+                    DPRINTM(DPRINT_REACTOS, "  Loading driver: '%s'\n", ImagePath);
 
                     if (nPos < 100) nPos += 5;
 
 
                     if (nPos < 100) nPos += 5;
 
@@ -467,8 +554,8 @@ FrLdrLoadBootDrivers(PCHAR szSystemRoot,
 
                 } else {
 
 
                 } else {
 
-                    DbgPrint((DPRINT_REACTOS, "  Skipping driver '%S' with Start %d, Tag %d and Group '%S' (Current group '%S')\n",
-                    ServiceName, StartValue, TagValue, DriverGroup, GroupName));
+                    DPRINTM(DPRINT_REACTOS, "  Skipping driver '%S' with Start %d, Tag %d and Group '%S' (Current group '%S')\n",
+                    ServiceName, StartValue, TagValue, DriverGroup, GroupName);
                 }
             }
 
                 }
             }
 
@@ -483,53 +570,106 @@ FrLdrLoadBootDrivers(PCHAR szSystemRoot,
 VOID
 LoadAndBootReactOS(PCSTR OperatingSystemName)
 {
 VOID
 LoadAndBootReactOS(PCSTR OperatingSystemName)
 {
-       PFILE FilePointer;
-       CHAR name[255];
-       CHAR value[255];
-       CHAR SystemPath[255];
-       CHAR szKernelName[255];
-       CHAR szFileName[255];
-       CHAR  MsgBuffer[256];
-       ULONG SectionId;
+    PFILE FilePointer;
+    CHAR name[255];
+    CHAR value[255];
+    CHAR SystemPath[255];
+    CHAR LivePath[255];
+    CHAR szKernelName[255];
+    CHAR szFileName[255];
+    CHAR  MsgBuffer[256];
+    ULONG_PTR SectionId;
     PIMAGE_NT_HEADERS NtHeader;
     PVOID LoadBase;
     PIMAGE_NT_HEADERS NtHeader;
     PVOID LoadBase;
+    ULONG_PTR Base;
+    ULONG Size;
+    
+    //
+    // Backdrop
+    //
+    UiDrawBackdrop();
+
+    //
+    // Open the operating system section
+    // specified in the .ini file
+    //
+    if (!IniOpenSection(OperatingSystemName, &SectionId))
+    {
+        sprintf(MsgBuffer,"Operating System section '%s' not found in freeldr.ini", OperatingSystemName);
+        UiMessageBox(MsgBuffer);
+        return;
+    }
 
 
-       ULONG_PTR Base;
-       ULONG Size;
-
-       extern BOOLEAN AcpiPresent;
-
-       //
-       // Open the operating system section
-       // specified in the .ini file
-       //
-       if (!IniOpenSection(OperatingSystemName, &SectionId))
-       {
-               sprintf(MsgBuffer,"Operating System section '%s' not found in freeldr.ini", OperatingSystemName);
-               UiMessageBox(MsgBuffer);
-               return;
-       }
+    //
+    // Read the command line
+    //
+    if (IniReadSettingByName(SectionId, "Options", value, sizeof(value)))
+    {
+        //
+        // Check if a ramdisk file was given
+        //
+        PCHAR File;
+        File = strstr(value, "/RDIMAGEPATH=");
+        if (File)
+        {
+            //
+            // Copy the file name and everything else after it
+            //
+            strcpy(szFileName, File + 13);
+            
+            //
+            // Null-terminate
+            //
+            *strstr(szFileName, " ") = ANSI_NULL;
+            
+            //
+            // Load the ramdisk
+            //
+            RamDiskLoadVirtualFile(szFileName);
+        }
+    }
 
 
-       UiDrawBackdrop();
-       UiDrawStatusText("Detecting Hardware...");
+    /*
+     * Setup multiboot information structure
+     */
     UiDrawProgressBarCenter(1, 100, szLoadingMsg);
     UiDrawProgressBarCenter(1, 100, szLoadingMsg);
-
-       /*
-        * Setup multiboot information structure
-        */
-       LoaderBlock.CommandLine = reactos_kernel_cmdline;
-       LoaderBlock.ModsCount = 0;
-       LoaderBlock.ModsAddr = reactos_modules;
+    UiDrawStatusText("Detecting Hardware...");
+    LoaderBlock.CommandLine = reactos_kernel_cmdline;
+    LoaderBlock.PageDirectoryStart = (ULONG_PTR)&PageDirectoryStart;
+    LoaderBlock.PageDirectoryEnd = (ULONG_PTR)&PageDirectoryEnd;
+    LoaderBlock.ModsCount = 0;
+    LoaderBlock.ModsAddr = reactos_modules;
     LoaderBlock.DrivesAddr = reactos_arc_disk_info;
     LoaderBlock.DrivesAddr = reactos_arc_disk_info;
-    LoaderBlock.MmapLength = (unsigned long)MachGetMemoryMap((PBIOS_MEMORY_MAP)(PVOID)&reactos_memory_map, 32) * sizeof(memory_map_t);
+    LoaderBlock.RdAddr = (ULONG_PTR)gRamDiskBase;
+    LoaderBlock.RdLength = gRamDiskSize;
+    LoaderBlock.MmapLength = (SIZE_T)MachVtbl.GetMemoryMap((PBIOS_MEMORY_MAP)reactos_memory_map, 32) * sizeof(memory_map_t);
     if (LoaderBlock.MmapLength)
     {
         ULONG i;
     if (LoaderBlock.MmapLength)
     {
         ULONG i;
-
-        LoaderBlock.MmapAddr = (unsigned long)&reactos_memory_map;
+        LoaderBlock.Flags |= MB_FLAGS_MEM_INFO | MB_FLAGS_MMAP_INFO;
+        LoaderBlock.MmapAddr = (ULONG_PTR)&reactos_memory_map;
         reactos_memory_map_descriptor_size = sizeof(memory_map_t); // GetBiosMemoryMap uses a fixed value of 24
         for (i=0; i<(LoaderBlock.MmapLength/sizeof(memory_map_t)); i++)
         {
         reactos_memory_map_descriptor_size = sizeof(memory_map_t); // GetBiosMemoryMap uses a fixed value of 24
         for (i=0; i<(LoaderBlock.MmapLength/sizeof(memory_map_t)); i++)
         {
+#ifdef _M_PPC
+            ULONG tmp;
+            /* Also swap from long long to high/low
+             * We also have unusable memory that will be available to kernel
+             * land.  Mark it here.
+             */
+            if (BiosMemoryAcpiReclaim == reactos_memory_map[i].type)
+            {
+                reactos_memory_map[i].type = BiosMemoryUsable;
+            }
+
+            tmp = reactos_memory_map[i].base_addr_low;
+            reactos_memory_map[i].base_addr_low = reactos_memory_map[i].base_addr_high;
+            reactos_memory_map[i].base_addr_high = tmp;
+            tmp = reactos_memory_map[i].length_low;
+            reactos_memory_map[i].length_low = reactos_memory_map[i].length_high;
+            reactos_memory_map[i].length_high = tmp;
+#endif
+
             if (BiosMemoryUsable == reactos_memory_map[i].type &&
                 0 == reactos_memory_map[i].base_addr_low)
             {
             if (BiosMemoryUsable == reactos_memory_map[i].type &&
                 0 == reactos_memory_map[i].base_addr_low)
             {
@@ -548,134 +688,133 @@ LoadAndBootReactOS(PCSTR OperatingSystemName)
         }
     }
 
         }
     }
 
-       /*
-        * Initialize the registry
-        */
-       RegInitializeRegistry();
+    /*
+     * Initialize the registry
+     */
+    RegInitializeRegistry();
 
 
-       /*
-        * Make sure the system path is set in the .ini file
-        */
-       if (!IniReadSettingByName(SectionId, "SystemPath", SystemPath, sizeof(SystemPath)))
-       {
-               UiMessageBox("System path not specified for selected operating system.");
-               return;
-       }
+    /*
+     * Make sure the system path is set in the .ini file
+     */
+    if (!IniReadSettingByName(SectionId, "SystemPath", SystemPath, sizeof(SystemPath)))
+    {
+        UiMessageBox("System path not specified for selected operating system.");
+        return;
+    }
 
 
-       /*
-        * Special case for Live CD.
-        */
-       if (!_stricmp(SystemPath, "LiveCD"))
-       {
-               /* Normalize */
-               MachDiskGetBootPath(SystemPath, sizeof(SystemPath));
-               strcat(SystemPath, "\\reactos");
-               strcat(strcpy(reactos_kernel_cmdline, SystemPath),
-                      " /MININT");
-       }
-       else
-       {
-               if (! MachDiskNormalizeSystemPath(SystemPath,
-                                                 sizeof(SystemPath)))
-               {
-                       UiMessageBox("Invalid system path");
-                       return;
-               }
-               /* copy system path into kernel command line */
-               strcpy(reactos_kernel_cmdline, SystemPath);
-       }
+    /*
+     * Special case for Live CD.
+     */
+    if (!_strnicmp(SystemPath, "LiveCD", strlen("LiveCD")))
+    {
+        /* Use everything following the "LiveCD" string as the path */
+        strcpy(LivePath, SystemPath + strlen("LiveCD"));
+        /* Normalize */
+        MachDiskGetBootPath(SystemPath, sizeof(SystemPath));
+        strcat(SystemPath, LivePath);
+        strcat(strcpy(reactos_kernel_cmdline, SystemPath),
+               " /MININT");
+    }
+    else
+    {
+        if (! MachDiskNormalizeSystemPath(SystemPath,
+                                          sizeof(SystemPath)))
+        {
+            UiMessageBox("Invalid system path");
+            return;
+        }
+        /* copy system path into kernel command line */
+        strcpy(reactos_kernel_cmdline, SystemPath);
+    }
 
 
-       /*
-        * Read the optional kernel parameters (if any)
-        */
-       if (IniReadSettingByName(SectionId, "Options", value, sizeof(value)))
-       {
-               strcat(reactos_kernel_cmdline, " ");
-               strcat(reactos_kernel_cmdline, value);
-       }
+    /*
+     * Read the optional kernel parameters (if any)
+     */
+    if (IniReadSettingByName(SectionId, "Options", value, sizeof(value)))
+    {
+        strcat(reactos_kernel_cmdline, " ");
+        strcat(reactos_kernel_cmdline, value);
+    }
 
 
-       /*
-        * Detect hardware
-        */
-       MachHwDetect();
+    /*
+     * Detect hardware
+     */
+    LoaderBlock.ArchExtra = (ULONG_PTR)MachHwDetect();
     UiDrawProgressBarCenter(5, 100, szLoadingMsg);
 
     UiDrawProgressBarCenter(5, 100, szLoadingMsg);
 
-       if (AcpiPresent) LoaderBlock.Flags |= MB_FLAGS_ACPI_TABLE;
     LoaderBlock.DrivesCount = reactos_disk_count;
 
     LoaderBlock.DrivesCount = reactos_disk_count;
 
-       UiDrawStatusText("Loading...");
+    UiDrawStatusText("Loading...");
 
 
-       /*
-        * Try to open system drive
-        */
-       if (!FsOpenSystemVolume(SystemPath, szBootPath, &LoaderBlock.BootDevice))
-       {
-               UiMessageBox("Failed to open boot drive.");
-               return;
-       }
+    /* Get boot path */
+    if (strchr(SystemPath, '\\') != NULL)
+        strcpy(szBootPath, strchr(SystemPath, '\\'));
+    else
+        szBootPath[0] = '\0';
 
 
-       /* append a backslash */
-       if ((strlen(szBootPath)==0) ||
-           szBootPath[strlen(szBootPath)] != '\\')
-               strcat(szBootPath, "\\");
+    /* append a backslash */
+    if ((strlen(szBootPath)==0) ||
+        szBootPath[strlen(szBootPath)] != '\\')
+        strcat(szBootPath, "\\");
 
 
-       DbgPrint((DPRINT_REACTOS,"SystemRoot: '%s'\n", szBootPath));
+       DPRINTM(DPRINT_REACTOS,"SystemRoot: '%s'\n", szBootPath);
+       strcpy(SystemRoot, szBootPath);
 
 
-       /*
-        * Find the kernel image name
-        * and try to load the kernel off the disk
-        */
-       if(IniReadSettingByName(SectionId, "Kernel", value, sizeof(value)))
-       {
-               /*
-                * Set the name and
-                */
-               if (value[0] == '\\')
-               {
-                       strcpy(szKernelName, value);
-               }
-               else
-               {
-                       strcpy(szKernelName, szBootPath);
-                       strcat(szKernelName, "SYSTEM32\\");
-                       strcat(szKernelName, value);
-               }
-       }
-       else
-       {
-               strcpy(value, "NTOSKRNL.EXE");
-               strcpy(szKernelName, szBootPath);
-               strcat(szKernelName, "SYSTEM32\\");
-               strcat(szKernelName, value);
-       }
+    /*
+     * Find the kernel image name
+     * and try to load the kernel off the disk
+     */
+    if(IniReadSettingByName(SectionId, "Kernel", value, sizeof(value)))
+    {
+        /*
+         * Set the name and
+         */
+        if (value[0] == '\\')
+        {
+            strcpy(szKernelName, value);
+        }
+        else
+        {
+            strcpy(szKernelName, szBootPath);
+            strcat(szKernelName, "SYSTEM32\\");
+            strcat(szKernelName, value);
+        }
+    }
+    else
+    {
+        strcpy(value, "NTOSKRNL.EXE");
+        strcpy(szKernelName, szBootPath);
+        strcat(szKernelName, "SYSTEM32\\");
+        strcat(szKernelName, value);
+    }
 
 
-       /*
-        * Find the HAL image name
-        * and try to load the kernel off the disk
-        */
-       if(IniReadSettingByName(SectionId, "Hal", value, sizeof(value)))
-       {
-               /*
-                * Set the name and
-                */
-               if (value[0] == '\\')
-               {
-                       strcpy(szHalName, value);
-               }
-               else
-               {
-                       strcpy(szHalName, szBootPath);
-                       strcat(szHalName, "SYSTEM32\\");
-                       strcat(szHalName, value);
-               }
-       }
-       else
-       {
-               strcpy(value, "HAL.DLL");
-               strcpy(szHalName, szBootPath);
-               strcat(szHalName, "SYSTEM32\\");
-               strcat(szHalName, value);
-       }
+    /*
+     * Find the HAL image name
+     * and try to load the kernel off the disk
+     */
+    if(IniReadSettingByName(SectionId, "Hal", value, sizeof(value)))
+    {
+        /*
+         * Set the name and
+         */
+        if (value[0] == '\\')
+        {
+            strcpy(szHalName, value);
+        }
+        else
+        {
+            strcpy(szHalName, szBootPath);
+            strcat(szHalName, "SYSTEM32\\");
+            strcat(szHalName, value);
+        }
+    }
+    else
+    {
+        strcpy(value, "HAL.DLL");
+        strcpy(szHalName, szBootPath);
+        strcat(szHalName, "SYSTEM32\\");
+        strcat(szHalName, value);
+    }
 
     /* Load the kernel */
     LoadBase = FrLdrLoadImage(szKernelName, 5, 1);
 
     /* Load the kernel */
     LoadBase = FrLdrLoadImage(szKernelName, 5, 1);
@@ -683,33 +822,33 @@ LoadAndBootReactOS(PCSTR OperatingSystemName)
 
     /* Get the NT header, kernel base and kernel entry */
     NtHeader = RtlImageNtHeader(LoadBase);
 
     /* Get the NT header, kernel base and kernel entry */
     NtHeader = RtlImageNtHeader(LoadBase);
-    KernelBase = NtHeader->OptionalHeader.ImageBase;
-    KernelEntry = RaToPa(NtHeader->OptionalHeader.AddressOfEntryPoint);
+    KernelBase = SWAPD(NtHeader->OptionalHeader.ImageBase);
+    KernelEntryPoint = (ROS_KERNEL_ENTRY_POINT)(KernelBase + SWAPD(NtHeader->OptionalHeader.AddressOfEntryPoint));
     LoaderBlock.KernelBase = KernelBase;
 
     LoaderBlock.KernelBase = KernelBase;
 
-       /*
-        * Load the System hive from disk
-        */
-       strcpy(szFileName, szBootPath);
-       strcat(szFileName, "SYSTEM32\\CONFIG\\SYSTEM");
+    /*
+     * Load the System hive from disk
+     */
+    strcpy(szFileName, szBootPath);
+    strcat(szFileName, "SYSTEM32\\CONFIG\\SYSTEM");
 
 
-       DbgPrint((DPRINT_REACTOS, "SystemHive: '%s'", szFileName));
+       DPRINTM(DPRINT_REACTOS, "SystemHive: '%s'", szFileName);
 
 
-       FilePointer = FsOpenFile(szFileName);
-       if (FilePointer == NULL)
-       {
-               UiMessageBox("Could not find the System hive!");
-               return;
-       }
+    FilePointer = FsOpenFile(szFileName);
+    if (!FilePointer)
+    {
+        UiMessageBox("Could not find the System hive!");
+        return;
+    }
 
 
-       /*
-        * Update the status bar with the current file
-        */
-       strcpy(name, "Reading ");
-       strcat(name, value);
-       while (strlen(name) < 80)
-               strcat(name, " ");
-       UiDrawStatusText(name);
+    /*
+     * Update the status bar with the current file
+     */
+    strcpy(name, "Reading ");
+    strcat(name, value);
+    while (strlen(name) < 80)
+        strcat(name, " ");
+    UiDrawStatusText(name);
 
        /*
         * Load the System hive
 
        /*
         * Load the System hive
@@ -720,82 +859,47 @@ LoadAndBootReactOS(PCSTR OperatingSystemName)
                UiMessageBox("Could not load the System hive!\n");
                return;
        }
                UiMessageBox("Could not load the System hive!\n");
                return;
        }
-       DbgPrint((DPRINT_REACTOS, "SystemHive loaded at 0x%x size %u", (unsigned)Base, (unsigned)Size));
-
-       /*
-        * Import the loaded system hive
-        */
-       RegImportBinaryHive((PCHAR)Base, Size);
-
-       /*
-        * Initialize the 'CurrentControlSet' link
-        */
-       RegInitCurrentControlSet(FALSE);
-
-       UiDrawProgressBarCenter(15, 100, szLoadingMsg);
+       DPRINTM(DPRINT_REACTOS, "SystemHive loaded at 0x%x size %u\n", (unsigned)Base, (unsigned)Size);
 
 
-       /*
-        * Export the hardware hive
-        */
-       Base = FrLdrCreateModule ("HARDWARE");
-       RegExportBinaryHive (L"\\Registry\\Machine\\HARDWARE", (PCHAR)Base, &Size);
-       FrLdrCloseModule (Base, Size);
+    /*
+     * Import the loaded system hive
+     */
+    RegImportBinaryHive((PCHAR)Base, Size);
 
 
-       UiDrawProgressBarCenter(20, 100, szLoadingMsg);
+    /*
+     * Initialize the 'CurrentControlSet' link
+     */
+    RegInitCurrentControlSet(FALSE);
 
 
-       /*
-        * Load NLS files
-        */
-       if (!FrLdrLoadNlsFiles(szBootPath, MsgBuffer))
-       {
-               UiMessageBox(MsgBuffer);
-               return;
-       }
-       UiDrawProgressBarCenter(30, 100, szLoadingMsg);
+    UiDrawProgressBarCenter(15, 100, szLoadingMsg);
 
 
-       /*
-        * Load boot drivers
-        */
-       FrLdrLoadBootDrivers(szBootPath, 40);
-       //UiUnInitialize("Booting ReactOS...");
+    UiDrawProgressBarCenter(20, 100, szLoadingMsg);
 
 
-       /*
-        * Now boot the kernel
-        */
-       DiskStopFloppyMotor();
-    MachVideoPrepareForReactOS(FALSE);
+    /*
+     * Load NLS files
+     */
+    if (!FrLdrLoadNlsFiles(szBootPath, MsgBuffer))
+    {
+        UiMessageBox(MsgBuffer);
+        return;
+    }
+    UiDrawProgressBarCenter(30, 100, szLoadingMsg);
+
+    /*
+     * Load boot drivers
+     */
+    FrLdrLoadBootDrivers(szBootPath, 40);
+    //UiUnInitialize("Booting ReactOS...");
+
+    //
+    // Perform architecture-specific pre-boot configuration
+    //
+    MachPrepareForReactOS(FALSE);
+
+    //
+    // Setup paging and jump to kernel
+    //
     FrLdrStartup(0x2badb002);
 }
 
     FrLdrStartup(0x2badb002);
 }
 
-#undef DbgPrint
-ULONG
-DbgPrint(const char *Format, ...)
-{
-       va_list ap;
-       CHAR Buffer[512];
-       ULONG Length;
-
-       va_start(ap, Format);
-
-       /* Construct a string */
-       Length = _vsnprintf(Buffer, 512, Format, ap);
-
-       /* Check if we went past the buffer */
-       if (Length == -1)
-       {
-               /* Terminate it if we went over-board */
-               Buffer[sizeof(Buffer) - 1] = '\n';
-
-               /* Put maximum */
-               Length = sizeof(Buffer);
-       }
-
-       /* Show it as a message box */
-       UiMessageBox(Buffer);
-
-       /* Cleanup and exit */
-       va_end(ap);
-       return 0;
-}
-
 /* EOF */
 /* EOF */