[FREELDR] NT loader: Allocate the Loader Block Extension much earlier in the process.

This commit is contained in:
Hermès Bélusca-Maïto 2019-10-06 18:24:48 +02:00
parent eeeca29c6c
commit 2d1a6b2db9
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
2 changed files with 45 additions and 30 deletions

View file

@ -17,7 +17,10 @@ DBG_DEFAULT_CHANNEL(WINDOWS);
#define TAG_BOOT_OPTIONS 'pOtB' #define TAG_BOOT_OPTIONS 'pOtB'
// TODO: Move to .h // TODO: Move to .h
VOID AllocateAndInitLPB(PLOADER_PARAMETER_BLOCK *OutLoaderBlock); VOID
AllocateAndInitLPB(
IN USHORT VersionToBoot,
OUT PLOADER_PARAMETER_BLOCK* OutLoaderBlock);
static VOID static VOID
SetupLdrLoadNlsData(PLOADER_PARAMETER_BLOCK LoaderBlock, HINF InfHandle, PCSTR SearchPath) SetupLdrLoadNlsData(PLOADER_PARAMETER_BLOCK LoaderBlock, HINF InfHandle, PCSTR SearchPath)
@ -79,6 +82,7 @@ SetupLdrLoadNlsData(PLOADER_PARAMETER_BLOCK LoaderBlock, HINF InfHandle, PCSTR S
static static
BOOLEAN BOOLEAN
SetupLdrInitErrataInf( SetupLdrInitErrataInf(
IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
IN HINF InfHandle, IN HINF InfHandle,
IN PCSTR SystemRoot) IN PCSTR SystemRoot)
{ {
@ -111,8 +115,8 @@ SetupLdrInitErrataInf(
return FALSE; return FALSE;
} }
WinLdrSystemBlock->Extension.EmInfFileImage = PaToVa(PhysicalBase); LoaderBlock->Extension->EmInfFileImage = PaToVa(PhysicalBase);
WinLdrSystemBlock->Extension.EmInfFileSize = FileSize; LoaderBlock->Extension->EmInfFileSize = FileSize;
return TRUE; return TRUE;
} }
@ -350,8 +354,8 @@ LoadReactOSSetup(
TRACE("BootOptions: '%s'\n", BootOptions); TRACE("BootOptions: '%s'\n", BootOptions);
/* Allocate and minimalist-initialize LPB */ /* Allocate and minimally-initialize the Loader Parameter Block */
AllocateAndInitLPB(&LoaderBlock); AllocateAndInitLPB(_WIN32_WINNT_WS03, &LoaderBlock);
/* Allocate and initialize setup loader block */ /* Allocate and initialize setup loader block */
SetupBlock = &WinLdrSystemBlock->SetupBlock; SetupBlock = &WinLdrSystemBlock->SetupBlock;
@ -375,7 +379,7 @@ LoadReactOSSetup(
SetupLdrLoadNlsData(LoaderBlock, InfHandle, FileName); SetupLdrLoadNlsData(LoaderBlock, InfHandle, FileName);
/* Load the Firmware Errata file from the installation medium */ /* Load the Firmware Errata file from the installation medium */
Success = SetupLdrInitErrataInf(InfHandle, BootPath); Success = SetupLdrInitErrataInf(LoaderBlock, InfHandle, BootPath);
TRACE("Firmware Errata file %s\n", (Success ? "loaded" : "not loaded")); TRACE("Firmware Errata file %s\n", (Success ? "loaded" : "not loaded"));
/* Not necessarily fatal if not found - carry on going */ /* Not necessarily fatal if not found - carry on going */

View file

@ -31,11 +31,14 @@ VOID DumpMemoryAllocMap(VOID);
// Init "phase 0" // Init "phase 0"
VOID VOID
AllocateAndInitLPB(PLOADER_PARAMETER_BLOCK *OutLoaderBlock) AllocateAndInitLPB(
IN USHORT VersionToBoot,
OUT PLOADER_PARAMETER_BLOCK* OutLoaderBlock)
{ {
PLOADER_PARAMETER_BLOCK LoaderBlock; PLOADER_PARAMETER_BLOCK LoaderBlock;
PLOADER_PARAMETER_EXTENSION Extension;
/* Allocate and zero-init the LPB */ /* Allocate and zero-init the Loader Parameter Block */
WinLdrSystemBlock = MmAllocateMemoryWithType(sizeof(LOADER_SYSTEM_BLOCK), WinLdrSystemBlock = MmAllocateMemoryWithType(sizeof(LOADER_SYSTEM_BLOCK),
LoaderSystemBlock); LoaderSystemBlock);
if (WinLdrSystemBlock == NULL) if (WinLdrSystemBlock == NULL)
@ -49,6 +52,13 @@ AllocateAndInitLPB(PLOADER_PARAMETER_BLOCK *OutLoaderBlock)
LoaderBlock = &WinLdrSystemBlock->LoaderBlock; LoaderBlock = &WinLdrSystemBlock->LoaderBlock;
LoaderBlock->NlsData = &WinLdrSystemBlock->NlsDataBlock; LoaderBlock->NlsData = &WinLdrSystemBlock->NlsDataBlock;
/* Initialize the Loader Block Extension */
Extension = &WinLdrSystemBlock->Extension;
LoaderBlock->Extension = Extension;
Extension->Size = sizeof(LOADER_PARAMETER_EXTENSION);
Extension->MajorVersion = (VersionToBoot & 0xFF00) >> 8;
Extension->MinorVersion = (VersionToBoot & 0xFF);
/* Init three critical lists, used right away */ /* Init three critical lists, used right away */
InitializeListHead(&LoaderBlock->LoadOrderListHead); InitializeListHead(&LoaderBlock->LoadOrderListHead);
InitializeListHead(&LoaderBlock->MemoryDescriptorListHead); InitializeListHead(&LoaderBlock->MemoryDescriptorListHead);
@ -99,16 +109,16 @@ WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock,
// SetupBlock->ArcSetupDeviceName must be the path to the setup **SOURCE**, // SetupBlock->ArcSetupDeviceName must be the path to the setup **SOURCE**,
// and not the setup boot path. Indeed they may differ!! // and not the setup boot path. Indeed they may differ!!
// //
/* If we have a setup block, adjust also its ARC path */
if (LoaderBlock->SetupLdrBlock) if (LoaderBlock->SetupLdrBlock)
{ {
PSETUP_LOADER_BLOCK SetupBlock = LoaderBlock->SetupLdrBlock; PSETUP_LOADER_BLOCK SetupBlock = LoaderBlock->SetupLdrBlock;
/* Matches ArcBoot path */ /* Adjust the ARC path in the setup block - Matches ArcBoot path */
SetupBlock->ArcSetupDeviceName = WinLdrSystemBlock->ArcBootDeviceName; SetupBlock->ArcSetupDeviceName = WinLdrSystemBlock->ArcBootDeviceName;
SetupBlock->ArcSetupDeviceName = PaToVa(SetupBlock->ArcSetupDeviceName); SetupBlock->ArcSetupDeviceName = PaToVa(SetupBlock->ArcSetupDeviceName);
/* Note: LoaderBlock->SetupLdrBlock is PaToVa'ed at the end of this function */ /* Convert the setup block pointer */
LoaderBlock->SetupLdrBlock = PaToVa(LoaderBlock->SetupLdrBlock);
} }
/* Fill ARC HalDevice, it matches ArcBoot path */ /* Fill ARC HalDevice, it matches ArcBoot path */
@ -162,7 +172,7 @@ WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock,
&ArcDiskSig->DiskSignature.ListEntry); &ArcDiskSig->DiskSignature.ListEntry);
} }
/* Convert all list's to Virtual address */ /* Convert all lists to Virtual address */
/* Convert the ArcDisks list to virtual address */ /* Convert the ArcDisks list to virtual address */
List_PaToVa(&LoaderBlock->ArcDiskInformation->DiskSignatureListHead); List_PaToVa(&LoaderBlock->ArcDiskInformation->DiskSignatureListHead);
@ -181,11 +191,9 @@ WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock,
/* Convert list of boot drivers */ /* Convert list of boot drivers */
List_PaToVa(&LoaderBlock->BootDriverListHead); List_PaToVa(&LoaderBlock->BootDriverListHead);
/* Initialize Extension now */ Extension = LoaderBlock->Extension;
Extension = &WinLdrSystemBlock->Extension;
Extension->Size = sizeof(LOADER_PARAMETER_EXTENSION); /* FIXME! HACK value for docking profile */
Extension->MajorVersion = (VersionToBoot & 0xFF00) >> 8;
Extension->MinorVersion = VersionToBoot & 0xFF;
Extension->Profile.Status = 2; Extension->Profile.Status = 2;
/* Check if FreeLdr detected a ACPI table */ /* Check if FreeLdr detected a ACPI table */
@ -214,11 +222,8 @@ WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock,
&Extension->DrvDBSize, &Extension->DrvDBSize,
LoaderRegistryData)); LoaderRegistryData));
/* Convert extension and setup block pointers */ /* Convert the extension block pointer */
LoaderBlock->Extension = PaToVa(Extension); LoaderBlock->Extension = PaToVa(LoaderBlock->Extension);
if (LoaderBlock->SetupLdrBlock)
LoaderBlock->SetupLdrBlock = PaToVa(LoaderBlock->SetupLdrBlock);
TRACE("WinLdrInitializePhase1() completed\n"); TRACE("WinLdrInitializePhase1() completed\n");
} }
@ -654,6 +659,7 @@ LoadWindowsCore(IN USHORT OperatingSystemVersion,
static static
BOOLEAN BOOLEAN
WinLdrInitErrataInf( WinLdrInitErrataInf(
IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
IN USHORT OperatingSystemVersion, IN USHORT OperatingSystemVersion,
IN PCSTR SystemRoot) IN PCSTR SystemRoot)
{ {
@ -706,8 +712,8 @@ WinLdrInitErrataInf(
return FALSE; return FALSE;
} }
WinLdrSystemBlock->Extension.EmInfFileImage = PaToVa(PhysicalBase); LoaderBlock->Extension->EmInfFileImage = PaToVa(PhysicalBase);
WinLdrSystemBlock->Extension.EmInfFileSize = FileSize; LoaderBlock->Extension->EmInfFileSize = FileSize;
return TRUE; return TRUE;
} }
@ -864,8 +870,8 @@ LoadAndBootWindows(
/* Let user know we started loading */ /* Let user know we started loading */
//UiDrawStatusText("Loading..."); //UiDrawStatusText("Loading...");
/* Allocate and minimalist-initialize LPB */ /* Allocate and minimally-initialize the Loader Parameter Block */
AllocateAndInitLPB(&LoaderBlock); AllocateAndInitLPB(OperatingSystemVersion, &LoaderBlock);
/* Load the system hive */ /* Load the system hive */
UiDrawBackdrop(); UiDrawBackdrop();
@ -876,6 +882,12 @@ LoadAndBootWindows(
if (!Success) if (!Success)
return ENOEXEC; return ENOEXEC;
/* Fixup the version number using data from the registry */
if (OperatingSystemVersion == 0)
OperatingSystemVersion = WinLdrDetectVersion();
LoaderBlock->Extension->MajorVersion = (OperatingSystemVersion & 0xFF00) >> 8;
LoaderBlock->Extension->MinorVersion = (OperatingSystemVersion & 0xFF);
/* Load NLS data, OEM font, and prepare boot drivers list */ /* Load NLS data, OEM font, and prepare boot drivers list */
Success = WinLdrScanSystemHive(LoaderBlock, BootPath); Success = WinLdrScanSystemHive(LoaderBlock, BootPath);
TRACE("SYSTEM hive %s\n", (Success ? "scanned" : "not scanned")); TRACE("SYSTEM hive %s\n", (Success ? "scanned" : "not scanned"));
@ -884,7 +896,7 @@ LoadAndBootWindows(
return ENOEXEC; return ENOEXEC;
/* Load the Firmware Errata file */ /* Load the Firmware Errata file */
Success = WinLdrInitErrataInf(OperatingSystemVersion, BootPath); Success = WinLdrInitErrataInf(LoaderBlock, OperatingSystemVersion, BootPath);
TRACE("Firmware Errata file %s\n", (Success ? "loaded" : "not loaded")); TRACE("Firmware Errata file %s\n", (Success ? "loaded" : "not loaded"));
/* Not necessarily fatal if not found - carry on going */ /* Not necessarily fatal if not found - carry on going */
@ -912,6 +924,8 @@ LoadAndBootWindowsCommon(
TRACE("LoadAndBootWindowsCommon()\n"); TRACE("LoadAndBootWindowsCommon()\n");
ASSERT(OperatingSystemVersion != 0);
#ifdef _M_IX86 #ifdef _M_IX86
/* Setup redirection support */ /* Setup redirection support */
WinLdrSetupEms((PCHAR)BootOptions); WinLdrSetupEms((PCHAR)BootOptions);
@ -925,9 +939,6 @@ LoadAndBootWindowsCommon(
UiDrawProgressBarCenter(20, 100, "Detecting hardware..."); UiDrawProgressBarCenter(20, 100, "Detecting hardware...");
LoaderBlock->ConfigurationRoot = MachHwDetect(); LoaderBlock->ConfigurationRoot = MachHwDetect();
if (OperatingSystemVersion == 0)
OperatingSystemVersion = WinLdrDetectVersion();
/* Load the operating system core: the Kernel, the HAL and the Kernel Debugger Transport DLL */ /* Load the operating system core: the Kernel, the HAL and the Kernel Debugger Transport DLL */
Success = LoadWindowsCore(OperatingSystemVersion, Success = LoadWindowsCore(OperatingSystemVersion,
LoaderBlock, LoaderBlock,