Author: tkreuzer Date: Thu Sep 15 10:46:02 2011 New Revision: 53709
URL: http://svn.reactos.org/svn/reactos?rev=53709&view=rev Log: [FREELDR/HAL/NDK] - Move some shared constants (HYPERSPACE_BASE, MM_HAL_VA_START, APIC_BASE) to NDK to avoid duplicating them, also fix wrong values for amd64 - Map the hal address space in amd64 freeldr - Fix use of uninitialized variable (HighPart of PHYSICAL_ADDRESS) in HalpAcpiCopyBiosTable - Fix some MSVC and amd64 warnings
Modified: trunk/reactos/boot/freeldr/freeldr/arch/amd64/winldr.c trunk/reactos/boot/freeldr/freeldr/include/arch/amd64/amd64.h trunk/reactos/boot/freeldr/freeldr/include/reactos.h trunk/reactos/hal/halx86/acpi/halacpi.c trunk/reactos/hal/halx86/apic/apic.h trunk/reactos/hal/halx86/apic/apictrap.S trunk/reactos/hal/halx86/generic/memory.c trunk/reactos/hal/halx86/include/halp.h trunk/reactos/include/ndk/amd64/ketypes.h trunk/reactos/include/ndk/i386/ketypes.h
Modified: trunk/reactos/boot/freeldr/freeldr/arch/amd64/winldr.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/a... ============================================================================== --- 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] Thu Sep 15 10:46:02 2011 @@ -235,22 +235,30 @@ BOOLEAN WinLdrMapSpecialPages() { - /* Map the PCR page */ - if (!MempMapSinglePage(KIP0PCRADDRESS, PcrBasePage * PAGE_SIZE)) - { - ERR("Could not map PCR @ %lx\n", PcrBasePage); - return FALSE; - } - - /* Map KI_USER_SHARED_DATA */ - if (!MempMapSinglePage(KI_USER_SHARED_DATA, (PcrBasePage+1) * PAGE_SIZE)) - { - ERR("Could not map KI_USER_SHARED_DATA\n"); - return FALSE; - } + PHARDWARE_PTE PpeBase, PdeBase, PteBase; + + /* Map the PCR page */ + if (!MempMapSinglePage(KIP0PCRADDRESS, PcrBasePage * PAGE_SIZE)) + { + ERR("Could not map PCR @ %lx\n", PcrBasePage); + return FALSE; + } + + /* Map KI_USER_SHARED_DATA */ + if (!MempMapSinglePage(KI_USER_SHARED_DATA, (PcrBasePage+1) * PAGE_SIZE)) + { + ERR("Could not map KI_USER_SHARED_DATA\n"); + return FALSE; + }
/* Map the APIC page */ WinLdrpMapApic(); + + /* Map the page tables for 4 MB HAL address space. */ + PpeBase = MempGetOrCreatePageDir(PxeBase, VAtoPXI(MM_HAL_VA_START)); + PdeBase = MempGetOrCreatePageDir(PpeBase, VAtoPPI(MM_HAL_VA_START)); + MempGetOrCreatePageDir(PdeBase, VAtoPDI(MM_HAL_VA_START)); + MempGetOrCreatePageDir(PdeBase, VAtoPDI(MM_HAL_VA_START + 2 * 1024 * 1024));
return TRUE; }
Modified: trunk/reactos/boot/freeldr/freeldr/include/arch/amd64/amd64.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/includ... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/include/arch/amd64/amd64.h [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/include/arch/amd64/amd64.h [iso-8859-1] Thu Sep 15 10:46:02 2011 @@ -36,14 +36,6 @@ #define VAtoPDI(va) ((((ULONG64)va) >> PDI_SHIFT) & 0x1FF) #define VAtoPTI(va) ((((ULONG64)va) >> PTI_SHIFT) & 0x1FF)
-#define HYPERSPACE_BASE 0xfffff70000000000ULL -#define HAL_BASE 0xffffffff80000000ULL -#define APIC_BASE 0xFFFFFFFFFFFE0000ULL - -#define APIC_PHYS_BASE 0xfee00000 - -#define NUM_PAGES_KERNEL - #ifndef ASM
VOID FrLdrSetupGdtIdt(VOID);
Modified: trunk/reactos/boot/freeldr/freeldr/include/reactos.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/includ... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/include/reactos.h [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/include/reactos.h [iso-8859-1] Thu Sep 15 10:46:02 2011 @@ -40,8 +40,6 @@ ((p) >> PFN_SHIFT)
#define STARTUP_BASE 0xC0000000 -#define HAL_BASE 0xFFC00000 -#define APIC_BASE 0xFFFE0000
#define LowMemPageTableIndex 0 #define StartupPageTableIndex (STARTUP_BASE >> 22)
Modified: trunk/reactos/hal/halx86/acpi/halacpi.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/hal/halx86/acpi/halacpi.c?r... ============================================================================== --- trunk/reactos/hal/halx86/acpi/halacpi.c [iso-8859-1] (original) +++ trunk/reactos/hal/halx86/acpi/halacpi.c [iso-8859-1] Thu Sep 15 10:46:02 2011 @@ -100,11 +100,11 @@ { /* Phase 0: Convert to pages and use the HAL heap */ PageCount = BYTES_TO_PAGES(Size); - PhysAddress.LowPart = HalpAllocPhysicalMemory(LoaderBlock, - 0x1000000, - PageCount, - FALSE); - if (PhysAddress.LowPart) + PhysAddress.QuadPart = HalpAllocPhysicalMemory(LoaderBlock, + 0x1000000, + PageCount, + FALSE); + if (PhysAddress.QuadPart) { /* Map it */ CachedTable = HalpMapPhysicalMemory64(PhysAddress, PageCount); @@ -217,7 +217,7 @@ } else { - /* To find tables, we need the RSDT */ + /* To find tables, we need the RSDT */ Rsdt = HalpAcpiGetTable(LoaderBlock, RSDT_SIGNATURE); if (Rsdt) { @@ -342,7 +342,7 @@ ASSERT(Header);
/* How many pages do we need? */ - PageCount = BYTES_TO_PAGES(Header->Length); + PageCount = BYTES_TO_PAGES(Header->Length); if (PageCount != 2) { /* We assumed two, but this is not the case, free the current mapping */ @@ -546,7 +546,7 @@ PCONFIGURATION_COMPONENT_DATA Next = NULL; PCM_PARTIAL_RESOURCE_LIST ResourceList; PACPI_BIOS_MULTI_NODE NodeData; - ULONG NodeLength; + SIZE_T NodeLength; PFN_NUMBER PageCount; PVOID MappedAddress; PHYSICAL_ADDRESS PhysicalAddress; @@ -605,12 +605,11 @@ PageCount = BYTES_TO_PAGES(NodeLength);
/* Allocate the memory */ - PhysicalAddress.HighPart = 0; - PhysicalAddress.LowPart = HalpAllocPhysicalMemory(LoaderBlock, - 0x1000000, - PageCount, - FALSE); - if (PhysicalAddress.LowPart) + PhysicalAddress.QuadPart = HalpAllocPhysicalMemory(LoaderBlock, + 0x1000000, + PageCount, + FALSE); + if (PhysicalAddress.QuadPart) { /* Map it if the allocation worked */ MappedAddress = HalpMapPhysicalMemory64(PhysicalAddress, PageCount); @@ -741,7 +740,7 @@ MmUnmapIoSpace(MappedAddress, TableLength << PAGE_SHIFT); }
- /* Cache the RSDT */ + /* Cache the RSDT */ HalpAcpiCacheTable(&Rsdt->Header);
/* Check for compatible loader block extension */ @@ -825,7 +824,7 @@ HalpNumaInitializeStaticConfiguration(LoaderBlock);
/* Initialize hotplug through the SRAT */ - HalpDynamicSystemResourceConfiguration(LoaderBlock); + HalpDynamicSystemResourceConfiguration(LoaderBlock); DPRINT1("ACPI SRAT at 0x%p\n", HalpAcpiSrat); if (HalpAcpiSrat) { @@ -843,14 +842,14 @@ HaliAcpiTimerInit(0, 0);
/* Do we have a low stub address yet? */ - if (!HalpLowStubPhysicalAddress.LowPart) + if (!HalpLowStubPhysicalAddress.QuadPart) { /* Allocate it */ - HalpLowStubPhysicalAddress.LowPart = HalpAllocPhysicalMemory(LoaderBlock, - 0x100000, - 1, - FALSE); - if (HalpLowStubPhysicalAddress.LowPart) + HalpLowStubPhysicalAddress.QuadPart = HalpAllocPhysicalMemory(LoaderBlock, + 0x100000, + 1, + FALSE); + if (HalpLowStubPhysicalAddress.QuadPart) { /* Map it */ HalpLowStub = HalpMapPhysicalMemory64(HalpLowStubPhysicalAddress, 1);
Modified: trunk/reactos/hal/halx86/apic/apic.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/hal/halx86/apic/apic.h?rev=... ============================================================================== --- trunk/reactos/hal/halx86/apic/apic.h [iso-8859-1] (original) +++ trunk/reactos/hal/halx86/apic/apic.h [iso-8859-1] Thu Sep 15 10:46:02 2011 @@ -1,7 +1,6 @@
#ifdef _M_AMD64 -#define APIC_BASE 0xFFFFFFFFFEE00000ULL -#define IOAPIC_BASE 0xFFFFFFFFFEE01000ULL // checkme +#define IOAPIC_BASE 0xFFFFFFFFFFFE1000ULL // checkme #define ZERO_VECTOR 0x00 // IRQL 00 #define APC_VECTOR 0x3D // IRQL 01 #define APIC_SPURIOUS_VECTOR 0x3f @@ -18,7 +17,6 @@ #define TprToIrql(Tpr) ((KIRQL)(Tpr >> 4)) #define CLOCK2_LEVEL CLOCK_LEVEL #else -#define APIC_BASE 0xFFFE0000 #define IOAPIC_BASE 0xFFFE1000 // checkme #define ZERO_VECTOR 0x00 // IRQL 00 #define APIC_SPURIOUS_VECTOR 0x1f
Modified: trunk/reactos/hal/halx86/apic/apictrap.S URL: http://svn.reactos.org/svn/reactos/trunk/reactos/hal/halx86/apic/apictrap.S?... ============================================================================== --- trunk/reactos/hal/halx86/apic/apictrap.S [iso-8859-1] (original) +++ trunk/reactos/hal/halx86/apic/apictrap.S [iso-8859-1] Thu Sep 15 10:46:02 2011 @@ -34,7 +34,7 @@ push rax lea rax, HackEoiReturn[rip] push rax - mov dword ptr [HEX(0FFFFFFFFFEE000B0)], 0 + mov dword ptr [HEX(0FFFFFFFFFFFE00B0)], 0 iretq HackEoiReturn: ret
Modified: trunk/reactos/hal/halx86/generic/memory.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/hal/halx86/generic/memory.c... ============================================================================== --- trunk/reactos/hal/halx86/generic/memory.c [iso-8859-1] (original) +++ trunk/reactos/hal/halx86/generic/memory.c [iso-8859-1] Thu Sep 15 10:46:02 2011 @@ -13,8 +13,7 @@ #include <debug.h>
/* Share with Mm headers? */ -#define MM_HAL_VA_START (PVOID)0xFFC00000 -#define MM_HAL_HEAP_START (PVOID)((ULONG_PTR)MM_HAL_VA_START + (1024 * 1024)) +#define MM_HAL_HEAP_START (PVOID)(MM_HAL_VA_START + (1024 * 1024))
/* GLOBALS *******************************************************************/
@@ -25,14 +24,15 @@
/* PRIVATE FUNCTIONS *********************************************************/
-ULONG +ULONG_PTR NTAPI HalpAllocPhysicalMemory(IN PLOADER_PARAMETER_BLOCK LoaderBlock, - IN ULONG MaxAddress, - IN ULONG PageCount, + IN ULONG_PTR MaxAddress, + IN PFN_NUMBER PageCount, IN BOOLEAN Aligned) { - ULONG UsedDescriptors, Alignment, PhysicalAddress; + ULONG UsedDescriptors, Alignment; + ULONG_PTR PhysicalAddress; PFN_NUMBER MaxPage, BasePage; PLIST_ENTRY NextEntry; PMEMORY_ALLOCATION_DESCRIPTOR MdBlock, NewBlock, FreeBlock; @@ -87,7 +87,7 @@
/* Okay, now get a descriptor */ NewBlock = &HalpAllocationDescriptorArray[HalpUsedAllocDescriptors]; - NewBlock->PageCount = PageCount; + NewBlock->PageCount = (ULONG)PageCount; NewBlock->BasePage = MdBlock->BasePage + Alignment; NewBlock->MemoryType = LoaderHALCachedMemory;
@@ -103,8 +103,8 @@ { /* Get the next descriptor */ FreeBlock = &HalpAllocationDescriptorArray[UsedDescriptors]; - FreeBlock->PageCount = MdBlock->PageCount - Alignment - PageCount; - FreeBlock->BasePage = MdBlock->BasePage + Alignment + PageCount; + FreeBlock->PageCount = MdBlock->PageCount - Alignment - (ULONG)PageCount; + FreeBlock->BasePage = MdBlock->BasePage + Alignment + (ULONG)PageCount;
/* One more */ HalpUsedAllocDescriptors++; @@ -120,8 +120,8 @@ else { /* Consume memory from this block */ - MdBlock->BasePage += PageCount; - MdBlock->PageCount -= PageCount; + MdBlock->BasePage += (ULONG)PageCount; + MdBlock->PageCount -= (ULONG)PageCount;
/* Insert the descriptor */ InsertTailList(&MdBlock->ListEntry, &NewBlock->ListEntry); @@ -137,10 +137,10 @@ PVOID NTAPI HalpMapPhysicalMemory64(IN PHYSICAL_ADDRESS PhysicalAddress, - IN ULONG PageCount) + IN PFN_NUMBER PageCount) { PHARDWARE_PTE PointerPte; - ULONG UsedPages = 0; + PFN_NUMBER UsedPages = 0; PVOID VirtualAddress, BaseAddress;
/* Start at the current HAL heap base */ @@ -205,13 +205,13 @@ VOID NTAPI HalpUnmapVirtualAddress(IN PVOID VirtualAddress, - IN ULONG PageCount) + IN PFN_NUMBER PageCount) { PHARDWARE_PTE PointerPte; ULONG i;
/* Only accept valid addresses */ - if (VirtualAddress < MM_HAL_VA_START) return; + if (VirtualAddress < (PVOID)MM_HAL_VA_START) return;
/* Align it down to page size */ VirtualAddress = (PVOID)((ULONG_PTR)VirtualAddress & ~(PAGE_SIZE - 1));
Modified: trunk/reactos/hal/halx86/include/halp.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/hal/halx86/include/halp.h?r... ============================================================================== --- trunk/reactos/hal/halx86/include/halp.h [iso-8859-1] (original) +++ trunk/reactos/hal/halx86/include/halp.h [iso-8859-1] Thu Sep 15 10:46:02 2011 @@ -639,18 +639,27 @@ // // Memory routines // +ULONG_PTR +NTAPI +HalpAllocPhysicalMemory( + IN PLOADER_PARAMETER_BLOCK LoaderBlock, + IN ULONG_PTR MaxAddress, + IN PFN_NUMBER PageCount, + IN BOOLEAN Aligned +); + PVOID NTAPI HalpMapPhysicalMemory64( IN PHYSICAL_ADDRESS PhysicalAddress, - IN ULONG NumberPage + IN PFN_NUMBER PageCount );
VOID NTAPI HalpUnmapVirtualAddress( IN PVOID VirtualAddress, - IN ULONG NumberPages + IN PFN_NUMBER NumberPages );
/* sysinfo.c */ @@ -736,22 +745,6 @@ NTAPI HalpReleaseCmosSpinLock( VOID -); - -ULONG -NTAPI -HalpAllocPhysicalMemory( - IN PLOADER_PARAMETER_BLOCK LoaderBlock, - IN ULONG MaxAddress, - IN ULONG PageCount, - IN BOOLEAN Aligned -); - -PVOID -NTAPI -HalpMapPhysicalMemory64( - IN PHYSICAL_ADDRESS PhysicalAddress, - IN ULONG PageCount );
NTSTATUS @@ -852,8 +845,8 @@ #ifdef _M_AMD64 #define KfLowerIrql KeLowerIrql #define KiEnterInterruptTrap(TrapFrame) /* We do all neccessary in asm code */ -#define KiEoiHelper() return -#define HalBeginSystemInterrupt(Irql, Vector, OldIrql) TRUE +#define KiEoiHelper(TrapFrame) return /* Just return to the caller */ +#define HalBeginSystemInterrupt(Irql, Vector, OldIrql) (KeRaiseIrql(Irql, OldIrql), TRUE) #ifndef CONFIG_SMP /* On UP builds, spinlocks don't exist at IRQL >= DISPATCH */ #define KiAcquireSpinLock(SpinLock)
Modified: trunk/reactos/include/ndk/amd64/ketypes.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/include/ndk/amd64/ketypes.h... ============================================================================== --- trunk/reactos/include/ndk/amd64/ketypes.h [iso-8859-1] (original) +++ trunk/reactos/include/ndk/amd64/ketypes.h [iso-8859-1] Thu Sep 15 10:46:02 2011 @@ -162,6 +162,9 @@ // HAL Variables // #define INITIAL_STALL_COUNT 100 +#define HYPERSPACE_BASE 0xfffff70000000000ULL +#define MM_HAL_VA_START 0xFFFFFFFFFFC00000ULL /* This is Vista+ */ +#define APIC_BASE 0xFFFFFFFFFFFE0000ULL
// // IOPM Definitions
Modified: trunk/reactos/include/ndk/i386/ketypes.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/include/ndk/i386/ketypes.h?... ============================================================================== --- trunk/reactos/include/ndk/i386/ketypes.h [iso-8859-1] (original) +++ trunk/reactos/include/ndk/i386/ketypes.h [iso-8859-1] Thu Sep 15 10:46:02 2011 @@ -136,6 +136,13 @@ // HAL Variables // #define INITIAL_STALL_COUNT 100 +#ifdef PAE +#define HYPERSPACE_BASE 0xc0400000 +#else +#define HYPERSPACE_BASE 0xc0800000 +#endif +#define MM_HAL_VA_START 0xFFC00000 +#define APIC_BASE 0xFFFE0000
// // IOPM Definitions