summaryrefslogtreecommitdiff
path: root/EdkCompatibilityPkg/Sample/Tools/Source/GenPage
diff options
context:
space:
mode:
Diffstat (limited to 'EdkCompatibilityPkg/Sample/Tools/Source/GenPage')
-rw-r--r--EdkCompatibilityPkg/Sample/Tools/Source/GenPage/Makefile95
-rw-r--r--EdkCompatibilityPkg/Sample/Tools/Source/GenPage/VirtualMemory.h127
-rw-r--r--EdkCompatibilityPkg/Sample/Tools/Source/GenPage/genpage.c344
3 files changed, 0 insertions, 566 deletions
diff --git a/EdkCompatibilityPkg/Sample/Tools/Source/GenPage/Makefile b/EdkCompatibilityPkg/Sample/Tools/Source/GenPage/Makefile
deleted file mode 100644
index 8c4addb43d..0000000000
--- a/EdkCompatibilityPkg/Sample/Tools/Source/GenPage/Makefile
+++ /dev/null
@@ -1,95 +0,0 @@
-#/*++
-#
-# Copyright (c) 2006 - 2007, Intel Corporation
-# All rights reserved. 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
-# http://opensource.org/licenses/bsd-license.php
-#
-# 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:
-#
-# Makefile
-#
-# Abstract:
-#
-# makefile for building the GenPage utility.
-#
-#--*/
-
-#
-# Make sure environmental variable EDK_SOURCE is set
-#
-!IFNDEF EDK_SOURCE
-!ERROR EDK_SOURCE environmental variable not set
-!ENDIF
-
-#
-# Do this if you want to compile from this directory
-#
-!IFNDEF TOOLCHAIN
-TOOLCHAIN = TOOLCHAIN_MSVC
-!ENDIF
-
-!INCLUDE $(BUILD_DIR)\PlatformTools.env
-
-#
-# Define some macros we use here. Should get rid of them someday and
-# get rid of the extra level of indirection.
-#
-COMMON_SOURCE = $(EDK_TOOLS_COMMON)
-
-#
-# Common information
-#
-
-INC=$(INC)
-
-#
-# Target specific information
-#
-
-TARGET_NAME=GenPage
-TARGET_SOURCE_DIR = $(EDK_TOOLS_SOURCE)\$(TARGET_NAME)
-
-TARGET_EXE = $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).exe
-
-TARGET_EXE_SOURCE = "$(TARGET_SOURCE_DIR)\GenPage.c"
-TARGET_EXE_INCLUDE = "$(TARGET_SOURCE_DIR)\VirtualMemory.h"
-
-#
-# Build targets
-#
-
-all: $(TARGET_EXE)
-
-#
-# Build EXE
-#
-
-$(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).obj: $(TARGET_EXE_SOURCE) $(TARGET_EXE_INCLUDE)
- $(CC) $(C_FLAGS) $(INC) $(TARGET_EXE_SOURCE) /Fo$(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).obj
-
-#
-# Add Binary Build description for this tool.
-#
-
-!IF (("$(EFI_BINARY_TOOLS)" == "YES") && EXIST($(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).exe))
-$(TARGET_EXE): $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).exe
- copy $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).exe $(TARGET_EXE) /Y
- if exist $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb \
- copy $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb /Y
-!ELSE
-$(TARGET_EXE): $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).obj
- $(LINK) $(MSVS_LINK_LIBPATHS) $(L_FLAGS) /out:$(TARGET_EXE) $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).obj
- if not exist $(EFI_PLATFORM_BIN)\Tools mkdir $(EFI_PLATFORM_BIN)\Tools
- if exist $(TARGET_EXE) copy $(TARGET_EXE) $(EFI_PLATFORM_BIN)\tools\$(TARGET_NAME).exe /Y
- if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb \
- copy $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb /Y
-!ENDIF
-
-clean:
- @if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).* del $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).* > NUL
-
diff --git a/EdkCompatibilityPkg/Sample/Tools/Source/GenPage/VirtualMemory.h b/EdkCompatibilityPkg/Sample/Tools/Source/GenPage/VirtualMemory.h
deleted file mode 100644
index d9d928f4e4..0000000000
--- a/EdkCompatibilityPkg/Sample/Tools/Source/GenPage/VirtualMemory.h
+++ /dev/null
@@ -1,127 +0,0 @@
-/*++
-
-Copyright 2006 - 2007, Intel Corporation
-All rights reserved. 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
-http://opensource.org/licenses/bsd-license.php
-
-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:
- VirtualMemory.h
-
-Abstract:
-
- x64 Long Mode Virtual Memory Management Definitions
-
- References:
- 1) IA-32 Intel(R) Atchitecture Software Developer's Manual Volume 1:Basic Architecture, Intel
- 2) IA-32 Intel(R) Atchitecture Software Developer's Manual Volume 2:Instruction Set Reference, Intel
- 3) IA-32 Intel(R) Atchitecture Software Developer's Manual Volume 3:System Programmer's Guide, Intel
- 4) AMD64 Architecture Programmer's Manual Volume 2: System Programming
---*/
-
-#ifndef _VIRTUAL_MEMORY_H_
-#define _VIRTUAL_MEMORY_H_
-
-#include "Tiano.h"
-
-#pragma pack(1)
-
-//
-// Page-Map Level-4 Offset (PML4) and
-// Page-Directory-Pointer Offset (PDPE) entries 4K & 2MB
-//
-
-typedef union {
- struct {
- UINT64 Present:1; // 0 = Not present in memory, 1 = Present in memory
- UINT64 ReadWrite:1; // 0 = Read-Only, 1= Read/Write
- UINT64 UserSupervisor:1; // 0 = Supervisor, 1=User
- UINT64 WriteThrough:1; // 0 = Write-Back caching, 1=Write-Through caching
- UINT64 CacheDisabled:1; // 0 = Cached, 1=Non-Cached
- UINT64 Accessed:1; // 0 = Not accessed, 1 = Accessed (set by CPU)
- UINT64 Reserved:1; // Reserved
- UINT64 MustBeZero:2; // Must Be Zero
- UINT64 Available:3; // Available for use by system software
- UINT64 PageTableBaseAddress:40; // Page Table Base Address
- UINT64 AvabilableHigh:11; // Available for use by system software
- UINT64 Nx:1; // No Execute bit
- } Bits;
- UINT64 Uint64;
-} X64_PAGE_MAP_AND_DIRECTORY_POINTER_2MB_4K;
-
-//
-// Page-Directory Offset 4K
-//
-typedef union {
- struct {
- UINT64 Present:1; // 0 = Not present in memory, 1 = Present in memory
- UINT64 ReadWrite:1; // 0 = Read-Only, 1= Read/Write
- UINT64 UserSupervisor:1; // 0 = Supervisor, 1=User
- UINT64 WriteThrough:1; // 0 = Write-Back caching, 1=Write-Through caching
- UINT64 CacheDisabled:1; // 0 = Cached, 1=Non-Cached
- UINT64 Accessed:1; // 0 = Not accessed, 1 = Accessed (set by CPU)
- UINT64 Reserved:1; // Reserved
- UINT64 MustBeZero:1; // Must Be Zero
- UINT64 Reserved2:1; // Reserved
- UINT64 Available:3; // Available for use by system software
- UINT64 PageTableBaseAddress:40; // Page Table Base Address
- UINT64 AvabilableHigh:11; // Available for use by system software
- UINT64 Nx:1; // No Execute bit
- } Bits;
- UINT64 Uint64;
-} X64_PAGE_DIRECTORY_ENTRY_4K;
-
-//
-// Page Table Entry 4K
-//
-typedef union {
- struct {
- UINT64 Present:1; // 0 = Not present in memory, 1 = Present in memory
- UINT64 ReadWrite:1; // 0 = Read-Only, 1= Read/Write
- UINT64 UserSupervisor:1; // 0 = Supervisor, 1=User
- UINT64 WriteThrough:1; // 0 = Write-Back caching, 1=Write-Through caching
- UINT64 CacheDisabled:1; // 0 = Cached, 1=Non-Cached
- UINT64 Accessed:1; // 0 = Not accessed, 1 = Accessed (set by CPU)
- UINT64 Dirty:1; // 0 = Not Dirty, 1 = written by processor on access to page
- UINT64 PAT:1; // 0 = Ignore Page Attribute Table
- UINT64 Global:1; // 0 = Not global page, 1 = global page TLB not cleared on CR3 write
- UINT64 Available:3; // Available for use by system software
- UINT64 PageTableBaseAddress:40; // Page Table Base Address
- UINT64 AvabilableHigh:11; // Available for use by system software
- UINT64 Nx:1; // 0 = Execute Code, 1 = No Code Execution
- } Bits;
- UINT64 Uint64;
-} X64_PAGE_TABLE_ENTRY_4K;
-
-
-//
-// Page Table Entry 2MB
-//
-typedef union {
- struct {
- UINT64 Present:1; // 0 = Not present in memory, 1 = Present in memory
- UINT64 ReadWrite:1; // 0 = Read-Only, 1= Read/Write
- UINT64 UserSupervisor:1; // 0 = Supervisor, 1=User
- UINT64 WriteThrough:1; // 0 = Write-Back caching, 1=Write-Through caching
- UINT64 CacheDisabled:1; // 0 = Cached, 1=Non-Cached
- UINT64 Accessed:1; // 0 = Not accessed, 1 = Accessed (set by CPU)
- UINT64 Dirty:1; // 0 = Not Dirty, 1 = written by processor on access to page
- UINT64 MustBe1:1; // Must be 1
- UINT64 Global:1; // 0 = Not global page, 1 = global page TLB not cleared on CR3 write
- UINT64 Available:3; // Available for use by system software
- UINT64 PAT:1; //
- UINT64 MustBeZero:8; // Must be zero;
- UINT64 PageTableBaseAddress:31; // Page Table Base Address
- UINT64 AvabilableHigh:11; // Available for use by system software
- UINT64 Nx:1; // 0 = Execute Code, 1 = No Code Execution
- } Bits;
- UINT64 Uint64;
-} X64_PAGE_TABLE_ENTRY_2M;
-
-#pragma pack()
-
-#endif
diff --git a/EdkCompatibilityPkg/Sample/Tools/Source/GenPage/genpage.c b/EdkCompatibilityPkg/Sample/Tools/Source/GenPage/genpage.c
deleted file mode 100644
index 7085f198aa..0000000000
--- a/EdkCompatibilityPkg/Sample/Tools/Source/GenPage/genpage.c
+++ /dev/null
@@ -1,344 +0,0 @@
-/*++
-
-Copyright 2006 - 2007, Intel Corporation
-All rights reserved. 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
-http://opensource.org/licenses/bsd-license.php
-
-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:
- GenPage.c
-
-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 "VirtualMemory.h"
-
-void
-memset (void *, char, long);
-
-unsigned int
-xtoi (char *);
-
-#define EFI_PAGE_BASE_OFFSET_IN_LDR 0x70000
-#define EFI_PAGE_BASE_ADDRESS (EFI_PAGE_BASE_OFFSET_IN_LDR + 0x20000)
-
-unsigned int gPageTableBaseAddress = EFI_PAGE_BASE_ADDRESS;
-unsigned int gPageTableOffsetInFile = EFI_PAGE_BASE_OFFSET_IN_LDR;
-
-#define EFI_MAX_ENTRY_NUM 512
-
-#define EFI_PML4_ENTRY_NUM 1
-#define EFI_PDPTE_ENTRY_NUM 4
-#define EFI_PDE_ENTRY_NUM EFI_MAX_ENTRY_NUM
-
-#define EFI_PML4_PAGE_NUM 1
-#define EFI_PDPTE_PAGE_NUM EFI_PML4_ENTRY_NUM
-#define EFI_PDE_PAGE_NUM (EFI_PML4_ENTRY_NUM * EFI_PDPTE_ENTRY_NUM)
-
-#define EFI_PAGE_NUMBER (EFI_PML4_PAGE_NUM + EFI_PDPTE_PAGE_NUM + EFI_PDE_PAGE_NUM)
-
-#define EFI_SIZE_OF_PAGE 0x1000
-#define EFI_PAGE_SIZE_2M 0x200000
-
-#define CONVERT_BIN_PAGE_ADDRESS(a) ((UINT8 *) a - PageTable + gPageTableBaseAddress)
-
-
-void *
-CreateIdentityMappingPageTables (
- void
- )
-/*++
-
-Routine Description:
- To create 4G PAE 2M pagetable
-
-Return:
- void * - buffer containing created pagetable
-
---*/
-{
- UINT64 PageAddress;
- UINT8 *PageTable;
- UINT8 *PageTablePtr;
- int PML4Index;
- int PDPTEIndex;
- int PDEIndex;
- X64_PAGE_MAP_AND_DIRECTORY_POINTER_2MB_4K *PageMapLevel4Entry;
- X64_PAGE_MAP_AND_DIRECTORY_POINTER_2MB_4K *PageDirectoryPointerEntry;
- X64_PAGE_TABLE_ENTRY_2M *PageDirectoryEntry2MB;
-
- PageTable = (void *)malloc (EFI_PAGE_NUMBER * EFI_SIZE_OF_PAGE);
- memset (PageTable, 0, (EFI_PAGE_NUMBER * EFI_SIZE_OF_PAGE));
- PageTablePtr = PageTable;
-
- 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
- //
- //
-
- PageMapLevel4Entry = (X64_PAGE_MAP_AND_DIRECTORY_POINTER_2MB_4K *)PageTablePtr;
-
- for (PML4Index = 0; PML4Index < EFI_PML4_ENTRY_NUM; PML4Index++, PageMapLevel4Entry++) {
- //
- // Each Page-Map-Level-4-Table Entry points to the base address of a Page-Directory-Pointer-Table Entry
- //
- PageTablePtr += EFI_SIZE_OF_PAGE;
- PageDirectoryPointerEntry = (X64_PAGE_MAP_AND_DIRECTORY_POINTER_2MB_4K *)PageTablePtr;
-
- //
- // Make a Page-Map-Level-4-Table Entry
- //
- PageMapLevel4Entry->Uint64 = (UINT64)(UINT32)(CONVERT_BIN_PAGE_ADDRESS (PageDirectoryPointerEntry));
- PageMapLevel4Entry->Bits.ReadWrite = 1;
- PageMapLevel4Entry->Bits.Present = 1;
-
- for (PDPTEIndex = 0; PDPTEIndex < EFI_PDPTE_ENTRY_NUM; PDPTEIndex++, PageDirectoryPointerEntry++) {
- //
- // Each Page-Directory-Pointer-Table Entry points to the base address of a Page-Directory Entry
- //
- PageTablePtr += EFI_SIZE_OF_PAGE;
- PageDirectoryEntry2MB = (X64_PAGE_TABLE_ENTRY_2M *)PageTablePtr;
-
- //
- // Make a Page-Directory-Pointer-Table Entry
- //
- PageDirectoryPointerEntry->Uint64 = (UINT64)(UINT32)(CONVERT_BIN_PAGE_ADDRESS (PageDirectoryEntry2MB));
- PageDirectoryPointerEntry->Bits.ReadWrite = 1;
- PageDirectoryPointerEntry->Bits.Present = 1;
-
- for (PDEIndex = 0; PDEIndex < EFI_PDE_ENTRY_NUM; PDEIndex++, PageDirectoryEntry2MB++) {
- //
- // Make a Page-Directory Entry
- //
- PageDirectoryEntry2MB->Uint64 = (UINT64)PageAddress;
- PageDirectoryEntry2MB->Bits.ReadWrite = 1;
- PageDirectoryEntry2MB->Bits.Present = 1;
- PageDirectoryEntry2MB->Bits.MustBe1 = 1;
-
- PageAddress += EFI_PAGE_SIZE_2M;
- }
- }
- }
-
- return PageTable;
-}
-
-int
-GenBinPage (
- 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
-
---*/
-{
- FILE *PageFile;
- FILE *NoPageFile;
- UINT8 Data;
- unsigned long FileSize;
-
- //
- // Open files
- //
- PageFile = fopen (PageFileName, "w+b");
- if (PageFile == NULL) {
- fprintf (stderr, "GenBinPage: Could not open file %s\n", PageFileName);
- return -1;
- }
-
- NoPageFile = fopen (NoPageFileName, "r+b");
- if (NoPageFile == NULL) {
- fprintf (stderr, "GenBinPage: Could not open file %s\n", NoPageFileName);
- fclose (PageFile);
- return -1;
- }
-
- //
- // Check size - should not be great than EFI_PAGE_BASE_OFFSET_IN_LDR
- //
- fseek (NoPageFile, 0, SEEK_END);
- FileSize = ftell (NoPageFile);
- fseek (NoPageFile, 0, SEEK_SET);
- if (FileSize > gPageTableOffsetInFile) {
- fprintf (stderr, "GenBinPage: file size too large - 0x%x\n", FileSize);
- fclose (PageFile);
- fclose (NoPageFile);
- return -1;
- }
-
- //
- // Write data
- //
- while (fread (&Data, sizeof(UINT8), 1, NoPageFile)) {
- fwrite (&Data, sizeof(UINT8), 1, PageFile);
- }
-
- //
- // Write PageTable
- //
- fseek (PageFile, gPageTableOffsetInFile, SEEK_SET);
- fwrite (BaseMemory, (EFI_PAGE_NUMBER * EFI_SIZE_OF_PAGE), 1, PageFile);
-
- //
- // Close files
- //
- fclose (PageFile);
- fclose (NoPageFile);
-
- return 0;
-}
-
-int
-main (
- int argc,
- char **argv
- )
-{
- void *BaseMemory;
- int result;
-
- //
- // Check parameter
- //
- if ((argc != 3) && (argc != 5)) {
- printf ("Usage: GenPage.exe NoPageFile PageFile [<PageTableBaseAddrss> <PageTableOffsetInFile>]\n");
- return 1;
- }
-
- //
- // Get PageTable parameter, if have
- //
- if (argc == 5) {
- gPageTableBaseAddress = xtoi (argv[3]);
- gPageTableOffsetInFile = xtoi (argv[4]);
- }
-
- //
- // Create X64 page table
- //
- BaseMemory = CreateIdentityMappingPageTables ();
-
- //
- // Add page table to binary file
- //
- result = GenBinPage (BaseMemory, argv[1], argv[2]);
- if (result < 0) {
- return 1;
- }
-
- return 0;
-}
-
-unsigned int
-xtoi (
- char *str
- )
-/*++
-
-Routine Description:
-
- Convert hex string to uint
-
-Arguments:
-
- Str - The string
-
-Returns:
-
---*/
-{
- unsigned int u;
- char c;
- unsigned int m;
-
- if (str == NULL) {
- return 0;
- }
-
- m = (unsigned int) -1 >> 4;
- //
- // skip preceeding white space
- //
- while (*str && *str == ' ') {
- str += 1;
- }
- //
- // skip preceeding zeros
- //
- while (*str && *str == '0') {
- str += 1;
- }
- //
- // skip preceeding white space
- //
- if (*str && (*str == 'x' || *str == 'X')) {
- str += 1;
- }
- //
- // convert hex digits
- //
- u = 0;
- c = *(str++);
- while (c) {
- if (c >= 'a' && c <= 'f') {
- c -= 'a' - 'A';
- }
-
- if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F')) {
- if (u > m) {
- return (unsigned int) -1;
- }
-
- u = u << 4 | c - (c >= 'A' ? 'A' - 10 : '0');
- } else {
- break;
- }
-
- c = *(str++);
- }
-
- return u;
-}
-