/** @file\r
Pre-Create a 4G page table (2M pages).\r
It's used in DUET x64 build needed to enter LongMode.\r
- \r
+\r
Create 4G page table (2M pages)\r
- \r
+\r
Linear Address\r
63 48 47 39 38 30 29 21 20 0\r
+--------+-------+---------------+-----------+-----------------------------+\r
Directory-Ptr Directory {512}\r
) {4}\r
\r
-Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials \r
-are licensed and made available under the terms and conditions of the BSD License \r
-which accompanies this distribution. The full text of the license may be found at \r
-http://opensource.org/licenses/bsd-license.php \r
- \r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution. The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
\r
**/\r
\r
)\r
{\r
printf ("Usage: GenPage.exe [options] EfiLoaderImageName \n\n\\r
-Copyright (c) 2008 - 2014, Intel Corporation. All rights reserved.\n\n\\r
+Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.\n\n\\r
Utility to generate the EfiLoader image containing a page table.\n\n\\r
optional arguments:\n\\r
-h, --help Show this help message and exit\n\\r
X64_PAGE_TABLE_ENTRY_2M *PageDirectoryEntry2MB;\r
\r
PageTable = (void *)malloc (EFI_PAGE_NUMBER * EFI_SIZE_OF_PAGE);\r
+ if (PageTable == NULL) {\r
+ Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");\r
+ return NULL;\r
+ }\r
memset (PageTable, 0, (EFI_PAGE_NUMBER * EFI_SIZE_OF_PAGE));\r
PageTablePtr = PageTable;\r
\r
for (PML4Index = 0; PML4Index < EFI_PML4_ENTRY_NUM; PML4Index++, PageMapLevel4Entry++) {\r
//\r
// Each Page-Map-Level-4-Table Entry points to the base address of a Page-Directory-Pointer-Table Entry\r
- // \r
+ //\r
PageTablePtr += EFI_SIZE_OF_PAGE;\r
PageDirectoryPointerEntry = (X64_PAGE_MAP_AND_DIRECTORY_POINTER_2MB_4K *)PageTablePtr;\r
\r
for (PDPTEIndex = 0; PDPTEIndex < EFI_PDPTE_ENTRY_NUM; PDPTEIndex++, PageDirectoryPointerEntry++) {\r
//\r
// Each Page-Directory-Pointer-Table Entry points to the base address of a Page-Directory Entry\r
- // \r
+ //\r
PageTablePtr += EFI_SIZE_OF_PAGE;\r
PageDirectoryEntry2MB = (X64_PAGE_TABLE_ENTRY_2M *)PageTablePtr;\r
\r
Usage();\r
return STATUS_ERROR;\r
}\r
- \r
+\r
argc --;\r
argv ++;\r
\r
if ((stricmp (argv[0], "-h") == 0) || (stricmp (argv[0], "--help") == 0)) {\r
Usage();\r
- return 0; \r
+ return 0;\r
}\r
\r
if (stricmp (argv[0], "--version") == 0) {\r
Version();\r
- return 0; \r
+ return 0;\r
}\r
- \r
+\r
while (argc > 0) {\r
if ((stricmp (argv[0], "-o") == 0) || (stricmp (argv[0], "--output") == 0)) {\r
if (argv[1] == NULL || argv[1][0] == '-') {\r
OutputFile = argv[1];\r
argc -= 2;\r
argv += 2;\r
- continue; \r
+ continue;\r
}\r
- \r
+\r
if ((stricmp (argv[0], "-b") == 0) || (stricmp (argv[0], "--baseaddr") == 0)) {\r
if (argv[1] == NULL || argv[1][0] == '-') {\r
Error (NULL, 0, 1003, "Invalid option value", "Base address is missing for -b option");\r
gPageTableBaseAddress = (UINT32) TempValue;\r
argc -= 2;\r
argv += 2;\r
- continue; \r
+ continue;\r
}\r
- \r
+\r
if ((stricmp (argv[0], "-f") == 0) || (stricmp (argv[0], "--offset") == 0)) {\r
if (argv[1] == NULL || argv[1][0] == '-') {\r
Error (NULL, 0, 1003, "Invalid option value", "Offset is missing for -f option");\r
gPageTableOffsetInFile = (UINT32) TempValue;\r
argc -= 2;\r
argv += 2;\r
- continue; \r
+ continue;\r
}\r
\r
if ((stricmp (argv[0], "-q") == 0) || (stricmp (argv[0], "--quiet") == 0)) {\r
argc --;\r
argv ++;\r
- continue; \r
+ continue;\r
}\r
- \r
+\r
if ((stricmp (argv[0], "-v") ==0) || (stricmp (argv[0], "--verbose") == 0)) {\r
argc --;\r
argv ++;\r
- continue; \r
+ continue;\r
}\r
- \r
+\r
if ((stricmp (argv[0], "-d") == 0) || (stricmp (argv[0], "--debug") == 0)) {\r
if (argv[1] == NULL || argv[1][0] == '-') {\r
Error (NULL, 0, 1003, "Invalid option value", "Debug Level is not specified.");\r
}\r
argc -= 2;\r
argv += 2;\r
- continue; \r
+ continue;\r
}\r
\r
if (argv[0][0] == '-') {\r
Error (NULL, 0, 1000, "Unknown option", argv[0]);\r
return STATUS_ERROR;\r
}\r
- \r
+\r
//\r
- // Don't recognize the paramter.\r
+ // Don't recognize the parameter.\r
//\r
InputFile = argv[0];\r
argc--;\r
argv++;\r
}\r
- \r
+\r
if (InputFile == NULL) {\r
Error (NULL, 0, 1003, "Invalid option value", "Input file is not specified");\r
return STATUS_ERROR;\r
}\r
- \r
+\r
//\r
// Create X64 page table\r
//\r
BaseMemory = CreateIdentityMappingPageTables ();\r
+ if (BaseMemory == NULL) {\r
+ Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");\r
+ return STATUS_ERROR;\r
+ }\r
\r
//\r
// Add page table to binary file\r
//\r
result = GenBinPage (BaseMemory, InputFile, OutputFile);\r
if (result < 0) {\r
+ free (BaseMemory);\r
return STATUS_ERROR;\r
}\r
\r
+ free (BaseMemory);\r
return 0;\r
}\r
\r