//FIXME: Do a better way to retrieve Arc disk information
extern ULONG reactos_disk_count;
extern ARC_DISK_SIGNATURE reactos_arc_disk_info[];
-extern char reactos_arc_strings[32][256];
extern BOOLEAN UseRealHeap;
extern ULONG LoaderPagesSpanned;
extern BOOLEAN WinLdrTerminalConnected;
extern void WinLdrSetupEms(IN PCHAR BootOptions);
+PLOADER_SYSTEM_BLOCK WinLdrSystemBlock;
+
// debug stuff
VOID DumpMemoryAllocMap(VOID);
PLOADER_PARAMETER_BLOCK LoaderBlock;
/* Allocate and zero-init the LPB */
- LoaderBlock = MmHeapAlloc(sizeof(LOADER_PARAMETER_BLOCK));
- RtlZeroMemory(LoaderBlock, sizeof(LOADER_PARAMETER_BLOCK));
+ WinLdrSystemBlock = MmAllocateMemoryWithType(sizeof(LOADER_SYSTEM_BLOCK),
+ LoaderSystemBlock);
+ if (WinLdrSystemBlock == NULL)
+ {
+ UiMessageBox("Failed to allocate memory for system block!");
+ return;
+ }
+
+ RtlZeroMemory(WinLdrSystemBlock, sizeof(LOADER_SYSTEM_BLOCK));
+
+ LoaderBlock = &WinLdrSystemBlock->LoaderBlock;
+ LoaderBlock->NlsData = &WinLdrSystemBlock->NlsDataBlock;
/* Init three critical lists, used right away */
InitializeListHead(&LoaderBlock->LoadOrderListHead);
InitializeListHead(&LoaderBlock->MemoryDescriptorListHead);
InitializeListHead(&LoaderBlock->BootDriverListHead);
- /* Alloc space for NLS (it will be converted to VA in WinLdrLoadNLS) */
- LoaderBlock->NlsData = MmHeapAlloc(sizeof(NLS_DATA_BLOCK));
- if (LoaderBlock->NlsData == NULL)
- {
- UiMessageBox("Failed to allocate memory for NLS table data!");
- return;
- }
- RtlZeroMemory(LoaderBlock->NlsData, sizeof(NLS_DATA_BLOCK));
-
*OutLoaderBlock = 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 */
TRACE("Options: %s\n", Options);
/* Fill Arc BootDevice */
- LoaderBlock->ArcBootDeviceName = MmHeapAlloc(strlen(ArcBoot)+1);
- strcpy(LoaderBlock->ArcBootDeviceName, ArcBoot);
+ LoaderBlock->ArcBootDeviceName = WinLdrSystemBlock->ArcBootDeviceName;
+ strncpy(LoaderBlock->ArcBootDeviceName, ArcBoot, MAX_PATH);
LoaderBlock->ArcBootDeviceName = PaToVa(LoaderBlock->ArcBootDeviceName);
/* Fill Arc HalDevice, it matches ArcBoot path */
- LoaderBlock->ArcHalDeviceName = MmHeapAlloc(strlen(ArcBoot)+1);
- strcpy(LoaderBlock->ArcHalDeviceName, ArcBoot);
+ LoaderBlock->ArcHalDeviceName = WinLdrSystemBlock->ArcBootDeviceName;
LoaderBlock->ArcHalDeviceName = PaToVa(LoaderBlock->ArcHalDeviceName);
/* Fill SystemRoot */
- LoaderBlock->NtBootPathName = MmHeapAlloc(strlen(SystemRoot)+1);
- strcpy(LoaderBlock->NtBootPathName, SystemRoot);
+ LoaderBlock->NtBootPathName = WinLdrSystemBlock->NtBootPathName;
+ strncpy(LoaderBlock->NtBootPathName, SystemRoot, MAX_PATH);
LoaderBlock->NtBootPathName = PaToVa(LoaderBlock->NtBootPathName);
/* Fill NtHalPathName */
- LoaderBlock->NtHalPathName = MmHeapAlloc(strlen(HalPath)+1);
- strcpy(LoaderBlock->NtHalPathName, HalPath);
+ LoaderBlock->NtHalPathName = WinLdrSystemBlock->NtHalPathName;
+ strncpy(LoaderBlock->NtHalPathName, HalPath, MAX_PATH);
LoaderBlock->NtHalPathName = PaToVa(LoaderBlock->NtHalPathName);
- /* Fill load options */
- LoaderBlock->LoadOptions = MmHeapAlloc(strlen(Options)+1);
- strcpy(LoaderBlock->LoadOptions, Options);
+ /* 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 */
- LoaderBlock->ArcDiskInformation = (PARC_DISK_INFORMATION)MmHeapAlloc(sizeof(ARC_DISK_INFORMATION));
+ LoaderBlock->ArcDiskInformation = &WinLdrSystemBlock->ArcDiskInformation;
InitializeListHead(&LoaderBlock->ArcDiskInformation->DiskSignatureListHead);
/* Convert ARC disk information from freeldr to a correct format */
for (i = 0; i < reactos_disk_count; i++)
{
- PARC_DISK_SIGNATURE ArcDiskInfo;
+ PARC_DISK_SIGNATURE_EX ArcDiskSig;
- /* Get the ARC structure */
- ArcDiskInfo = (PARC_DISK_SIGNATURE)MmHeapAlloc(sizeof(ARC_DISK_SIGNATURE));
- RtlZeroMemory(ArcDiskInfo, sizeof(ARC_DISK_SIGNATURE));
+ /* Allocate the ARC structure */
+ ArcDiskSig = HeapAllocate(FrLdrDefaultHeap,
+ sizeof(ARC_DISK_SIGNATURE_EX),
+ 'giSD');
/* Copy the data over */
- ArcDiskInfo->Signature = reactos_arc_disk_info[i].Signature;
- ArcDiskInfo->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 */
- ArcDiskInfo->ArcName = (PCHAR)MmHeapAlloc(sizeof(CHAR)*256);
- strcpy(ArcDiskInfo->ArcName, reactos_arc_disk_info[i].ArcName);
- ArcDiskInfo->ArcName = (PCHAR)PaToVa(ArcDiskInfo->ArcName);
+ strncpy(ArcDiskSig->ArcName, reactos_arc_disk_info[i].ArcName, MAX_PATH);
+ ArcDiskSig->DiskSignature.ArcName = PaToVa(ArcDiskSig->ArcName);
/* Mark partition table as valid */
- ArcDiskInfo->ValidPartitionTable = TRUE;
+ ArcDiskSig->DiskSignature.ValidPartitionTable = TRUE;
/* Insert into the list */
InsertTailList(&LoaderBlock->ArcDiskInformation->DiskSignatureListHead,
- &ArcDiskInfo->ListEntry);
+ &ArcDiskSig->DiskSignature.ListEntry);
}
/* Convert all list's to Virtual address */
List_PaToVa(&LoaderBlock->BootDriverListHead);
/* Initialize Extension now */
- Extension = MmHeapAlloc(sizeof(LOADER_PARAMETER_EXTENSION));
- if (Extension == NULL)
- {
- UiMessageBox("Failed to allocate LPB Extension!");
- return;
- }
- RtlZeroMemory(Extension, sizeof(LOADER_PARAMETER_EXTENSION));
-
- /* Fill LPB extension */
+ Extension = &WinLdrSystemBlock->Extension;
Extension->Size = sizeof(LOADER_PARAMETER_EXTENSION);
Extension->MajorVersion = (VersionToBoot & 0xFF00) >> 8;
Extension->MinorVersion = VersionToBoot & 0xFF;
/* Set headless block pointer */
if (WinLdrTerminalConnected)
{
- Extension->HeadlessLoaderBlock = MmHeapAlloc(sizeof(HEADLESS_LOADER_BLOCK));
- if (Extension->HeadlessLoaderBlock == NULL)
- {
- UiMessageBox("Failed to allocate HLB Extension!");
- while (TRUE);
- return;
- }
- RtlCopyMemory(
- Extension->HeadlessLoaderBlock,
- &LoaderRedirectionInformation,
- sizeof(HEADLESS_LOADER_BLOCK));
+ Extension->HeadlessLoaderBlock = &WinLdrSystemBlock->HeadlessLoaderBlock;
+ RtlCopyMemory(Extension->HeadlessLoaderBlock,
+ &LoaderRedirectionInformation,
+ sizeof(HEADLESS_LOADER_BLOCK));
Extension->HeadlessLoaderBlock = PaToVa(Extension->HeadlessLoaderBlock);
}
#endif
strcpy(MiscFiles, BootPath);
strcat(MiscFiles, "AppPatch\\drvmain.sdb");
Extension->DrvDBImage = PaToVa(WinLdrLoadModule(MiscFiles,
- &Extension->DrvDBSize, LoaderRegistryData));
+ &Extension->DrvDBSize,
+ LoaderRegistryData));
/* Convert extension and setup block pointers */
LoaderBlock->Extension = PaToVa(Extension);
if (LoaderBlock->SetupLdrBlock)
LoaderBlock->SetupLdrBlock = PaToVa(LoaderBlock->SetupLdrBlock);
+ TRACE("WinLdrInitializePhase1() completed\n");
}
-BOOLEAN
-WinLdrLoadDeviceDriver(PLOADER_PARAMETER_BLOCK LoaderBlock,
+static BOOLEAN
+WinLdrLoadDeviceDriver(PLIST_ENTRY LoadOrderListHead,
LPSTR BootPath,
PUNICODE_STRING FilePath,
ULONG Flags,
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, DllName, DriverDTE);
+ Status = WinLdrCheckForLoadedDll(LoadOrderListHead, DllName, DriverDTE);
if (Status)
{
// We've got the pointer to its DTE, just return success
return FALSE;
// Allocate a DTE for it
- Status = WinLdrAllocateDataTableEntry(LoaderBlock, DllName, DllName, DriverBase, DriverDTE);
+ Status = WinLdrAllocateDataTableEntry(LoadOrderListHead, DllName, DllName, DriverBase, DriverDTE);
if (!Status)
{
ERR("WinLdrAllocateDataTableEntry() failed\n");
// Look for any dependencies it may have, and load them too
sprintf(FullPath,"%s%s", BootPath, DriverPath);
- Status = WinLdrScanImportDescriptorTable(LoaderBlock, FullPath, *DriverDTE);
+ Status = WinLdrScanImportDescriptorTable(LoadOrderListHead, FullPath, *DriverDTE);
if (!Status)
{
ERR("WinLdrScanImportDescriptorTable() failed for %s\n", FullPath);
// 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
return _WIN32_WINNT_WS03;
}
+static
PVOID
LoadModule(
PLOADER_PARAMETER_BLOCK LoaderBlock,
PCCH Path,
PCCH File,
+ TYPE_OF_MEMORY MemoryType,
PLDR_DATA_TABLE_ENTRY *Dte,
ULONG Percentage)
{
strcat(FullFileName, "SYSTEM32\\");
strcat(FullFileName, File);
- Status = WinLdrLoadImage(FullFileName, LoaderSystemCode, &BaseAdress);
+ Status = WinLdrLoadImage(FullFileName, MemoryType, &BaseAdress);
TRACE("%s loaded with status %d at %p\n",
File, Status, BaseAdress);
strcpy(FullFileName, "WINDOWS\\SYSTEM32\\");
strcat(FullFileName, File);
- WinLdrAllocateDataTableEntry(LoaderBlock, File,
+ WinLdrAllocateDataTableEntry(&LoaderBlock->LoadOrderListHead, File,
FullFileName, BaseAdress, Dte);
return BaseAdress;
}
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...");
if (!HasSection ||
!IniReadSettingByName(SectionId, "SystemPath", BootPath, sizeof(BootPath)))
{
- strcpy(BootPath, OperatingSystemName);
+ strcpy(BootPath, SectionName);
}
/* Special case for LiveCD */
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 != '"')
AllocateAndInitLPB(&LoaderBlock);
#ifdef _M_IX86
- /* Setup redirection support */
+ /* Setup redirection support */
WinLdrSetupEms(BootOptions);
#endif
OperatingSystemVersion = WinLdrDetectVersion();
/* Load kernel */
- LoadModule(LoaderBlock, BootPath, "NTOSKRNL.EXE", &KernelDTE, 30);
+ LoadModule(LoaderBlock, BootPath, "NTOSKRNL.EXE", LoaderSystemCode, &KernelDTE, 30);
/* Load HAL */
- LoadModule(LoaderBlock, BootPath, "HAL.DLL", &HalDTE, 45);
+ LoadModule(LoaderBlock, BootPath, "HAL.DLL", LoaderHalCode, &HalDTE, 45);
/* Load kernel-debugger support dll */
if (OperatingSystemVersion > _WIN32_WINNT_WIN2K)
{
- LoadModule(LoaderBlock, BootPath, "KDCOM.DLL", &KdComDTE, 60);
+ LoadModule(LoaderBlock, BootPath, "KDCOM.DLL", LoaderSystemCode, &KdComDTE, 60);
}
/* Load all referenced DLLs for kernel, HAL and kdcom.dll */
strcpy(FileName, BootPath);
strcat(FileName, "system32\\");
- Status = WinLdrScanImportDescriptorTable(LoaderBlock, FileName, KernelDTE);
- Status &= WinLdrScanImportDescriptorTable(LoaderBlock, FileName, HalDTE);
+ Status = WinLdrScanImportDescriptorTable(&LoaderBlock->LoadOrderListHead, FileName, KernelDTE);
+ Status &= WinLdrScanImportDescriptorTable(&LoaderBlock->LoadOrderListHead, FileName, HalDTE);
if (KdComDTE)
- Status &= WinLdrScanImportDescriptorTable(LoaderBlock, FileName, KdComDTE);
+ Status &= WinLdrScanImportDescriptorTable(&LoaderBlock->LoadOrderListHead, FileName, KdComDTE);
if (!Status)
{
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) {};