[FREELDR] Allow Freeloader to boot Vista revamp of PR #1905 (#6479)

[FREELDR] Add "WindowsVista" boot type
[FREELDR] Set GDT correctly for Vista
[FREELDR] Map first page of memory, this is an observed behavior, and
also increases stability boot Checked windows 2003 SP2 ntoskrnl with
freeloader.
[SDK] Don't assert on big keys in bootloader

Co-authored-by: Justin Miller <justin.miller@reactos.org>
This commit is contained in:
Mark Harmstone 2019-09-09 19:45:42 +01:00 committed by Justin Miller
parent 6d853be981
commit dd6c1c8843
8 changed files with 47 additions and 21 deletions

View file

@ -69,6 +69,7 @@ OSLoadingMethods[] =
#endif #endif
{"Windows" , EditCustomBootNTOS , LoadAndBootWindows}, {"Windows" , EditCustomBootNTOS , LoadAndBootWindows},
{"Windows2003" , EditCustomBootNTOS , LoadAndBootWindows}, {"Windows2003" , EditCustomBootNTOS , LoadAndBootWindows},
{"WindowsVista", EditCustomBootNTOS , LoadAndBootWindows},
}; };
/* FUNCTIONS ******************************************************************/ /* FUNCTIONS ******************************************************************/

View file

@ -346,7 +346,8 @@ Amd64SetupIdt(PVOID IdtBase)
} }
VOID VOID
WinLdrSetProcessorContext(void) WinLdrSetProcessorContext(
_In_ USHORT OperatingSystemVersion)
{ {
TRACE("WinLdrSetProcessorContext\n"); TRACE("WinLdrSetProcessorContext\n");

View file

@ -249,7 +249,8 @@ MempAllocatePageTables(VOID)
} }
VOID VOID
WinLdrSetProcessorContext(VOID) WinLdrSetProcessorContext(
_In_ USHORT OperatingSystemVersion)
{ {
ARM_CONTROL_REGISTER ControlRegister; ARM_CONTROL_REGISTER ControlRegister;
ARM_TTB_REGISTER TtbRegister; ARM_TTB_REGISTER TtbRegister;

View file

@ -245,7 +245,7 @@ MempSetupPaging(IN PFN_NUMBER StartPage,
} }
PhysicalPT[Page & 0x3ff].PageFrameNumber = Page; PhysicalPT[Page & 0x3ff].PageFrameNumber = Page;
PhysicalPT[Page & 0x3ff].Valid = (Page != 0); PhysicalPT[Page & 0x3ff].Valid = 1;
PhysicalPT[Page & 0x3ff].Write = (Page != 0); PhysicalPT[Page & 0x3ff].Write = (Page != 0);
if (KernelMapping) if (KernelMapping)
@ -429,7 +429,8 @@ void WinLdrSetupMachineDependent(PLOADER_PARAMETER_BLOCK LoaderBlock)
VOID VOID
WinLdrSetProcessorContext(void) WinLdrSetProcessorContext(
_In_ USHORT OperatingSystemVersion)
{ {
GDTIDT GdtDesc, IdtDesc, OldIdt; GDTIDT GdtDesc, IdtDesc, OldIdt;
PKGDTENTRY pGdt; PKGDTENTRY pGdt;
@ -526,15 +527,19 @@ WinLdrSetProcessorContext(void)
* Longhorn/Vista reports LimitLow == 0x0fff == MM_PAGE_SIZE - 1, whereas * Longhorn/Vista reports LimitLow == 0x0fff == MM_PAGE_SIZE - 1, whereas
* Windows 7+ uses larger sizes there (not aligned on a page boundary). * Windows 7+ uses larger sizes there (not aligned on a page boundary).
*/ */
#if 1 if (OperatingSystemVersion < _WIN32_WINNT_VISTA)
{
/* Server 2003 way */ /* Server 2003 way */
KiSetGdtEntryEx(KiGetGdtEntry(pGdt, KGDT_R0_PCR), (ULONG32)Pcr, 0x1, KiSetGdtEntryEx(KiGetGdtEntry(pGdt, KGDT_R0_PCR), (ULONG32)Pcr, 0x1,
TYPE_DATA, DPL_SYSTEM, TRUE, 2); TYPE_DATA, DPL_SYSTEM, TRUE, 2);
#else }
else
{
/* Vista+ way */ /* Vista+ way */
KiSetGdtEntry(KiGetGdtEntry(pGdt, KGDT_R0_PCR), (ULONG32)Pcr, MM_PAGE_SIZE - 1, KiSetGdtEntry(KiGetGdtEntry(pGdt, KGDT_R0_PCR), (ULONG32)Pcr, MM_PAGE_SIZE - 1,
TYPE_DATA, DPL_SYSTEM, 2); TYPE_DATA, DPL_SYSTEM, 2);
#endif }
// DumpGDTEntry(GdtDesc.Base, KGDT_R0_PCR); // DumpGDTEntry(GdtDesc.Base, KGDT_R0_PCR);
/* KGDT_R3_TEB (0x38) Thread Environment Block Selector (Ring 3) */ /* KGDT_R3_TEB (0x38) Thread Environment Block Selector (Ring 3) */

View file

@ -255,6 +255,15 @@ WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock,
// FIXME: Extension->AcpiTableSize; // FIXME: Extension->AcpiTableSize;
} }
if (VersionToBoot >= _WIN32_WINNT_VISTA)
{
Extension->BootViaWinload = 1;
Extension->LoaderPerformanceData = PaToVa(&WinLdrSystemBlock->LoaderPerformanceData);
InitializeListHead(&Extension->BootApplicationPersistentData);
List_PaToVa(&Extension->BootApplicationPersistentData);
}
#ifdef _M_IX86 #ifdef _M_IX86
/* Set headless block pointer */ /* Set headless block pointer */
if (WinLdrTerminalConnected) if (WinLdrTerminalConnected)
@ -999,6 +1008,10 @@ LoadAndBootWindows(
{ {
OperatingSystemVersion = _WIN32_WINNT_NT4; OperatingSystemVersion = _WIN32_WINNT_NT4;
} }
else if (_stricmp(ArgValue, "WindowsVista") == 0)
{
OperatingSystemVersion = _WIN32_WINNT_VISTA;
}
else else
{ {
ERR("Unknown 'BootType' value '%s', aborting!\n", ArgValue); ERR("Unknown 'BootType' value '%s', aborting!\n", ArgValue);
@ -1245,7 +1258,7 @@ LoadAndBootWindowsCommon(
WinLdrSetupMemoryLayout(LoaderBlock); WinLdrSetupMemoryLayout(LoaderBlock);
/* Set processor context */ /* Set processor context */
WinLdrSetProcessorContext(); WinLdrSetProcessorContext(OperatingSystemVersion);
/* Save final value of LoaderPagesSpanned */ /* Save final value of LoaderPagesSpanned */
LoaderBlock->Extension->LoaderPagesSpanned = LoaderPagesSpanned; LoaderBlock->Extension->LoaderPagesSpanned = LoaderPagesSpanned;

View file

@ -58,6 +58,7 @@ typedef struct _LOADER_SYSTEM_BLOCK
CHAR NtBootPathName[MAX_PATH+1]; CHAR NtBootPathName[MAX_PATH+1];
CHAR NtHalPathName[MAX_PATH+1]; CHAR NtHalPathName[MAX_PATH+1];
ARC_DISK_INFORMATION ArcDiskInformation; ARC_DISK_INFORMATION ArcDiskInformation;
LOADER_PERFORMANCE_DATA LoaderPerformanceData;
} LOADER_SYSTEM_BLOCK, *PLOADER_SYSTEM_BLOCK; } LOADER_SYSTEM_BLOCK, *PLOADER_SYSTEM_BLOCK;
extern PLOADER_SYSTEM_BLOCK WinLdrSystemBlock; extern PLOADER_SYSTEM_BLOCK WinLdrSystemBlock;
@ -164,7 +165,8 @@ VOID
WinLdrSetupMachineDependent(PLOADER_PARAMETER_BLOCK LoaderBlock); WinLdrSetupMachineDependent(PLOADER_PARAMETER_BLOCK LoaderBlock);
VOID VOID
WinLdrSetProcessorContext(VOID); WinLdrSetProcessorContext(
_In_ USHORT OperatingSystemVersion);
// arch/xxx/winldr.c // arch/xxx/winldr.c
BOOLEAN BOOLEAN

View file

@ -185,7 +185,7 @@ WinLdrSetupMemoryLayout(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock)
PPAGE_LOOKUP_TABLE_ITEM MemoryMap; PPAGE_LOOKUP_TABLE_ITEM MemoryMap;
ULONG LastPageType; ULONG LastPageType;
//PKTSS Tss; //PKTSS Tss;
//BOOLEAN Status; BOOLEAN Status;
/* Cleanup heap */ /* Cleanup heap */
FrLdrHeapCleanupAll(); FrLdrHeapCleanupAll();
@ -229,15 +229,14 @@ WinLdrSetupMemoryLayout(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock)
MemoryMapSizeInPages = (NoEntries * sizeof(PAGE_LOOKUP_TABLE_ITEM) + MM_PAGE_SIZE - 1) / MM_PAGE_SIZE; MemoryMapSizeInPages = (NoEntries * sizeof(PAGE_LOOKUP_TABLE_ITEM) + MM_PAGE_SIZE - 1) / MM_PAGE_SIZE;
TRACE("Got memory map with %d entries\n", NoEntries); TRACE("Got memory map with %d entries\n", NoEntries);
#if 0
// Always contiguously map low 1Mb of memory // Always map first page of memory
Status = MempSetupPaging(0, 0x100, FALSE); Status = MempSetupPaging(0, 1, FALSE);
if (!Status) if (!Status)
{ {
ERR("Error during MempSetupPaging of low 1Mb\n"); ERR("Error during MempSetupPaging of first page\n");
return FALSE; return FALSE;
} }
#endif
/* Before creating the map, we need to map pages to kernel mode */ /* Before creating the map, we need to map pages to kernel mode */
LastPageIndex = 1; LastPageIndex = 1;

View file

@ -379,8 +379,12 @@ extern ULONG CmlibTraceLevel;
// //
// Hack since big keys are not yet supported // Hack since big keys are not yet supported
// //
#ifdef _BLDR_
#define ASSERT_VALUE_BIG(h, s) DbgPrint("Big keys aren't supported!\n");
#else
#define ASSERT_VALUE_BIG(h, s) \ #define ASSERT_VALUE_BIG(h, s) \
ASSERTMSG("Big keys not supported!\n", !CmpIsKeyValueBig(h, s)); ASSERTMSG("Big keys not supported!\n", !CmpIsKeyValueBig(h, s));
#endif
// //
// Returns whether or not this is a small valued key // Returns whether or not this is a small valued key