[FREELDR]

- Fix memory type for hal and referenced dlls
- Don't allocate the LPB, MADs and all the other stuff from the heap, instead allocate one block of memory for the LPB, extension, etc and strings (fits into one page) and another page for the MADs limit to 200 MADs, 1024 is way over the top)
- Map only those pages into kernel mode, that the kernel will need, this way we don't need to unmap anything later.

svn path=/trunk/; revision=53864
This commit is contained in:
Timo Kreuzer 2011-09-26 16:06:19 +00:00
parent 6f431e5648
commit b2a2d9d793
7 changed files with 175 additions and 169 deletions

View file

@ -166,7 +166,8 @@ MempMapRangeOfPages(ULONG64 VirtualAddress, ULONG64 PhysicalAddress, ULONG cPage
BOOLEAN
MempSetupPaging(IN ULONG StartPage,
IN ULONG NumberOfPages)
IN ULONG NumberOfPages,
IN BOOLEAN KernelMapping)
{
TRACE(">>> MempSetupPaging(0x%lx, %ld, %p)\n",
StartPage, NumberOfPages, StartPage * PAGE_SIZE + KSEG0_BASE);
@ -383,9 +384,6 @@ void WinLdrSetupMachineDependent(PLOADER_PARAMETER_BLOCK LoaderBlock)
}
RtlZeroMemory((PVOID)Pcr, 2 * MM_PAGE_SIZE);
/* Allocate a kernel stack */
Pcr = (ULONG_PTR)MmAllocateMemoryWithType(2 * MM_PAGE_SIZE, LoaderStartupPcrPage);
/* Allocate TSS */
BlockSize = (sizeof(KTSS) + MM_PAGE_SIZE) & ~(MM_PAGE_SIZE - 1);
Tss = (ULONG_PTR)MmAllocateMemoryWithType(BlockSize, LoaderMemoryData);

View file

@ -144,13 +144,15 @@ MempAllocatePTE(ULONG Entry, PHARDWARE_PTE *PhysicalPT, PHARDWARE_PTE *KernelPT)
BOOLEAN
MempSetupPaging(IN ULONG StartPage,
IN ULONG NumberOfPages)
IN ULONG NumberOfPages,
IN BOOLEAN KernelMapping)
{
PHARDWARE_PTE PhysicalPT;
PHARDWARE_PTE KernelPT;
ULONG Entry, Page;
//Print(L"MempSetupPaging: SP 0x%X, Number: 0x%X\n", StartPage, NumberOfPages);
TRACE("MempSetupPaging: SP 0x%X, Number: 0x%X, Kernel: %s\n",
StartPage, NumberOfPages, KernelMapping ? "yes" : "no");
// HACK
if (StartPage+NumberOfPages >= 0x80000)
@ -184,9 +186,13 @@ MempSetupPaging(IN ULONG StartPage,
PhysicalPT[Page & 0x3ff].Valid = (Page != 0);
PhysicalPT[Page & 0x3ff].Write = (Page != 0);
KernelPT[Page & 0x3ff].PageFrameNumber = Page;
KernelPT[Page & 0x3ff].Valid = (Page != 0);
KernelPT[Page & 0x3ff].Write = (Page != 0);
if (KernelMapping)
{
if (KernelPT[Page & 0x3ff].Valid) WARN("xxx already mapped \n");
KernelPT[Page & 0x3ff].PageFrameNumber = Page;
KernelPT[Page & 0x3ff].Valid = (Page != 0);
KernelPT[Page & 0x3ff].Write = (Page != 0);
}
}
return TRUE;

View file

@ -20,6 +20,8 @@
#pragma once
#include <arc/setupblk.h>
/* Entry-point to kernel */
typedef VOID (NTAPI *KERNEL_ENTRY_POINT) (PLOADER_PARAMETER_BLOCK LoaderBlock);
@ -54,6 +56,34 @@ typedef struct /* Root System Descriptor Pointer */
} RSDP_DESCRIPTOR, *PRSDP_DESCRIPTOR;
#include <poppack.h>
typedef struct _ARC_DISK_SIGNATURE_EX
{
ARC_DISK_SIGNATURE DiskSignature;
CHAR ArcName[MAX_PATH];
} ARC_DISK_SIGNATURE_EX, *PARC_DISK_SIGNATURE_EX;
#define MAX_OPTIONS_LENGTH 255
typedef struct _LOADER_SYSTEM_BLOCK
{
LOADER_PARAMETER_BLOCK LoaderBlock;
LOADER_PARAMETER_EXTENSION Extension;
SETUP_LOADER_BLOCK SetupBlock;
#ifdef _M_IX86
HEADLESS_LOADER_BLOCK HeadlessLoaderBlock;
#endif
NLS_DATA_BLOCK NlsDataBlock;
CHAR LoadOptions[MAX_OPTIONS_LENGTH+1];
CHAR ArcBootDeviceName[MAX_PATH+1];
// CHAR ArcHalDeviceName[MAX_PATH];
CHAR NtBootPathName[MAX_PATH+1];
CHAR NtHalPathName[MAX_PATH+1];
ARC_DISK_INFORMATION ArcDiskInformation;
ARC_DISK_SIGNATURE_EX ArcDiskSignature[];
} LOADER_SYSTEM_BLOCK, *PLOADER_SYSTEM_BLOCK;
extern PLOADER_SYSTEM_BLOCK WinLdrSystemBlock;
///////////////////////////////////////////////////////////////////////////////////////
//
// ReactOS Loading Functions
@ -144,7 +174,8 @@ MempAllocatePageTables();
BOOLEAN
MempSetupPaging(IN ULONG StartPage,
IN ULONG NumberOfPages);
IN ULONG NumberOfPages,
IN BOOLEAN KernelMapping);
VOID
MempUnmapPage(ULONG Page);

View file

@ -76,7 +76,7 @@ WinLdrCheckForLoadedDll(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock,
/* Compare names */
if (WinLdrpCompareDllName(DllName, &DataTableEntry->BaseDllName))
{
/* Yes, found it, report pointer to the loaded module's DTE
/* Yes, found it, report pointer to the loaded module's DTE
to the caller and increase load count for it */
*LoadedEntry = DataTableEntry;
DataTableEntry->LoadCount++;
@ -266,6 +266,7 @@ WinLdrLoadImage(IN PCHAR FileName,
LONG Status;
LARGE_INTEGER Position;
ULONG i, BytesRead;
TRACE("WinLdrLoadImage(%s, %ld, *)\n", FileName, MemoryType);
/* Open the image file */
Status = ArcOpen(FileName, OpenReadOnly, &FileId);
@ -424,7 +425,7 @@ WinLdrLoadImage(IN PCHAR FileName,
/* Relocate the image, if it needs it */
if (NtHeaders->OptionalHeader.ImageBase != (ULONG_PTR)VirtualBase)
{
WARN("Relocating %p -> %p\n", NtHeaders->OptionalHeader.ImageBase,
WARN("Relocating %p -> %p\n", NtHeaders->OptionalHeader.ImageBase,
VirtualBase);
return (BOOLEAN)LdrRelocateImageWithBias(PhysicalBase,
(ULONG_PTR)VirtualBase - (ULONG_PTR)PhysicalBase,
@ -434,6 +435,7 @@ WinLdrLoadImage(IN PCHAR FileName,
FALSE);
}
TRACE("WinLdrLoadImage() done, PA = %p\n", *ImageBasePA);
return TRUE;
}
@ -447,7 +449,7 @@ WinLdrpCompareDllName(IN PCH DllName,
PWSTR Buffer;
UNICODE_STRING UnicodeNamePA;
ULONG i, Length;
/* First obvious check: for length of two names */
Length = strlen(DllName);
@ -615,7 +617,7 @@ WinLdrpBindImportName(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock,
/* Everything allright, get the ordinal */
Ordinal = OrdinalTable[Middle];
//TRACE("WinLdrpBindImportName() found Ordinal %d\n", Ordinal);
}
}
@ -733,7 +735,7 @@ WinLdrpLoadAndScanReferencedDll(PLOADER_PARAMETER_BLOCK WinLdrBlock,
//Print(L"Loading referenced DLL: %s\n", FullDllName);
/* Load the image */
Status = WinLdrLoadImage(FullDllName, LoaderHalCode, &BasePA);
Status = WinLdrLoadImage(FullDllName, LoaderSystemCode, &BasePA);
if (!Status)
{

View file

@ -36,15 +36,6 @@ WinLdrSetProcessorContext(void);
// TODO: Move to .h
VOID AllocateAndInitLPB(PLOADER_PARAMETER_BLOCK *OutLoaderBlock);
//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;
VOID
SetupLdrLoadNlsData(PLOADER_PARAMETER_BLOCK LoaderBlock, HINF InfHandle, LPCSTR SearchPath)
{
@ -226,8 +217,7 @@ VOID LoadReactOSSetup(VOID)
AllocateAndInitLPB(&LoaderBlock);
/* Allocate and initialize setup loader block */
SetupBlock = MmHeapAlloc(sizeof(SETUP_LOADER_BLOCK));
RtlZeroMemory(SetupBlock, sizeof(SETUP_LOADER_BLOCK));
SetupBlock = &WinLdrSystemBlock->SetupBlock;
LoaderBlock->SetupLdrBlock = SetupBlock;
/* Set textmode setup flag */

View file

@ -29,7 +29,6 @@ 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;
@ -39,6 +38,8 @@ extern HEADLESS_LOADER_BLOCK LoaderRedirectionInformation;
extern BOOLEAN WinLdrTerminalConnected;
extern void WinLdrSetupEms(IN PCHAR BootOptions);
PLOADER_SYSTEM_BLOCK WinLdrSystemBlock;
// debug stuff
VOID DumpMemoryAllocMap(VOID);
@ -47,25 +48,29 @@ VOID
AllocateAndInitLPB(PLOADER_PARAMETER_BLOCK *OutLoaderBlock)
{
PLOADER_PARAMETER_BLOCK LoaderBlock;
ULONG SystemBlockSize;
/* Allocate and zero-init the LPB */
LoaderBlock = MmHeapAlloc(sizeof(LOADER_PARAMETER_BLOCK));
RtlZeroMemory(LoaderBlock, sizeof(LOADER_PARAMETER_BLOCK));
SystemBlockSize = sizeof(LOADER_SYSTEM_BLOCK) +
reactos_disk_count * sizeof(ARC_DISK_SIGNATURE_EX);
WinLdrSystemBlock = MmAllocateMemoryWithType(SystemBlockSize,
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;
}
@ -99,58 +104,56 @@ WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock,
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);
LoaderBlock->LoadOptions = WinLdrSystemBlock->LoadOptions;
strncpy(LoaderBlock->LoadOptions, Options, MAX_OPTIONS_LENGTH);
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 ArcDiskSig;
/* Get the ARC structure */
ArcDiskInfo = (PARC_DISK_SIGNATURE)MmHeapAlloc(sizeof(ARC_DISK_SIGNATURE));
RtlZeroMemory(ArcDiskInfo, sizeof(ARC_DISK_SIGNATURE));
ArcDiskSig = &WinLdrSystemBlock->ArcDiskSignature[i].DiskSignature;
/* Copy the data over */
ArcDiskInfo->Signature = reactos_arc_disk_info[i].Signature;
ArcDiskInfo->CheckSum = reactos_arc_disk_info[i].CheckSum;
ArcDiskSig->Signature = reactos_arc_disk_info[i].Signature;
ArcDiskSig->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);
ArcDiskSig->ArcName = WinLdrSystemBlock->ArcDiskSignature[i].ArcName;
strncpy(ArcDiskSig->ArcName, reactos_arc_disk_info[i].ArcName, MAX_PATH);
ArcDiskSig->ArcName = PaToVa(ArcDiskSig->ArcName);
/* Mark partition table as valid */
ArcDiskInfo->ValidPartitionTable = TRUE;
ArcDiskSig->ValidPartitionTable = TRUE;
/* Insert into the list */
InsertTailList(&LoaderBlock->ArcDiskInformation->DiskSignatureListHead,
&ArcDiskInfo->ListEntry);
&ArcDiskSig->ListEntry);
}
/* Convert all list's to Virtual address */
@ -174,15 +177,7 @@ WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock,
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;
@ -199,17 +194,10 @@ WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock,
/* 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
@ -217,7 +205,8 @@ WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock,
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);
@ -421,11 +410,13 @@ WinLdrDetectVersion()
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)
{
@ -442,7 +433,7 @@ LoadModule(
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);
@ -582,15 +573,15 @@ LoadAndBootWindowsCommon(
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 */

View file

@ -53,63 +53,21 @@ WinLdrInsertDescriptor(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
MEMORY_ALLOCATION_DESCRIPTOR *Mad;
ULONG MadCount = 0;
/* 200 MADs fit into 1 page, that should really be enough! */
#define MAX_MAD_COUNT 200
/* FUNCTIONS **************************************************************/
VOID
MempDisablePages()
{
ULONG i;
//
// We need to delete kernel mapping from memory areas which are
// marked as Special or Permanent memory (thus non-accessible)
//
for (i=0; i<MadCount; i++)
{
ULONG StartPage, EndPage, Page;
StartPage = Mad[i].BasePage;
EndPage = Mad[i].BasePage + Mad[i].PageCount;
if (Mad[i].MemoryType == LoaderFirmwarePermanent ||
Mad[i].MemoryType == LoaderSpecialMemory ||
Mad[i].MemoryType == LoaderFree ||
(Mad[i].MemoryType == LoaderFirmwareTemporary && EndPage <= LoaderPagesSpanned) ||
Mad[i].MemoryType == LoaderOsloaderStack ||
Mad[i].MemoryType == LoaderLoadedProgram)
{
//
// But, the first megabyte of memory always stays!
// And, to tell the truth, we don't care about what's higher
// than LoaderPagesSpanned
if (Mad[i].MemoryType == LoaderFirmwarePermanent ||
Mad[i].MemoryType == LoaderSpecialMemory)
{
if (StartPage < 0x100)
StartPage = 0x100;
if (EndPage > LoaderPagesSpanned)
EndPage = LoaderPagesSpanned;
}
for (Page = StartPage; Page < EndPage; Page++)
{
MempUnmapPage(Page);
}
}
}
}
VOID
MempAddMemoryBlock(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
ULONG BasePage,
ULONG PageCount,
ULONG Type)
{
BOOLEAN Status;
BOOLEAN Status = TRUE;
TRACE("MempAddMemoryBlock(BasePage=0x%lx, PageCount=0x%lx, Type=%ld)\n",
BasePage, PageCount, Type);
//
// Check for memory block after 4GB - we don't support it yet
// Note: Even last page before 4GB limit is not supported
@ -133,6 +91,16 @@ MempAddMemoryBlock(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
PageCount = MM_MAX_PAGE - BasePage;
}
/* Check if we have slots left */
if (MadCount >= MAX_MAD_COUNT)
{
ERR("Error: no MAD slots left!\n");
return;
}
/* Get rid of the loader heap */
//if (Type == LoaderOsloaderHeap) Type = LoaderFirmwareTemporary;
//
// Set Base page, page count and type
//
@ -140,26 +108,6 @@ MempAddMemoryBlock(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
Mad[MadCount].PageCount = PageCount;
Mad[MadCount].MemoryType = Type;
//
// Check if it's more than the allowed for OS loader
// if yes - don't map the pages, just add as FirmwareTemporary
//
if (BasePage + PageCount > LoaderPagesSpanned)
{
if (Mad[MadCount].MemoryType != LoaderSpecialMemory &&
Mad[MadCount].MemoryType != LoaderFirmwarePermanent &&
Mad[MadCount].MemoryType != LoaderFree)
{
TRACE("Setting page %x %x to Temporary from %d\n",
BasePage, PageCount, Mad[MadCount].MemoryType);
Mad[MadCount].MemoryType = LoaderFirmwareTemporary;
}
WinLdrInsertDescriptor(LoaderBlock, &Mad[MadCount]);
MadCount++;
return;
}
//
// Add descriptor
@ -167,19 +115,61 @@ MempAddMemoryBlock(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
WinLdrInsertDescriptor(LoaderBlock, &Mad[MadCount]);
MadCount++;
//
// Map it (don't map low 1Mb because it was already contiguously
// mapped in WinLdrPrepareMemoryLayout)
//
if (BasePage >= 0x100)
{
Status = MempSetupPaging(BasePage, PageCount);
if (!Status)
{
ERR("Error during MempSetupPaging\n");
return;
}
}
switch (Type)
{
/* Pages used by the loader */
case LoaderLoadedProgram:
case LoaderOsloaderStack:
case LoaderFirmwareTemporary:
case LoaderFirmwarePermanent:
/* Map these pages into user mode */
Status = MempSetupPaging(BasePage, PageCount, FALSE);
break;
/* Pages used by the kernel */
case LoaderExceptionBlock:
case LoaderSystemBlock:
case LoaderSystemCode:
case LoaderHalCode:
case LoaderBootDriver:
case LoaderConsoleInDriver:
case LoaderConsoleOutDriver:
case LoaderStartupDpcStack:
case LoaderStartupKernelStack:
case LoaderStartupPanicStack:
case LoaderStartupPcrPage:
case LoaderStartupPdrPage:
case LoaderRegistryData:
case LoaderMemoryData:
case LoaderNlsData:
case LoaderOsloaderHeap: // FIXME
/* Map these pages into kernel mode */
Status = MempSetupPaging(BasePage, PageCount, TRUE);
break;
/* Pages not in use */
case LoaderFree:
case LoaderBad:
break;
/* Invisible to kernel */
case LoaderSpecialMemory:
case LoaderHALCachedMemory:
case LoaderBBTMemory:
break;
// FIXME: not known (not used anyway)
case LoaderReserve:
case LoaderXIPRom:
case LoaderLargePageFiller:
case LoaderErrorLogMemory:
break;
}
if (!Status)
{
ERR("Error during MempSetupPaging\n");
}
}
#ifdef _M_ARM
@ -219,7 +209,8 @@ WinLdrSetupMemoryLayout(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock)
//
// Allocate memory for memory allocation descriptors
Mad = MmHeapAlloc(sizeof(MEMORY_ALLOCATION_DESCRIPTOR) * 1024);
Mad = MmAllocateMemoryWithType(sizeof(MEMORY_ALLOCATION_DESCRIPTOR) * MAX_MAD_COUNT,
LoaderMemoryData);
// Setup an entry for each descriptor
MemoryMap = MmGetMemoryMap(&NoEntries);
@ -236,7 +227,7 @@ WinLdrSetupMemoryLayout(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock)
TRACE("Got memory map with %d entries\n", NoEntries);
// Always contiguously map low 1Mb of memory
Status = MempSetupPaging(0, 0x100);
Status = MempSetupPaging(0, 0x100, FALSE);
if (!Status)
{
ERR("Error during MempSetupPaging of low 1Mb\n");
@ -314,9 +305,6 @@ WinLdrSetupMemoryLayout(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock)
return;
}*/
// Unmap what is not needed from kernel page table
MempDisablePages();
// Fill the memory descriptor list and
//PrepareMemoryDescriptorList();
TRACE("Memory Descriptor List prepared, printing PDE\n");