Author: fireball
Date: Fri Aug 24 01:29:28 2007
New Revision: 28497
URL:
http://svn.reactos.org/svn/reactos?rev=28497&view=rev
Log:
- Make freeldr do identity memory mapping. This simplifies a lot of things throughout the
code, and finally places the kernel at the same addresses where NT kernel is located.
- Fix code in ntoskrnl which was based on (wrong) assumptions.
Modified:
trunk/reactos/boot/freeldr/freeldr/arch/i386/loader.c
trunk/reactos/boot/freeldr/freeldr/include/reactos.h
trunk/reactos/boot/freeldr/freeldr/reactos/reactos.c
trunk/reactos/boot/freeldr/freeldr/reactos/setupldr.c
trunk/reactos/ntoskrnl/ke/freeldr.c
trunk/reactos/ntoskrnl/mm/mminit.c
trunk/reactos/tools/rbuild/module.cpp
Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/loader.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/arch/i386/loader.c (original)
+++ trunk/reactos/boot/freeldr/freeldr/arch/i386/loader.c Fri Aug 24 01:29:28 2007
@@ -33,8 +33,8 @@
/* Unrelocated Kernel Base in Virtual Memory */
ULONG_PTR KernelBase;
-/* Kernel Entrypoint in Physical Memory */
-ULONG_PTR KernelEntry;
+/* Kernel Entrypoint in Virtual Memory */
+ULONG_PTR KernelEntryPoint;
/* Page Directory and Tables for non-PAE Systems */
extern PAGE_DIRECTORY_X86 startup_pagedirectory;
@@ -297,9 +297,9 @@
ULONG ExportDirSize;
/* HAL and NTOS use a virtual address, switch it to physical mode */
- if ((ULONG_PTR)BaseAddress & 0x80000000)
- {
- BaseAddress = (PVOID)((ULONG_PTR)BaseAddress - KSEG0_BASE + 0x200000);
+ if ((ULONG_PTR)BaseAddress & KSEG0_BASE)
+ {
+ BaseAddress = RVA(BaseAddress, -KSEG0_BASE);
}
ExportDir = (PIMAGE_EXPORT_DIRECTORY)
@@ -439,7 +439,7 @@
*ImportAddressList = LdrPEGetExportByName((PVOID)LoaderModule->ModStart,
pe_name->Name, pe_name->Hint);
/* Fixup the address to be virtual */
- *ImportAddressList = (PVOID)((ULONG_PTR)*ImportAddressList + (KSEG0_BASE -
0x200000));
+ *ImportAddressList = RVA(*ImportAddressList, KSEG0_BASE);
//DbgPrint("Looked for: %s and found: %p\n", pe_name->Name,
*ImportAddressList);
if ((*ImportAddressList) == NULL)
@@ -592,7 +592,7 @@
/* Set the virtual (image) and physical (load) addresses */
LoadBase = (PVOID)NextModuleBase;
- ImageBase = RVA(LoadBase , -KERNEL_BASE_PHYS + KSEG0_BASE);
+ ImageBase = RVA(LoadBase, KSEG0_BASE);
/* Save the Image Size */
ImageSize = FsGetFileSize(Image);
Modified: trunk/reactos/boot/freeldr/freeldr/include/reactos.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/inclu…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/include/reactos.h (original)
+++ trunk/reactos/boot/freeldr/freeldr/include/reactos.h Fri Aug 24 01:29:28 2007
@@ -21,7 +21,7 @@
#define __REACTOS_H
/* Base Addres of Kernel in Physical Memory */
-#define KERNEL_BASE_PHYS 0x200000
+#define KERNEL_BASE_PHYS 0x800000
/* Bits to shift to convert a Virtual Address into an Offset in the Page Table */
#define PFN_SHIFT 12
@@ -29,10 +29,6 @@
/* Bits to shift to convert a Virtual Address into an Offset in the Page Directory */
#define PDE_SHIFT 22
#define PDE_SHIFT_PAE 18
-
-/* Converts a Relative Address read from the Kernel into a Physical Address */
-#define RaToPa(p) \
- (ULONG_PTR)((ULONG_PTR)p + KERNEL_BASE_PHYS)
/* Converts a Physical Address Pointer into a Page Frame Number */
#define PaPtrToPfn(p) \
@@ -54,8 +50,6 @@
#define KpcrPageTableIndex (KPCR_BASE >> 22)
#define ApicPageTableIndex (APIC_BASE >> 22)
#define KuserPageTableIndex (KI_USER_SHARED_DATA >> 22)
-
-#define KernelEntryPoint (KernelEntry - KERNEL_BASE_PHYS) + KernelBase
typedef struct _PAGE_DIRECTORY_X86
{
Modified: trunk/reactos/boot/freeldr/freeldr/reactos/reactos.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/react…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/reactos/reactos.c (original)
+++ trunk/reactos/boot/freeldr/freeldr/reactos/reactos.c Fri Aug 24 01:29:28 2007
@@ -36,7 +36,7 @@
CHAR SystemRoot[255];
static CHAR szLoadingMsg[] = "Loading ReactOS...";
BOOLEAN FrLdrBootType;
-extern ULONG_PTR KernelBase, KernelEntry;
+extern ULONG_PTR KernelBase, KernelEntryPoint;
BOOLEAN
FrLdrLoadDriver(PCHAR szFileName,
@@ -759,7 +759,7 @@
/* Get the NT header, kernel base and kernel entry */
NtHeader = RtlImageNtHeader(LoadBase);
KernelBase = NtHeader->OptionalHeader.ImageBase;
- KernelEntry = RaToPa(NtHeader->OptionalHeader.AddressOfEntryPoint);
+ KernelEntryPoint = KernelBase + NtHeader->OptionalHeader.AddressOfEntryPoint;
LoaderBlock.KernelBase = KernelBase;
/*
Modified: trunk/reactos/boot/freeldr/freeldr/reactos/setupldr.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/react…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/reactos/setupldr.c (original)
+++ trunk/reactos/boot/freeldr/freeldr/reactos/setupldr.c Fri Aug 24 01:29:28 2007
@@ -31,7 +31,7 @@
char szBootPath[256];
char szHalName[256];
CHAR SystemRoot[255];
-extern ULONG_PTR KernelBase, KernelEntry;
+extern ULONG_PTR KernelBase, KernelEntryPoint;
extern BOOLEAN FrLdrLoadDriver(PCHAR szFileName, INT nPos);
@@ -83,7 +83,7 @@
/* Get the NT header, kernel base and kernel entry */
NtHeader = RtlImageNtHeader(LoadBase);
KernelBase = NtHeader->OptionalHeader.ImageBase;
- KernelEntry = RaToPa(NtHeader->OptionalHeader.AddressOfEntryPoint);
+ KernelEntryPoint = KernelBase + NtHeader->OptionalHeader.AddressOfEntryPoint;
LoaderBlock.KernelBase = KernelBase;
/* Update Processbar and return success */
Modified: trunk/reactos/ntoskrnl/ke/freeldr.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/freeldr.c?rev=…
==============================================================================
--- trunk/reactos/ntoskrnl/ke/freeldr.c (original)
+++ trunk/reactos/ntoskrnl/ke/freeldr.c Fri Aug 24 01:29:28 2007
@@ -102,7 +102,7 @@
if (!_stricmp(DriverName, "ansi.nls"))
{
/* ANSI Code page */
- ModStart = (PVOID)((ULONG_PTR)ModStart + (KSEG0_BASE - 0x200000));
+ ModStart = RVA(ModStart, KSEG0_BASE);
LoaderBlock->NlsData->AnsiCodePageData = ModStart;
/* Create an MD for it */
@@ -117,7 +117,7 @@
else if (!_stricmp(DriverName, "oem.nls"))
{
/* OEM Code page */
- ModStart = (PVOID)((ULONG_PTR)ModStart + (KSEG0_BASE - 0x200000));
+ ModStart = RVA(ModStart, KSEG0_BASE);
LoaderBlock->NlsData->OemCodePageData = ModStart;
/* Create an MD for it */
@@ -132,7 +132,7 @@
else if (!_stricmp(DriverName, "casemap.nls"))
{
/* Unicode Code page */
- ModStart = (PVOID)((ULONG_PTR)ModStart + (KSEG0_BASE - 0x200000));
+ ModStart = RVA(ModStart, KSEG0_BASE);
LoaderBlock->NlsData->UnicodeCodePageData = ModStart;
/* Create an MD for it */
@@ -150,7 +150,7 @@
!(_stricmp(DriverName, "system.hiv")))
{
/* Save registry data */
- ModStart = (PVOID)((ULONG_PTR)ModStart + (KSEG0_BASE - 0x200000));
+ ModStart = RVA(ModStart, KSEG0_BASE);
LoaderBlock->RegistryBase = ModStart;
LoaderBlock->RegistryLength = ModSize;
@@ -172,7 +172,7 @@
!(_stricmp(DriverName, "hardware.hiv")))
{
/* Create an MD for it */
- ModStart = (PVOID)((ULONG_PTR)ModStart + (KSEG0_BASE - 0x200000));
+ ModStart = RVA(ModStart, KSEG0_BASE);
MdEntry = &BldrMemoryDescriptors[i];
MdEntry->MemoryType = LoaderRegistryData;
MdEntry->BasePage = (ULONG_PTR)ModStart >> PAGE_SHIFT;
@@ -284,6 +284,11 @@
LoaderBlock->Extension->Size = sizeof(LOADER_PARAMETER_EXTENSION);
LoaderBlock->Extension->MajorVersion = 5;
LoaderBlock->Extension->MinorVersion = 2;
+
+ /* Save the number of pages the kernel images take */
+ LoaderBlock->Extension->LoaderPagesSpanned =
+ MmFreeLdrLastKrnlPhysAddr - MmFreeLdrFirstKrnlPhysAddr;
+ LoaderBlock->Extension->LoaderPagesSpanned /= PAGE_SIZE;
/* Now setup the setup block if we have one */
if (LoaderBlock->SetupLdrBlock)
@@ -379,9 +384,8 @@
ModsCount - 1].
ModEnd);
MmFreeLdrFirstKrnlPhysAddr = KeRosLoaderBlock->ModsAddr[0].ModStart -
- KSEG0_BASE + 0x200000;
- MmFreeLdrLastKrnlPhysAddr = MmFreeLdrLastKernelAddress -
- KSEG0_BASE + 0x200000;
+ KSEG0_BASE;
+ MmFreeLdrLastKrnlPhysAddr = MmFreeLdrLastKernelAddress - KSEG0_BASE;
#if defined(_M_IX86)
/* Set up the VDM Data */
Modified: trunk/reactos/ntoskrnl/mm/mminit.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/mminit.c?rev=2…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/mminit.c (original)
+++ trunk/reactos/ntoskrnl/mm/mminit.c Fri Aug 24 01:29:28 2007
@@ -90,8 +90,13 @@
MmInitMemoryAreas();
- /* Start the paged and nonpaged pool at a 4MB boundary. */
- MiNonPagedPoolStart = (PVOID)ROUND_UP((ULONG_PTR)LastKernelAddress + PAGE_SIZE,
0x400000);
+ /*
+ * FreeLDR Marks 6MB "in use" at the start of the kernel base,
+ * so start the non-paged pool at a boundary of 6MB from where
+ * the last driver was loaded. This should be the end of the
+ * FreeLDR-marked region.
+ */
+ MiNonPagedPoolStart = (PVOID)ROUND_UP((ULONG_PTR)LastKernelAddress + PAGE_SIZE,
0x600000);
MiNonPagedPoolLength = MM_NONPAGED_POOL_SIZE;
MmPagedPoolBase = (PVOID)ROUND_UP((ULONG_PTR)MiNonPagedPoolStart +
MiNonPagedPoolLength + PAGE_SIZE, 0x400000);
Modified: trunk/reactos/tools/rbuild/module.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/rbuild/module.cpp?re…
==============================================================================
--- trunk/reactos/tools/rbuild/module.cpp (original)
+++ trunk/reactos/tools/rbuild/module.cpp Fri Aug 24 01:29:28 2007
@@ -992,7 +992,7 @@
switch ( type )
{
case Kernel:
- return "0x80000000";
+ return "0x80800000";
case Win32DLL:
case Win32OCX:
return "0x10000000";