Code Scrub DxeIpl module.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@5502 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
qhuang8 2008-07-16 13:17:50 +00:00
parent f8ea30263c
commit b98da1b1f9
9 changed files with 151 additions and 166 deletions

View File

@ -21,10 +21,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Ppi/EndOfPeiPhase.h>
#include <Ppi/MemoryDiscovered.h>
#include <Ppi/ReadOnlyVariable2.h>
#include <Guid/MemoryTypeInformation.h>
#include <Ppi/Decompress.h>
#include <Ppi/FirmwareVolumeInfo.h>
#include <Ppi/GuidedSectionExtraction.h>
#include <Guid/MemoryTypeInformation.h>
#include <Guid/MemoryAllocationHob.h>
#include <Guid/FirmwareFileSystem2.h>
@ -48,13 +49,18 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#define STACK_SIZE 0x20000
#define BSP_STORE_SIZE 0x4000
//
// This macro aligns the ActualSize with a given alignment and is used to
// calculate the size an image occupies.
//
#define GET_OCCUPIED_SIZE(ActualSize, Alignment) ((ActualSize + (Alignment - 1)) & ~(Alignment - 1))
//
// Indicate whether DxeIpl has been shadowed to memory.
//
extern BOOLEAN gInMemory;
/**
Loads and relocates a PE/COFF image into memory.
@ -109,7 +115,6 @@ GetImageReadFunction (
);
/**
Main entry point to last PEIM
@ -168,7 +173,98 @@ UpdateStackHob (
IN UINT64 Length
);
/**
The ExtractSection() function processes the input section and
returns a pointer to the section contents. If the section being
extracted does not require processing (if the section
GuidedSectionHeader.Attributes has the
EFI_GUIDED_SECTION_PROCESSING_REQUIRED field cleared), then
OutputBuffer is just updated to point to the start of the
section's contents. Otherwise, *Buffer must be allocated
from PEI permanent memory.
@param This Indicates the
EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI instance.
Buffer containing the input GUIDed section to be
processed. OutputBuffer OutputBuffer is
allocated from PEI permanent memory and contains
the new section stream.
@param InputSection A pointer to the input buffer, which contains
the input section to be processed.
@param OutputBuffer A pointer to a caller-allocated buffer, whose
size is specified by the contents of OutputSize.
@param OutputSize A pointer to a caller-allocated
UINTN in which the size of *OutputBuffer
allocation is stored. If the function
returns anything other than EFI_SUCCESS,
the value of OutputSize is undefined.
@param AuthenticationStatus A pointer to a caller-allocated
UINT32 that indicates the
authentication status of the
output buffer. If the input
section's GuidedSectionHeader.
Attributes field has the
EFI_GUIDED_SECTION_AUTH_STATUS_VALID
bit as clear,
AuthenticationStatus must return
zero. These bits reflect the
status of the extraction
operation. If the function
returns anything other than
EFI_SUCCESS, the value of
AuthenticationStatus is
undefined.
@retval EFI_SUCCESS The InputSection was
successfully processed and the
section contents were returned.
@retval EFI_OUT_OF_RESOURCES The system has insufficient
resources to process the request.
@retval EFI_INVALID_PARAMETER The GUID in InputSection does
not match this instance of the
GUIDed Section Extraction PPI.
**/
EFI_STATUS
CustomGuidedSectionExtract (
IN CONST EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI *This,
IN CONST VOID *InputSection,
OUT VOID **OutputBuffer,
OUT UINTN *OutputSize,
OUT UINT32 *AuthenticationStatus
);
/**
Decompresses a section to the output buffer.
This function lookes up the compression type field in the input section and
applies the appropriate compression algorithm to compress the section to a
callee allocated buffer.
@param This Points to this instance of the
EFI_PEI_DECOMPRESS_PEI PPI.
@param CompressionSection Points to the compressed section.
@param OutputBuffer Holds the returned pointer to the decompressed
sections.
@param OutputSize Holds the returned size of the decompress
section streams.
@retval EFI_SUCCESS The section was decompressed successfully.
OutputBuffer contains the resulting data and
OutputSize contains the resulting size.
**/
EFI_STATUS
EFIAPI
Decompress (
IN CONST EFI_PEI_DECOMPRESS_PPI *This,
IN CONST EFI_COMPRESSION_SECTION *CompressionSection,
OUT VOID **OutputBuffer,
OUT UINTN *OutputSize
);
/**
Initializes the Dxe Ipl PPI

View File

@ -2,7 +2,8 @@
#
# Component description file for DxeIpl module
#
# The responsibility of this module is to load the DXE Core from a Firmware Volume. This implementation i used to load a 32-bit DXE Core.
# The responsibility of this module is to load the DXE Core from a Firmware Volume.
# This implementation is used to load a 32-bit DXE Core.
#
# Copyright (c) 2006 - 2008, Intel Corporation. <BR>
# All rights reserved. This program and the accompanying materials
@ -29,7 +30,7 @@
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
# VALID_ARCHITECTURES = IA32 X64 IPF
#
[Sources.common]
@ -52,11 +53,6 @@
Ipf/DxeLoadFunc.c
Ipf/ImageRead.c
[Sources.EBC]
X64/DxeLoadFunc.c
Ia32/ImageRead.c
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec

View File

@ -14,123 +14,30 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "DxeIpl.h"
#include <Ppi/GuidedSectionExtraction.h>
/**
The ExtractSection() function processes the input section and
returns a pointer to the section contents. If the section being
extracted does not require processing (if the section
GuidedSectionHeader.Attributes has the
EFI_GUIDED_SECTION_PROCESSING_REQUIRED field cleared), then
OutputBuffer is just updated to point to the start of the
section's contents. Otherwise, *Buffer must be allocated
from PEI permanent memory.
@param This Indicates the
EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI instance.
Buffer containing the input GUIDed section to be
processed. OutputBuffer OutputBuffer is
allocated from PEI permanent memory and contains
the new section stream.
@param InputSection A pointer to the input buffer, which contains
the input section to be processed.
@param OutputBuffer A pointer to a caller-allocated buffer, whose
size is specified by the contents of OutputSize.
@param OutputSize A pointer to a caller-allocated
UINTN in which the size of *OutputBuffer
allocation is stored. If the function
returns anything other than EFI_SUCCESS,
the value of OutputSize is undefined.
@param AuthenticationStatus A pointer to a caller-allocated
UINT32 that indicates the
authentication status of the
output buffer. If the input
section's GuidedSectionHeader.
Attributes field has the
EFI_GUIDED_SECTION_AUTH_STATUS_VALID
bit as clear,
AuthenticationStatus must return
zero. These bits reflect the
status of the extraction
operation. If the function
returns anything other than
EFI_SUCCESS, the value of
AuthenticationStatus is
undefined.
@retval EFI_SUCCESS The InputSection was
successfully processed and the
section contents were returned.
@retval EFI_OUT_OF_RESOURCES The system has insufficient
resources to process the request.
@retval EFI_INVALID_PARAMETER The GUID in InputSection does
not match this instance of the
GUIDed Section Extraction PPI.
**/
EFI_STATUS
CustomGuidedSectionExtract (
IN CONST EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI *This,
IN CONST VOID *InputSection,
OUT VOID **OutputBuffer,
OUT UINTN *OutputSize,
OUT UINT32 *AuthenticationStatus
);
/**
Decompresses a section to the output buffer.
This function lookes up the compression type field in the input section and
applies the appropriate compression algorithm to compress the section to a
callee allocated buffer.
@param This Points to this instance of the
EFI_PEI_DECOMPRESS_PEI PPI.
@param CompressionSection Points to the compressed section.
@param OutputBuffer Holds the returned pointer to the decompressed
sections.
@param OutputSize Holds the returned size of the decompress
section streams.
@retval EFI_SUCCESS The section was decompressed successfully.
OutputBuffer contains the resulting data and
OutputSize contains the resulting size.
**/
EFI_STATUS
EFIAPI
Decompress (
IN CONST EFI_PEI_DECOMPRESS_PPI *This,
IN CONST EFI_COMPRESSION_SECTION *CompressionSection,
OUT VOID **OutputBuffer,
OUT UINTN *OutputSize
);
//
// This global variable indicates whether this module has been shadowed
// to memory.
//
BOOLEAN gInMemory = FALSE;
//
// Module Globals used in the DXE to PEI handoff
// These must be module globals, so the stack can be switched
//
STATIC EFI_DXE_IPL_PPI mDxeIplPpi = {
CONST EFI_DXE_IPL_PPI mDxeIplPpi = {
DxeLoadCore
};
STATIC EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI mCustomGuidedSectionExtractionPpi = {
CONST EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI mCustomGuidedSectionExtractionPpi = {
CustomGuidedSectionExtract
};
STATIC EFI_PEI_DECOMPRESS_PPI mDecompressPpi = {
CONST EFI_PEI_DECOMPRESS_PPI mDecompressPpi = {
Decompress
};
STATIC EFI_PEI_PPI_DESCRIPTOR mPpiList[] = {
CONST EFI_PEI_PPI_DESCRIPTOR mPpiList[] = {
{
EFI_PEI_PPI_DESCRIPTOR_PPI,
&gEfiDxeIplPpiGuid,
@ -143,7 +50,7 @@ STATIC EFI_PEI_PPI_DESCRIPTOR mPpiList[] = {
}
};
STATIC EFI_PEI_PPI_DESCRIPTOR mPpiSignal = {
CONST EFI_PEI_PPI_DESCRIPTOR mPpiSignal = {
(EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
&gEfiEndOfPeiSignalPpiGuid,
NULL
@ -171,8 +78,7 @@ PeimInitializeDxeIpl (
UINTN ExtractHandlerNumber;
EFI_PEI_PPI_DESCRIPTOR *GuidPpi;
Status = PeiServicesGetBootMode (&BootMode);
ASSERT_EFI_ERROR (Status);
BootMode = GetBootModeHob ();
if (BootMode != BOOT_ON_S3_RESUME) {
Status = PeiServicesRegisterForShadow (FfsHandle);
@ -183,8 +89,6 @@ PeimInitializeDxeIpl (
return Status;
} else if (Status == EFI_ALREADY_STARTED) {
gInMemory = TRUE;
//
// Get custom extract guided section method guid list
//
@ -194,7 +98,6 @@ PeimInitializeDxeIpl (
// Install custom extraction guid ppi
//
if (ExtractHandlerNumber > 0) {
GuidPpi = NULL;
GuidPpi = (EFI_PEI_PPI_DESCRIPTOR *) AllocatePool (ExtractHandlerNumber * sizeof (EFI_PEI_PPI_DESCRIPTOR));
ASSERT (GuidPpi != NULL);
while (ExtractHandlerNumber-- > 0) {
@ -220,11 +123,11 @@ PeimInitializeDxeIpl (
}
/**
Main entry point to last PEIM
Main entry point to last PEIM.
@param This Entry point for DXE IPL PPI
@param This Entry point for DXE IPL PPI.
@param PeiServices General purpose services available to every PEIM.
@param HobList Address to the Pei HOB list
@param HobList Address to the Pei HOB list.
@return EFI_SUCCESS DXE core was successfully loaded.
@return EFI_OUT_OF_RESOURCES There are not enough resources to load DXE core.
@ -252,8 +155,7 @@ DxeLoadCore (
//
// if in S3 Resume, restore configure
//
Status = PeiServicesGetBootMode (&BootMode);
ASSERT_EFI_ERROR(Status);
BootMode = GetBootModeHob ();
if (BootMode == BOOT_ON_S3_RESUME) {
Status = AcpiS3ResumeOs();
@ -305,7 +207,7 @@ DxeLoadCore (
Status = DxeIplFindDxeCore (&FileHandle);
ASSERT_EFI_ERROR (Status);
CopyMem(&DxeCoreFileName, &(((EFI_FFS_FILE_HEADER*)FileHandle)->Name), sizeof (EFI_GUID));
CopyGuid(&DxeCoreFileName, &(((EFI_FFS_FILE_HEADER*)FileHandle)->Name));
//
// Load the DXE Core from a Firmware Volume, may use LoadFile ppi to do this for save code size.
@ -316,7 +218,6 @@ DxeLoadCore (
&DxeCoreSize,
&DxeCoreEntryPoint
);
ASSERT_EFI_ERROR (Status);
//
@ -325,7 +226,7 @@ DxeLoadCore (
BuildModuleHob (
&DxeCoreFileName,
DxeCoreAddress,
EFI_SIZE_TO_PAGES ((UINT32) DxeCoreSize) * EFI_PAGE_SIZE,
EFI_SIZE_TO_PAGES ((UINTN) DxeCoreSize) * EFI_PAGE_SIZE,
DxeCoreEntryPoint
);
@ -342,14 +243,8 @@ DxeLoadCore (
EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION PtrPeImage;
PtrPeImage.Pe32 = (EFI_IMAGE_NT_HEADERS32 *) ((UINTN) DxeCoreAddress + ((EFI_IMAGE_DOS_HEADER *) (UINTN) DxeCoreAddress)->e_lfanew);
if (PtrPeImage.Pe32->FileHeader.Machine != IMAGE_FILE_MACHINE_IA64) {
DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Loading DXE CORE at 0x%10p EntryPoint=0x%10p\n", (VOID *)(UINTN)DxeCoreAddress, (VOID *)(UINTN)DxeCoreEntryPoint));
} else {
//
// For IPF Image, the real entry point should be print.
//
DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Loading DXE CORE at 0x%10p EntryPoint=0x%10p\n", (VOID *)(UINTN)DxeCoreAddress, (VOID *)(UINTN)(*(UINT64 *)(UINTN)DxeCoreEntryPoint)));
}
DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Loading DXE CORE at 0x%10p EntryPoint=0x%10p\n", (VOID *)(UINTN)DxeCoreAddress, FUNCTION_ENTRY_POINT (DxeCoreEntryPoint)));
DEBUG_CODE_END ();
//
@ -406,8 +301,6 @@ DxeIplFindDxeCore (
}
/**
Loads and relocates a PE/COFF image into memory.
@ -432,6 +325,7 @@ PeiLoadFile (
EFI_STATUS Status;
PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;
VOID *Pe32Data;
//
// First try to find the PE32 section in this ffs file.
//
@ -440,7 +334,6 @@ PeiLoadFile (
FileHandle,
&Pe32Data
);
if (EFI_ERROR (Status)) {
//
// NO image types we support so exit.
@ -615,7 +508,6 @@ CustomGuidedSectionExtract (
ScratchBuffer,
AuthenticationStatus
);
if (EFI_ERROR (Status)) {
//
// Decode failed

View File

@ -44,10 +44,6 @@ GLOBAL_REMOVE_IF_UNREFERENCED IA32_DESCRIPTOR gLidtDescriptor = {
0
};
/**
Transfers control to DxeCore.
@ -93,7 +89,7 @@ HandOffToDxeCore (
TopOfStack = BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SIZE) * EFI_PAGE_SIZE - 32;
//
// X64 Calling Conventions requires that the stack must be aligned to 16 bytes
// x64 Calling Conventions requires that the stack must be aligned to 16 bytes
//
TopOfStack = (EFI_PHYSICAL_ADDRESS) (UINTN) ALIGN_POINTER (TopOfStack, 16);
@ -128,7 +124,6 @@ HandOffToDxeCore (
EFI_SIZE_TO_PAGES((SizeOfTemplate + sizeof (X64_IDT_GATE_DESCRIPTOR)) * 32),
&VectorAddress
);
ASSERT_EFI_ERROR (Status);
IdtTable = (X64_IDT_GATE_DESCRIPTOR *) (UINTN) (VectorAddress + SizeOfTemplate * 32);
@ -152,7 +147,8 @@ HandOffToDxeCore (
AsmWriteIdtr (&gLidtDescriptor);
}
//
// Go to Long Mode. Interrupts will not get turned on until the CPU AP is loaded.
// Go to Long Mode and transfer control to DxeCore.
// Interrupts will not get turned on until the CPU AP is loaded.
// Call x64 drivers passing in single argument, a pointer to the HOBs.
//
AsmEnablePaging64 (
@ -181,6 +177,9 @@ HandOffToDxeCore (
//
UpdateStackHob (BaseOfStack, STACK_SIZE);
//
// Transfer the control to the entry point of DxeCore.
//
SwitchStack (
(SWITCH_STACK_ENTRY_POINT)(UINTN)DxeCoreEntryPoint,
HobList.Raw,

View File

@ -14,10 +14,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include "DxeIpl.h"
/**
Support routine for the PE/COFF Loader that reads a buffer from a PE/COFF file
@ -50,8 +46,6 @@ PeiImageRead (
//
// This function assumes 32-bit alignment to increase performance
//
// ASSERT (ALIGN_POINTER (Destination32, sizeof (UINT32)) == Destination32);
// ASSERT (ALIGN_POINTER (Source32, sizeof (UINT32)) == Source32);
Length = *ReadSize;
while (Length-- != 0) {
@ -72,7 +66,7 @@ PeiImageRead (
@param ImageContext A pointer to the structure of
PE_COFF_LOADER_IMAGE_CONTEXT
@retval EFI_SUCCESS This function always return EFI_SUCCESS.
@retval EFI_SUCCESS This function always returns EFI_SUCCESS.
**/
EFI_STATUS

View File

@ -74,6 +74,9 @@ HandOffToDxeCore (
//
UpdateStackHob ((EFI_PHYSICAL_ADDRESS)(UINTN) BaseOfStack, STACK_SIZE);
//
// Transfer the control to the entry point of DxeCore.
//
SwitchStack (
(SWITCH_STACK_ENTRY_POINT)(UINTN)DxeCoreEntryPoint,
HobList.Raw,

View File

@ -57,7 +57,7 @@ PeiImageRead (
@param ImageContext A pointer to the structure of
PE_COFF_LOADER_IMAGE_CONTEXT
@retval EFI_SUCCESS This function always return EFI_SUCCESS.
@retval EFI_SUCCESS This function always returns EFI_SUCCESS.
**/
EFI_STATUS

View File

@ -63,6 +63,9 @@ HandOffToDxeCore (
//
UpdateStackHob ((EFI_PHYSICAL_ADDRESS)(UINTN) BaseOfStack, STACK_SIZE);
//
// Transfer the control to the entry point of DxeCore.
//
SwitchStack (
(SWITCH_STACK_ENTRY_POINT)(UINTN)DxeCoreEntryPoint,
HobList.Raw,

View File

@ -304,7 +304,6 @@
MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBusDxe.inf
MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDiskDxe.inf
MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf
MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf
MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf
MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf
@ -349,6 +348,7 @@
MdeModulePkg/Universal/DebugSupportDxe/DebugSupportDxe.inf
MdeModulePkg/Universal/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf
MdeModulePkg/Library/GraphicsLib/GraphicsLib.inf
MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf
[Components.X64]
MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
@ -358,11 +358,13 @@
MdeModulePkg/Universal/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf
MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariableRuntimeDxe.inf
MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf
[Components.IPF]
MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
MdeModulePkg/Universal/EbcDxe/EbcDxe.inf
MdeModulePkg/Universal/DebugSupportDxe/DebugSupportDxe.inf
MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf
[Components.EBC]
#BugBug: Need DXE I/O library instance for EBC.