/** @file
Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
Abstract:
Pre-Create a 4G page table (2M pages).
It's used in DUET x64 build needed to enter LongMode.
Create 4G page table (2M pages)
Linear Address
63 48 47 39 38 30 29 21 20 0
+--------+-------+---------------+-----------+-----------------------------+
PML4 Directory-Ptr Directory Offset
Paging-Structures :=
PML4
(
Directory-Ptr Directory {512}
) {4}
**/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "VirtualMemory.h"
#include "EfiUtilityMsgs.h"
#include "ParseInf.h"
//
// Utility Name
//
//
// Utility version information
//
#define UTILITY_MAJOR_VERSION 0
void
Version (
void
)
/*++
Routine Description:
Displays the standard utility information to SDTOUT
Arguments:
None
Returns:
None
--*/
{
printf ("%s v%d.%d %s -Utility to generate the EfiLoader image containing page table.\n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION, __BUILD_VERSION);
printf ("Copyright (c) 2008 - 2011 Intel Corporation. All rights reserved.\n");
}
Usage (
void
)
{
Version();
printf ("\nUsage: \n\
GenPage\n\
-o, --output Filename\n\
The file that contains both non-page table part and\n\
page table\n\
[-b, --baseaddr baseaddress]\n\
The page table location\n\
[-f, --offset offset]\n\
The position that the page table will appear in the\n\
output file\n\
[-v, --verbose] Turn on verbose output with informational messages\n\
printed\n\
[--version] Print version and copyright of this program and exit\n\
[-q, --quiet] Disable all messages except unrecoverable errors\n\
[-d, --debug[#]] Enable debug messages, at level #\n\
[-h, --help] Print copyright, version and usage of this program\n\
and exit\n\
EfiLoaderImageName\n");
}
void *
void
)
/*++
Routine Description:
To create 4G PAE 2M pagetable
Return:
void * - buffer containing created pagetable
--*/
{
int PML4Index;
int PDPTEIndex;
int PDEIndex;
PageAddress = 0;
//
// Page Table structure 3 level 2MB.
//
// Page-Map-Level-4-Table : bits 47-39
// Page-Directory-Pointer-Table : bits 38-30
//
// Page Table 2MB : Page-Directory(2M) : bits 29-21
//
//
//
// Each Page-Map-Level-4-Table Entry points to the base address of a Page-Directory-Pointer-Table Entry
//
//
// Make a Page-Map-Level-4-Table Entry
//
PageMapLevel4Entry->Uint64 = (UINT64)(UINT32)(CONVERT_BIN_PAGE_ADDRESS (PageDirectoryPointerEntry));
//
// Each Page-Directory-Pointer-Table Entry points to the base address of a Page-Directory Entry
//
//
// Make a Page-Directory-Pointer-Table Entry
//
PageDirectoryPointerEntry->Uint64 = (UINT64)(UINT32)(CONVERT_BIN_PAGE_ADDRESS (PageDirectoryEntry2MB));
//
// Make a Page-Directory Entry
//
}
}
}
return PageTable;
}
void *BaseMemory,
char *NoPageFileName,
char *PageFileName
)
/*++
Routine Description:
Write the buffer containing page table to file at a specified offset.
Here the offset is defined as EFI_PAGE_BASE_OFFSET_IN_LDR.
Arguments:
BaseMemory - buffer containing page table
NoPageFileName - file to write page table
PageFileName - file save to after writing
return:
0 : successful
-1 : failed
--*/
{
unsigned long FileSize;
//
// Open files
//
Error (NoPageFileName, 0, 0x4002, "Invalid parameter option", "Output File %s open failure", PageFileName);
return -1;
}
if (NoPageFile == NULL) {
Error (NoPageFileName, 0, 0x4002, "Invalid parameter option", "Input File %s open failure", NoPageFileName);
return -1;
}
//
// Check size - should not be great than EFI_PAGE_BASE_OFFSET_IN_LDR
//
if (FileSize > gPageTableOffsetInFile) {
Error (NoPageFileName, 0, 0x4002, "Invalid parameter option", "Input file size (0x%lx) exceeds the Page Table Offset (0x%x)", FileSize, (unsigned) gPageTableOffsetInFile);
fclose (NoPageFile);
return -1;
}
//
// Write data
//
}
//
// Write PageTable
//
//
// Close files
//
fclose (NoPageFile);
return 0;
}
int
main (
int argc,
char **argv
)
{
SetUtilityName("GenPage");
if (argc == 1) {
Usage();
return STATUS_ERROR;
}
argc --;
argv ++;
Usage();
return 0;
}
Version();
return 0;
}
while (argc > 0) {
return STATUS_ERROR;
}
argc -= 2;
argv += 2;
continue;
}
return STATUS_ERROR;
}
return STATUS_ERROR;
}
argc -= 2;
argv += 2;
continue;
}
return STATUS_ERROR;
}
return STATUS_ERROR;
}
argc -= 2;
argv += 2;
continue;
}
argc --;
argv ++;
continue;
}
argc --;
argv ++;
continue;
}
return STATUS_ERROR;
}
return STATUS_ERROR;
}
if (TempValue > 9) {
Error (NULL, 0, 1003, "Invalid option value", "Debug Level range is 0-9, currnt input level is %d", (int) TempValue);
return STATUS_ERROR;
}
argc -= 2;
argv += 2;
continue;
}
if (argv[0][0] == '-') {
return STATUS_ERROR;
}
//
// Don't recognize the paramter.
//
argc--;
argv++;
}
return STATUS_ERROR;
}
//
// Create X64 page table
//
//
// Add page table to binary file
//
if (result < 0) {
return STATUS_ERROR;
}
return 0;
}