* FreeLoader
*
* Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
+ * Copyright (C) 2005 Alex Ionescu <alex@relsoft.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include <freeldr.h>
#include <debug.h>
-#include <arch.h>
-#include <reactos.h>
-#include <rtl.h>
-#include <disk.h>
-#include <fs.h>
-#include <ui.h>
-#include <multiboot.h>
-#include <mm.h>
-#include <machine.h>
-#include <inifile.h>
-
-#include "registry.h"
-
-
-#define NDEBUG
-
-#define IsRecognizedPartition(P) \
- ((P) == PARTITION_FAT_12 || \
- (P) == PARTITION_FAT_16 || \
- (P) == PARTITION_HUGE || \
- (P) == PARTITION_IFS || \
- (P) == PARTITION_EXT2 || \
- (P) == PARTITION_FAT32 || \
- (P) == PARTITION_FAT32_XINT13 || \
- (P) == PARTITION_XINT13)
-
-static BOOL
-LoadKernel(PCHAR szFileName, int nPos)
+
+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
+// 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;
+char reactos_arc_hardware_data[HW_MAX_ARC_HEAP_SIZE] = {0};
+
+CHAR szHalName[255];
+CHAR szBootPath[255];
+CHAR SystemRoot[255];
+static CHAR szLoadingMsg[] = "Loading ReactOS...";
+BOOLEAN FrLdrBootType;
+ULONG_PTR KernelBase;
+ROS_KERNEL_ENTRY_POINT KernelEntryPoint;
+
+BOOLEAN
+FrLdrLoadDriver(PCHAR szFileName,
+ INT nPos)
{
- PFILE FilePointer;
- PCHAR szShortName;
- char szBuffer[256];
-
- szShortName = strrchr(szFileName, '\\');
- if (szShortName == NULL)
- szShortName = szFileName;
- else
- szShortName = szShortName + 1;
-
- FilePointer = FsOpenFile(szFileName);
- if (FilePointer == NULL)
+ PFILE FilePointer;
+ CHAR value[256], *FinalSlash;
+ LPSTR p;
+
+ if (!_stricmp(szFileName, "hal.dll"))
{
- strcpy(szBuffer, szShortName);
- strcat(szBuffer, " not found.");
- UiMessageBox(szBuffer);
- return(FALSE);
+ /* Use the boot.ini name instead */
+ szFileName = szHalName;
}
- /*
- * Update the status bar with the current file
- */
- strcpy(szBuffer, "Reading ");
- strcat(szBuffer, szShortName);
- UiDrawStatusText(szBuffer);
+ FinalSlash = strrchr(szFileName, '\\');
+ if(FinalSlash)
+ szFileName = FinalSlash + 1;
- /*
- * Load the kernel
- */
- MultiBootLoadKernel(FilePointer);
+ /* Open the Driver */
+ FilePointer = FsOpenFile(szFileName);
- UiDrawProgressBarCenter(nPos, 100, "Loading ReactOS...");
+ /* Try under the system root in the main dir and drivers */
+ if (FilePointer == NULL)
+ {
+ strcpy(value, SystemRoot);
+ if(value[strlen(value)-1] != '\\')
+ strcat(value, "\\");
+ strcat(value, szFileName);
+ FilePointer = FsOpenFile(value);
+ }
- return(TRUE);
-}
+ if (FilePointer == NULL)
+ {
+ strcpy(value, SystemRoot);
+ if(value[strlen(value)-1] != '\\')
+ strcat(value, "\\");
+ strcat(value, "SYSTEM32\\");
+ strcat(value, szFileName);
+ FilePointer = FsOpenFile(value);
+ }
-static BOOL
-LoadSymbolFile(PCHAR szSystemRoot,
- PCHAR ModuleName,
- int nPos)
-{
- CHAR SymbolFileName[1024];
- PFILE FilePointer;
- U32 Length;
- PCHAR Start;
- PCHAR Ext;
- char value[256];
- char *p;
-
- /* Get the path to the symbol store */
- strcpy(SymbolFileName, szSystemRoot);
- strcat(SymbolFileName, "symbols\\");
-
- /* Get the symbol filename from the module name */
- Start = strrchr(ModuleName, '\\');
- if (Start == NULL)
- Start = ModuleName;
- else
- Start++;
-
- Ext = strrchr(ModuleName, '.');
- if (Ext != NULL)
- Length = Ext - Start;
- else
- Length = strlen(Start);
-
- strncat(SymbolFileName, Start, Length);
- strcat(SymbolFileName, ".sym");
-
- FilePointer = FsOpenFile((PCHAR)&SymbolFileName[0]);
- if (FilePointer == NULL)
+ if (FilePointer == NULL)
{
- DbgPrint((DPRINT_REACTOS, "Symbol file %s not loaded.\n", SymbolFileName));
- /* This is not critical */
- return FALSE;
+ strcpy(value, SystemRoot);
+ if(value[strlen(value)-1] != '\\')
+ strcat(value, "\\");
+ strcat(value, "SYSTEM32\\DRIVERS\\");
+ strcat(value, szFileName);
+ FilePointer = FsOpenFile(value);
}
- DbgPrint((DPRINT_REACTOS, "Symbol file %s is loaded.\n", SymbolFileName));
+ /* Make sure we did */
+ if (FilePointer == NULL) {
- /*
- * Update the status bar with the current file
- */
- strcpy(value, "Reading ");
- p = strrchr(SymbolFileName, '\\');
- if (p == NULL)
- strcat(value, SymbolFileName);
- else
- strcat(value, p + 1);
- UiDrawStatusText(value);
+ /* Fail if file wasn't opened */
+ strcpy(value, szFileName);
+ strcat(value, " not found.");
+ return(FALSE);
+ }
- /*
- * Load the symbol file
- */
- MultiBootLoadModule(FilePointer, SymbolFileName, NULL);
+ /* Update the status bar with the current file */
+ strcpy(value, "Reading ");
+ p = strrchr(szFileName, '\\');
+ if (p == NULL) {
- UiDrawProgressBarCenter(nPos, 100, "Loading ReactOS...");
+ strcat(value, szFileName);
- return (TRUE);
-}
+ } else {
+ strcat(value, p + 1);
-static BOOL
-LoadDriver(PCHAR szFileName, int nPos)
+ }
+ UiDrawStatusText(value);
+
+ /* Load the driver */
+ FrLdrMapImage(FilePointer, szFileName, 0);
+
+ /* Update status and return */
+ UiDrawProgressBarCenter(nPos, 100, szLoadingMsg);
+ return(TRUE);
+}
+
+PVOID
+NTAPI
+FrLdrLoadImage(IN PCHAR szFileName,
+ IN INT nPos,
+ IN ULONG ImageType)
{
- PFILE FilePointer;
- char value[256];
- char *p;
+ PFILE FilePointer;
+ PCHAR szShortName;
+ CHAR szBuffer[256], szFullPath[256];
+ PVOID LoadBase;
+
+ /* Extract filename without path */
+ szShortName = strrchr(szFileName, '\\');
+ if (!szShortName)
+ {
+ /* No path, leave it alone */
+ szShortName = szFileName;
- FilePointer = FsOpenFile(szFileName);
- if (FilePointer == NULL)
+ /* Which means we need to build a path now */
+ strcpy(szBuffer, szFileName);
+ strcpy(szFullPath, szBootPath);
+ if (!FrLdrBootType)
+ {
+ strcat(szFullPath, "SYSTEM32\\DRIVERS\\");
+ }
+ else
+ {
+ strcat(szFullPath, "\\");
+ }
+ strcat(szFullPath, szBuffer);
+ szFileName = szFullPath;
+ }
+ else
{
- strcpy(value, szFileName);
- strcat(value, " not found.");
- UiMessageBox(value);
- return(FALSE);
+ /* Skip the path */
+ szShortName = szShortName + 1;
}
- /*
- * 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
- */
- MultiBootLoadModule(FilePointer, szFileName, NULL);
-
- UiDrawProgressBarCenter(nPos, 100, "Loading ReactOS...");
-
- return(TRUE);
-}
+ /* Open the image */
+ FilePointer = FsOpenFile(szFileName);
+ if (!FilePointer)
+ {
+ /* Return failure on the short name */
+ strcpy(szBuffer, szShortName);
+ strcat(szBuffer, " not found.");
+ UiMessageBox(szBuffer);
+ return FALSE;
+ }
+
+ /* Update the status bar with the current file */
+ strcpy(szBuffer, "Reading ");
+ strcat(szBuffer, szShortName);
+ UiDrawStatusText(szBuffer);
+ /* Do the actual loading */
+ LoadBase = FrLdrMapImage(FilePointer, szShortName, ImageType);
-static BOOL
-LoadNlsFile(PCHAR szFileName, PCHAR szModuleName)
+ /* Update Processbar and return success */
+ if (!FrLdrBootType) UiDrawProgressBarCenter(nPos, 100, szLoadingMsg);
+ return LoadBase;
+}
+
+static BOOLEAN
+FrLdrLoadNlsFile(PCSTR szFileName,
+ PCSTR szModuleName)
{
- PFILE FilePointer;
- char value[256];
- char *p;
+ PFILE FilePointer;
+ CHAR value[256];
+ LPSTR p;
- FilePointer = FsOpenFile(szFileName);
- if (FilePointer == NULL)
- {
- strcpy(value, szFileName);
- strcat(value, " not found.");
- UiMessageBox(value);
- return(FALSE);
+ /* Open the Driver */
+ FilePointer = FsOpenFile(szFileName);
+
+ /* Make sure we did */
+ if (FilePointer == NULL) {
+
+ /* Fail if file wasn't opened */
+ strcpy(value, szFileName);
+ strcat(value, " not found.");
+ UiMessageBox(value);
+ 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
- */
- MultiBootLoadModule(FilePointer, szModuleName, NULL);
-
- return(TRUE);
-}
+ /* Update the status bar with the current file */
+ strcpy(value, "Reading ");
+ p = strrchr(szFileName, '\\');
+ if (p == NULL) {
+ strcat(value, szFileName);
-static VOID
-LoadBootDrivers(PCHAR szSystemRoot, int nPos)
+ } else {
+
+ strcat(value, p + 1);
+ }
+ UiDrawStatusText(value);
+
+ /* Load the driver */
+ FrLdrLoadModule(FilePointer, szModuleName, NULL);
+ return(TRUE);
+}
+
+static BOOLEAN
+FrLdrLoadNlsFiles(PCHAR szSystemRoot,
+ PCHAR szErrorOut)
{
- S32 rc = 0;
- HKEY hGroupKey, hOrderKey, hServiceKey, hDriverKey;
- char GroupNameBuffer[512];
- char ServiceName[256];
- U32 OrderList[128];
- U32 BufferSize;
- U32 Index;
- U32 TagIndex;
- char *GroupName;
-
- U32 ValueSize;
- U32 ValueType;
- U32 StartValue;
- U32 TagValue;
- UCHAR DriverGroup[256];
- U32 DriverGroupSize;
-
- UCHAR ImagePath[256];
- UCHAR TempImagePath[256];
-
- /* get 'service group order' key */
- rc = RegOpenKey(NULL,
- "\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\ServiceGroupOrder",
- &hGroupKey);
- if (rc != ERROR_SUCCESS)
- {
- DbgPrint((DPRINT_REACTOS, "Failed to open the 'ServiceGroupOrder' key (rc %d)\n", (int)rc));
- return;
+ LONG rc = ERROR_SUCCESS;
+ FRLDRHKEY hKey;
+ WCHAR szIdBuffer[80];
+ WCHAR szNameBuffer[80];
+ CHAR szFileName[256];
+ ULONG BufferSize;
+
+ /* open the codepage key */
+ rc = RegOpenKey(NULL,
+ L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage",
+ &hKey);
+ if (rc != ERROR_SUCCESS) {
+
+ strcpy(szErrorOut, "Couldn't open CodePage registry key");
+ return(FALSE);
}
-
- /* get 'group order list' key */
- rc = RegOpenKey(NULL,
- "\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\GroupOrderList",
- &hOrderKey);
- if (rc != ERROR_SUCCESS)
- {
- DbgPrint((DPRINT_REACTOS, "Failed to open the 'GroupOrderList' key (rc %d)\n", (int)rc));
- return;
+
+ /* get ANSI codepage */
+ BufferSize = sizeof(szIdBuffer);
+ rc = RegQueryValue(hKey, L"ACP", NULL, (PUCHAR)szIdBuffer, &BufferSize);
+ if (rc != ERROR_SUCCESS) {
+
+ strcpy(szErrorOut, "Couldn't get ACP NLS setting");
+ return(FALSE);
}
- /* enumerate drivers */
- rc = RegOpenKey(NULL,
- "\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Services",
- &hServiceKey);
- if (rc != ERROR_SUCCESS)
- {
- DbgPrint((DPRINT_REACTOS, "Failed to open the 'Services' key (rc %d)\n", (int)rc));
- return;
+ BufferSize = sizeof(szNameBuffer);
+ rc = RegQueryValue(hKey, szIdBuffer, NULL, (PUCHAR)szNameBuffer, &BufferSize);
+ if (rc != ERROR_SUCCESS) {
+
+ strcpy(szErrorOut, "ACP NLS Setting exists, but isn't readable");
+ return(FALSE);
}
- BufferSize = sizeof(GroupNameBuffer);
- rc = RegQueryValue(hGroupKey, "List", NULL, (PUCHAR)GroupNameBuffer, &BufferSize);
- DbgPrint((DPRINT_REACTOS, "RegQueryValue(): rc %d\n", (int)rc));
- if (rc != ERROR_SUCCESS)
- return;
+ /* load ANSI codepage table */
+ sprintf(szFileName,"%ssystem32\\%S", szSystemRoot, szNameBuffer);
+ DbgPrint((DPRINT_REACTOS, "ANSI file: %s\n", szFileName));
+ if (!FrLdrLoadNlsFile(szFileName, "ansi.nls")) {
- DbgPrint((DPRINT_REACTOS, "BufferSize: %d \n", (int)BufferSize));
+ strcpy(szErrorOut, "Couldn't load ansi.nls");
+ return(FALSE);
+ }
- DbgPrint((DPRINT_REACTOS, "GroupNameBuffer: '%s' \n", GroupNameBuffer));
+ /* get OEM codepage */
+ BufferSize = sizeof(szIdBuffer);
+ rc = RegQueryValue(hKey, L"OEMCP", NULL, (PUCHAR)szIdBuffer, &BufferSize);
+ if (rc != ERROR_SUCCESS) {
- GroupName = GroupNameBuffer;
- while (*GroupName)
- {
- DbgPrint((DPRINT_REACTOS, "Driver group: '%s'\n", GroupName));
+ strcpy(szErrorOut, "Couldn't get OEMCP NLS setting");
+ return(FALSE);
+ }
- BufferSize = sizeof(OrderList);
- rc = RegQueryValue(hOrderKey, GroupName, NULL, (PUCHAR)OrderList, &BufferSize);
- if (rc != ERROR_SUCCESS)
- {
- OrderList[0] = 0;
- }
-
- for (TagIndex = 1; TagIndex <= OrderList[0]; TagIndex++)
- {
- /* enumerate all drivers */
- Index = 0;
- while (TRUE)
- {
- ValueSize = sizeof(ServiceName);
- rc = RegEnumKey(hServiceKey, Index, ServiceName, &ValueSize);
- DbgPrint((DPRINT_REACTOS, "RegEnumKey(): rc %d\n", (int)rc));
- if (rc == ERROR_NO_MORE_ITEMS)
- break;
- if (rc != ERROR_SUCCESS)
- return;
- DbgPrint((DPRINT_REACTOS, "Service %d: '%s'\n", (int)Index, ServiceName));
-
- /* open driver Key */
- rc = RegOpenKey(hServiceKey, ServiceName, &hDriverKey);
-
- ValueSize = sizeof(U32);
- rc = RegQueryValue(hDriverKey, "Start", &ValueType, (PUCHAR)&StartValue, &ValueSize);
- DbgPrint((DPRINT_REACTOS, " Start: %x \n", (int)StartValue));
-
- ValueSize = sizeof(U32);
- rc = RegQueryValue(hDriverKey, "Tag", &ValueType, (PUCHAR)&TagValue, &ValueSize);
- if (rc != ERROR_SUCCESS)
- {
- TagValue = (U32)-1;
- }
- DbgPrint((DPRINT_REACTOS, " Tag: %x \n", (int)TagValue));
-
-
- DriverGroupSize = 256;
- rc = RegQueryValue(hDriverKey, "Group", NULL, (PUCHAR)DriverGroup, &DriverGroupSize);
- DbgPrint((DPRINT_REACTOS, " Group: '%s' \n", DriverGroup));
-
- if ((StartValue == 0) && (TagValue == OrderList[TagIndex]) &&(stricmp(DriverGroup, GroupName) == 0))
- {
- ValueSize = 256;
- rc = RegQueryValue(hDriverKey,
- "ImagePath",
- NULL,
- (PUCHAR)TempImagePath,
- &ValueSize);
- if (rc != ERROR_SUCCESS)
- {
- DbgPrint((DPRINT_REACTOS, " ImagePath: not found\n"));
- strcpy(ImagePath, szSystemRoot);
- strcat(ImagePath, "system32\\drivers\\");
- strcat(ImagePath, ServiceName);
- strcat(ImagePath, ".sys");
- }
- else if (TempImagePath[0] != '\\')
- {
- strcpy(ImagePath, szSystemRoot);
- strcat(ImagePath, TempImagePath);
- }
- else
- {
- strcpy(ImagePath, TempImagePath);
- DbgPrint((DPRINT_REACTOS, " ImagePath: '%s'\n", ImagePath));
- }
- DbgPrint((DPRINT_REACTOS, " Loading driver: '%s'\n", ImagePath));
-
- if (nPos < 100)
- nPos += 5;
-
- LoadDriver(ImagePath, nPos);
- LoadSymbolFile(szSystemRoot, ImagePath, nPos);
- }
- 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));
- }
- Index++;
- }
- }
-
- Index = 0;
- while (TRUE)
- {
- ValueSize = sizeof(ServiceName);
- rc = RegEnumKey(hServiceKey, Index, ServiceName, &ValueSize);
- DbgPrint((DPRINT_REACTOS, "RegEnumKey(): rc %d\n", (int)rc));
- if (rc == ERROR_NO_MORE_ITEMS)
- break;
- if (rc != ERROR_SUCCESS)
- return;
- DbgPrint((DPRINT_REACTOS, "Service %d: '%s'\n", (int)Index, ServiceName));
-
- /* open driver Key */
- rc = RegOpenKey(hServiceKey, ServiceName, &hDriverKey);
-
- ValueSize = sizeof(U32);
- rc = RegQueryValue(hDriverKey, "Start", &ValueType, (PUCHAR)&StartValue, &ValueSize);
- DbgPrint((DPRINT_REACTOS, " Start: %x \n", (int)StartValue));
-
- ValueSize = sizeof(U32);
- rc = RegQueryValue(hDriverKey, "Tag", &ValueType, (PUCHAR)&TagValue, &ValueSize);
- if (rc != ERROR_SUCCESS)
- {
- TagValue = (U32)-1;
- }
- DbgPrint((DPRINT_REACTOS, " Tag: %x \n", (int)TagValue));
-
- DriverGroupSize = 256;
- rc = RegQueryValue(hDriverKey, "Group", NULL, (PUCHAR)DriverGroup, &DriverGroupSize);
- DbgPrint((DPRINT_REACTOS, " Group: '%s' \n", DriverGroup));
-
- for (TagIndex = 1; TagIndex <= OrderList[0]; TagIndex++)
- {
- if (TagValue == OrderList[TagIndex])
- break;
- }
-
- if ((StartValue == 0) && (TagIndex > OrderList[0]) && (stricmp(DriverGroup, GroupName) == 0))
- {
- ValueSize = 256;
- rc = RegQueryValue(hDriverKey,
- "ImagePath",
- NULL,
- (PUCHAR)TempImagePath,
- &ValueSize);
- if (rc != ERROR_SUCCESS)
- {
- DbgPrint((DPRINT_REACTOS, " ImagePath: not found\n"));
- strcpy(ImagePath, szSystemRoot);
- strcat(ImagePath, "system32\\drivers\\");
- strcat(ImagePath, ServiceName);
- strcat(ImagePath, ".sys");
- }
- else if (TempImagePath[0] != '\\')
- {
- strcpy(ImagePath, szSystemRoot);
- strcat(ImagePath, TempImagePath);
- }
- else
- {
- strcpy(ImagePath, TempImagePath);
- DbgPrint((DPRINT_REACTOS, " ImagePath: '%s'\n", ImagePath));
- }
- DbgPrint((DPRINT_REACTOS, " Loading driver: '%s'\n", ImagePath));
-
- if (nPos < 100)
- nPos += 5;
-
- LoadDriver(ImagePath, nPos);
- LoadSymbolFile(szSystemRoot, ImagePath, nPos);
- }
- else
- {
- DbgPrint((DPRINT_REACTOS, " Skipping driver '%s' with Start %d, Tag %d and Group '%s' (Current group '%s')\n",
- ServiceName, StartValue, TagValue, DriverGroup, GroupName));
- }
- Index++;
- }
+ BufferSize = sizeof(szNameBuffer);
+ rc = RegQueryValue(hKey, szIdBuffer, NULL, (PUCHAR)szNameBuffer, &BufferSize);
+ if (rc != ERROR_SUCCESS) {
- GroupName = GroupName + strlen(GroupName) + 1;
+ strcpy(szErrorOut, "OEMCP NLS setting exists, but isn't readable");
+ return(FALSE);
}
-}
+ /* load OEM codepage table */
+ sprintf(szFileName, "%ssystem32\\%S", szSystemRoot, szNameBuffer);
+ DbgPrint((DPRINT_REACTOS, "Oem file: %s\n", szFileName));
+ if (!FrLdrLoadNlsFile(szFileName, "oem.nls")) {
-static BOOL
-LoadNlsFiles(PCHAR szSystemRoot, PCHAR szErrorOut)
-{
- S32 rc = ERROR_SUCCESS;
- HKEY hKey;
- char szIdBuffer[80];
- char szNameBuffer[80];
- char szFileName[256];
- U32 BufferSize;
-
- /* open the codepage key */
- rc = RegOpenKey(NULL,
- "\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage",
- &hKey);
- if (rc != ERROR_SUCCESS) {
- strcpy(szErrorOut, "Couldn't open CodePage registry key");
- return(FALSE);
- }
-
-
- /* get ANSI codepage */
- BufferSize = 80;
- rc = RegQueryValue(hKey, "ACP", NULL, (PUCHAR)szIdBuffer, &BufferSize);
- if (rc != ERROR_SUCCESS) {
- strcpy(szErrorOut, "Couldn't get ACP NLS setting");
- return(FALSE);
- }
-
- BufferSize = 80;
- rc = RegQueryValue(hKey, szIdBuffer, NULL, (PUCHAR)szNameBuffer, &BufferSize);
- if (rc != ERROR_SUCCESS) {
- strcpy(szErrorOut, "ACP NLS Setting exists, but isn't readable");
- return(FALSE);
- }
-
- /* load ANSI codepage table */
- strcpy(szFileName, szSystemRoot);
- strcat(szFileName, "system32\\");
- strcat(szFileName, szNameBuffer);
- DbgPrint((DPRINT_REACTOS, "ANSI file: %s\n", szFileName));
- if (!LoadNlsFile(szFileName, "ansi.nls")) {
- strcpy(szErrorOut, "Couldn't load ansi.nls");
- return(FALSE);
- }
-
- /* get OEM codepage */
- BufferSize = 80;
- rc = RegQueryValue(hKey, "OEMCP", NULL, (PUCHAR)szIdBuffer, &BufferSize);
- if (rc != ERROR_SUCCESS) {
- strcpy(szErrorOut, "Couldn't get OEMCP NLS setting");
- return(FALSE);
- }
-
- BufferSize = 80;
- rc = RegQueryValue(hKey, szIdBuffer, NULL, (PUCHAR)szNameBuffer, &BufferSize);
- if (rc != ERROR_SUCCESS) {
- strcpy(szErrorOut, "OEMCP NLS setting exists, but isn't readable");
- return(FALSE);
- }
-
- /* load OEM codepage table */
- strcpy(szFileName, szSystemRoot);
- strcat(szFileName, "system32\\");
- strcat(szFileName, szNameBuffer);
- DbgPrint((DPRINT_REACTOS, "Oem file: %s\n", szFileName));
- if (!LoadNlsFile(szFileName, "oem.nls")) {
- strcpy(szErrorOut, "Couldn't load oem.nls");
- return(FALSE);
- }
-
- /* open the language key */
- rc = RegOpenKey(NULL,
- "\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\Language",
- &hKey);
- if (rc != ERROR_SUCCESS) {
- strcpy(szErrorOut, "Couldn't open Language registry key");
- return(FALSE);
- }
-
- /* get the Unicode case table */
- BufferSize = 80;
- rc = RegQueryValue(hKey, "Default", NULL, (PUCHAR)szIdBuffer, &BufferSize);
- if (rc != ERROR_SUCCESS) {
- strcpy(szErrorOut, "Couldn't get Language Default setting");
- return(FALSE);
- }
-
- BufferSize = 80;
- rc = RegQueryValue(hKey, szIdBuffer, NULL, (PUCHAR)szNameBuffer, &BufferSize);
- if (rc != ERROR_SUCCESS) {
- strcpy(szErrorOut,
- "Language Default setting exists, but isn't readable");
- return(FALSE);
- }
-
- /* load Unicode case table */
- strcpy(szFileName, szSystemRoot);
- strcat(szFileName, "system32\\");
- strcat(szFileName, szNameBuffer);
- DbgPrint((DPRINT_REACTOS, "Casemap file: %s\n", szFileName));
- if (!LoadNlsFile(szFileName, "casemap.nls")) {
- strcpy(szErrorOut, "casemap.nls");
- return(FALSE);
- }
-
- return(TRUE);
+ strcpy(szErrorOut, "Couldn't load oem.nls");
+ return(FALSE);
+ }
+
+ /* open the language key */
+ rc = RegOpenKey(NULL,
+ L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\Language",
+ &hKey);
+ if (rc != ERROR_SUCCESS) {
+
+ strcpy(szErrorOut, "Couldn't open Language registry key");
+ return(FALSE);
+ }
+
+ /* get the Unicode case table */
+ BufferSize = sizeof(szIdBuffer);
+ rc = RegQueryValue(hKey, L"Default", NULL, (PUCHAR)szIdBuffer, &BufferSize);
+ if (rc != ERROR_SUCCESS) {
+
+ strcpy(szErrorOut, "Couldn't get Language Default setting");
+ return(FALSE);
+ }
+
+ BufferSize = sizeof(szNameBuffer);
+ rc = RegQueryValue(hKey, szIdBuffer, NULL, (PUCHAR)szNameBuffer, &BufferSize);
+ if (rc != ERROR_SUCCESS) {
+
+ strcpy(szErrorOut, "Language Default setting exists, but isn't readable");
+ return(FALSE);
+ }
+
+ /* load Unicode case table */
+ sprintf(szFileName, "%ssystem32\\%S", szSystemRoot, szNameBuffer);
+ DbgPrint((DPRINT_REACTOS, "Casemap file: %s\n", szFileName));
+ if (!FrLdrLoadNlsFile(szFileName, "casemap.nls")) {
+
+ strcpy(szErrorOut, "casemap.nls");
+ return(FALSE);
+ }
+
+ return(TRUE);
}
+static VOID
+FrLdrLoadBootDrivers(PCHAR szSystemRoot,
+ INT nPos)
+{
+ LONG rc = 0;
+ FRLDRHKEY hGroupKey, hOrderKey, hServiceKey, hDriverKey;
+ WCHAR GroupNameBuffer[512];
+ WCHAR ServiceName[256];
+ ULONG OrderList[128];
+ ULONG BufferSize;
+ ULONG Index;
+ ULONG TagIndex;
+ LPWSTR GroupName;
+
+ ULONG ValueSize;
+ ULONG ValueType;
+ ULONG StartValue;
+ ULONG TagValue;
+ WCHAR DriverGroup[256];
+ ULONG DriverGroupSize;
+
+ CHAR ImagePath[256];
+ WCHAR TempImagePath[256];
+
+ /* get 'service group order' key */
+ rc = RegOpenKey(NULL,
+ L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\ServiceGroupOrder",
+ &hGroupKey);
+ if (rc != ERROR_SUCCESS) {
+
+ DbgPrint((DPRINT_REACTOS, "Failed to open the 'ServiceGroupOrder' key (rc %d)\n", (int)rc));
+ return;
+ }
+
+ /* get 'group order list' key */
+ rc = RegOpenKey(NULL,
+ L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\GroupOrderList",
+ &hOrderKey);
+ if (rc != ERROR_SUCCESS) {
+
+ DbgPrint((DPRINT_REACTOS, "Failed to open the 'GroupOrderList' key (rc %d)\n", (int)rc));
+ return;
+ }
+
+ /* enumerate drivers */
+ rc = RegOpenKey(NULL,
+ L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Services",
+ &hServiceKey);
+ if (rc != ERROR_SUCCESS) {
+
+ DbgPrint((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);
+ DbgPrint((DPRINT_REACTOS, "RegQueryValue(): rc %d\n", (int)rc));
+ if (rc != ERROR_SUCCESS) return;
+ DbgPrint((DPRINT_REACTOS, "BufferSize: %d \n", (int)BufferSize));
+ DbgPrint((DPRINT_REACTOS, "GroupNameBuffer: '%S' \n", GroupNameBuffer));
-void
-LoadAndBootReactOS(PUCHAR OperatingSystemName)
+ /* Loop through each group */
+ GroupName = GroupNameBuffer;
+ while (*GroupName) {
+ DbgPrint((DPRINT_REACTOS, "Driver group: '%S'\n", GroupName));
+
+ /* Query the Order */
+ BufferSize = sizeof(OrderList);
+ rc = RegQueryValue(hOrderKey, GroupName, NULL, (PUCHAR)OrderList, &BufferSize);
+ if (rc != ERROR_SUCCESS) OrderList[0] = 0;
+
+ /* enumerate all drivers */
+ for (TagIndex = 1; TagIndex <= SWAPD(OrderList[0]); TagIndex++) {
+
+ Index = 0;
+
+ while (TRUE) {
+
+ /* Get the Driver's Name */
+ ValueSize = sizeof(ServiceName);
+ rc = RegEnumKey(hServiceKey, Index, ServiceName, &ValueSize);
+ DbgPrint((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;
+ DbgPrint((DPRINT_REACTOS, "Service %d: '%S'\n", (int)Index, ServiceName));
+
+ /* 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;
+ DbgPrint((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;
+ DbgPrint((DPRINT_REACTOS, " Tag: %x \n", (int)TagValue));
+
+ /* Read the driver's group */
+ DriverGroupSize = sizeof(DriverGroup);
+ rc = RegQueryValue(hDriverKey, L"Group", NULL, (PUCHAR)DriverGroup, &DriverGroupSize);
+ DbgPrint((DPRINT_REACTOS, " Group: '%S' \n", DriverGroup));
+
+ /* Make sure it should be started */
+ if ((StartValue == 0) &&
+ (TagValue == OrderList[TagIndex]) &&
+ (_wcsicmp(DriverGroup, GroupName) == 0)) {
+
+ /* Get the Driver's Location */
+ ValueSize = sizeof(TempImagePath);
+ rc = RegQueryValue(hDriverKey, L"ImagePath", NULL, (PUCHAR)TempImagePath, &ValueSize);
+
+ /* Write the whole path if it suceeded, else prepare to fail */
+ if (rc != ERROR_SUCCESS) {
+ DbgPrint((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);
+ DbgPrint((DPRINT_REACTOS, " ImagePath: '%s'\n", ImagePath));
+ }
+
+ DbgPrint((DPRINT_REACTOS, " Loading driver: '%s'\n", ImagePath));
+
+ /* Update the position if needed */
+ if (nPos < 100) nPos += 5;
+
+ FrLdrLoadImage(ImagePath, nPos, 2);
+
+ } 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));
+ }
+ }
+
+ Index++;
+ }
+ }
+
+ Index = 0;
+ while (TRUE) {
+
+ /* Get the Driver's Name */
+ ValueSize = sizeof(ServiceName);
+ rc = RegEnumKey(hServiceKey, Index, ServiceName, &ValueSize);
+
+ DbgPrint((DPRINT_REACTOS, "RegEnumKey(): rc %d\n", (int)rc));
+ if (rc == ERROR_NO_MORE_ITEMS) break;
+ if (rc != ERROR_SUCCESS) return;
+ DbgPrint((DPRINT_REACTOS, "Service %d: '%S'\n", (int)Index, ServiceName));
+
+ /* 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;
+ DbgPrint((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;
+ DbgPrint((DPRINT_REACTOS, " Tag: %x \n", (int)TagValue));
+
+ /* Read the driver's group */
+ DriverGroupSize = sizeof(DriverGroup);
+ rc = RegQueryValue(hDriverKey, L"Group", NULL, (PUCHAR)DriverGroup, &DriverGroupSize);
+ DbgPrint((DPRINT_REACTOS, " Group: '%S' \n", DriverGroup));
+
+ for (TagIndex = 1; TagIndex <= OrderList[0]; TagIndex++) {
+ if (TagValue == OrderList[TagIndex]) break;
+ }
+
+ if ((StartValue == 0) &&
+ (TagIndex > OrderList[0]) &&
+ (_wcsicmp(DriverGroup, GroupName) == 0)) {
+
+ ValueSize = sizeof(TempImagePath);
+ rc = RegQueryValue(hDriverKey, L"ImagePath", NULL, (PUCHAR)TempImagePath, &ValueSize);
+ if (rc != ERROR_SUCCESS) {
+ DbgPrint((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);
+ DbgPrint((DPRINT_REACTOS, " ImagePath: '%s'\n", ImagePath));
+ }
+ DbgPrint((DPRINT_REACTOS, " Loading driver: '%s'\n", ImagePath));
+
+ if (nPos < 100) nPos += 5;
+
+ FrLdrLoadImage(ImagePath, nPos, 2);
+
+ } else {
+
+ DbgPrint((DPRINT_REACTOS, " Skipping driver '%S' with Start %d, Tag %d and Group '%S' (Current group '%S')\n",
+ ServiceName, StartValue, TagValue, DriverGroup, GroupName));
+ }
+ }
+
+ Index++;
+ }
+
+ /* Move to the next group name */
+ GroupName = GroupName + wcslen(GroupName) + 1;
+ }
+}
+
+VOID
+LoadAndBootReactOS(PCSTR OperatingSystemName)
{
PFILE FilePointer;
- char name[1024];
- char value[1024];
- char szKernelName[1024];
- char szHalName[1024];
- char szFileName[1024];
- char szBootPath[256];
- int i;
- char MsgBuffer[256];
- U32 SectionId;
-
- char* Base;
- U32 Size;
-
- PARTITION_TABLE_ENTRY PartitionTableEntry;
- U32 rosPartition;
+ CHAR name[255];
+ CHAR value[255];
+ CHAR SystemPath[255];
+ CHAR szKernelName[255];
+ CHAR szFileName[255];
+ CHAR MsgBuffer[256];
+ ULONG SectionId;
+ PIMAGE_NT_HEADERS NtHeader;
+ PVOID LoadBase;
+ ULONG_PTR Base;
+ ULONG Size;
//
// Open the operating system section
return;
}
+ UiDrawBackdrop();
+ UiDrawStatusText("Detecting Hardware...");
+ UiDrawProgressBarCenter(1, 100, szLoadingMsg);
+
/*
* Setup multiboot information structure
*/
- mb_info.flags = MB_INFO_FLAG_MEM_SIZE | MB_INFO_FLAG_BOOT_DEVICE | MB_INFO_FLAG_COMMAND_LINE | MB_INFO_FLAG_MODULES;
- mb_info.boot_device = 0xffffffff;
- mb_info.cmdline = (unsigned long)multiboot_kernel_cmdline;
- mb_info.mods_count = 0;
- mb_info.mods_addr = (unsigned long)multiboot_modules;
- mb_info.mmap_length = (unsigned long)MachGetMemoryMap((PBIOS_MEMORY_MAP)(PVOID)&multiboot_memory_map, 32) * sizeof(memory_map_t);
- if (mb_info.mmap_length)
- {
- mb_info.mmap_addr = (unsigned long)&multiboot_memory_map;
- mb_info.flags |= MB_INFO_FLAG_MEM_SIZE | MB_INFO_FLAG_MEMORY_MAP;
- multiboot_memory_map_descriptor_size = sizeof(memory_map_t); // GetBiosMemoryMap uses a fixed value of 24
- DbgPrint((DPRINT_REACTOS, "memory map length: %d\n", mb_info.mmap_length));
- DbgPrint((DPRINT_REACTOS, "dumping memory map:\n"));
- for (i=0; i<(mb_info.mmap_length/sizeof(memory_map_t)); i++)
- {
- if (MEMTYPE_USABLE == multiboot_memory_map[i].type &&
- 0 == multiboot_memory_map[i].base_addr_low)
- {
- mb_info.mem_lower = (multiboot_memory_map[i].base_addr_low + multiboot_memory_map[i].length_low) / 1024;
- if (640 < mb_info.mem_lower)
- {
- mb_info.mem_lower = 640;
- }
- }
- if (MEMTYPE_USABLE == multiboot_memory_map[i].type &&
- multiboot_memory_map[i].base_addr_low <= 1024 * 1024 &&
- 1024 * 1024 <= multiboot_memory_map[i].base_addr_low + multiboot_memory_map[i].length_low)
- {
- mb_info.mem_upper = (multiboot_memory_map[i].base_addr_low + multiboot_memory_map[i].length_low) / 1024 - 1024;
- }
- DbgPrint((DPRINT_REACTOS, "start: %x\t size: %x\t type %d\n",
- multiboot_memory_map[i].base_addr_low,
- multiboot_memory_map[i].length_low,
- multiboot_memory_map[i].type));
- }
- }
- DbgPrint((DPRINT_REACTOS, "low_mem = %d\n", mb_info.mem_lower));
- DbgPrint((DPRINT_REACTOS, "high_mem = %d\n", mb_info.mem_upper));
+ LoaderBlock.CommandLine = reactos_kernel_cmdline;
+ LoaderBlock.PageDirectoryStart = (ULONG)&PageDirectoryStart;
+ LoaderBlock.PageDirectoryEnd = (ULONG)&PageDirectoryEnd;
+ LoaderBlock.ModsCount = 0;
+ LoaderBlock.ModsAddr = reactos_modules;
+ LoaderBlock.DrivesAddr = reactos_arc_disk_info;
+ LoaderBlock.MmapLength = (unsigned long)MachGetMemoryMap((PBIOS_MEMORY_MAP)reactos_memory_map, 32) * sizeof(memory_map_t);
+ if (LoaderBlock.MmapLength)
+ {
+ ULONG i;
+ LoaderBlock.Flags |= MB_FLAGS_MEM_INFO | MB_FLAGS_MMAP_INFO;
+ LoaderBlock.MmapAddr = (unsigned long)&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++)
+ {
+#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)
+ {
+ LoaderBlock.MemLower = (reactos_memory_map[i].base_addr_low + reactos_memory_map[i].length_low) / 1024;
+ if (640 < LoaderBlock.MemLower)
+ {
+ LoaderBlock.MemLower = 640;
+ }
+ }
+ if (BiosMemoryUsable == reactos_memory_map[i].type &&
+ reactos_memory_map[i].base_addr_low <= 1024 * 1024 &&
+ 1024 * 1024 <= reactos_memory_map[i].base_addr_low + reactos_memory_map[i].length_low)
+ {
+ LoaderBlock.MemHigher = (reactos_memory_map[i].base_addr_low + reactos_memory_map[i].length_low) / 1024 - 1024;
+ }
+ }
+ }
/*
* Initialize the registry
/*
* Make sure the system path is set in the .ini file
*/
- if (!IniReadSettingByName(SectionId, "SystemPath", value, 1024))
+ if (!IniReadSettingByName(SectionId, "SystemPath", SystemPath, sizeof(SystemPath)))
{
UiMessageBox("System path not specified for selected operating system.");
return;
/*
* Special case for Live CD.
*/
- if (!stricmp(value, "LiveCD"))
+ if (!_stricmp(SystemPath, "LiveCD"))
{
- strcpy(szBootPath, "\\reactos");
-
- /* Set kernel command line */
- sprintf(multiboot_kernel_cmdline,
- "multi(0)disk(0)cdrom(%u)\\reactos /MININT",
- (unsigned int)BootDrive);
+ /* Normalize */
+ MachDiskGetBootPath(SystemPath, sizeof(SystemPath));
+ strcat(SystemPath, "\\reactos");
+ strcat(strcpy(reactos_kernel_cmdline, SystemPath),
+ " /MININT");
}
else
{
- /*
- * Verify system path
- */
- if (!DissectArcPath(value, szBootPath, &BootDrive, &BootPartition))
- {
- sprintf(MsgBuffer,"Invalid system path: '%s'", value);
- UiMessageBox(MsgBuffer);
- return;
- }
-
- /* recalculate the boot partition for freeldr */
- i = 0;
- rosPartition = 0;
- while (1)
+ if (! MachDiskNormalizeSystemPath(SystemPath,
+ sizeof(SystemPath)))
{
- if (!MachDiskGetPartitionEntry(BootDrive, ++i, &PartitionTableEntry))
- {
- BootPartition = 0;
- break;
- }
- if (IsRecognizedPartition(PartitionTableEntry.SystemIndicator))
- {
- if (++rosPartition == BootPartition)
- {
- BootPartition = i;
- break;
- }
- }
- }
-
- if (BootPartition == 0)
- {
- sprintf(MsgBuffer,"Invalid system path: '%s'", value);
- UiMessageBox(MsgBuffer);
+ UiMessageBox("Invalid system path");
return;
}
-
- /* copy ARC path into kernel command line */
- strcpy(multiboot_kernel_cmdline, value);
+ /* copy system path into kernel command line */
+ strcpy(reactos_kernel_cmdline, SystemPath);
}
- /* Set boot drive and partition */
- ((char *)(&mb_info.boot_device))[0] = (char)BootDrive;
- ((char *)(&mb_info.boot_device))[1] = (char)BootPartition;
-
/*
* Read the optional kernel parameters (if any)
*/
- if (IniReadSettingByName(SectionId, "Options", value, 1024))
+ if (IniReadSettingByName(SectionId, "Options", value, sizeof(value)))
{
- strcat(multiboot_kernel_cmdline, " ");
- strcat(multiboot_kernel_cmdline, value);
+ strcat(reactos_kernel_cmdline, " ");
+ strcat(reactos_kernel_cmdline, value);
}
- /* append a backslash */
- if ((strlen(szBootPath)==0) ||
- szBootPath[strlen(szBootPath)] != '\\')
- strcat(szBootPath, "\\");
-
- DbgPrint((DPRINT_REACTOS,"SystemRoot: '%s'\n", szBootPath));
-
-
- UiDrawBackdrop();
- UiDrawStatusText("Detecting Hardware...");
-
/*
* Detect hardware
*/
- MachHwDetect();
+ LoaderBlock.ArchExtra = (ULONG)MachHwDetect();
+ UiDrawProgressBarCenter(5, 100, szLoadingMsg);
+ LoaderBlock.DrivesCount = reactos_disk_count;
UiDrawStatusText("Loading...");
- UiDrawProgressBarCenter(0, 100, "Loading ReactOS...");
+
+ //
+ // If we have a ramdisk, this will switch to the ramdisk disk routines
+ // which read from memory instead of using the firmware. This has to be done
+ // after hardware detection, since hardware detection will require using the
+ // real routines in order to perform disk-detection (just because we're on a
+ // ram-boot doesn't mean the user doesn't have actual disks installed too!)
+ //
+ RamDiskSwitchFromBios();
/*
- * Try to open boot drive
+ * Try to open system drive
*/
- if (!FsOpenVolume(BootDrive, BootPartition))
+ if (!FsOpenSystemVolume(SystemPath, szBootPath, &LoaderBlock.BootDevice))
{
UiMessageBox("Failed to open boot drive.");
return;
}
+ /* append a backslash */
+ if ((strlen(szBootPath)==0) ||
+ szBootPath[strlen(szBootPath)] != '\\')
+ strcat(szBootPath, "\\");
+
+ DbgPrint((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, 1024))
+ if(IniReadSettingByName(SectionId, "Kernel", value, sizeof(value)))
{
/*
* Set the name and
strcat(szKernelName, value);
}
- if (!LoadKernel(szKernelName, 5))
- return;
-
/*
* Find the HAL image name
* and try to load the kernel off the disk
*/
- if(IniReadSettingByName(SectionId, "Hal", value, 1024))
+ if(IniReadSettingByName(SectionId, "Hal", value, sizeof(value)))
{
/*
* Set the name and
strcat(szHalName, value);
}
- if (!LoadDriver(szHalName, 10))
- return;
+ /* Load the kernel */
+ LoadBase = FrLdrLoadImage(szKernelName, 5, 1);
+ if (!LoadBase) return;
+
+ /* Get the NT header, kernel base and kernel entry */
+ NtHeader = RtlImageNtHeader(LoadBase);
+ KernelBase = SWAPD(NtHeader->OptionalHeader.ImageBase);
+ KernelEntryPoint = (ROS_KERNEL_ENTRY_POINT)(KernelBase + SWAPD(NtHeader->OptionalHeader.AddressOfEntryPoint));
+ LoaderBlock.KernelBase = KernelBase;
/*
* Load the System hive from disk
/*
* Load the System hive
*/
- Base = MultiBootLoadModule(FilePointer, szFileName, &Size);
- if (Base == NULL || Size == 0)
+ Base = FrLdrLoadModule(FilePointer, szFileName, &Size);
+ if (Base == 0 || Size == 0)
{
UiMessageBox("Could not load the System hive!\n");
return;
/*
* Import the loaded system hive
*/
- RegImportBinaryHive(Base, Size);
+ RegImportBinaryHive((PCHAR)Base, Size);
/*
* Initialize the 'CurrentControlSet' link
*/
RegInitCurrentControlSet(FALSE);
- UiDrawProgressBarCenter(15, 100, "Loading ReactOS...");
+ UiDrawProgressBarCenter(15, 100, szLoadingMsg);
- /*
- * Export the hardware hive
- */
- Base = MultiBootCreateModule ("HARDWARE");
- RegExportBinaryHive ("\\Registry\\Machine\\HARDWARE", Base, &Size);
- MultiBootCloseModule (Base, Size);
-
- UiDrawProgressBarCenter(20, 100, "Loading ReactOS...");
+ UiDrawProgressBarCenter(20, 100, szLoadingMsg);
/*
* Load NLS files
*/
- if (!LoadNlsFiles(szBootPath, MsgBuffer))
+ if (!FrLdrLoadNlsFiles(szBootPath, MsgBuffer))
{
- UiMessageBox(MsgBuffer);
+ UiMessageBox(MsgBuffer);
return;
}
- UiDrawProgressBarCenter(25, 100, "Loading ReactOS...");
+ UiDrawProgressBarCenter(30, 100, szLoadingMsg);
/*
- * Load symbol files
+ * Load boot drivers
*/
- LoadSymbolFile(szBootPath, szKernelName, 30);
- LoadSymbolFile(szBootPath, szHalName, 30);
+ FrLdrLoadBootDrivers(szBootPath, 40);
+ //UiUnInitialize("Booting ReactOS...");
+
+ //
+ // Perform architecture-specific pre-boot configuration
+ //
+ MachPrepareForReactOS(FALSE);
+
+ //
+ // Setup paging and jump to kernel
+ //
+ FrLdrStartup(0x2badb002);
+}
- UiDrawProgressBarCenter(30, 100, "Loading ReactOS...");
+#undef DbgPrint
+ULONG
+DbgPrint(const char *Format, ...)
+{
+ va_list ap;
+ CHAR Buffer[512];
+ ULONG Length;
- /*
- * Load boot drivers
- */
- LoadBootDrivers(szBootPath, 30);
+ va_start(ap, Format);
+ /* Construct a string */
+ Length = _vsnprintf(Buffer, 512, Format, ap);
-#if 0
- /*
- * Clear the screen and redraw the backdrop and status bar
- */
- UiDrawBackdrop();
- UiDrawStatusText("Press any key to boot");
+ /* Check if we went past the buffer */
+ if (Length == -1)
+ {
+ /* Terminate it if we went over-board */
+ Buffer[sizeof(Buffer) - 1] = '\n';
- /*
- * Wait for user
- */
- strcpy(name, "Kernel and Drivers loaded.\nPress any key to boot ");
- strcat(name, OperatingSystemName);
- strcat(name, ".");
- MessageBox(name);
-#endif
+ /* Put maximum */
+ Length = sizeof(Buffer);
+ }
- UiUnInitialize("Booting ReactOS...");
+ /* Show it as a message box */
+ UiMessageBox(Buffer);
- /*
- * Now boot the kernel
- */
- DiskStopFloppyMotor();
- boot_reactos();
+ /* Cleanup and exit */
+ va_end(ap);
+ return 0;
}
/* EOF */