/** @file\r
-\r
-Copyright 2006 - 2010, Intel Corporation \r
-All rights reserved. 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
-Module Name:\r
- GenPage.c\r
- \r
-Abstract:\r
Pre-Create a 4G page table (2M pages).\r
It's used in DUET x64 build needed to enter LongMode.\r
\r
(\r
Directory-Ptr Directory {512}\r
) {4}\r
+\r
+Copyright (c) 2006 - 2016, 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
#include <stdio.h>\r
//\r
// Utility Name\r
//\r
-#define UTILITY_NAME "GenBootSector"\r
+#define UTILITY_NAME "GenPage"\r
\r
//\r
// Utility version information\r
//\r
#define UTILITY_MAJOR_VERSION 0\r
-#define UTILITY_MINOR_VERSION 1\r
+#define UTILITY_MINOR_VERSION 2\r
\r
void\r
Version (\r
\r
--*/\r
{\r
- printf ("%s v%d.%d -Utility to generate the EfiLoader image containing page table.\n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION);\r
- printf ("Copyright (c) 2008 - 2010 Intel Corporation. All rights reserved.\n");\r
+ printf ("%s Version %d.%d %s\n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION, __BUILD_VERSION);\r
}\r
\r
VOID\r
void\r
)\r
{\r
- Version();\r
- printf ("\nUsage: \n\\r
- GenPage\n\\r
- -o, --output Filename containing page table\n\\r
- [-b, --baseaddr baseaddress of page table]\n\\r
- [-f, --offset offset in the file that page table will reside]\n\\r
- [-v, --verbose]\n\\r
- [--version]\n\\r
- [-q, --quiet disable all messages except fatal errors]\n\\r
- [-d, --debug[#]\n\\r
- [-h, --help]\n\\r
- EfiLoaderImageName\n");\r
+ printf ("Usage: GenPage.exe [options] EfiLoaderImageName \n\n\\r
+Copyright (c) 2008 - 2014, 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
+ --version Show program's version number and exit\n\\r
+ -d [DEBUG], --debug [DEBUG]\n\\r
+ Output DEBUG statements, where DEBUG_LEVEL is 0 (min)\n\\r
+ - 9 (max)\n\\r
+ -v, --verbose Print informational statements\n\\r
+ -q, --quiet Returns the exit code, error messages will be\n\\r
+ displayed\n\\r
+ -s, --silent Returns only the exit code; informational and error\n\\r
+ messages are not displayed\n\\r
+ -o OUTPUT_FILENAME, --output OUTPUT_FILENAME\n\\r
+ Output file contain both the non-page table part and\n\\r
+ the page table\n\\r
+ -b BASE_ADDRESS, --baseaddr BASE_ADDRESS\n\\r
+ The page table location\n\\r
+ -f OFFSET, --offset OFFSET\n\\r
+ The position that the page table will appear in the\n\\r
+ output file\n\\r
+ --sfo Reserved for future use\n");\r
\r
}\r
\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
//\r
// Open files\r
//\r
- PageFile = fopen (PageFileName, "w+b");\r
+ PageFile = fopen (LongFilePath (PageFileName), "w+b");\r
if (PageFile == NULL) {\r
Error (NoPageFileName, 0, 0x4002, "Invalid parameter option", "Output File %s open failure", PageFileName);\r
return -1;\r
}\r
\r
- NoPageFile = fopen (NoPageFileName, "r+b");\r
+ NoPageFile = fopen (LongFilePath (NoPageFileName), "r+b");\r
if (NoPageFile == NULL) {\r
Error (NoPageFileName, 0, 0x4002, "Invalid parameter option", "Input File %s open failure", NoPageFileName);\r
fclose (PageFile);\r
}\r
\r
//\r
- // Don't recognize the paramter.\r
+ // Don't recognize the parameter.\r
//\r
InputFile = argv[0];\r
argc--;\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