Author: ion
Date: Sun Oct 8 02:23:35 2006
New Revision: 24435
URL:
http://svn.reactos.org/svn/reactos?rev=24435&view=rev
Log:
- FreeLDR: Create the loader entry for ntoskrnl now that FreeLDR PE-loads it since last
year. This lets us remove a large hack in ntoskrnl which was manually creating the entry
and filling it in.
- Rename some LastKrnl... addresses into MmFreeLdr to easily identify them, and remove the
need to use MmFreeLdrMemLower and MmFreeLdrPageDirectoryStart.
- Remove the static KERNEL_BASE definition based on a GCC-specific external. Everything
now uses the actual module entry's saved base address.
- Fix a Ps Initialization hack and properly set the boot PDE.
- Add a hack for NTLDR's lack of MmFreeLdrMemHigher and MmFreeLdrPageDirectoryEnd.
Modified:
trunk/reactos/boot/freeldr/freeldr/arch/i386/loader.c
trunk/reactos/ntoskrnl/ex/init.c
trunk/reactos/ntoskrnl/include/internal/ke.h
trunk/reactos/ntoskrnl/include/internal/ldr.h
trunk/reactos/ntoskrnl/ke/bug.c
trunk/reactos/ntoskrnl/ke/freeldr.c
trunk/reactos/ntoskrnl/ke/i386/kiinit.c
trunk/reactos/ntoskrnl/ldr/loader.c
trunk/reactos/ntoskrnl/mm/freelist.c
trunk/reactos/ntoskrnl/mm/mminit.c
trunk/reactos/ntoskrnl/ps/psmgr.c
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 Sun Oct 8 02:23:35 2006
@@ -693,6 +693,13 @@
RelocationDir = (PIMAGE_BASE_RELOCATION)((ULONG_PTR)RelocationDir +
RelocationDir->SizeOfBlock);
}
+ /* Fill out Module Data Structure */
+ reactos_modules[0].ModStart = KernelBase;
+ reactos_modules[0].ModEnd = KernelBase + ImageSize;
+ strcpy(reactos_module_strings[0], "ntoskrnl.exe");
+ reactos_modules[0].String = (ULONG_PTR)reactos_module_strings[0];
+ LoaderBlock.ModsCount++;
+
/* Increase the next Load Base */
NextModuleBase = ROUND_UP(KERNEL_BASE_PHYS + ImageSize, PAGE_SIZE);
Modified: trunk/reactos/ntoskrnl/ex/init.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ex/init.c?rev=244…
==============================================================================
--- trunk/reactos/ntoskrnl/ex/init.c (original)
+++ trunk/reactos/ntoskrnl/ex/init.c Sun Oct 8 02:23:35 2006
@@ -423,8 +423,7 @@
0,
&Size,
MEM_COMMIT,
- PAGE_READWRITE
- );
+ PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
/* Failed */
Modified: trunk/reactos/ntoskrnl/include/internal/ke.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/…
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/ke.h (original)
+++ trunk/reactos/ntoskrnl/include/internal/ke.h Sun Oct 8 02:23:35 2006
@@ -57,16 +57,16 @@
extern ADDRESS_RANGE KeMemoryMap[64];
extern ULONG KeMemoryMapRangeCount;
-extern ULONG_PTR FirstKrnlPhysAddr;
-extern ULONG_PTR LastKrnlPhysAddr;
-extern ULONG_PTR LastKernelAddress;
+
+extern ULONG_PTR MmFreeLdrFirstKrnlPhysAddr;
+extern ULONG_PTR MmFreeLdrLastKrnlPhysAddr;
+extern ULONG_PTR MmFreeLdrLastKernelAddress;
extern PVOID KeUserApcDispatcher;
extern PVOID KeUserCallbackDispatcher;
extern PVOID KeUserExceptionDispatcher;
extern PVOID KeRaiseUserExceptionDispatcher;
extern LARGE_INTEGER SystemBootTime;
-extern ULONG_PTR KERNEL_BASE;
extern ULONG KeI386NpxPresent;
extern ULONG KeI386XMMIPresent;
extern ULONG KeI386FxsrPresent;
Modified: trunk/reactos/ntoskrnl/include/internal/ldr.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/…
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/ldr.h (original)
+++ trunk/reactos/ntoskrnl/include/internal/ldr.h Sun Oct 8 02:23:35 2006
@@ -21,7 +21,9 @@
VOID
NTAPI
-LdrInitModuleManagement(VOID);
+LdrInitModuleManagement(
+ IN PVOID KernelBase
+);
NTSTATUS
NTAPI
Modified: trunk/reactos/ntoskrnl/ke/bug.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/bug.c?rev=2443…
==============================================================================
--- trunk/reactos/ntoskrnl/ke/bug.c (original)
+++ trunk/reactos/ntoskrnl/ke/bug.c Sun Oct 8 02:23:35 2006
@@ -126,6 +126,12 @@
LDR_RESOURCE_INFO ResourceInfo;
PIMAGE_RESOURCE_DATA_ENTRY ResourceDataEntry;
NTSTATUS Status;
+ PLDR_DATA_TABLE_ENTRY LdrEntry;
+
+ /* Get the kernel entry */
+ LdrEntry = CONTAINING_RECORD(KeLoaderBlock->LoadOrderListHead.Flink,
+ LDR_DATA_TABLE_ENTRY,
+ InLoadOrderLinks);
/* Cache the Bugcheck Message Strings. Prepare the Lookup Data */
ResourceInfo.Type = 11;
@@ -133,7 +139,7 @@
ResourceInfo.Language = 9;
/* Do the lookup. */
- Status = LdrFindResource_U((PVOID)KERNEL_BASE,
+ Status = LdrFindResource_U(LdrEntry->DllBase,
&ResourceInfo,
RESOURCE_DATA_LEVEL,
&ResourceDataEntry);
@@ -142,7 +148,7 @@
if (NT_SUCCESS(Status))
{
/* Now actually get a pointer to it */
- Status = LdrAccessResource((PVOID)KERNEL_BASE,
+ Status = LdrAccessResource(LdrEntry->DllBase,
ResourceDataEntry,
(PVOID*)&BugCheckData,
NULL);
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 Sun Oct 8 02:23:35 2006
@@ -22,11 +22,10 @@
/* FreeLDR Memory Data */
ADDRESS_RANGE KeMemoryMap[64];
ULONG KeMemoryMapRangeCount;
-ULONG_PTR FirstKrnlPhysAddr;
-ULONG_PTR LastKrnlPhysAddr;
-ULONG_PTR LastKernelAddress;
-ULONG MmFreeLdrMemHigher, MmFreeLdrMemLower;
-ULONG MmFreeLdrPageDirectoryStart, MmFreeLdrPageDirectoryEnd;
+ULONG_PTR MmFreeLdrFirstKrnlPhysAddr, MmFreeLdrLastKrnlPhysAddr;
+ULONG_PTR MmFreeLdrLastKernelAddress;
+ULONG MmFreeLdrMemHigher;
+ULONG MmFreeLdrPageDirectoryEnd;
/* FreeLDR Loader Data */
ROS_LOADER_PARAMETER_BLOCK KeRosLoaderBlock;
@@ -34,8 +33,6 @@
BOOLEAN AcpiTableDetected;
/* FreeLDR PE Hack Data */
-extern unsigned int _image_base__;
-ULONG_PTR KERNEL_BASE = (ULONG_PTR)&_image_base__;
extern LDR_DATA_TABLE_ENTRY HalModuleObject;
/* NT Loader Data */
@@ -72,8 +69,6 @@
/* First get some kernel-loader globals */
AcpiTableDetected = (RosLoaderBlock->Flags & MB_FLAGS_ACPI_TABLE) ? TRUE :
FALSE;
MmFreeLdrMemHigher = RosLoaderBlock->MemHigher;
- MmFreeLdrMemLower = RosLoaderBlock->MemLower;
- MmFreeLdrPageDirectoryStart = RosLoaderBlock->PageDirectoryStart;
MmFreeLdrPageDirectoryEnd = RosLoaderBlock->PageDirectoryEnd;
KeLoaderModuleCount = RosLoaderBlock->ModsCount;
@@ -299,8 +294,8 @@
ULONG HalBase;
ULONG DriverBase;
ULONG DriverSize;
- PIMAGE_NT_HEADERS NtHeader;
- PIMAGE_OPTIONAL_HEADER OptHead;
+ //PIMAGE_NT_HEADERS NtHeader;
+ //PIMAGE_OPTIONAL_HEADER OptHead;
PLOADER_PARAMETER_BLOCK NtLoaderBlock;
CHAR* s;
PKTSS Tss;
@@ -322,10 +317,10 @@
/* Copy the Loader Block Data locally since Low-Memory will be wiped */
memcpy(&KeRosLoaderBlock, LoaderBlock, sizeof(ROS_LOADER_PARAMETER_BLOCK));
- memcpy(&KeLoaderModules[1],
+ memcpy(&KeLoaderModules[0],
(PVOID)KeRosLoaderBlock.ModsAddr,
sizeof(LOADER_MODULE) * KeRosLoaderBlock.ModsCount);
- KeRosLoaderBlock.ModsCount++;
+ //KeRosLoaderBlock.ModsCount++;
KeRosLoaderBlock.ModsAddr = (ULONG)&KeLoaderModules;
/* Check for BIOS memory map */
@@ -370,19 +365,6 @@
strcpy(KeLoaderCommandLine, (PCHAR)LoaderBlock->CommandLine);
KeRosLoaderBlock.CommandLine = (ULONG)KeLoaderCommandLine;
- /* Write the first Module (the Kernel) */
- strcpy(KeLoaderModuleStrings[0], "ntoskrnl.exe");
- KeLoaderModules[0].String = (ULONG)KeLoaderModuleStrings[0];
- KeLoaderModules[0].ModStart = KERNEL_BASE;
-
- /* Read PE Data */
- NtHeader = RtlImageNtHeader((PVOID)KeLoaderModules[0].ModStart);
- OptHead = &NtHeader->OptionalHeader;
-
- /* Set Kernel Ending */
- KeLoaderModules[0].ModEnd = KeLoaderModules[0].ModStart +
- PAGE_ROUND_UP((ULONG)OptHead->SizeOfImage);
-
/* Create a block for each module */
for (i = 1; i < KeRosLoaderBlock.ModsCount; i++)
{
@@ -400,36 +382,36 @@
KeLoaderModules[i].ModStart -= 0x200000;
/* Add the Kernel Base Address in Virtual Memory */
- KeLoaderModules[i].ModStart += KERNEL_BASE;
+ KeLoaderModules[i].ModStart += KSEG0_BASE;
/* Substract the base Address in Physical Memory */
KeLoaderModules[i].ModEnd -= 0x200000;
/* Add the Kernel Base Address in Virtual Memory */
- KeLoaderModules[i].ModEnd += KERNEL_BASE;
+ KeLoaderModules[i].ModEnd += KSEG0_BASE;
/* Select the proper String */
KeLoaderModules[i].String = (ULONG)KeLoaderModuleStrings[i];
}
/* Choose last module address as the final kernel address */
- LastKernelAddress = PAGE_ROUND_UP(KeLoaderModules[KeRosLoaderBlock.
- ModsCount - 1].ModEnd);
+ MmFreeLdrLastKernelAddress =
+ PAGE_ROUND_UP(KeLoaderModules[KeRosLoaderBlock.ModsCount - 1].ModEnd);
/* Select the HAL Base */
HalBase = KeLoaderModules[1].ModStart;
/* Choose Driver Base */
- DriverBase = LastKernelAddress;
+ DriverBase = MmFreeLdrLastKernelAddress;
LdrHalBase = (ULONG_PTR)DriverBase;
/* Initialize Module Management */
- LdrInitModuleManagement();
+ LdrInitModuleManagement((PVOID)KeLoaderModules[0].ModStart);
/* Load HAL.DLL with the PE Loader */
LdrSafePEProcessModule((PVOID)HalBase,
(PVOID)DriverBase,
- (PVOID)KERNEL_BASE,
+ (PVOID)KeLoaderModules[0].ModStart,
&DriverSize);
//
@@ -446,19 +428,21 @@
OptionalHeader.SizeOfImage;
/* Increase the last kernel address with the size of HAL */
- LastKernelAddress += PAGE_ROUND_UP(DriverSize);
+ MmFreeLdrLastKernelAddress += PAGE_ROUND_UP(DriverSize);
/* Now select the final beginning and ending Kernel Addresses */
- FirstKrnlPhysAddr = KeLoaderModules[0].ModStart - KERNEL_BASE + 0x200000;
- LastKrnlPhysAddr = LastKernelAddress - KERNEL_BASE + 0x200000;
+ MmFreeLdrFirstKrnlPhysAddr = KeLoaderModules[0].ModStart -
+ KSEG0_BASE + 0x200000;
+ MmFreeLdrLastKrnlPhysAddr = MmFreeLdrLastKernelAddress -
+ KSEG0_BASE + 0x200000;
/* Setup the IDT */
KeInitExceptions(); // ONCE HACK BELOW IS GONE, MOVE TO KISYSTEMSTARTUP!
KeInitInterrupts(); // ROS HACK DEPRECATED SOON BY NEW HAL
/* Load the Kernel with the PE Loader */
- LdrSafePEProcessModule((PVOID)KERNEL_BASE,
- (PVOID)KERNEL_BASE,
+ LdrSafePEProcessModule((PVOID)KeLoaderModules[0].ModStart,
+ (PVOID)KeLoaderModules[0].ModStart,
(PVOID)DriverBase,
&DriverSize);
Modified: trunk/reactos/ntoskrnl/ke/i386/kiinit.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/i386/kiinit.c?…
==============================================================================
--- trunk/reactos/ntoskrnl/ke/i386/kiinit.c (original)
+++ trunk/reactos/ntoskrnl/ke/i386/kiinit.c Sun Oct 8 02:23:35 2006
@@ -427,9 +427,9 @@
((PETHREAD)InitThread)->ThreadsProcess = (PEPROCESS)InitProcess;
/* Initialize Kernel Memory Address Space */
- MmInit1(FirstKrnlPhysAddr,
- LastKrnlPhysAddr,
- LastKernelAddress,
+ MmInit1(MmFreeLdrFirstKrnlPhysAddr,
+ MmFreeLdrLastKrnlPhysAddr,
+ MmFreeLdrLastKernelAddress,
(PADDRESS_RANGE)&KeMemoryMap,
KeMemoryMapRangeCount,
4096);
Modified: trunk/reactos/ntoskrnl/ldr/loader.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ldr/loader.c?rev=…
==============================================================================
--- trunk/reactos/ntoskrnl/ldr/loader.c (original)
+++ trunk/reactos/ntoskrnl/ldr/loader.c Sun Oct 8 02:23:35 2006
@@ -107,7 +107,7 @@
VOID
INIT_FUNCTION
NTAPI
-LdrInitModuleManagement ( VOID )
+LdrInitModuleManagement ( PVOID KernelBase )
{
PIMAGE_NT_HEADERS NtHeader;
@@ -117,11 +117,11 @@
/* Initialize ModuleObject for NTOSKRNL */
RtlZeroMemory(&NtoskrnlModuleObject, sizeof(LDR_DATA_TABLE_ENTRY));
- NtoskrnlModuleObject.DllBase = (PVOID) KERNEL_BASE;
+ NtoskrnlModuleObject.DllBase = (PVOID) KernelBase;
RtlInitUnicodeString(&NtoskrnlModuleObject.FullDllName, KERNEL_MODULE_NAME);
LdrpBuildModuleBaseName(&NtoskrnlModuleObject.BaseDllName,
&NtoskrnlModuleObject.FullDllName);
- NtHeader = RtlImageNtHeader((PVOID)KERNEL_BASE);
+ NtHeader = RtlImageNtHeader((PVOID)KernelBase);
NtoskrnlModuleObject.EntryPoint = (PVOID) ((ULONG_PTR) NtoskrnlModuleObject.DllBase +
NtHeader->OptionalHeader.AddressOfEntryPoint);
DPRINT("ModuleObject:%08x entrypoint at %x\n", &NtoskrnlModuleObject,
NtoskrnlModuleObject.EntryPoint);
NtoskrnlModuleObject.SizeOfImage = NtHeader->OptionalHeader.SizeOfImage;
Modified: trunk/reactos/ntoskrnl/mm/freelist.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/freelist.c?rev…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/freelist.c (original)
+++ trunk/reactos/ntoskrnl/mm/freelist.c Sun Oct 8 02:23:35 2006
@@ -332,8 +332,9 @@
NTSTATUS Status;
PFN_TYPE LastPage;
PFN_TYPE FirstUninitializedPage;
-
- DPRINT("MmInitializePageList(FirstPhysKernelAddress %x, "
+ ULONG PdeStart = PsGetCurrentProcess()->Pcb.DirectoryTableBase.LowPart;
+
+ DPRINT1("MmInitializePageList(FirstPhysKernelAddress %x, "
"LastPhysKernelAddress %x, "
"MemorySizeInPages %x, LastKernelAddress %x)\n",
FirstPhysKernelAddress,
@@ -452,7 +453,7 @@
MmStats.NrReservedPages++;
}
/* Protect the Page Directory. This will be changed in r3 */
- else if (j >= (MmFreeLdrPageDirectoryStart / PAGE_SIZE) && j <
(MmFreeLdrPageDirectoryEnd / PAGE_SIZE))
+ else if (j >= (PdeStart / PAGE_SIZE) && j <
(MmFreeLdrPageDirectoryEnd / PAGE_SIZE))
{
MmPageArray[j].Flags.Type = MM_PHYSICAL_PAGE_BIOS;
MmPageArray[j].Flags.Zero = 0;
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 Sun Oct 8 02:23:35 2006
@@ -158,8 +158,9 @@
0,
BoundaryAddressMultiple);
- BaseAddress = (PVOID)KERNEL_BASE;
- Length = PAGE_ROUND_UP(((ULONG_PTR)&_text_end__)) - KERNEL_BASE;
+ extern unsigned int _image_base__;
+ BaseAddress = (PVOID)&_image_base__;
+ Length = PAGE_ROUND_UP(((ULONG_PTR)&_text_end__)) -
(ULONG_PTR)&_image_base__;
ParamLength = ParamLength - Length;
/*
@@ -304,6 +305,9 @@
FirstKrnlPhysAddr,
LastKrnlPhysAddr,
LastKernelAddress);
+
+ /* Set the page directory */
+ PsGetCurrentProcess()->Pcb.DirectoryTableBase.LowPart =
(ULONG)MmGetPageDirectory();
if ((BIOSMemoryMap != NULL) && (AddressRangeCount > 0))
{
@@ -323,6 +327,10 @@
}
}
+ /* NTLDR Hacks */
+ if (!MmFreeLdrMemHigher) MmFreeLdrMemHigher = 32768;
+ if (!MmFreeLdrPageDirectoryEnd) MmFreeLdrPageDirectoryEnd = 0x40000;
+
if (MmFreeLdrMemHigher >= (MaxMem - 1) * 1024)
{
MmFreeLdrMemHigher = (MaxMem - 1) * 1024;
@@ -390,6 +398,10 @@
AddressRangeCount);
kernel_len = LastKrnlPhysAddr - FirstKrnlPhysAddr;
+ //extern LOADER_MODULE KeLoaderModules[];
+ //DPRINT1("Module one: %p %p\n", KeLoaderModules[0].ModStart,
KeLoaderModules[0].ModEnd);
+ //while (TRUE);
+
/*
* Unmap low memory
*/
@@ -413,9 +425,9 @@
#endif
DPRINT("Invalidating between %x and %x\n",
- LastKernelAddress, KERNEL_BASE + 0x00600000);
+ LastKernelAddress, KSEG0_BASE + 0x00600000);
for (MappingAddress = LastKernelAddress;
- MappingAddress < KERNEL_BASE + 0x00600000;
+ MappingAddress < KSEG0_BASE + 0x00600000;
MappingAddress += PAGE_SIZE)
{
MmRawDeleteVirtualMapping((PVOID)MappingAddress);
Modified: trunk/reactos/ntoskrnl/ps/psmgr.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ps/psmgr.c?rev=24…
==============================================================================
--- trunk/reactos/ntoskrnl/ps/psmgr.c (original)
+++ trunk/reactos/ntoskrnl/ps/psmgr.c Sun Oct 8 02:23:35 2006
@@ -392,10 +392,6 @@
(PVOID*)&PsInitialSystemProcess,
NULL);
- /* The PD we gave it is invalid at this point, do what old ROS did */
- PsInitialSystemProcess->Pcb.DirectoryTableBase.LowPart =
(ULONG)MmGetPageDirectory();
- PsIdleProcess->Pcb.DirectoryTableBase =
PsInitialSystemProcess->Pcb.DirectoryTableBase;
-
/* Copy the process names */
strcpy(PsIdleProcess->ImageFileName, "Idle");
strcpy(PsInitialSystemProcess->ImageFileName, "System");