mirror of
https://github.com/reactos/reactos.git
synced 2025-02-24 01:15:09 +00:00
- 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. svn path=/trunk/; revision=28497
This commit is contained in:
parent
7cc80286e0
commit
c2de09f61a
7 changed files with 31 additions and 28 deletions
|
@ -33,8 +33,8 @@ PLOADER_MODULE CurrentModule = NULL;
|
|||
/* 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 @@ LdrPEGetExportByName(PVOID BaseAddress,
|
|||
ULONG ExportDirSize;
|
||||
|
||||
/* HAL and NTOS use a virtual address, switch it to physical mode */
|
||||
if ((ULONG_PTR)BaseAddress & 0x80000000)
|
||||
if ((ULONG_PTR)BaseAddress & KSEG0_BASE)
|
||||
{
|
||||
BaseAddress = (PVOID)((ULONG_PTR)BaseAddress - KSEG0_BASE + 0x200000);
|
||||
BaseAddress = RVA(BaseAddress, -KSEG0_BASE);
|
||||
}
|
||||
|
||||
ExportDir = (PIMAGE_EXPORT_DIRECTORY)
|
||||
|
@ -439,7 +439,7 @@ LdrPEProcessImportDirectoryEntry(PVOID DriverBase,
|
|||
*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 @@ FrLdrMapImage(IN FILE *Image,
|
|||
|
||||
/* 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);
|
||||
|
|
|
@ -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
|
||||
|
@ -30,10 +30,6 @@
|
|||
#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) \
|
||||
(((ULONG_PTR)&p) >> PFN_SHIFT)
|
||||
|
@ -55,8 +51,6 @@
|
|||
#define ApicPageTableIndex (APIC_BASE >> 22)
|
||||
#define KuserPageTableIndex (KI_USER_SHARED_DATA >> 22)
|
||||
|
||||
#define KernelEntryPoint (KernelEntry - KERNEL_BASE_PHYS) + KernelBase
|
||||
|
||||
typedef struct _PAGE_DIRECTORY_X86
|
||||
{
|
||||
HARDWARE_PTE Pde[1024];
|
||||
|
|
|
@ -36,7 +36,7 @@ CHAR szBootPath[255];
|
|||
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 @@ LoadAndBootReactOS(PCSTR OperatingSystemName)
|
|||
/* 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;
|
||||
|
||||
/*
|
||||
|
|
|
@ -31,7 +31,7 @@ memory_map_t reactos_memory_map[32]; // Memory map
|
|||
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 @@ static FrLdrLoadKernel(IN PCHAR szFileName,
|
|||
/* 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 */
|
||||
|
|
|
@ -102,7 +102,7 @@ KiRosFrldrLpbToNtLpb(IN PROS_LOADER_PARAMETER_BLOCK RosLoaderBlock,
|
|||
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 @@ KiRosFrldrLpbToNtLpb(IN PROS_LOADER_PARAMETER_BLOCK RosLoaderBlock,
|
|||
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 @@ KiRosFrldrLpbToNtLpb(IN PROS_LOADER_PARAMETER_BLOCK RosLoaderBlock,
|
|||
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 @@ KiRosFrldrLpbToNtLpb(IN PROS_LOADER_PARAMETER_BLOCK RosLoaderBlock,
|
|||
!(_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 @@ KiRosFrldrLpbToNtLpb(IN PROS_LOADER_PARAMETER_BLOCK RosLoaderBlock,
|
|||
!(_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;
|
||||
|
@ -285,6 +285,11 @@ KiRosFrldrLpbToNtLpb(IN PROS_LOADER_PARAMETER_BLOCK RosLoaderBlock,
|
|||
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 @@ KiRosPrepareForSystemStartup(IN ULONG Dummy,
|
|||
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 */
|
||||
|
|
|
@ -90,8 +90,13 @@ MmInitVirtualMemory(ULONG_PTR LastKernelAddress,
|
|||
|
||||
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);
|
||||
|
|
|
@ -992,7 +992,7 @@ Module::GetDefaultModuleBaseaddress () const
|
|||
switch ( type )
|
||||
{
|
||||
case Kernel:
|
||||
return "0x80000000";
|
||||
return "0x80800000";
|
||||
case Win32DLL:
|
||||
case Win32OCX:
|
||||
return "0x10000000";
|
||||
|
|
Loading…
Reference in a new issue