#include <ndk/ldrtypes.h>
#include <debug.h>
+DBG_DEFAULT_CHANNEL(WINDOWS);
+
//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 */
strncpy(ArcBoot, BootPath, PathSeparator);
ArcBoot[PathSeparator] = 0;
- DPRINTM(DPRINT_WINDOWS, "ArcBoot: %s\n", ArcBoot);
- DPRINTM(DPRINT_WINDOWS, "SystemRoot: %s\n", SystemRoot);
- DPRINTM(DPRINT_WINDOWS, "Options: %s\n", Options);
+ TRACE("ArcBoot: %s\n", ArcBoot);
+ TRACE("SystemRoot: %s\n", SystemRoot);
+ 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;
}
- DPRINTM(DPRINT_WINDOWS, "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)
{
- DPRINTM(DPRINT_WINDOWS, "WinLdrAllocateDataTableEntry() failed\n");
+ ERR("WinLdrAllocateDataTableEntry() failed\n");
return FALSE;
}
// 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)
{
- DPRINTM(DPRINT_WINDOWS, "WinLdrScanImportDescriptorTable() failed for %s\n",
- FullPath);
+ ERR("WinLdrScanImportDescriptorTable() failed for %s\n", FullPath);
return FALSE;
}
{
BootDriver = CONTAINING_RECORD(NextBd, BOOT_DRIVER_LIST_ENTRY, Link);
- DPRINTM(DPRINT_WINDOWS, "BootDriver %wZ DTE %08X RegPath: %wZ\n", &BootDriver->FilePath,
+ TRACE("BootDriver %wZ DTE %08X RegPath: %wZ\n", &BootDriver->FilePath,
BootDriver->LdrEntry, &BootDriver->RegistryPath);
// 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
//sprintf(ProgressString, "Loading %s...", FileName);
//UiDrawProgressBarCenter(1, 100, ProgressString);
- DPRINTM(DPRINT_WINDOWS, "Loading module %s\n", ModuleName);
+ TRACE("Loading module %s\n", ModuleName);
*Size = 0;
/* Open the image file */
return NULL;
}
- DPRINTM(DPRINT_WINDOWS, "Loaded %s at 0x%x with size 0x%x\n", ModuleName, PhysicalBase, FileSize);
+ TRACE("Loaded %s at 0x%x with size 0x%x\n", ModuleName, PhysicalBase, FileSize);
return PhysicalBase;
}
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);
- DPRINTM(DPRINT_WINDOWS, "%s loaded with status %d at %p\n",
+ 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 != '"')
p++;
strcpy(BootOptions, p);
- DPRINTM(DPRINT_WINDOWS,"BootOptions: '%s'\n", BootOptions);
+ TRACE("BootOptions: '%s'\n", BootOptions);
}
/* Append boot-time options */
/* Let user know we started loading */
//UiDrawStatusText("Loading...");
- DPRINTM(DPRINT_WINDOWS,"BootPath: '%s'\n", BootPath);
+ TRACE("BootPath: '%s'\n", BootPath);
/* Allocate and minimalistic-initialize LPB */
AllocateAndInitLPB(&LoaderBlock);
#ifdef _M_IX86
- /* Setup redirection support */
+ /* Setup redirection support */
WinLdrSetupEms(BootOptions);
#endif
UiDrawBackdrop();
UiDrawProgressBarCenter(15, 100, "Loading system hive...");
Status = WinLdrInitSystemHive(LoaderBlock, BootPath);
- DPRINTM(DPRINT_WINDOWS, "SYSTEM hive loaded with status %d\n", Status);
+ TRACE("SYSTEM hive loaded with status %d\n", Status);
/* Load NLS data, OEM font, and prepare boot drivers list */
Status = WinLdrScanSystemHive(LoaderBlock, BootPath);
- DPRINTM(DPRINT_WINDOWS, "SYSTEM hive scanned with status %d\n", Status);
+ TRACE("SYSTEM hive scanned with status %d\n", Status);
LoadAndBootWindowsCommon(OperatingSystemVersion,
PLOADER_PARAMETER_BLOCK LoaderBlockVA;
BOOLEAN Status;
CHAR FileName[MAX_PATH];
- PVOID NtosBase = NULL, HalBase = NULL, KdComBase = NULL;
PLDR_DATA_TABLE_ENTRY KernelDTE, HalDTE, KdComDTE = NULL;
KERNEL_ENTRY_POINT KiSystemStartup;
LPCSTR SystemRoot;
+ TRACE("LoadAndBootWindowsCommon()\n");
/* Convert BootPath to SystemRoot */
SystemRoot = strstr(BootPath, "\\");
OperatingSystemVersion = WinLdrDetectVersion();
/* Load kernel */
- NtosBase = LoadModule(LoaderBlock, BootPath, "NTOSKRNL.EXE", &KernelDTE, 30);
+ LoadModule(LoaderBlock, BootPath, "NTOSKRNL.EXE", LoaderSystemCode, &KernelDTE, 30);
/* Load HAL */
- HalBase = 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)
{
- KdComBase = 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)
{
UiDrawBackdrop();
UiDrawProgressBarCenter(100, 100, "Loading boot drivers...");
Status = WinLdrLoadBootDrivers(LoaderBlock, (PCHAR)BootPath);
- DPRINTM(DPRINT_WINDOWS, "Boot drivers loaded with status %d\n", Status);
+ TRACE("Boot drivers loaded with status %d\n", Status);
/* Initialize Phase 1 - no drivers loading anymore */
WinLdrInitializePhase1(LoaderBlock, BootOptions, SystemRoot, BootPath, OperatingSystemVersion);
/* Map pages and create memory descriptors */
WinLdrSetupMemoryLayout(LoaderBlock);
- /* Save final value of LoaderPagesSpanned */
- LoaderBlock->Extension->LoaderPagesSpanned = LoaderPagesSpanned;
-
/* Set processor context */
WinLdrSetProcessorContext();
- DPRINTM(DPRINT_WINDOWS, "Hello from paged mode, KiSystemStartup %p, LoaderBlockVA %p!\n",
+ /* Save final value of LoaderPagesSpanned */
+ LoaderBlock->Extension->LoaderPagesSpanned = LoaderPagesSpanned;
+
+ TRACE("Hello from paged mode, KiSystemStartup %p, LoaderBlockVA %p!\n",
KiSystemStartup, LoaderBlockVA);
// Zero KI_USER_SHARED_DATA page
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) {};
{
MemoryDescriptor = CONTAINING_RECORD(NextMd, MEMORY_ALLOCATION_DESCRIPTOR, ListEntry);
- DPRINTM(DPRINT_WINDOWS, "BP %08X PC %04X MT %d\n", MemoryDescriptor->BasePage,
+ TRACE("BP %08X PC %04X MT %d\n", MemoryDescriptor->BasePage,
MemoryDescriptor->PageCount, MemoryDescriptor->MemoryType);
NextMd = MemoryDescriptor->ListEntry.Flink;
{
BootDriver = CONTAINING_RECORD(NextBd, BOOT_DRIVER_LIST_ENTRY, Link);
- DPRINTM(DPRINT_WINDOWS, "BootDriver %wZ DTE %08X RegPath: %wZ\n", &BootDriver->FilePath,
+ TRACE("BootDriver %wZ DTE %08X RegPath: %wZ\n", &BootDriver->FilePath,
BootDriver->LdrEntry, &BootDriver->RegistryPath);
NextBd = BootDriver->Link.Flink;
{
ArcDisk = CONTAINING_RECORD(NextBd, ARC_DISK_SIGNATURE, ListEntry);
- DPRINTM(DPRINT_WINDOWS, "ArcDisk %s checksum: 0x%X, signature: 0x%X\n",
+ TRACE("ArcDisk %s checksum: 0x%X, signature: 0x%X\n",
ArcDisk->ArcName, ArcDisk->CheckSum, ArcDisk->Signature);
NextBd = ArcDisk->ListEntry.Flink;