[ros-diffs] [tkreuzer] 43601: [FREELDR] - Move definition of KIP0PCRADDRESS into arch specific header - Implement WinLdrSetupForNt for amd64 (copied x86 version) - Fix mapping of PCR and KI_USER_SHARED_DATA - Don't enable paging again, it is already enabled on amd64 - Fix WinLdrSetProcessorContext to take a ULONG_PTR not ULONG for Pcr and Tss

tkreuzer at svn.reactos.org tkreuzer at svn.reactos.org
Mon Oct 19 14:50:37 CEST 2009


Author: tkreuzer
Date: Mon Oct 19 14:50:36 2009
New Revision: 43601

URL: http://svn.reactos.org/svn/reactos?rev=43601&view=rev
Log:
[FREELDR]
- Move definition of KIP0PCRADDRESS into arch specific header
- Implement WinLdrSetupForNt for amd64 (copied x86 version)
- Fix mapping of PCR and KI_USER_SHARED_DATA
- Don't enable paging again, it is already enabled on amd64
- Fix WinLdrSetProcessorContext to take a ULONG_PTR not ULONG for Pcr and Tss

Modified:
    branches/ros-amd64-bringup/reactos/boot/freeldr/freeldr/include/arch/amd64/amd64.h
    branches/ros-amd64-bringup/reactos/boot/freeldr/freeldr/include/arch/i386/i386.h
    branches/ros-amd64-bringup/reactos/boot/freeldr/freeldr/windows/amd64/ntsetup.c
    branches/ros-amd64-bringup/reactos/boot/freeldr/freeldr/windows/amd64/wlmemory.c
    branches/ros-amd64-bringup/reactos/boot/freeldr/freeldr/windows/wlmemory.c

Modified: branches/ros-amd64-bringup/reactos/boot/freeldr/freeldr/include/arch/amd64/amd64.h
URL: http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/boot/freeldr/freeldr/include/arch/amd64/amd64.h?rev=43601&r1=43600&r2=43601&view=diff
==============================================================================
--- branches/ros-amd64-bringup/reactos/boot/freeldr/freeldr/include/arch/amd64/amd64.h [iso-8859-1] (original)
+++ branches/ros-amd64-bringup/reactos/boot/freeldr/freeldr/include/arch/amd64/amd64.h [iso-8859-1] Mon Oct 19 14:50:36 2009
@@ -20,6 +20,10 @@
 
 #ifndef __AMD64_AMD64_H_
 #define __AMD64_AMD64_H_
+
+// This is needed because headers define wrong one for ReactOS
+#undef KIP0PCRADDRESS
+#define KIP0PCRADDRESS                      0xFFFFF78000001000ULL /* FIXME!!! */
 
 #define STACK64ADDR	0x74000	/* The 64-bit stack top will be at 0x74000 */
 

Modified: branches/ros-amd64-bringup/reactos/boot/freeldr/freeldr/include/arch/i386/i386.h
URL: http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/boot/freeldr/freeldr/include/arch/i386/i386.h?rev=43601&r1=43600&r2=43601&view=diff
==============================================================================
--- branches/ros-amd64-bringup/reactos/boot/freeldr/freeldr/include/arch/i386/i386.h [iso-8859-1] (original)
+++ branches/ros-amd64-bringup/reactos/boot/freeldr/freeldr/include/arch/i386/i386.h [iso-8859-1] Mon Oct 19 14:50:36 2009
@@ -21,6 +21,9 @@
 #ifndef __I386_I386_H_
 #define __I386_I386_H_
 
+// This is needed because headers define wrong one for ReactOS
+#undef KIP0PCRADDRESS
+#define KIP0PCRADDRESS                      0xffdff000
 
 
 #endif /* __I386_I386_H_ */

Modified: branches/ros-amd64-bringup/reactos/boot/freeldr/freeldr/windows/amd64/ntsetup.c
URL: http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/boot/freeldr/freeldr/windows/amd64/ntsetup.c?rev=43601&r1=43600&r2=43601&view=diff
==============================================================================
--- branches/ros-amd64-bringup/reactos/boot/freeldr/freeldr/windows/amd64/ntsetup.c [iso-8859-1] (original)
+++ branches/ros-amd64-bringup/reactos/boot/freeldr/freeldr/windows/amd64/ntsetup.c [iso-8859-1] Mon Oct 19 14:50:36 2009
@@ -40,5 +40,45 @@
                       ULONG *PcrBasePage,
                       ULONG *TssBasePage)
 {
+	ULONG TssSize;
+	ULONG TssPages;
+	ULONG_PTR Pcr = 0;
+	ULONG_PTR Tss = 0;
+	ULONG BlockSize, NumPages;
 
+	LoaderBlock->u.I386.CommonDataArea = NULL; // Force No ABIOS support
+	LoaderBlock->u.I386.MachineType = MACHINE_TYPE_ISA;
+
+	/* Allocate 2 pages for PCR */
+	Pcr = (ULONG_PTR)MmAllocateMemoryWithType(2 * MM_PAGE_SIZE, LoaderStartupPcrPage);
+	*PcrBasePage = Pcr >> MM_PAGE_SHIFT;
+	RtlZeroMemory((PVOID)Pcr, 2 * MM_PAGE_SIZE);
+
+	if (Pcr == 0)
+	{
+		UiMessageBox("Can't allocate PCR\n");
+		return;
+	}
+
+	/* Allocate TSS */
+	TssSize = (sizeof(KTSS) + MM_PAGE_SIZE) & ~(MM_PAGE_SIZE - 1);
+	TssPages = TssSize / MM_PAGE_SIZE;
+
+	Tss = (ULONG_PTR)MmAllocateMemoryWithType(TssSize, LoaderMemoryData);
+
+	*TssBasePage = Tss >> MM_PAGE_SHIFT;
+
+	/* Allocate space for new GDT + IDT */
+	BlockSize = NUM_GDT*sizeof(KGDTENTRY) + NUM_IDT*sizeof(KIDTENTRY);//FIXME: Use GDT/IDT limits here?
+	NumPages = (BlockSize + MM_PAGE_SIZE - 1) >> MM_PAGE_SHIFT;
+	*GdtIdt = (PKGDTENTRY)MmAllocateMemoryWithType(NumPages * MM_PAGE_SIZE, LoaderMemoryData);
+
+	if (*GdtIdt == NULL)
+	{
+		UiMessageBox("Can't allocate pages for GDT+IDT!\n");
+		return;
+	}
+
+	/* Zero newly prepared GDT+IDT */
+	RtlZeroMemory(*GdtIdt, NumPages << MM_PAGE_SHIFT);
 }

Modified: branches/ros-amd64-bringup/reactos/boot/freeldr/freeldr/windows/amd64/wlmemory.c
URL: http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/boot/freeldr/freeldr/windows/amd64/wlmemory.c?rev=43601&r1=43600&r2=43601&view=diff
==============================================================================
--- branches/ros-amd64-bringup/reactos/boot/freeldr/freeldr/windows/amd64/wlmemory.c [iso-8859-1] (original)
+++ branches/ros-amd64-bringup/reactos/boot/freeldr/freeldr/windows/amd64/wlmemory.c [iso-8859-1] Mon Oct 19 14:50:36 2009
@@ -15,10 +15,6 @@
 
 //extern ULONG LoaderPagesSpanned;
 
-// This is needed because headers define wrong one for ReactOS
-#undef KIP0PCRADDRESS
-#define KIP0PCRADDRESS                      0xffdff000
-
 #define HYPER_SPACE_ENTRY       0x300
 
 // This is needed only for SetProcessorContext routine
@@ -100,7 +96,7 @@
 }
 
 BOOLEAN
-MempMapSinglePage(ULONGLONG VirtualAddress, ULONGLONG PhysicalAddress)
+MempMapSinglePage(ULONG64 VirtualAddress, ULONG64 PhysicalAddress)
 {
 	PPAGE_DIRECTORY_AMD64 pDir3, pDir2, pDir1;
 	ULONG Index;
@@ -110,11 +106,15 @@
 	pDir1 = MempGetOrCreatePageDir(pDir2, VAtoPDI(VirtualAddress));
 
 	if (!pDir1)
+	{
+        DPRINTM(DPRINT_WINDOWS,"!!!No Dir %p, %p, %p, %p\n", pPML4, pDir3, pDir2, pDir1);
 		return FALSE;
+	}
 
 	Index = VAtoPTI(VirtualAddress);
 	if (pDir1->Pde[Index].Valid)
 	{
+        DPRINTM(DPRINT_WINDOWS,"!!!Already mapped %ld\n", Index);
 		return FALSE;
 	}
 
@@ -201,14 +201,14 @@
 WinLdrMapSpecialPages(ULONG PcrBasePage)
 {
     /* Map the PCR page */
-    if (!MempMapSinglePage(PcrBasePage * PAGE_SIZE, KIP0PCRADDRESS))
+    if (!MempMapSinglePage(KIP0PCRADDRESS, PcrBasePage * PAGE_SIZE))
     {
         DPRINTM(DPRINT_WINDOWS, "Could not map PCR @ %lx\n", PcrBasePage);
         return FALSE;
     }
 
     /* Map KI_USER_SHARED_DATA */
-    if (!MempMapSinglePage((PcrBasePage+1) * PAGE_SIZE, KI_USER_SHARED_DATA))
+    if (!MempMapSinglePage(KI_USER_SHARED_DATA, (PcrBasePage+1) * PAGE_SIZE))
     {
         DPRINTM(DPRINT_WINDOWS, "Could not map KI_USER_SHARED_DATA\n");
         return FALSE;
@@ -284,6 +284,8 @@
 VOID
 WinLdrSetProcessorContext(PVOID GdtIdt, IN ULONG64 Pcr, IN ULONG64 Tss)
 {
+    DPRINTM(DPRINT_WINDOWS, "WinLdrSetProcessorContext %p\n", Pcr);
+
 	/* Disable Interrupts */
 	_disable();
 
@@ -293,18 +295,13 @@
 	/* Set the new PML4 */
 	__writecr3((ULONGLONG)pPML4);
 
-	// Enable paging by modifying CR0
-	__writecr0(__readcr0() | CR0_PG);
-
-	// Kernel expects the PCR to be zero-filled on startup
-	// FIXME: Why zero it here when we can zero it right after allocation?
-	RtlZeroMemory((PVOID)Pcr, MM_PAGE_SIZE); //FIXME: Why zero only 1 page when we allocate 2?
-
 	RtlZeroMemory(GdtIdt, PAGE_SIZE);
 
     WinLdrSetupGdt(GdtIdt, Tss);
 
-    WinLdrSetupIdt(GdtIdt);
+    WinLdrSetupIdt((PVOID)((ULONG64)GdtIdt + 2048)); // HACK!
+
+    DPRINTM(DPRINT_WINDOWS, "leave WinLdrSetProcessorContext\n");
 
 }
 

Modified: branches/ros-amd64-bringup/reactos/boot/freeldr/freeldr/windows/wlmemory.c
URL: http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/boot/freeldr/freeldr/windows/wlmemory.c?rev=43601&r1=43600&r2=43601&view=diff
==============================================================================
--- branches/ros-amd64-bringup/reactos/boot/freeldr/freeldr/windows/wlmemory.c [iso-8859-1] (original)
+++ branches/ros-amd64-bringup/reactos/boot/freeldr/freeldr/windows/wlmemory.c [iso-8859-1] Mon Oct 19 14:50:36 2009
@@ -14,10 +14,6 @@
 #include <debug.h>
 
 extern ULONG LoaderPagesSpanned;
-
-// This is needed because headers define wrong one for ReactOS
-#undef KIP0PCRADDRESS
-#define KIP0PCRADDRESS                      0xffdff000
 
 PCHAR  MemTypeDesc[]  = {
     "ExceptionBlock    ", // ?
@@ -63,7 +59,7 @@
 WinLdrRemoveDescriptor(IN PMEMORY_ALLOCATION_DESCRIPTOR Descriptor);
 
 VOID
-WinLdrSetProcessorContext(PVOID GdtIdt, IN ULONG Pcr, IN ULONG Tss);
+WinLdrSetProcessorContext(PVOID GdtIdt, IN ULONG_PTR Pcr, IN ULONG_PTR Tss);
 
 BOOLEAN
 MempAllocatePageTables();




More information about the Ros-diffs mailing list