\r
#include "VirtualMemory.h"\r
\r
-EFI_PHYSICAL_ADDRESS\r
+UINTN\r
CreateIdentityMappingPageTables (\r
VOID\r
)\r
\r
--*/\r
{ \r
- UINT32 RegEax;\r
UINT8 PhysicalAddressBits;\r
EFI_PHYSICAL_ADDRESS PageAddress;\r
UINTN IndexOfPml4Entries;\r
PAGE_MAP_AND_DIRECTORY_POINTER *PageMap;\r
PAGE_MAP_AND_DIRECTORY_POINTER *PageDirectoryPointerEntry;\r
PAGE_TABLE_ENTRY *PageDirectoryEntry;\r
+ UINTN TotalPagesNum;\r
+ UINTN BigPageAddress;\r
+ VOID *Hob;\r
\r
//\r
- // By architecture only one PageMapLevel4 exists - so lets allocate storage for it.\r
- //\r
- PageMap = AllocatePages (1);\r
- ASSERT (PageMap != NULL);\r
-\r
- //\r
- // Get physical address bits supported.\r
+ // Get physical address bits supported from CPU HOB.\r
//\r
- AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL);\r
- if (RegEax >= 0x80000008) {\r
- AsmCpuid (0x80000008, &RegEax, NULL, NULL, NULL);\r
- PhysicalAddressBits = (UINT8) RegEax;\r
- } else {\r
- PhysicalAddressBits = 36;\r
+ PhysicalAddressBits = 36;\r
+ \r
+ Hob = GetFirstHob (EFI_HOB_TYPE_CPU);\r
+ if (Hob != NULL) {\r
+ PhysicalAddressBits = ((EFI_HOB_CPU *) Hob)->SizeOfMemorySpace; \r
}\r
\r
//\r
NumberOfPdpEntriesNeeded = 512;\r
}\r
\r
+ //\r
+ // Pre-allocate big pages to avoid later allocations. \r
+ //\r
+ TotalPagesNum = (NumberOfPdpEntriesNeeded + 1) * NumberOfPml4EntriesNeeded + 1;\r
+ BigPageAddress = (UINTN) AllocatePages (TotalPagesNum);\r
+ ASSERT (BigPageAddress != 0);\r
+\r
+ //\r
+ // By architecture only one PageMapLevel4 exists - so lets allocate storage for it.\r
+ //\r
+ PageMap = (VOID *) BigPageAddress;\r
+ BigPageAddress += EFI_PAGE_SIZE;\r
+\r
PageMapLevel4Entry = PageMap;\r
PageAddress = 0;\r
for (IndexOfPml4Entries = 0; IndexOfPml4Entries < NumberOfPml4EntriesNeeded; IndexOfPml4Entries++, PageMapLevel4Entry++) {\r
// Each PML4 entry points to a page of Page Directory Pointer entires.\r
// So lets allocate space for them and fill them in in the IndexOfPdpEntries loop.\r
//\r
- PageDirectoryPointerEntry = AllocatePages (1);\r
- ASSERT (PageDirectoryPointerEntry != NULL);\r
+ PageDirectoryPointerEntry = (VOID *) BigPageAddress;\r
+ BigPageAddress += EFI_PAGE_SIZE;\r
\r
//\r
// Make a PML4 Entry\r
// Each Directory Pointer entries points to a page of Page Directory entires.\r
// So allocate space for them and fill them in in the IndexOfPageDirectoryEntries loop.\r
// \r
- PageDirectoryEntry = AllocatePages (1);\r
- ASSERT (PageDirectoryEntry != NULL);\r
+ PageDirectoryEntry = (VOID *) BigPageAddress;\r
+ BigPageAddress += EFI_PAGE_SIZE;\r
\r
//\r
// Fill in a Page Directory Pointer Entries\r
);\r
}\r
\r
- return (EFI_PHYSICAL_ADDRESS) (UINTN)PageMap; // FIXME\r
+ return (UINTN)PageMap; // FIXME\r
}\r
\r