Author: tkreuzer
Date: Mon Sep 26 16:06:19 2011
New Revision: 53864
URL:
http://svn.reactos.org/svn/reactos?rev=53864&view=rev
Log:
[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.
Modified:
trunk/reactos/boot/freeldr/freeldr/arch/amd64/winldr.c
trunk/reactos/boot/freeldr/freeldr/arch/i386/winldr.c
trunk/reactos/boot/freeldr/freeldr/include/winldr.h
trunk/reactos/boot/freeldr/freeldr/windows/peloader.c
trunk/reactos/boot/freeldr/freeldr/windows/setupldr.c
trunk/reactos/boot/freeldr/freeldr/windows/winldr.c
trunk/reactos/boot/freeldr/freeldr/windows/wlmemory.c
Modified: trunk/reactos/boot/freeldr/freeldr/arch/amd64/winldr.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/arch/amd64/winldr.c [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/arch/amd64/winldr.c [iso-8859-1] Mon Sep 26
16:06:19 2011
@@ -166,7 +166,8 @@
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 @@
}
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);
Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/winldr.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/arch/i386/winldr.c [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/arch/i386/winldr.c [iso-8859-1] Mon Sep 26 16:06:19
2011
@@ -144,13 +144,15 @@
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 @@
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;
Modified: trunk/reactos/boot/freeldr/freeldr/include/winldr.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/inclu…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/include/winldr.h [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/include/winldr.h [iso-8859-1] Mon Sep 26 16:06:19
2011
@@ -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 @@
} 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 @@
BOOLEAN
MempSetupPaging(IN ULONG StartPage,
- IN ULONG NumberOfPages);
+ IN ULONG NumberOfPages,
+ IN BOOLEAN KernelMapping);
VOID
MempUnmapPage(ULONG Page);
Modified: trunk/reactos/boot/freeldr/freeldr/windows/peloader.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/windo…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/windows/peloader.c [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/windows/peloader.c [iso-8859-1] Mon Sep 26 16:06:19
2011
@@ -76,7 +76,7 @@
/* 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 @@
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 @@
/* 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 @@
FALSE);
}
+ TRACE("WinLdrLoadImage() done, PA = %p\n", *ImageBasePA);
return TRUE;
}
@@ -447,7 +449,7 @@
PWSTR Buffer;
UNICODE_STRING UnicodeNamePA;
ULONG i, Length;
-
+
/* First obvious check: for length of two names */
Length = strlen(DllName);
@@ -615,7 +617,7 @@
/* Everything allright, get the ordinal */
Ordinal = OrdinalTable[Middle];
-
+
//TRACE("WinLdrpBindImportName() found Ordinal %d\n", Ordinal);
}
}
@@ -733,7 +735,7 @@
//Print(L"Loading referenced DLL: %s\n", FullDllName);
/* Load the image */
- Status = WinLdrLoadImage(FullDllName, LoaderHalCode, &BasePA);
+ Status = WinLdrLoadImage(FullDllName, LoaderSystemCode, &BasePA);
if (!Status)
{
Modified: trunk/reactos/boot/freeldr/freeldr/windows/setupldr.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/windo…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/windows/setupldr.c [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/windows/setupldr.c [iso-8859-1] Mon Sep 26 16:06:19
2011
@@ -35,15 +35,6 @@
// 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 @@
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 */
Modified: trunk/reactos/boot/freeldr/freeldr/windows/winldr.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/windo…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/windows/winldr.c [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/windows/winldr.c [iso-8859-1] Mon Sep 26 16:06:19
2011
@@ -29,7 +29,6 @@
//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 BOOLEAN WinLdrTerminalConnected;
extern void WinLdrSetupEms(IN PCHAR BootOptions);
+PLOADER_SYSTEM_BLOCK WinLdrSystemBlock;
+
// debug stuff
VOID DumpMemoryAllocMap(VOID);
@@ -47,24 +48,28 @@
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 @@
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 @@
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 @@
/* 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 @@
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 @@
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 @@
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 @@
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 */
Modified: trunk/reactos/boot/freeldr/freeldr/windows/wlmemory.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/windo…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/windows/wlmemory.c [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/windows/wlmemory.c [iso-8859-1] Mon Sep 26 16:06:19
2011
@@ -53,54 +53,10 @@
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,
@@ -108,8 +64,10 @@
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 @@
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 @@
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 @@
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 @@
//
// 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 @@
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");
@@ -313,9 +304,6 @@
UiMessageBox("Error during MempSetupPaging");
return;
}*/
-
- // Unmap what is not needed from kernel page table
- MempDisablePages();
// Fill the memory descriptor list and
//PrepareMemoryDescriptorList();