From 65e3f333b3b97c8098e95ff27b3292b5c1dc31d1 Mon Sep 17 00:00:00 2001 From: andrewfish Date: Sat, 14 May 2011 16:00:22 +0000 Subject: [PATCH] Added generic EFIABI SEC to InOsEmuPkg. Add library to abstract FV cracking and remove code from original Sec/OS App. Add a PeiServicesLib wrapper for SEC that uses passed in PEI list and can abstract FV reading. Don't load images for XIP code and just run from FV directly on Mac OS X, or from dlopen on Linux. Moved temp ram switch code into generic SEC. Fixed design issue with PeiServiceTablePointerLib. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11646 6f19259b-4bc3-4df7-8a09-765794883524 --- InOsEmuPkg/InOsEmuPkg.dec | 3 +- InOsEmuPkg/Include/Library/PpiListLib.h | 21 + .../Include/Ppi/EmuPeiServicesTableUpdate.h | 27 - InOsEmuPkg/Include/Ppi/EmuThunk.h | 1 - .../PeiCoreServicesTablePointerLib.inf | 4 - .../PeiServicesTablePointer.c | 73 +-- .../PeiEmuPeCoffGetEntryPointLib.c | 2 +- .../PeiEmuSerialPortLib.inf | 2 +- .../PeiServicesTablePointer.c | 6 +- .../PeiServicesTablePointerLib.inf | 3 +- .../Sec => Library/SecPeiServicesLib}/FwVol.c | 590 +++++++++--------- .../SecPeiServicesLib/PeiServicesLib.c | 569 +++++++++++++++++ .../SecPeiServicesLib/SecPeiServicesLib.inf | 45 ++ InOsEmuPkg/Library/SecPpiListLib/PpiListLib.c | 17 + .../Library/SecPpiListLib/SecPpiListLib.inf | 31 + InOsEmuPkg/Sec/Sec.c | 149 +++++ InOsEmuPkg/Sec/Sec.h | 51 ++ InOsEmuPkg/Sec/Sec.inf | 44 ++ InOsEmuPkg/Sec/X64/SwitchRam.S | 68 ++ InOsEmuPkg/Unix/Sec/Gasket.h | 9 - InOsEmuPkg/Unix/Sec/SecMain.c | 424 +++++-------- InOsEmuPkg/Unix/Sec/SecMain.h | 21 +- InOsEmuPkg/Unix/Sec/SecMain.inf | 8 +- InOsEmuPkg/Unix/Sec/X64/Gasket.S | 24 - InOsEmuPkg/Unix/Sec/X64/SwitchStack.S | 58 -- InOsEmuPkg/Unix/UnixX64.dsc | 28 +- InOsEmuPkg/Unix/UnixX64.fdf | 8 + 27 files changed, 1519 insertions(+), 767 deletions(-) create mode 100644 InOsEmuPkg/Include/Library/PpiListLib.h delete mode 100644 InOsEmuPkg/Include/Ppi/EmuPeiServicesTableUpdate.h rename InOsEmuPkg/{Unix/Sec => Library/SecPeiServicesLib}/FwVol.c (85%) create mode 100644 InOsEmuPkg/Library/SecPeiServicesLib/PeiServicesLib.c create mode 100644 InOsEmuPkg/Library/SecPeiServicesLib/SecPeiServicesLib.inf create mode 100644 InOsEmuPkg/Library/SecPpiListLib/PpiListLib.c create mode 100644 InOsEmuPkg/Library/SecPpiListLib/SecPpiListLib.inf create mode 100644 InOsEmuPkg/Sec/Sec.c create mode 100644 InOsEmuPkg/Sec/Sec.h create mode 100644 InOsEmuPkg/Sec/Sec.inf create mode 100644 InOsEmuPkg/Sec/X64/SwitchRam.S diff --git a/InOsEmuPkg/InOsEmuPkg.dec b/InOsEmuPkg/InOsEmuPkg.dec index 6b4aca28c2..f49b2c73e7 100644 --- a/InOsEmuPkg/InOsEmuPkg.dec +++ b/InOsEmuPkg/InOsEmuPkg.dec @@ -29,6 +29,7 @@ ThunkProtocolList|Include/Library/ThunkProtocolList.h EmuThunkLib|Include/Library/EmuThunkLib.h KeyMap|Include/Library/KeyMapLib.h + PpiListLib|Include/Library/PpiListLib.h [Protocols] gEmuThunkProtocolGuid = { 0x398DCA31, 0x3505, 0xDB47, { 0xBD, 0x93, 0x1D, 0x38, 0x5F, 0x79, 0x13, 0x15 } } @@ -38,8 +39,6 @@ [Ppis] gEmuThunkPpiGuid = { 0xE113F896, 0x75CF, 0xF640, { 0x81, 0x7F, 0xC8, 0x5A, 0x79, 0xE8, 0xAE, 0x67 } } - gEmuPeiServicesTableUpdatePpiGuid = { 0xFA93020C, 0x6CDF, 0x1946, { 0x86, 0x35, 0x72, 0xCB, 0x51, 0x9E, 0xCF, 0xFD } } - [Guids] gInOsEmuPkgTokenSpaceGuid = { 0x4F792E68, 0xE8C8, 0x794E, { 0xB1, 0xD8, 0x37, 0x03, 0xF3, 0xF2, 0xD5, 0xA5 } } diff --git a/InOsEmuPkg/Include/Library/PpiListLib.h b/InOsEmuPkg/Include/Library/PpiListLib.h new file mode 100644 index 0000000000..061cfca34e --- /dev/null +++ b/InOsEmuPkg/Include/Library/PpiListLib.h @@ -0,0 +1,21 @@ +/*++ @file + +Copyright (c) 2011, Apple Inc. 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. + +**/ + +#ifndef __PPI_LIST_LIB_H__ +#define __PPI_LIST_LIB_H__ + + +extern CONST EFI_PEI_PPI_DESCRIPTOR *gPpiList; + + +#endif diff --git a/InOsEmuPkg/Include/Ppi/EmuPeiServicesTableUpdate.h b/InOsEmuPkg/Include/Ppi/EmuPeiServicesTableUpdate.h deleted file mode 100644 index f706eac5c0..0000000000 --- a/InOsEmuPkg/Include/Ppi/EmuPeiServicesTableUpdate.h +++ /dev/null @@ -1,27 +0,0 @@ -/** @file - Emulator Thunk to abstract OS services from pure EFI code - - Copyright (c) 2008 - 2011, Apple Inc. 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. - -**/ - -#ifndef __EMU_PEI_SERVICE_TABLE_UPDATE_PPI_H__ -#define __EMU_PEI_SERVICE_TABLE_UPDATE_PPI_H__ - -#define _EMU_PEI_SERVICE_TABLE_UPDATE_PPI_GUID \ - { 0xFA93020C, 0x6CDF, 0x1946, { 0x86, 0x35, 0x72, 0xCB, 0x51, 0x9E, 0xCF, 0xFD } } - - - - -extern EFI_GUID gEmuPeiServicesTableUpdatePpiGuid; - -#endif diff --git a/InOsEmuPkg/Include/Ppi/EmuThunk.h b/InOsEmuPkg/Include/Ppi/EmuThunk.h index 61047e3bfd..20cdc462f9 100644 --- a/InOsEmuPkg/Include/Ppi/EmuThunk.h +++ b/InOsEmuPkg/Include/Ppi/EmuThunk.h @@ -120,7 +120,6 @@ typedef struct { EMU_PEI_AUTOSCAN MemoryAutoScan; EMU_PEI_FD_INFORMATION FirmwareDevices; EMU_PEI_THUNK_INTERFACE Thunk; - EMU_PEI_LOAD_FILE LoadFile; } EMU_THUNK_PPI; extern EFI_GUID gEmuThunkPpiGuid; diff --git a/InOsEmuPkg/Library/PeiCoreServicesTablePointerLib/PeiCoreServicesTablePointerLib.inf b/InOsEmuPkg/Library/PeiCoreServicesTablePointerLib/PeiCoreServicesTablePointerLib.inf index 2510d690e2..279e088dff 100644 --- a/InOsEmuPkg/Library/PeiCoreServicesTablePointerLib/PeiCoreServicesTablePointerLib.inf +++ b/InOsEmuPkg/Library/PeiCoreServicesTablePointerLib/PeiCoreServicesTablePointerLib.inf @@ -35,11 +35,7 @@ [Packages] MdePkg/MdePkg.dec - InOsEmuPkg/InOsEmuPkg.dec [LibraryClasses] DebugLib -[Ppis] - gEmuPeiServicesTableUpdatePpiGuid - diff --git a/InOsEmuPkg/Library/PeiCoreServicesTablePointerLib/PeiServicesTablePointer.c b/InOsEmuPkg/Library/PeiCoreServicesTablePointerLib/PeiServicesTablePointer.c index 1c689390f8..9b02316af4 100644 --- a/InOsEmuPkg/Library/PeiCoreServicesTablePointerLib/PeiServicesTablePointer.c +++ b/InOsEmuPkg/Library/PeiCoreServicesTablePointerLib/PeiServicesTablePointer.c @@ -1,13 +1,10 @@ /** @file - PEI Services Table Pointer Library for PEI Core. + PEI Services Table Pointer Library. - This library is used for PEI Core which does executed from flash device directly but - executed in memory. When the PEI Core does a Set of the PEI Service table pointer - a PPI is reinstalled so that PEIMs can update the copy of the PEI Services table - they have cached. + This library is used for PEIM which does executed from flash device directly but + executed in memory. Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.
- Portiions copyrigth (c) 2011, Apple Inc. 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 @@ -22,10 +19,7 @@ #include #include -#include - - -CONST EFI_PEI_SERVICES **gPeiServices = NULL; +CONST EFI_PEI_SERVICES **gPeiServices; /** Caches a pointer PEI Services Table. @@ -41,39 +35,11 @@ CONST EFI_PEI_SERVICES **gPeiServices = NULL; VOID EFIAPI SetPeiServicesTablePointer ( - IN CONST EFI_PEI_SERVICES **PeiServicesTablePointer + IN CONST EFI_PEI_SERVICES ** PeiServicesTablePointer ) { - EFI_STATUS Status; - EFI_PEI_PPI_DESCRIPTOR *PpiDescriptor; - VOID *NotUsed; - - gPeiServices = PeiServicesTablePointer; - - Status = (*PeiServicesTablePointer)->LocatePpi ( - PeiServicesTablePointer, - &gEmuPeiServicesTableUpdatePpiGuid, // GUID - 0, // INSTANCE - &PpiDescriptor, // EFI_PEI_PPI_DESCRIPTOR - &NotUsed // PPI - ); - if (!EFI_ERROR (Status)) { - // - // Standard PI Mechanism is to use negative offset from IDT. - // We can't do that in the emulator, so we make up a constant location - // that every one can use. The first try may fail as the PEI Core is still - // initializing its self, but that is OK. - // - - // Reinstall PPI to consumers know to update PEI Services pointer - Status = (*PeiServicesTablePointer)->ReInstallPpi ( - PeiServicesTablePointer, - PpiDescriptor, - PpiDescriptor - ); - - } - + ASSERT (PeiServicesTablePointer != NULL); + gPeiServices = PeiServicesTablePointer; } /** @@ -95,8 +61,31 @@ GetPeiServicesTablePointer ( ) { ASSERT (gPeiServices != NULL); - ASSERT (*gPeiServices != NULL); return gPeiServices; } +/** + The constructor function caches the pointer to PEI services. + + The constructor function caches the pointer to PEI services. + It will always return EFI_SUCCESS. + + @param FileHandle The handle of FFS header the loaded driver. + @param PeiServices The pointer to the PEI services. + + @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS. + +**/ +EFI_STATUS +EFIAPI +PeiServicesTablePointerLibConstructor ( + IN EFI_PEI_FILE_HANDLE FileHandle, + IN CONST EFI_PEI_SERVICES **PeiServices + ) +{ + gPeiServices = PeiServices; + return EFI_SUCCESS; +} + + diff --git a/InOsEmuPkg/Library/PeiEmuPeCoffGetEntryPointLib/PeiEmuPeCoffGetEntryPointLib.c b/InOsEmuPkg/Library/PeiEmuPeCoffGetEntryPointLib/PeiEmuPeCoffGetEntryPointLib.c index 0b4be07ce6..e229805cfe 100644 --- a/InOsEmuPkg/Library/PeiEmuPeCoffGetEntryPointLib/PeiEmuPeCoffGetEntryPointLib.c +++ b/InOsEmuPkg/Library/PeiEmuPeCoffGetEntryPointLib/PeiEmuPeCoffGetEntryPointLib.c @@ -56,7 +56,7 @@ PeCoffLoaderGetEntryPoint ( // Status = PeiServicesLocatePpi ( &gEmuThunkPpiGuid, - 0, + 0, NULL, (VOID **) &ThunkPpi ); diff --git a/InOsEmuPkg/Library/PeiEmuSerialPortLib/PeiEmuSerialPortLib.inf b/InOsEmuPkg/Library/PeiEmuSerialPortLib/PeiEmuSerialPortLib.inf index 663967ddd9..911957ce3a 100644 --- a/InOsEmuPkg/Library/PeiEmuSerialPortLib/PeiEmuSerialPortLib.inf +++ b/InOsEmuPkg/Library/PeiEmuSerialPortLib/PeiEmuSerialPortLib.inf @@ -20,7 +20,7 @@ FILE_GUID = E4541241-8897-411a-91F8-7D7E45837146 MODULE_TYPE = PEIM VERSION_STRING = 1.0 - LIBRARY_CLASS = SerialPortLib| PEI_CORE PEIM + LIBRARY_CLASS = SerialPortLib| PEI_CORE PEIM SEC # # VALID_ARCHITECTURES = IA32 X64 IPF EBC diff --git a/InOsEmuPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointer.c b/InOsEmuPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointer.c index 6a58a74f87..3454660fec 100644 --- a/InOsEmuPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointer.c +++ b/InOsEmuPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointer.c @@ -20,7 +20,7 @@ #include #include -#include +#include CONST EFI_PEI_SERVICES **gPeiServices = NULL; @@ -100,7 +100,7 @@ PeiServicesTablePointerNotifyCallback ( EFI_PEI_NOTIFY_DESCRIPTOR mNotifyOnThunkList = { (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST), - &gEmuPeiServicesTableUpdatePpiGuid, + &gEfiPeiMemoryDiscoveredPpiGuid, PeiServicesTablePointerNotifyCallback }; @@ -125,6 +125,8 @@ PeiServicesTablePointerLibConstructor ( { EFI_STATUS Status; + gPeiServices = (CONST EFI_PEI_SERVICES **)PeiServices; + // register to be told when PeiServices pointer is updated Status = (*PeiServices)->NotifyPpi (PeiServices, &mNotifyOnThunkList); ASSERT_EFI_ERROR (Status); diff --git a/InOsEmuPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf b/InOsEmuPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf index 29d790a32a..b5e9949e0f 100644 --- a/InOsEmuPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf +++ b/InOsEmuPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf @@ -37,11 +37,10 @@ [Packages] MdePkg/MdePkg.dec - InOsEmuPkg/InOsEmuPkg.dec [LibraryClasses] DebugLib [Ppis] - gEmuPeiServicesTableUpdatePpiGuid + gEfiPeiMemoryDiscoveredPpiGuid diff --git a/InOsEmuPkg/Unix/Sec/FwVol.c b/InOsEmuPkg/Library/SecPeiServicesLib/FwVol.c similarity index 85% rename from InOsEmuPkg/Unix/Sec/FwVol.c rename to InOsEmuPkg/Library/SecPeiServicesLib/FwVol.c index a9a09a4096..ae4ebfbdb5 100644 --- a/InOsEmuPkg/Unix/Sec/FwVol.c +++ b/InOsEmuPkg/Library/SecPeiServicesLib/FwVol.c @@ -1,309 +1,281 @@ -/*++ @file - A simple FV stack so the SEC can extract the SEC Core from an - FV. - -Copyright (c) 2006, 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. - -**/ - -#include "SecMain.h" - -#define GET_OCCUPIED_SIZE(ActualSize, Alignment) \ - (ActualSize) + (((Alignment) - ((ActualSize) & ((Alignment) - 1))) & ((Alignment) - 1)) - -EFI_FFS_FILE_STATE -GetFileState ( - IN UINT8 ErasePolarity, - IN EFI_FFS_FILE_HEADER *FfsHeader - ) -/*++ - -Routine Description: - Returns the highest bit set of the State field - -Arguments: - ErasePolarity - Erase Polarity as defined by EFI_FVB2_ERASE_POLARITY - in the Attributes field. - FfsHeader - Pointer to FFS File Header. - -Returns: - Returns the highest bit in the State field - -**/ -{ - EFI_FFS_FILE_STATE FileState; - EFI_FFS_FILE_STATE HighestBit; - - FileState = FfsHeader->State; - - if (ErasePolarity != 0) { - FileState = (EFI_FFS_FILE_STATE)~FileState; - } - - HighestBit = 0x80; - while (HighestBit != 0 && (HighestBit & FileState) == 0) { - HighestBit >>= 1; - } - - return HighestBit; -} - -UINT8 -CalculateHeaderChecksum ( - IN EFI_FFS_FILE_HEADER *FileHeader - ) -/*++ - -Routine Description: - Calculates the checksum of the header of a file. - -Arguments: - FileHeader - Pointer to FFS File Header. - -Returns: - Checksum of the header. - -**/ -{ - UINT8 *ptr; - UINTN Index; - UINT8 Sum; - - Sum = 0; - ptr = (UINT8 *) FileHeader; - - for (Index = 0; Index < sizeof (EFI_FFS_FILE_HEADER) - 3; Index += 4) { - Sum = (UINT8) (Sum + ptr[Index]); - Sum = (UINT8) (Sum + ptr[Index + 1]); - Sum = (UINT8) (Sum + ptr[Index + 2]); - Sum = (UINT8) (Sum + ptr[Index + 3]); - } - - for (; Index < sizeof (EFI_FFS_FILE_HEADER); Index++) { - Sum = (UINT8) (Sum + ptr[Index]); - } - // - // State field (since this indicates the different state of file). - // - Sum = (UINT8) (Sum - FileHeader->State); - // - // Checksum field of the file is not part of the header checksum. - // - Sum = (UINT8) (Sum - FileHeader->IntegrityCheck.Checksum.File); - - return Sum; -} - -EFI_STATUS -SecFfsFindNextFile ( - IN EFI_FV_FILETYPE SearchType, - IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader, - IN OUT EFI_FFS_FILE_HEADER **FileHeader - ) -/*++ - -Routine Description: - Given the input file pointer, search for the next matching file in the - FFS volume as defined by SearchType. The search starts from FileHeader inside - the Firmware Volume defined by FwVolHeader. - -Arguments: - SearchType - Filter to find only files of this type. - Type EFI_FV_FILETYPE_ALL causes no filtering to be done. - FwVolHeader - Pointer to the FV header of the volume to search. - This parameter must point to a valid FFS volume. - FileHeader - Pointer to the current file from which to begin searching. - This pointer will be updated upon return to reflect the file - found. - -Returns: - EFI_NOT_FOUND - No files matching the search criteria were found - EFI_SUCCESS - -**/ -{ - EFI_FFS_FILE_HEADER *FfsFileHeader; - UINT32 FileLength; - UINT32 FileOccupiedSize; - UINT32 FileOffset; - UINT64 FvLength; - UINT8 ErasePolarity; - UINT8 FileState; - - FvLength = FwVolHeader->FvLength; - if (FwVolHeader->Attributes & EFI_FVB2_ERASE_POLARITY) { - ErasePolarity = 1; - } else { - ErasePolarity = 0; - } - // - // If FileHeader is not specified (NULL) start with the first file in the - // firmware volume. Otherwise, start from the FileHeader. - // - if (*FileHeader == NULL) { - FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FwVolHeader + FwVolHeader->HeaderLength); - } else { - // - // Length is 24 bits wide so mask upper 8 bits - // FileLength is adjusted to FileOccupiedSize as it is 8 byte aligned. - // - FileLength = *(UINT32 *) (*FileHeader)->Size & 0x00FFFFFF; - FileOccupiedSize = GET_OCCUPIED_SIZE (FileLength, 8); - FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) *FileHeader + FileOccupiedSize); - } - - FileOffset = (UINT32) ((UINT8 *) FfsFileHeader - (UINT8 *) FwVolHeader); - - while (FileOffset < (FvLength - sizeof (EFI_FFS_FILE_HEADER))) { - // - // Get FileState which is the highest bit of the State - // - FileState = GetFileState (ErasePolarity, FfsFileHeader); - - switch (FileState) { - - case EFI_FILE_HEADER_INVALID: - FileOffset += sizeof (EFI_FFS_FILE_HEADER); - FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsFileHeader + sizeof (EFI_FFS_FILE_HEADER)); - break; - - case EFI_FILE_DATA_VALID: - case EFI_FILE_MARKED_FOR_UPDATE: - if (CalculateHeaderChecksum (FfsFileHeader) == 0) { - FileLength = *(UINT32 *) (FfsFileHeader->Size) & 0x00FFFFFF; - FileOccupiedSize = GET_OCCUPIED_SIZE (FileLength, 8); - - if ((SearchType == FfsFileHeader->Type) || (SearchType == EFI_FV_FILETYPE_ALL)) { - - *FileHeader = FfsFileHeader; - - return EFI_SUCCESS; - } - - FileOffset += FileOccupiedSize; - FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsFileHeader + FileOccupiedSize); - } else { - return EFI_NOT_FOUND; - } - break; - - case EFI_FILE_DELETED: - FileLength = *(UINT32 *) (FfsFileHeader->Size) & 0x00FFFFFF; - FileOccupiedSize = GET_OCCUPIED_SIZE (FileLength, 8); - FileOffset += FileOccupiedSize; - FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsFileHeader + FileOccupiedSize); - break; - - default: - return EFI_NOT_FOUND; - - } - } - - return EFI_NOT_FOUND; -} - -EFI_STATUS -SecFfsFindSectionData ( - IN EFI_SECTION_TYPE SectionType, - IN EFI_FFS_FILE_HEADER *FfsFileHeader, - IN OUT VOID **SectionData - ) -/*++ - -Routine Description: - Given the input file pointer, search for the next matching section in the - FFS volume. - -Arguments: - SearchType - Filter to find only sections of this type. - FfsFileHeader - Pointer to the current file to search. - SectionData - Pointer to the Section matching SectionType in FfsFileHeader. - NULL if section not found - -Returns: - EFI_NOT_FOUND - No files matching the search criteria were found - EFI_SUCCESS - -**/ -{ - UINT32 FileSize; - EFI_COMMON_SECTION_HEADER *Section; - UINT32 SectionLength; - UINT32 ParsedLength; - - // - // Size is 24 bits wide so mask upper 8 bits. - // Does not include FfsFileHeader header size - // FileSize is adjusted to FileOccupiedSize as it is 8 byte aligned. - // - Section = (EFI_COMMON_SECTION_HEADER *) (FfsFileHeader + 1); - FileSize = *(UINT32 *) (FfsFileHeader->Size) & 0x00FFFFFF; - FileSize -= sizeof (EFI_FFS_FILE_HEADER); - - *SectionData = NULL; - ParsedLength = 0; - while (ParsedLength < FileSize) { - if (Section->Type == SectionType) { - *SectionData = (VOID *) (Section + 1); - return EFI_SUCCESS; - } - // - // Size is 24 bits wide so mask upper 8 bits. - // SectionLength is adjusted it is 4 byte aligned. - // Go to the next section - // - SectionLength = *(UINT32 *) Section->Size & 0x00FFFFFF; - SectionLength = GET_OCCUPIED_SIZE (SectionLength, 4); - - ParsedLength += SectionLength; - Section = (EFI_COMMON_SECTION_HEADER *) ((UINT8 *) Section + SectionLength); - } - - return EFI_NOT_FOUND; -} - -EFI_STATUS -SecFfsFindPeiCore ( - IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader, - OUT VOID **Pe32Data - ) -/*++ - -Routine Description: - Given the pointer to the Firmware Volume Header find the SEC - core and return it's PE32 image. - -Arguments: - FwVolHeader - Pointer to memory mapped FV - Pe32Data - Pointer to SEC PE32 iamge. - -Returns: - EFI_SUCCESS - Pe32Data is valid - other - Failure - -**/ -{ - EFI_STATUS Status; - EFI_FFS_FILE_HEADER *FileHeader; - EFI_FV_FILETYPE SearchType; - - SearchType = EFI_FV_FILETYPE_PEI_CORE; - FileHeader = NULL; - do { - Status = SecFfsFindNextFile (SearchType, FwVolHeader, &FileHeader); - if (!EFI_ERROR (Status)) { - Status = SecFfsFindSectionData (EFI_SECTION_PE32, FileHeader, Pe32Data); - return Status; - } - } while (!EFI_ERROR (Status)); - - return Status; -} +/*++ @file + A simple FV stack so the SEC can extract the SEC Core from an + FV. + +Copyright (c) 2006, 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. + +**/ + +#include + + +#define GET_OCCUPIED_SIZE(ActualSize, Alignment) \ + (ActualSize) + (((Alignment) - ((ActualSize) & ((Alignment) - 1))) & ((Alignment) - 1)) + +EFI_FFS_FILE_STATE +GetFileState ( + IN UINT8 ErasePolarity, + IN EFI_FFS_FILE_HEADER *FfsHeader + ) +/*++ + +Routine Description: + Returns the highest bit set of the State field + +Arguments: + ErasePolarity - Erase Polarity as defined by EFI_FVB2_ERASE_POLARITY + in the Attributes field. + FfsHeader - Pointer to FFS File Header. + +Returns: + Returns the highest bit in the State field + +**/ +{ + EFI_FFS_FILE_STATE FileState; + EFI_FFS_FILE_STATE HighestBit; + + FileState = FfsHeader->State; + + if (ErasePolarity != 0) { + FileState = (EFI_FFS_FILE_STATE)~FileState; + } + + HighestBit = 0x80; + while (HighestBit != 0 && (HighestBit & FileState) == 0) { + HighestBit >>= 1; + } + + return HighestBit; +} + +UINT8 +CalculateHeaderChecksum ( + IN EFI_FFS_FILE_HEADER *FileHeader + ) +/*++ + +Routine Description: + Calculates the checksum of the header of a file. + +Arguments: + FileHeader - Pointer to FFS File Header. + +Returns: + Checksum of the header. + +**/ +{ + UINT8 *ptr; + UINTN Index; + UINT8 Sum; + + Sum = 0; + ptr = (UINT8 *) FileHeader; + + for (Index = 0; Index < sizeof (EFI_FFS_FILE_HEADER) - 3; Index += 4) { + Sum = (UINT8) (Sum + ptr[Index]); + Sum = (UINT8) (Sum + ptr[Index + 1]); + Sum = (UINT8) (Sum + ptr[Index + 2]); + Sum = (UINT8) (Sum + ptr[Index + 3]); + } + + for (; Index < sizeof (EFI_FFS_FILE_HEADER); Index++) { + Sum = (UINT8) (Sum + ptr[Index]); + } + // + // State field (since this indicates the different state of file). + // + Sum = (UINT8) (Sum - FileHeader->State); + // + // Checksum field of the file is not part of the header checksum. + // + Sum = (UINT8) (Sum - FileHeader->IntegrityCheck.Checksum.File); + + return Sum; +} + +EFI_STATUS +SecFfsFindNextFile ( + IN EFI_FV_FILETYPE SearchType, + IN EFI_PEI_FV_HANDLE FvHandle, + IN OUT EFI_PEI_FILE_HANDLE *FileHandle + ) +/*++ + +Routine Description: + Given the input file pointer, search for the next matching file in the + FFS volume as defined by SearchType. The search starts from FileHeader inside + the Firmware Volume defined by FwVolHeader. + +Arguments: + SearchType - Filter to find only files of this type. + Type EFI_FV_FILETYPE_ALL causes no filtering to be done. + FwVolHeader - Pointer to the FV header of the volume to search. + This parameter must point to a valid FFS volume. + FileHeader - Pointer to the current file from which to begin searching. + This pointer will be updated upon return to reflect the file + found. + +Returns: + EFI_NOT_FOUND - No files matching the search criteria were found + EFI_SUCCESS + +**/ +{ + EFI_FFS_FILE_HEADER *FfsFileHeader; + UINT32 FileLength; + UINT32 FileOccupiedSize; + UINT32 FileOffset; + UINT64 FvLength; + UINT8 ErasePolarity; + UINT8 FileState; + EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader; + EFI_FFS_FILE_HEADER **FileHeader; + + // + // Convert the handle of FV to FV header for memory-mapped firmware volume + // + FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) FvHandle; + FileHeader = (EFI_FFS_FILE_HEADER **)FileHandle; + + FvLength = FwVolHeader->FvLength; + if (FwVolHeader->Attributes & EFI_FVB2_ERASE_POLARITY) { + ErasePolarity = 1; + } else { + ErasePolarity = 0; + } + // + // If FileHeader is not specified (NULL) start with the first file in the + // firmware volume. Otherwise, start from the FileHeader. + // + if (*FileHeader == NULL) { + FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FwVolHeader + FwVolHeader->HeaderLength); + } else { + // + // Length is 24 bits wide so mask upper 8 bits + // FileLength is adjusted to FileOccupiedSize as it is 8 byte aligned. + // + FileLength = *(UINT32 *) (*FileHeader)->Size & 0x00FFFFFF; + FileOccupiedSize = GET_OCCUPIED_SIZE (FileLength, 8); + FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) *FileHeader + FileOccupiedSize); + } + + FileOffset = (UINT32) ((UINT8 *) FfsFileHeader - (UINT8 *) FwVolHeader); + + while (FileOffset < (FvLength - sizeof (EFI_FFS_FILE_HEADER))) { + // + // Get FileState which is the highest bit of the State + // + FileState = GetFileState (ErasePolarity, FfsFileHeader); + + switch (FileState) { + + case EFI_FILE_HEADER_INVALID: + FileOffset += sizeof (EFI_FFS_FILE_HEADER); + FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsFileHeader + sizeof (EFI_FFS_FILE_HEADER)); + break; + + case EFI_FILE_DATA_VALID: + case EFI_FILE_MARKED_FOR_UPDATE: + if (CalculateHeaderChecksum (FfsFileHeader) == 0) { + FileLength = *(UINT32 *) (FfsFileHeader->Size) & 0x00FFFFFF; + FileOccupiedSize = GET_OCCUPIED_SIZE (FileLength, 8); + + if ((SearchType == FfsFileHeader->Type) || (SearchType == EFI_FV_FILETYPE_ALL)) { + + *FileHeader = FfsFileHeader; + + return EFI_SUCCESS; + } + + FileOffset += FileOccupiedSize; + FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsFileHeader + FileOccupiedSize); + } else { + return EFI_NOT_FOUND; + } + break; + + case EFI_FILE_DELETED: + FileLength = *(UINT32 *) (FfsFileHeader->Size) & 0x00FFFFFF; + FileOccupiedSize = GET_OCCUPIED_SIZE (FileLength, 8); + FileOffset += FileOccupiedSize; + FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsFileHeader + FileOccupiedSize); + break; + + default: + return EFI_NOT_FOUND; + + } + } + + return EFI_NOT_FOUND; +} + +EFI_STATUS +SecFfsFindSectionData ( + IN EFI_SECTION_TYPE SectionType, + IN EFI_FFS_FILE_HEADER *FfsFileHeader, + IN OUT VOID **SectionData + ) +/*++ + +Routine Description: + Given the input file pointer, search for the next matching section in the + FFS volume. + +Arguments: + SearchType - Filter to find only sections of this type. + FfsFileHeader - Pointer to the current file to search. + SectionData - Pointer to the Section matching SectionType in FfsFileHeader. + NULL if section not found + +Returns: + EFI_NOT_FOUND - No files matching the search criteria were found + EFI_SUCCESS + +**/ +{ + UINT32 FileSize; + EFI_COMMON_SECTION_HEADER *Section; + UINT32 SectionLength; + UINT32 ParsedLength; + + // + // Size is 24 bits wide so mask upper 8 bits. + // Does not include FfsFileHeader header size + // FileSize is adjusted to FileOccupiedSize as it is 8 byte aligned. + // + Section = (EFI_COMMON_SECTION_HEADER *) (FfsFileHeader + 1); + FileSize = *(UINT32 *) (FfsFileHeader->Size) & 0x00FFFFFF; + FileSize -= sizeof (EFI_FFS_FILE_HEADER); + + *SectionData = NULL; + ParsedLength = 0; + while (ParsedLength < FileSize) { + if (Section->Type == SectionType) { + *SectionData = (VOID *) (Section + 1); + return EFI_SUCCESS; + } + // + // Size is 24 bits wide so mask upper 8 bits. + // SectionLength is adjusted it is 4 byte aligned. + // Go to the next section + // + SectionLength = *(UINT32 *) Section->Size & 0x00FFFFFF; + SectionLength = GET_OCCUPIED_SIZE (SectionLength, 4); + + ParsedLength += SectionLength; + Section = (EFI_COMMON_SECTION_HEADER *) ((UINT8 *) Section + SectionLength); + } + + return EFI_NOT_FOUND; +} + diff --git a/InOsEmuPkg/Library/SecPeiServicesLib/PeiServicesLib.c b/InOsEmuPkg/Library/SecPeiServicesLib/PeiServicesLib.c new file mode 100644 index 0000000000..cee715d876 --- /dev/null +++ b/InOsEmuPkg/Library/SecPeiServicesLib/PeiServicesLib.c @@ -0,0 +1,569 @@ +/** @file + Implementation for PEI Services Library. + + Copyright (c) 2006 - 2010, 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. + +**/ + + +#include + +#include +#include +#include +#include + + + +EFI_STATUS +SecFfsFindNextFile ( + IN EFI_FV_FILETYPE SearchType, + IN EFI_PEI_FV_HANDLE VolumeHandle, + IN OUT EFI_PEI_FILE_HANDLE *FileHandle + ); + +EFI_STATUS +SecFfsFindSectionData ( + IN EFI_SECTION_TYPE SectionType, + IN EFI_PEI_FILE_HANDLE FileHandle, + OUT VOID **SectionData + ); + + +/** + This service enables a given PEIM to register an interface into the PEI Foundation. + + @param PpiList A pointer to the list of interfaces that the caller shall install. + + @retval EFI_SUCCESS The interface was successfully installed. + @retval EFI_INVALID_PARAMETER The PpiList pointer is NULL. + @retval EFI_INVALID_PARAMETER Any of the PEI PPI descriptors in the list do not have the + EFI_PEI_PPI_DESCRIPTOR_PPI bit set in the Flags field. + @retval EFI_OUT_OF_RESOURCES There is no additional space in the PPI database. + +**/ +EFI_STATUS +EFIAPI +PeiServicesInstallPpi ( + IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList + ) +{ + ASSERT (FALSE); + return EFI_OUT_OF_RESOURCES; +} + +/** + This service enables PEIMs to replace an entry in the PPI database with an alternate entry. + + @param OldPpi The pointer to the old PEI PPI Descriptors. + @param NewPpi The pointer to the new PEI PPI Descriptors. + + @retval EFI_SUCCESS The interface was successfully installed. + @retval EFI_INVALID_PARAMETER The OldPpi or NewPpi is NULL. + @retval EFI_INVALID_PARAMETER Any of the PEI PPI descriptors in the list do not have the + EFI_PEI_PPI_DESCRIPTOR_PPI bit set in the Flags field. + @retval EFI_OUT_OF_RESOURCES There is no additional space in the PPI database. + @retval EFI_NOT_FOUND The PPI for which the reinstallation was requested has not been + installed. + +**/ +EFI_STATUS +EFIAPI +PeiServicesReInstallPpi ( + IN CONST EFI_PEI_PPI_DESCRIPTOR *OldPpi, + IN CONST EFI_PEI_PPI_DESCRIPTOR *NewPpi + ) +{ + ASSERT (FALSE); + return EFI_OUT_OF_RESOURCES; +} + +/** + This service enables PEIMs to discover a given instance of an interface. + + So this is, well a hack, so we can reuse the same libraries as the PEI Core + for XIP modules.... + + @param Guid A pointer to the GUID whose corresponding interface needs to be + found. + @param Instance The N-th instance of the interface that is required. + @param PpiDescriptor A pointer to instance of the EFI_PEI_PPI_DESCRIPTOR. + @param Ppi A pointer to the instance of the interface. + + @retval EFI_SUCCESS The interface was successfully returned. + @retval EFI_NOT_FOUND The PPI descriptor is not found in the database. + +**/ +EFI_STATUS +EFIAPI +PeiServicesLocatePpi ( + IN CONST EFI_GUID *Guid, + IN UINTN Instance, + IN OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor, + IN OUT VOID **Ppi + ) +{ + EFI_PEI_PPI_DESCRIPTOR *PpiList; + + if (Instance != 0) { + return EFI_NOT_FOUND; + } + + + for (PpiList = (EFI_PEI_PPI_DESCRIPTOR *)gPpiList; ; PpiList++) { + if (CompareGuid (PpiList->Guid, Guid)) { + if (PpiDescriptor != NULL) { + *PpiDescriptor = PpiList; + } + if (Ppi != NULL) { + *Ppi = PpiList->Ppi; + } + return EFI_SUCCESS; + } + + if ((PpiList->Flags & EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) == EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) { + break; + } + } + + + return EFI_NOT_FOUND; +} + +/** + This service enables PEIMs to register a given service to be invoked when another service is + installed or reinstalled. + + @param NotifyList A pointer to the list of notification interfaces + that the caller shall install. + + @retval EFI_SUCCESS The interface was successfully installed. + @retval EFI_INVALID_PARAMETER The NotifyList pointer is NULL. + @retval EFI_INVALID_PARAMETER Any of the PEI notify descriptors in the list do + not have the EFI_PEI_PPI_DESCRIPTOR_NOTIFY_TYPES + bit set in the Flags field. + @retval EFI_OUT_OF_RESOURCES There is no additional space in the PPI database. + +**/ +EFI_STATUS +EFIAPI +PeiServicesNotifyPpi ( + IN CONST EFI_PEI_NOTIFY_DESCRIPTOR *NotifyList + ) +{ + ASSERT (FALSE); + return EFI_OUT_OF_RESOURCES; +} + +/** + This service enables PEIMs to ascertain the present value of the boot mode. + + @param BootMode A pointer to contain the value of the boot mode. + + @retval EFI_SUCCESS The boot mode was returned successfully. + @retval EFI_INVALID_PARAMETER BootMode is NULL. + +**/ +EFI_STATUS +EFIAPI +PeiServicesGetBootMode ( + OUT EFI_BOOT_MODE *BootMode + ) +{ + ASSERT (FALSE); + return EFI_OUT_OF_RESOURCES; +} + +/** + This service enables PEIMs to update the boot mode variable. + + @param BootMode The value of the boot mode to set. + + @retval EFI_SUCCESS The value was successfully updated + +**/ +EFI_STATUS +EFIAPI +PeiServicesSetBootMode ( + IN EFI_BOOT_MODE BootMode + ) +{ + ASSERT (FALSE); + return EFI_OUT_OF_RESOURCES; +} + +/** + This service enables a PEIM to ascertain the address of the list of HOBs in memory. + + @param HobList A pointer to the list of HOBs that the PEI Foundation + will initialize. + + @retval EFI_SUCCESS The list was successfully returned. + @retval EFI_NOT_AVAILABLE_YET The HOB list is not yet published. + +**/ +EFI_STATUS +EFIAPI +PeiServicesGetHobList ( + OUT VOID **HobList + ) +{ + ASSERT (FALSE); + return EFI_OUT_OF_RESOURCES; +} + +/** + This service enables PEIMs to create various types of HOBs. + + @param Type The type of HOB to be installed. + @param Length The length of the HOB to be added. + @param Hob The address of a pointer that will contain the + HOB header. + + @retval EFI_SUCCESS The HOB was successfully created. + @retval EFI_OUT_OF_RESOURCES There is no additional space for HOB creation. + +**/ +EFI_STATUS +EFIAPI +PeiServicesCreateHob ( + IN UINT16 Type, + IN UINT16 Length, + OUT VOID **Hob + ) +{ + ASSERT (FALSE); + return EFI_OUT_OF_RESOURCES; +} + +/** + This service enables PEIMs to discover additional firmware volumes. + + @param Instance This instance of the firmware volume to find. The + value 0 is the Boot Firmware Volume (BFV). + @param VolumeHandle Handle of the firmware volume header of the volume + to return. + + @retval EFI_SUCCESS The volume was found. + @retval EFI_NOT_FOUND The volume was not found. + @retval EFI_INVALID_PARAMETER FwVolHeader is NULL. + +**/ +EFI_STATUS +EFIAPI +PeiServicesFfsFindNextVolume ( + IN UINTN Instance, + IN OUT EFI_PEI_FV_HANDLE *VolumeHandle + ) +{ + ASSERT (FALSE); + return EFI_OUT_OF_RESOURCES; +} + +/** + This service enables PEIMs to discover additional firmware files. + + @param SearchType A filter to find files only of this type. + @param VolumeHandle The pointer to the firmware volume header of the + volume to search. This parameter must point to a + valid FFS volume. + @param FileHandle Handle of the current file from which to begin searching. + + @retval EFI_SUCCESS The file was found. + @retval EFI_NOT_FOUND The file was not found. + @retval EFI_NOT_FOUND The header checksum was not zero. + +**/ +EFI_STATUS +EFIAPI +PeiServicesFfsFindNextFile ( + IN EFI_FV_FILETYPE SearchType, + IN EFI_PEI_FV_HANDLE VolumeHandle, + IN OUT EFI_PEI_FILE_HANDLE *FileHandle + ) +{ + return SecFfsFindNextFile (SearchType, VolumeHandle, FileHandle); +} + +/** + This service enables PEIMs to discover sections of a given type within a valid FFS file. + + @param SectionType The value of the section type to find. + @param FileHandle A pointer to the file header that contains the set + of sections to be searched. + @param SectionData A pointer to the discovered section, if successful. + + @retval EFI_SUCCESS The section was found. + @retval EFI_NOT_FOUND The section was not found. + +**/ +EFI_STATUS +EFIAPI +PeiServicesFfsFindSectionData ( + IN EFI_SECTION_TYPE SectionType, + IN EFI_PEI_FILE_HANDLE FileHandle, + OUT VOID **SectionData + ) +{ + return SecFfsFindSectionData (SectionType, FileHandle, SectionData); +} + +/** + This service enables PEIMs to register the permanent memory configuration + that has been initialized with the PEI Foundation. + + @param MemoryBegin The value of a region of installed memory. + @param MemoryLength The corresponding length of a region of installed memory. + + @retval EFI_SUCCESS The region was successfully installed in a HOB. + @retval EFI_INVALID_PARAMETER MemoryBegin and MemoryLength are illegal for this system. + @retval EFI_OUT_OF_RESOURCES There is no additional space for HOB creation. + +**/ +EFI_STATUS +EFIAPI +PeiServicesInstallPeiMemory ( + IN EFI_PHYSICAL_ADDRESS MemoryBegin, + IN UINT64 MemoryLength + ) +{ + ASSERT (FALSE); + return EFI_OUT_OF_RESOURCES; +} + +/** + This service enables PEIMs to allocate memory after the permanent memory has been + installed by a PEIM. + + @param MemoryType Type of memory to allocate. + @param Pages The number of pages to allocate. + @param Memory Pointer of memory allocated. + + @retval EFI_SUCCESS The memory range was successfully allocated. + @retval EFI_INVALID_PARAMETER Type is not equal to AllocateAnyPages. + @retval EFI_NOT_AVAILABLE_YET Called with permanent memory not available. + @retval EFI_OUT_OF_RESOURCES The pages could not be allocated. + +**/ +EFI_STATUS +EFIAPI +PeiServicesAllocatePages ( + IN EFI_MEMORY_TYPE MemoryType, + IN UINTN Pages, + OUT EFI_PHYSICAL_ADDRESS *Memory + ) +{ + ASSERT (FALSE); + return EFI_OUT_OF_RESOURCES; +} + +/** + This service allocates memory from the Hand-Off Block (HOB) heap. + + @param Size The number of bytes to allocate from the pool. + @param Buffer If the call succeeds, a pointer to a pointer to + the allocate buffer; otherwise, undefined. + + @retval EFI_SUCCESS The allocation was successful + @retval EFI_OUT_OF_RESOURCES There is not enough heap to allocate the requested size. + +**/ +EFI_STATUS +EFIAPI +PeiServicesAllocatePool ( + IN UINTN Size, + OUT VOID **Buffer + ) +{ + ASSERT (FALSE); + return EFI_OUT_OF_RESOURCES; +} + +/** + Resets the entire platform. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_NOT_AVAILABLE_YET The service has not been installed yet. + +**/ +EFI_STATUS +EFIAPI +PeiServicesResetSystem ( + VOID + ) +{ + ASSERT (FALSE); + return EFI_OUT_OF_RESOURCES; +} + +/** + This service is a wrapper for the PEI Service RegisterForShadow(), except the + pointer to the PEI Services Table has been removed. See the Platform + Initialization Pre-EFI Initialization Core Interface Specification for details. + + @param FileHandle PEIM's file handle. Must be the currently + executing PEIM. + + @retval EFI_SUCCESS The PEIM was successfully registered for + shadowing. + + @retval EFI_ALREADY_STARTED The PEIM was previously + registered for shadowing. + + @retval EFI_NOT_FOUND The FileHandle does not refer to a + valid file handle. +**/ +EFI_STATUS +EFIAPI +PeiServicesRegisterForShadow ( + IN EFI_PEI_FILE_HANDLE FileHandle + ) +{ + ASSERT (FALSE); + return EFI_OUT_OF_RESOURCES; +} + +/** + This service is a wrapper for the PEI Service FfsGetFileInfo(), except the pointer to the PEI Services + Table has been removed. See the Platform Initialization Pre-EFI Initialization Core Interface + Specification for details. + + @param FileHandle The handle of the file. + + @param FileInfo Upon exit, points to the file's + information. + + @retval EFI_SUCCESS File information returned. + + @retval EFI_INVALID_PARAMETER If FileHandle does not + represent a valid file. + + @retval EFI_INVALID_PARAMETER FileInfo is NULL. + +**/ +EFI_STATUS +EFIAPI +PeiServicesFfsGetFileInfo ( + IN CONST EFI_PEI_FILE_HANDLE FileHandle, + OUT EFI_FV_FILE_INFO *FileInfo + ) +{ + ASSERT (FALSE); + return EFI_OUT_OF_RESOURCES; +} + + +/** + This service is a wrapper for the PEI Service FfsFindByName(), except the pointer to the PEI Services + Table has been removed. See the Platform Initialization Pre-EFI Initialization Core Interface + Specification for details. + + @param FileName A pointer to the name of the file to + find within the firmware volume. + + @param VolumeHandle The firmware volume to search FileHandle + Upon exit, points to the found file's + handle or NULL if it could not be found. + @param FileHandle The pointer to found file handle + + @retval EFI_SUCCESS File was found. + + @retval EFI_NOT_FOUND File was not found. + + @retval EFI_INVALID_PARAMETER VolumeHandle or FileHandle or + FileName was NULL. + +**/ +EFI_STATUS +EFIAPI +PeiServicesFfsFindFileByName ( + IN CONST EFI_GUID *FileName, + IN CONST EFI_PEI_FV_HANDLE VolumeHandle, + OUT EFI_PEI_FILE_HANDLE *FileHandle + ) +{ + ASSERT (FALSE); + return EFI_OUT_OF_RESOURCES; +} + + +/** + This service is a wrapper for the PEI Service FfsGetVolumeInfo(), except the pointer to the PEI Services + Table has been removed. See the Platform Initialization Pre-EFI Initialization Core Interface + Specification for details. + + @param VolumeHandle Handle of the volume. + + @param VolumeInfo Upon exit, points to the volume's + information. + + @retval EFI_SUCCESS File information returned. + + @retval EFI_INVALID_PARAMETER If FileHandle does not + represent a valid file. + + @retval EFI_INVALID_PARAMETER If FileInfo is NULL. + +**/ +EFI_STATUS +EFIAPI +PeiServicesFfsGetVolumeInfo ( + IN EFI_PEI_FV_HANDLE VolumeHandle, + OUT EFI_FV_INFO *VolumeInfo + ) +{ + ASSERT (FALSE); + return EFI_OUT_OF_RESOURCES; +} + +/** + Install a EFI_PEI_FIRMWARE_VOLUME_INFO_PPI instance so the PEI Core will be notified about a new firmware volume. + + This function allocates, initializes, and installs a new EFI_PEI_FIRMWARE_VOLUME_INFO_PPI using + the parameters passed in to initialize the fields of the EFI_PEI_FIRMWARE_VOLUME_INFO_PPI instance. + If the resources can not be allocated for EFI_PEI_FIRMWARE_VOLUME_INFO_PPI, then ASSERT(). + If the EFI_PEI_FIRMWARE_VOLUME_INFO_PPI can not be installed, then ASSERT(). + + + @param FvFormat Unique identifier of the format of the memory-mapped + firmware volume. This parameter is optional and + may be NULL. If NULL is specified, the + EFI_FIRMWARE_FILE_SYSTEM2_GUID format is assumed. + @param FvInfo Points to a buffer which allows the + EFI_PEI_FIRMWARE_VOLUME_PPI to process the volume. + The format of this buffer is specific to the FvFormat. + For memory-mapped firmware volumes, this typically + points to the first byte of the firmware volume. + @param FvInfoSize The size, in bytes, of FvInfo. For memory-mapped + firmware volumes, this is typically the size of + the firmware volume. + @param ParentFvName If the new firmware volume originated from a file + in a different firmware volume, then this parameter + specifies the GUID name of the originating firmware + volume. Otherwise, this parameter must be NULL. + @param ParentFileName If the new firmware volume originated from a file + in a different firmware volume, then this parameter + specifies the GUID file name of the originating + firmware file. Otherwise, this parameter must be NULL. +**/ +VOID +EFIAPI +PeiServicesInstallFvInfoPpi ( + IN CONST EFI_GUID *FvFormat, OPTIONAL + IN CONST VOID *FvInfo, + IN UINT32 FvInfoSize, + IN CONST EFI_GUID *ParentFvName, OPTIONAL + IN CONST EFI_GUID *ParentFileName OPTIONAL + ) +{ + ASSERT (FALSE); + return; +} + diff --git a/InOsEmuPkg/Library/SecPeiServicesLib/SecPeiServicesLib.inf b/InOsEmuPkg/Library/SecPeiServicesLib/SecPeiServicesLib.inf new file mode 100644 index 0000000000..6e9cf3a226 --- /dev/null +++ b/InOsEmuPkg/Library/SecPeiServicesLib/SecPeiServicesLib.inf @@ -0,0 +1,45 @@ +## @file +# PEI Services Library implementation. +# +# Copyright (c) 2007 - 2010, 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. +# +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = SecPeiServicesLib + FILE_GUID = E3E4A441-8465-0F41-8AF4-F67EBE984099 + MODULE_TYPE = PEIM + VERSION_STRING = 1.0 + LIBRARY_CLASS = PeiServicesLib|SEC PEIM PEI_CORE + PI_SPECIFICATION_VERSION = 0x0001000A + +# +# VALID_ARCHITECTURES = IA32 X64 IPF EBC (EBC is for build only) +# + +[Sources] + PeiServicesLib.c + FwVol.c + + +[Packages] + MdePkg/MdePkg.dec + InOsEmuPkg/InOsEmuPkg.dec + +[LibraryClasses] + DebugLib + BaseMemoryLib + PpiListLib + + + + diff --git a/InOsEmuPkg/Library/SecPpiListLib/PpiListLib.c b/InOsEmuPkg/Library/SecPpiListLib/PpiListLib.c new file mode 100644 index 0000000000..42c0d97942 --- /dev/null +++ b/InOsEmuPkg/Library/SecPpiListLib/PpiListLib.c @@ -0,0 +1,17 @@ +/*++ @file + +Copyright (c) 2011, Apple Inc. 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. + +**/ + +#include + +CONST EFI_PEI_PPI_DESCRIPTOR *gPpiList = NULL; + diff --git a/InOsEmuPkg/Library/SecPpiListLib/SecPpiListLib.inf b/InOsEmuPkg/Library/SecPpiListLib/SecPpiListLib.inf new file mode 100644 index 0000000000..07c2c35836 --- /dev/null +++ b/InOsEmuPkg/Library/SecPpiListLib/SecPpiListLib.inf @@ -0,0 +1,31 @@ +## @file +# Place thunk PPI in HOB. +# +# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.
+# Portions copyright (c) 2011, Apple Inc. 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. +# +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = SecPpiListLib + FILE_GUID = F950E820-0457-8143-86AD-30E4A45FD4BF + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = PpiListLib|SEC BASE USER_DEFINED + +[Sources] + PpiListLib.c + +[Packages] + MdePkg/MdePkg.dec + InOsEmuPkg/InOsEmuPkg.dec + diff --git a/InOsEmuPkg/Sec/Sec.c b/InOsEmuPkg/Sec/Sec.c new file mode 100644 index 0000000000..4e350f1706 --- /dev/null +++ b/InOsEmuPkg/Sec/Sec.c @@ -0,0 +1,149 @@ +/*++ @file + Stub SEC that is called from the OS appliation that is the root of the emulator. + + The OS application will call the SEC with the PEI Entry Point API. + +Copyright (c) 2011, Apple Inc. 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. + +**/ + +#include "Sec.h" + + + +EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI mSecTemporaryRamSupportPpi = { + SecTemporaryRamSupport +}; + + +EFI_PEI_PPI_DESCRIPTOR gPrivateDispatchTable[] = { + { + EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST, + &gEfiTemporaryRamSupportPpiGuid, + &mSecTemporaryRamSupportPpi + } +}; + + + +/** + The entry point of PE/COFF Image for the PEI Core, that has been hijacked by this + SEC that sits on top of an OS application. So the entry and exit of this module + has the same API. + + This function is the entry point for the PEI Foundation, which allows the SEC phase + to pass information about the stack, temporary RAM and the Boot Firmware Volume. + In addition, it also allows the SEC phase to pass services and data forward for use + during the PEI phase in the form of one or more PPIs. + There is no limit to the number of additional PPIs that can be passed from SEC into + the PEI Foundation. As part of its initialization phase, the PEI Foundation will add + these SEC-hosted PPIs to its PPI database such that both the PEI Foundation and any + modules can leverage the associated service calls and/or code in these early PPIs. + This function is required to call ProcessModuleEntryPointList() with the Context + parameter set to NULL. ProcessModuleEntryPoint() is never expected to return. + The PEI Core is responsible for calling ProcessLibraryConstructorList() as soon as + the PEI Services Table and the file handle for the PEI Core itself have been established. + If ProcessModuleEntryPointList() returns, then ASSERT() and halt the system. + + @param SecCoreData Points to a data structure containing information about the PEI + core's operating environment, such as the size and location of + temporary RAM, the stack location and the BFV location. + + @param PpiList Points to a list of one or more PPI descriptors to be installed + initially by the PEI core. An empty PPI list consists of a single + descriptor with the end-tag EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST. + As part of its initialization phase, the PEI Foundation will add + these SEC-hosted PPIs to its PPI database such that both the PEI + Foundation and any modules can leverage the associated service calls + and/or code in these early PPIs. + +**/ +VOID +EFIAPI +_ModuleEntryPoint ( + IN EFI_SEC_PEI_HAND_OFF *SecCoreData, + IN EFI_PEI_PPI_DESCRIPTOR *PpiList + ) +{ + EFI_STATUS Status; + EFI_PEI_FV_HANDLE VolumeHandle; + EFI_PEI_FILE_HANDLE FileHandle; + VOID *PeCoffImage; + EFI_PEI_CORE_ENTRY_POINT EntryPoint; + EFI_PEI_PPI_DESCRIPTOR *Ppi; + EFI_PEI_PPI_DESCRIPTOR *SecPpiList; + UINTN SecReseveredMemorySize; + UINTN Index; + + gPpiList = PpiList; + ProcessLibraryConstructorList (); + + DEBUG ((EFI_D_ERROR, "SEC Has Started\n")); + + // + // Add Our PPIs to the list + // + SecReseveredMemorySize = sizeof (gPrivateDispatchTable); + for (Ppi = PpiList, Index = 1; ; Ppi++, Index++) { + SecReseveredMemorySize += sizeof (EFI_PEI_PPI_DESCRIPTOR); + + if ((Ppi->Flags & EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) == EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) { + // Since we are appending, need to clear out privious list terminator. + Ppi->Flags &= ~EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST; + break; + } + } + + // Keep everything on a good alignment + SecReseveredMemorySize = ALIGN_VALUE (SecReseveredMemorySize, CPU_STACK_ALIGNMENT); + +#if 0 + // Tell the PEI Core to not use our buffer in temp RAM + SecPpiList = (EFI_PEI_PPI_DESCRIPTOR *)SecCoreData->PeiTemporaryRamBase; + SecCoreData->PeiTemporaryRamBase = (VOID *)((UINTN)SecCoreData->PeiTemporaryRamBase + SecReseveredMemorySize); + SecCoreData->PeiTemporaryRamSize -= SecReseveredMemorySize; +#else + { + // + // When I subtrack from SecCoreData->PeiTemporaryRamBase PEI Core crashes? Either there is a bug + // or I don't understand temp RAM correctly? + // + EFI_PEI_PPI_DESCRIPTOR PpiArray[10]; + + SecPpiList = &PpiArray[0]; + ASSERT (sizeof (PpiArray) >= SecReseveredMemorySize); + } +#endif + // Copy existing list, and append our entries. + CopyMem (SecPpiList, PpiList, sizeof (EFI_PEI_PPI_DESCRIPTOR) * Index); + CopyMem (&SecPpiList[Index], gPrivateDispatchTable, sizeof (gPrivateDispatchTable)); + + // Find PEI Core and transfer control + VolumeHandle = (EFI_PEI_FV_HANDLE)(UINTN)SecCoreData->BootFirmwareVolumeBase; + FileHandle = NULL; + Status = PeiServicesFfsFindNextFile (EFI_FV_FILETYPE_PEI_CORE, VolumeHandle, &FileHandle); + ASSERT_EFI_ERROR (Status); + + Status = PeiServicesFfsFindSectionData (EFI_SECTION_PE32, FileHandle, &PeCoffImage); + ASSERT_EFI_ERROR (Status); + + Status = PeCoffLoaderGetEntryPoint (PeCoffImage, (VOID **)&EntryPoint); + ASSERT_EFI_ERROR (Status); + + // Transfer control to PEI Core + EntryPoint (SecCoreData, SecPpiList); + + // PEI Core never returns + ASSERT (FALSE); + return; +} + + + diff --git a/InOsEmuPkg/Sec/Sec.h b/InOsEmuPkg/Sec/Sec.h new file mode 100644 index 0000000000..d0bc9e176e --- /dev/null +++ b/InOsEmuPkg/Sec/Sec.h @@ -0,0 +1,51 @@ +/*++ @file + Stub SEC that is called from the OS appliation that is the root of the emulator. + + The OS application will call the SEC with the PEI Entry Point API. + +Copyright (c) 2011, Apple Inc. 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. + +**/ + +#ifndef __SEC_H___ +#define __SEC_H___ + + +#include +#include +#include +#include +#include +#include + +#include + + +// +// I think this shold be defined in a MdePkg include file? +// +VOID +EFIAPI +ProcessLibraryConstructorList ( + VOID + ); + +EFI_STATUS +EFIAPI +SecTemporaryRamSupport ( + IN CONST EFI_PEI_SERVICES **PeiServices, + IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase, + IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase, + IN UINTN CopySize + ); + + +#endif + diff --git a/InOsEmuPkg/Sec/Sec.inf b/InOsEmuPkg/Sec/Sec.inf new file mode 100644 index 0000000000..b09785af40 --- /dev/null +++ b/InOsEmuPkg/Sec/Sec.inf @@ -0,0 +1,44 @@ +## @file +# Entry Point of Emu Emulator +# +# Main executable file of Unix Emulator that loads PEI core after initialization finished. +# Portions copyright (c) 2011, Apple Inc. 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. +# +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = EmuSec + FILE_GUID = BCAF98C9-22B0-3B4F-9CBD-C8A6B4DBCEE9 + MODULE_TYPE = SEC + VERSION_STRING = 1.0 + + +[Sources] + Sec.c + +[Sources.X64] + X64/SwitchRam.S + +[Packages] + MdePkg/MdePkg.dec + InOsEmuPkg/InOsEmuPkg.dec + +[LibraryClasses] + DebugLib + PeCoffGetEntryPointLib + PeiServicesLib + PpiListLib + BaseMemoryLib + +[Ppis] + gEfiTemporaryRamSupportPpiGuid + \ No newline at end of file diff --git a/InOsEmuPkg/Sec/X64/SwitchRam.S b/InOsEmuPkg/Sec/X64/SwitchRam.S new file mode 100644 index 0000000000..6bb2857ff0 --- /dev/null +++ b/InOsEmuPkg/Sec/X64/SwitchRam.S @@ -0,0 +1,68 @@ +#------------------------------------------------------------------------------ +# +# Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.
+# Portitions copyright (c) 2011, Apple Inc. 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. +# +#------------------------------------------------------------------------------ + + + +// EFI_STATUS +// EFIAPI +// SecTemporaryRamSupport ( +// IN CONST EFI_PEI_SERVICES **PeiServices, // %rcx +// IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase, // %rdx +// IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase, // %r8 +// IN UINTN CopySize // %r9 +// ) +// +ASM_GLOBAL ASM_PFX(SecTemporaryRamSupport) +ASM_PFX(SecTemporaryRamSupport): + // Adjust callers %rbp to account for stack move + subq %rdx, %rbp // Calc offset of %rbp in Temp Memory + addq %r8, %rbp // add in permanent base to offset + + pushq %rbp // stack frame is for the debugger + movq %rsp, %rbp + + pushq %rdx // Save TemporaryMemoryBase + pushq %r8 // Save PermanentMemoryBase + pushq %r9 // Save CopySize + + // + // Copy all of temp RAM to permanent memory, including stack + // + // CopyMem (PermanentMemoryBase, TemporaryMemoryBase, CopySize); + // %rcx, %rdx, %r8 + movq %r8, %rcx // Shift arguments + movq %r9, %r8 + call ASM_PFX(CopyMem) + // Temp mem stack now copied to permanent location. %esp still in temp memory + + popq %r9 // CopySize (old stack) + popq %r8 // PermanentMemoryBase (old stack) + popq %rdx // TemporaryMemoryBase (old stack) + + movq %rsp, %rcx // Move to new stack + subq %rdx, %rcx // Calc offset of stack in Temp Memory + addq %r8, %rcx // Calc PermanentMemoryBase address + movq %rcx, %rsp // Update stack + // Stack now points to permanent memory + + // ZeroMem (TemporaryMemoryBase /* rcx */, CopySize /* rdx */); + movq %rdx, %rcx + movq %r9, %rdx + call ASM_PFX(ZeroMem) + + // This data comes off the NEW stack + popq %rbp + ret + + diff --git a/InOsEmuPkg/Unix/Sec/Gasket.h b/InOsEmuPkg/Unix/Sec/Gasket.h index 665a075e3f..9b74276dcf 100644 --- a/InOsEmuPkg/Unix/Sec/Gasket.h +++ b/InOsEmuPkg/Unix/Sec/Gasket.h @@ -109,15 +109,6 @@ GasketSecGetNextProtocol ( // PPIs produced by SEC - -EFI_STATUS -EFIAPI -GasketSecUnixPeiLoadFile ( - IN VOID *Pe32Data, - IN EFI_PHYSICAL_ADDRESS *ImageAddress, - IN UINT64 *ImageSize, - OUT EFI_PHYSICAL_ADDRESS *EntryPoint - ); EFI_STATUS EFIAPI diff --git a/InOsEmuPkg/Unix/Sec/SecMain.c b/InOsEmuPkg/Unix/Sec/SecMain.c index 8677ab5938..b67a9f1ca1 100644 --- a/InOsEmuPkg/Unix/Sec/SecMain.c +++ b/InOsEmuPkg/Unix/Sec/SecMain.c @@ -27,13 +27,9 @@ char *gGdbWorkingFileName = NULL; EMU_THUNK_PPI mSecEmuThunkPpi = { GasketSecUnixPeiAutoScan, GasketSecUnixFdAddress, - GasketSecEmuThunkAddress, - GasketSecUnixPeiLoadFile + GasketSecEmuThunkAddress }; -EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI mSecTemporaryRamSupportPpi = { - GasketSecTemporaryRamSupport -}; @@ -44,8 +40,8 @@ EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI mSecTemporaryRamSupportPpi = { // The number of array elements is allocated base on parsing // EFI_FIRMWARE_VOLUMES and the memory is never freed. // -UINTN gFdInfoCount = 0; -EMU_FD_INFO *gFdInfo; +UINTN gFdInfoCount = 0; +EMU_FD_INFO *gFdInfo; // // Array that supports seperate memory rantes. @@ -53,8 +49,8 @@ EMU_FD_INFO *gFdInfo; // The number of array elements is allocated base on parsing // EFI_MEMORY_SIZE and the memory is never freed. // -UINTN gSystemMemoryCount = 0; -EMU_SYSTEM_MEMORY *gSystemMemory; +UINTN gSystemMemoryCount = 0; +EMU_SYSTEM_MEMORY *gSystemMemory; @@ -63,33 +59,6 @@ IMAGE_CONTEXT_TO_MOD_HANDLE *mImageContextModHandleArray = NULL; -EFI_PHYSICAL_ADDRESS * -MapMemory ( - INTN fd, - UINT64 length, - INTN prot, - INTN flags); - -EFI_STATUS -MapFile ( - IN CHAR8 *FileName, - IN OUT EFI_PHYSICAL_ADDRESS *BaseAddress, - OUT UINT64 *Length - ); - -EFI_STATUS -EFIAPI -SecNt32PeCoffRelocateImage ( - IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext - ); - - -int -main ( - IN int Argc, - IN char **Argv, - IN char **Envp - ) /*++ Routine Description: @@ -105,6 +74,12 @@ Returns: 1 - Abnormal exit **/ +int +main ( + IN int Argc, + IN char **Argv, + IN char **Envp + ) { EFI_STATUS Status; EFI_PHYSICAL_ADDRESS InitialStackMemory; @@ -115,25 +90,24 @@ Returns: UINTN PeiIndex; CHAR8 *FileName; BOOLEAN Done; - VOID *PeiCoreFile; + EFI_PEI_FILE_HANDLE FileHandle; + VOID *SecFile; CHAR16 *MemorySizeStr; CHAR16 *FirmwareVolumesStr; UINTN *StackPointer; - setbuf(stdout, 0); - setbuf(stderr, 0); + setbuf (stdout, 0); + setbuf (stderr, 0); MemorySizeStr = (CHAR16 *) PcdGetPtr (PcdEmuMemorySize); FirmwareVolumesStr = (CHAR16 *) PcdGetPtr (PcdEmuFirmwareVolume); - printf ("\nEDK SEC Main UNIX Emulation Environment from edk2.sourceforge.net\n"); + printf ("\nEDK II UNIX Emulation Environment from edk2.sourceforge.net\n"); // // PPIs pased into PEI_CORE // - AddThunkPpi (EFI_PEI_PPI_DESCRIPTOR_PPI, &gEfiTemporaryRamSupportPpiGuid, &mSecTemporaryRamSupportPpi); AddThunkPpi (EFI_PEI_PPI_DESCRIPTOR_PPI, &gEmuThunkPpiGuid, &mSecEmuThunkPpi); - AddThunkPpi (EFI_PEI_PPI_DESCRIPTOR_PPI, &gEmuPeiServicesTableUpdatePpiGuid, NULL); SecInitThunkProtocol (); @@ -149,6 +123,10 @@ Returns: AddThunkProtocol (&gPthreadThunkIo, (CHAR16 *)PcdGetPtr (PcdEmuApCount), FALSE); // EmuSecLibConstructor (); + + + gPpiList = GetThunkPpiList (); + #ifdef __APPLE__ // @@ -185,23 +163,24 @@ Returns: printf (" BootMode 0x%02x\n", (unsigned int)PcdGet32 (PcdEmuBootMode)); // - // Open up a 128K file to emulate temp memory for PEI. + // Open up a 128K file to emulate temp memory for SEC. // on a real platform this would be SRAM, or using the cache as RAM. // Set InitialStackMemory to zero so UnixOpenFile will allocate a new mapping // InitialStackMemorySize = STACK_SIZE; - InitialStackMemory = (UINTN)MapMemory(0, - (UINT32) InitialStackMemorySize, - PROT_READ | PROT_WRITE | PROT_EXEC, - MAP_ANONYMOUS | MAP_PRIVATE); + InitialStackMemory = (UINTN)MapMemory ( + 0, (UINT32) InitialStackMemorySize, + PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANONYMOUS | MAP_PRIVATE + ); if (InitialStackMemory == 0) { printf ("ERROR : Can not open SecStack Exiting\n"); exit (1); } - printf (" SEC passing in %u KB of temp RAM at 0x%08lx to PEI\n", + printf (" OS Emulator passing in %u KB of temp RAM at 0x%08lx to SEC\n", (unsigned int)(InitialStackMemorySize / 1024), - (unsigned long)InitialStackMemory); + (unsigned long)InitialStackMemory + ); for (StackPointer = (UINTN*) (UINTN) InitialStackMemory; StackPointer < (UINTN*)(UINTN)((UINTN) InitialStackMemory + (UINT64) InitialStackMemorySize); @@ -219,40 +198,49 @@ Returns: } Index2 = 0; - for (Done = FALSE, Index = 0, PeiIndex = 0, PeiCoreFile = NULL; + for (Done = FALSE, Index = 0, PeiIndex = 0, SecFile = NULL; FirmwareVolumesStr[Index2] != 0; Index++) { - for (Index1 = 0; (FirmwareVolumesStr[Index2] != '!') && (FirmwareVolumesStr[Index2] != 0); Index2++) + for (Index1 = 0; (FirmwareVolumesStr[Index2] != '!') && (FirmwareVolumesStr[Index2] != 0); Index2++) { FileName[Index1++] = FirmwareVolumesStr[Index2]; - if (FirmwareVolumesStr[Index2] == '!') + } + if (FirmwareVolumesStr[Index2] == '!') { Index2++; + } FileName[Index1] = '\0'; // // Open the FD and remmeber where it got mapped into our processes address space // Status = MapFile ( - FileName, - &gFdInfo[Index].Address, - &gFdInfo[Index].Size - ); + FileName, + &gFdInfo[Index].Address, + &gFdInfo[Index].Size + ); if (EFI_ERROR (Status)) { printf ("ERROR : Can not open Firmware Device File %s (%x). Exiting.\n", FileName, (unsigned int)Status); exit (1); } - printf (" FD loaded from %s at 0x%08lx", - FileName, (unsigned long)gFdInfo[Index].Address); + printf (" FD loaded from %s at 0x%08lx",FileName, (unsigned long)gFdInfo[Index].Address); - if (PeiCoreFile == NULL) { + if (SecFile == NULL) { // - // Assume the beginning of the FD is an FV and look for the PEI Core. + // Assume the beginning of the FD is an FV and look for the SEC Core. // Load the first one we find. // - Status = SecFfsFindPeiCore ((EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) gFdInfo[Index].Address, &PeiCoreFile); + FileHandle = NULL; + Status = PeiServicesFfsFindNextFile ( + EFI_FV_FILETYPE_SECURITY_CORE, + (EFI_PEI_FV_HANDLE)(UINTN)gFdInfo[Index].Address, + &FileHandle + ); if (!EFI_ERROR (Status)) { - PeiIndex = Index; - printf (" contains SEC Core"); + Status = PeiServicesFfsFindSectionData (EFI_SECTION_PE32, FileHandle, &SecFile); + if (!EFI_ERROR (Status)) { + PeiIndex = Index; + printf (" contains SEC Core"); + } } } @@ -275,26 +263,28 @@ Returns: Index1++; } gSystemMemory[Index++].Size = val * 0x100000; - if (MemorySizeStr[Index1] == 0) + if (MemorySizeStr[Index1] == 0) { break; + } Index1++; } printf ("\n"); // - // Hand off to PEI Core + // Hand off to SEC // - SecLoadFromCore ((UINTN) InitialStackMemory, (UINTN) InitialStackMemorySize, (UINTN) gFdInfo[0].Address, PeiCoreFile); + SecLoadFromCore ((UINTN) InitialStackMemory, (UINTN) InitialStackMemorySize, (UINTN) gFdInfo[0].Address, SecFile); // - // If we get here, then the PEI Core returned. This is an error as PEI should - // always hand off to DXE. + // If we get here, then the SEC Core returned. This is an error as SEC should + // always hand off to PEI Core and then on to DXE Core. // - printf ("ERROR : PEI Core returned\n"); + printf ("ERROR : SEC returned\n"); exit (1); } + EFI_PHYSICAL_ADDRESS * MapMemory ( INTN fd, @@ -318,8 +308,7 @@ MapMemory ( } if ((((UINTN)res) & ~(align-1)) == (UINTN)res) { isAligned=1; - } - else { + } else { munmap(res, length); base += align; } @@ -327,12 +316,7 @@ MapMemory ( return res; } -EFI_STATUS -MapFile ( - IN CHAR8 *FileName, - IN OUT EFI_PHYSICAL_ADDRESS *BaseAddress, - OUT UINT64 *Length - ) + /*++ Routine Description: @@ -356,24 +340,32 @@ Returns: EFI_DEVICE_ERROR - An error occured attempting to map the opened file **/ +EFI_STATUS +MapFile ( + IN CHAR8 *FileName, + IN OUT EFI_PHYSICAL_ADDRESS *BaseAddress, + OUT UINT64 *Length + ) { int fd; VOID *res; UINTN FileSize; fd = open (FileName, O_RDONLY); - if (fd < 0) + if (fd < 0) { return EFI_NOT_FOUND; + } FileSize = lseek (fd, 0, SEEK_END); - res = MapMemory(fd, FileSize, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE); + res = MapMemory (fd, FileSize, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE); close (fd); - if (res == MAP_FAILED) + if (res == MAP_FAILED) { return EFI_DEVICE_ERROR; - + } + *Length = (UINT64) FileSize; *BaseAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) res; @@ -382,35 +374,33 @@ Returns: -VOID -SecLoadFromCore ( - IN UINTN LargestRegion, - IN UINTN LargestRegionSize, - IN UINTN BootFirmwareVolumeBase, - IN VOID *PeiCorePe32File - ) /*++ Routine Description: - This is the service to load the PEI Core from the Firmware Volume + This is the service to load the SEC Core from the Firmware Volume Arguments: - LargestRegion - Memory to use for PEI. + LargestRegion - Memory to use for SEC. LargestRegionSize - Size of Memory to use for PEI BootFirmwareVolumeBase - Start of the Boot FV - PeiCorePe32File - PEI Core PE32 + PeiCorePe32File - SEC PE32 Returns: Success means control is transfered and thus we should never return **/ +VOID +SecLoadFromCore ( + IN UINTN LargestRegion, + IN UINTN LargestRegionSize, + IN UINTN BootFirmwareVolumeBase, + IN VOID *PeiCorePe32File + ) { EFI_STATUS Status; EFI_PHYSICAL_ADDRESS TopOfMemory; VOID *TopOfStack; - UINT64 PeiCoreSize; EFI_PHYSICAL_ADDRESS PeiCoreEntryPoint; - EFI_PHYSICAL_ADDRESS PeiImageAddress; EFI_SEC_PEI_HAND_OFF *SecCoreData; UINTN PeiStackSize; @@ -442,7 +432,7 @@ Returns: // // Bind this information into the SEC hand-off state // - SecCoreData = (EFI_SEC_PEI_HAND_OFF*)(UINTN) TopOfStack; + SecCoreData = (EFI_SEC_PEI_HAND_OFF*)(UINTN) TopOfStack; SecCoreData->DataSize = sizeof(EFI_SEC_PEI_HAND_OFF); SecCoreData->BootFirmwareVolumeBase = (VOID*)BootFirmwareVolumeBase; SecCoreData->BootFirmwareVolumeSize = PcdGet32 (PcdEmuFirmwareFdSize); @@ -454,41 +444,30 @@ Returns: SecCoreData->PeiTemporaryRamSize = STACK_SIZE - PeiStackSize; // - // Load the PEI Core from a Firmware Volume + // Find the SEC Core Entry Point // - Status = SecUnixPeiLoadFile ( - PeiCorePe32File, - &PeiImageAddress, - &PeiCoreSize, - &PeiCoreEntryPoint - ); + Status = SecPeCoffGetEntryPoint (PeiCorePe32File, (VOID **)&PeiCoreEntryPoint); if (EFI_ERROR (Status)) { return ; } // - // Transfer control to the PEI Core + // Transfer control to the SEC Core // PeiSwitchStacks ( (SWITCH_STACK_ENTRY_POINT) (UINTN) PeiCoreEntryPoint, SecCoreData, - (VOID *)GetThunkPpiList (), + (VOID *)gPpiList, NULL, TopOfStack ); // - // If we get here, then the PEI Core returned. This is an error + // If we get here, then the SEC Core returned. This is an error // return ; } -EFI_STATUS -EFIAPI -SecUnixPeiAutoScan ( - IN UINTN Index, - OUT EFI_PHYSICAL_ADDRESS *MemoryBase, - OUT UINT64 *MemorySize - ) + /*++ Routine Description: @@ -509,6 +488,13 @@ Returns: EFI_UNSUPPORTED - If Index is not supported **/ +EFI_STATUS +EFIAPI +SecUnixPeiAutoScan ( + IN UINTN Index, + OUT EFI_PHYSICAL_ADDRESS *MemoryBase, + OUT UINT64 *MemorySize + ) { void *res; @@ -517,11 +503,14 @@ Returns: } *MemoryBase = 0; - res = MapMemory(0, gSystemMemory[Index].Size, - PROT_READ | PROT_WRITE | PROT_EXEC, - MAP_PRIVATE | MAP_ANONYMOUS); - if (res == MAP_FAILED) + res = MapMemory ( + 0, gSystemMemory[Index].Size, + PROT_READ | PROT_WRITE | PROT_EXEC, + MAP_PRIVATE | MAP_ANONYMOUS + ); + if (res == MAP_FAILED) { return EFI_DEVICE_ERROR; + } *MemorySize = gSystemMemory[Index].Size; *MemoryBase = (UINTN)res; gSystemMemory[Index].Memory = *MemoryBase; @@ -529,11 +518,7 @@ Returns: return EFI_SUCCESS; } -VOID * -EFIAPI -SecEmuThunkAddress ( - VOID - ) + /*++ Routine Description: @@ -548,93 +533,16 @@ Returns: EFI_SUCCESS - Data returned **/ +VOID * +EFIAPI +SecEmuThunkAddress ( + VOID + ) { return &gEmuThunkProtocol; } -EFI_STATUS -SecUnixPeiLoadFile ( - IN VOID *Pe32Data, - OUT EFI_PHYSICAL_ADDRESS *ImageAddress, - OUT UINT64 *ImageSize, - OUT EFI_PHYSICAL_ADDRESS *EntryPoint - ) -/*++ - -Routine Description: - Loads and relocates a PE/COFF image into memory. - -Arguments: - Pe32Data - The base address of the PE/COFF file that is to be loaded and relocated - ImageAddress - The base address of the relocated PE/COFF image - ImageSize - The size of the relocated PE/COFF image - EntryPoint - The entry point of the relocated PE/COFF image - -Returns: - EFI_SUCCESS - The file was loaded and relocated - EFI_OUT_OF_RESOURCES - There was not enough memory to load and relocate the PE/COFF file - -**/ -{ - EFI_STATUS Status; - PE_COFF_LOADER_IMAGE_CONTEXT ImageContext; - - ZeroMem (&ImageContext, sizeof (ImageContext)); - ImageContext.Handle = Pe32Data; - - ImageContext.ImageRead = (PE_COFF_LOADER_READ_FILE) SecImageRead; - - Status = PeCoffLoaderGetImageInfo (&ImageContext); - if (EFI_ERROR (Status)) { - return Status; - } - - - // - // Allocate space in UNIX (not emulator) memory. Extra space is for alignment - // - ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) MapMemory ( - 0, - (UINT32) (ImageContext.ImageSize + (ImageContext.SectionAlignment * 2)), - PROT_READ | PROT_WRITE | PROT_EXEC, - MAP_ANONYMOUS | MAP_PRIVATE - ); - if (ImageContext.ImageAddress == 0) { - return EFI_OUT_OF_RESOURCES; - } - - // - // Align buffer on section boundry - // - ImageContext.ImageAddress += ImageContext.SectionAlignment - 1; - ImageContext.ImageAddress &= ~((EFI_PHYSICAL_ADDRESS)(ImageContext.SectionAlignment - 1)); - - - Status = PeCoffLoaderLoadImage (&ImageContext); - if (EFI_ERROR (Status)) { - return Status; - } - - Status = PeCoffLoaderRelocateImage (&ImageContext); - if (EFI_ERROR (Status)) { - return Status; - } - - - SecPeCoffRelocateImageExtraAction (&ImageContext); - - // - // BugBug: Flush Instruction Cache Here when CPU Lib is ready - // - - *ImageAddress = ImageContext.ImageAddress; - *ImageSize = ImageContext.ImageSize; - *EntryPoint = ImageContext.EntryPoint; - - return EFI_SUCCESS; -} - RETURN_STATUS EFIAPI @@ -643,27 +551,28 @@ SecPeCoffGetEntryPoint ( IN OUT VOID **EntryPoint ) { - EFI_STATUS Status; - EFI_PHYSICAL_ADDRESS ImageAddress; - UINT64 ImageSize; - EFI_PHYSICAL_ADDRESS PhysEntryPoint; + EFI_STATUS Status; + PE_COFF_LOADER_IMAGE_CONTEXT ImageContext; + + ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)Pe32Data; + ImageContext.SizeOfHeaders = PeCoffGetSizeOfHeaders (Pe32Data); + ImageContext.PdbPointer = PeCoffLoaderGetPdbPointer (Pe32Data); + Status = PeCoffLoaderGetEntryPoint (Pe32Data, EntryPoint); + if (!EFI_ERROR (Status)) { + return Status; + } - Status = SecUnixPeiLoadFile (Pe32Data, &ImageAddress, &ImageSize, &PhysEntryPoint); + ImageContext.EntryPoint = (UINTN)EntryPoint; - *EntryPoint = (VOID *)(UINTN)PhysEntryPoint; + // On Unix a dlopen is done that will change the entry point + SecPeCoffRelocateImageExtraAction (&ImageContext); + *EntryPoint = (VOID *)(UINTN)ImageContext.EntryPoint; + return Status; } -EFI_STATUS -EFIAPI -SecUnixFdAddress ( - IN UINTN Index, - IN OUT EFI_PHYSICAL_ADDRESS *FdBase, - IN OUT UINT64 *FdSize, - IN OUT EFI_PHYSICAL_ADDRESS *FixUp - ) /*++ Routine Description: @@ -681,6 +590,14 @@ Returns: EFI_UNSUPPORTED - Index does nto map to an FD in the system **/ +EFI_STATUS +EFIAPI +SecUnixFdAddress ( + IN UINTN Index, + IN OUT EFI_PHYSICAL_ADDRESS *FdBase, + IN OUT UINT64 *FdSize, + IN OUT EFI_PHYSICAL_ADDRESS *FixUp + ) { if (Index >= gFdInfoCount) { return EFI_UNSUPPORTED; @@ -706,49 +623,7 @@ Returns: return EFI_SUCCESS; } -EFI_STATUS -EFIAPI -SecImageRead ( - IN VOID *FileHandle, - IN UINTN FileOffset, - IN OUT UINTN *ReadSize, - OUT VOID *Buffer - ) -/*++ -Routine Description: - Support routine for the PE/COFF Loader that reads a buffer from a PE/COFF file - -Arguments: - FileHandle - The handle to the PE/COFF file - FileOffset - The offset, in bytes, into the file to read - ReadSize - The number of bytes to read from the file starting at FileOffset - Buffer - A pointer to the buffer to read the data into. - -Returns: - EFI_SUCCESS - ReadSize bytes of data were read into Buffer from the PE/COFF file starting at FileOffset - -**/ -{ - CHAR8 *Destination8; - CHAR8 *Source8; - UINTN Length; - - Destination8 = Buffer; - Source8 = (CHAR8 *) ((UINTN) FileHandle + FileOffset); - Length = *ReadSize; - while (Length--) { - *(Destination8++) = *(Source8++); - } - - return EFI_SUCCESS; -} - -UINTN -CountSeperatorsInString ( - IN const CHAR16 *String, - IN CHAR16 Seperator - ) /*++ Routine Description: @@ -762,6 +637,11 @@ Returns: Number of Seperator in String **/ +UINTN +CountSeperatorsInString ( + IN const CHAR16 *String, + IN CHAR16 Seperator + ) { UINTN Count; @@ -775,11 +655,6 @@ Returns: } -EFI_STATUS -AddHandle ( - IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, - IN VOID *ModHandle - ) /*++ Routine Description: @@ -796,6 +671,11 @@ Returns: EFI_SUCCESS - ModHandle was stored. **/ +EFI_STATUS +AddHandle ( + IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, + IN VOID *ModHandle + ) { UINTN Index; IMAGE_CONTEXT_TO_MOD_HANDLE *Array; @@ -835,10 +715,6 @@ Returns: } -VOID * -RemoveHandle ( - IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext - ) /*++ Routine Description: @@ -853,6 +729,10 @@ Returns: NULL - No ModHandle associated with ImageContext **/ +VOID * +RemoveHandle ( + IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext + ) { UINTN Index; IMAGE_CONTEXT_TO_MOD_HANDLE *Array; @@ -890,7 +770,7 @@ Returns: // b SecGdbScriptBreak // command // silent -// source SecMain.dll.gdb +// source SecMain.gdb // c // end // @@ -1057,11 +937,13 @@ SecPeCoffRelocateImageExtraAction ( return; } - fprintf (stderr, + fprintf ( + stderr, "Loading %s 0x%08lx - entry point 0x%08lx\n", ImageContext->PdbPointer, (unsigned long)ImageContext->ImageAddress, - (unsigned long)ImageContext->EntryPoint); + (unsigned long)ImageContext->EntryPoint + ); Handle = dlopen (ImageContext->PdbPointer, RTLD_NOW); @@ -1073,7 +955,7 @@ SecPeCoffRelocateImageExtraAction ( if (Entry != NULL) { ImageContext->EntryPoint = (UINTN)Entry; - printf("Change %s Entrypoint to :0x%08lx\n", ImageContext->PdbPointer, (unsigned long)Entry); + printf ("Change %s Entrypoint to :0x%08lx\n", ImageContext->PdbPointer, (unsigned long)Entry); } SecUnixLoaderBreak (); diff --git a/InOsEmuPkg/Unix/Sec/SecMain.h b/InOsEmuPkg/Unix/Sec/SecMain.h index 6e352b11b5..317bd5d8b5 100644 --- a/InOsEmuPkg/Unix/Sec/SecMain.h +++ b/InOsEmuPkg/Unix/Sec/SecMain.h @@ -28,11 +28,12 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include +#include +#include +#include #include #include -#include -#include #include #include @@ -289,7 +290,23 @@ VOID SecInitThunkProtocol ( VOID ); + +EFI_PHYSICAL_ADDRESS * +MapMemory ( + INTN fd, + UINT64 length, + INTN prot, + INTN flags); + +EFI_STATUS +MapFile ( + IN CHAR8 *FileName, + IN OUT EFI_PHYSICAL_ADDRESS *BaseAddress, + OUT UINT64 *Length + ); + + VOID SecSleep (UINT64 Milliseconds); VOID SecEnableInterrupt (VOID); diff --git a/InOsEmuPkg/Unix/Sec/SecMain.inf b/InOsEmuPkg/Unix/Sec/SecMain.inf index 24a36be955..c4b8ad1813 100644 --- a/InOsEmuPkg/Unix/Sec/SecMain.inf +++ b/InOsEmuPkg/Unix/Sec/SecMain.inf @@ -32,7 +32,6 @@ [Sources] SecMain.c EmuThunk.c - FwVol.c X11GraphicsWindow.c Pthreads.c PosixFileSystem.c @@ -46,7 +45,6 @@ MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec InOsEmuPkg/InOsEmuPkg.dec - InOsEmuPkg/InOsEmuPkg.dec [LibraryClasses] DebugLib @@ -57,13 +55,13 @@ PeCoffLib ThunkPpiList ThunkProtocolList - + PpiListLib + PeiServicesLib + PeCoffGetEntryPointLib [Ppis] gEfiPeiStatusCodePpiGuid # PPI ALWAYS_PRODUCED - gEfiTemporaryRamSupportPpiGuid gEmuThunkPpiGuid - gEmuPeiServicesTableUpdatePpiGuid [Protocols] gEmuIoThunkProtocolGuid diff --git a/InOsEmuPkg/Unix/Sec/X64/Gasket.S b/InOsEmuPkg/Unix/Sec/X64/Gasket.S index fde3028da9..3dc0fa1f28 100644 --- a/InOsEmuPkg/Unix/Sec/X64/Gasket.S +++ b/InOsEmuPkg/Unix/Sec/X64/Gasket.S @@ -727,30 +727,6 @@ ASM_PFX(ReverseGasketUint64Uint64): ret -// Sec PPI Callbacks - Check Me - -ASM_GLOBAL ASM_PFX(GasketSecUnixPeiLoadFile) -ASM_PFX(GasketSecUnixPeiLoadFile): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - movq %rdx, %rsi - movq %r8, %rdx - movq %r9, %rcx - - call ASM_PFX(SecUnixPeiLoadFile) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - - ASM_GLOBAL ASM_PFX(GasketSecUnixPeiAutoScan) ASM_PFX(GasketSecUnixPeiAutoScan): pushq %rbp // stack frame is for the debugger diff --git a/InOsEmuPkg/Unix/Sec/X64/SwitchStack.S b/InOsEmuPkg/Unix/Sec/X64/SwitchStack.S index 0d4e5029c9..76567ac0e1 100644 --- a/InOsEmuPkg/Unix/Sec/X64/SwitchStack.S +++ b/InOsEmuPkg/Unix/Sec/X64/SwitchStack.S @@ -52,61 +52,3 @@ ASM_PFX(PeiSwitchStacks): -// EFI_STATUS -// EFIAPI -// SecTemporaryRamSupport ( -// IN CONST EFI_PEI_SERVICES **PeiServices, // %rcx -// IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase, // %rdx -// IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase, // %r8 -// IN UINTN CopySize // %r9 -// ) -// -ASM_GLOBAL ASM_PFX(GasketSecTemporaryRamSupport) -ASM_PFX(GasketSecTemporaryRamSupport): - // Adjust callers %rbp to account for stack move - subq %rdx, %rbp // Calc offset of %rbp in Temp Memory - addq %r8, %rbp // add in permanent base to offset - - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - pushq %rdx // Save TemporaryMemoryBase - pushq %r8 // Save PermanentMemoryBase - pushq %r9 // Save CopySize - - // - // Copy all of temp RAM to permanent memory, including stack - // - // CopyMem (PermanentMemoryBase, TemporaryMemoryBase, CopySize); - // %rdi, %rsi, %rdx - movq %r8, %rdi // Swizzle args - movq %rdx, %rsi - movq %r9, %rdx - call ASM_PFX(CopyMem) - // Temp mem stack now copied to permanent location. %esp still in temp memory - - popq %r9 // CopySize (old stack) - popq %r8 // PermanentMemoryBase (old stack) - popq %rdx // TemporaryMemoryBase (old stack) - - movq %rsp, %rcx // Move to new stack - subq %rdx, %rcx // Calc offset of stack in Temp Memory - addq %r8, %rcx // Calc PermanentMemoryBase address - movq %rcx, %rsp // Update stack - // Stack now points to permanent memory - - // ZeroMem (TemporaryMemoryBase /* rdi */, CopySize /* rsi */); - movq %rdx, %rdi - movq %r9, %rsi - call ASM_PFX(ZeroMem) - - // This data comes off the NEW stack - popq %rdi - popq %rsi - popq %rbp - ret - - diff --git a/InOsEmuPkg/Unix/UnixX64.dsc b/InOsEmuPkg/Unix/UnixX64.dsc index 88c4218d2d..e9dffb0d90 100644 --- a/InOsEmuPkg/Unix/UnixX64.dsc +++ b/InOsEmuPkg/Unix/UnixX64.dsc @@ -110,15 +110,27 @@ DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf +[LibraryClasses.common.SEC] + PeiServicesLib|InOsEmuPkg/Library/SecPeiServicesLib/SecPeiServicesLib.inf + PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf + PeCoffGetEntryPointLib|InOsEmuPkg/Library/PeiEmuPeCoffGetEntryPointLib/PeiEmuPeCoffGetEntryPointLib.inf + PeCoffExtraActionLib|InOsEmuPkg/Library/PeiEmuPeCoffExtraActionLib/PeiEmuPeCoffExtraActionLib.inf + SerialPortLib|InOsEmuPkg/Library/PeiEmuSerialPortLib/PeiEmuSerialPortLib.inf + PpiListLib|InOsEmuPkg/Library/SecPpiListLib/SecPpiListLib.inf + [LibraryClasses.common.USER_DEFINED, LibraryClasses.common.BASE] DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/BasePeCoffExtraActionLibNull.inf MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf - PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf - + PpiListLib|InOsEmuPkg/Library/SecPpiListLib/SecPpiListLib.inf ThunkPpiList|InOsEmuPkg/Library/ThunkPpiList/ThunkPpiList.inf ThunkProtocolList|InOsEmuPkg/Library/ThunkProtocolList/ThunkProtocolList.inf + PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf + PpiListLib|InOsEmuPkg/Library/SecPpiListLib/SecPpiListLib.inf + PeiServicesLib|InOsEmuPkg/Library/SecPeiServicesLib/SecPeiServicesLib.inf + +# PeCoffExtraActionLib|InOsEmuPkg/Library/PeiEmuPeCoffExtraActionLib/PeiEmuPeCoffExtraActionLib.inf [LibraryClasses.common.PEIM, LibraryClasses.common.PEI_CORE] @@ -128,11 +140,11 @@ PeCoffGetEntryPointLib|InOsEmuPkg/Library/PeiEmuPeCoffGetEntryPointLib/PeiEmuPeCoffGetEntryPointLib.inf PeCoffExtraActionLib|InOsEmuPkg/Library/PeiEmuPeCoffExtraActionLib/PeiEmuPeCoffExtraActionLib.inf ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf + SerialPortLib|InOsEmuPkg/Library/PeiEmuSerialPortLib/PeiEmuSerialPortLib.inf [LibraryClasses.common.PEI_CORE] PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf PeiServicesTablePointerLib|InOsEmuPkg/Library/PeiCoreServicesTablePointerLib/PeiCoreServicesTablePointerLib.inf - SerialPortLib|InOsEmuPkg/Library/PeiEmuSerialPortLib/PeiEmuSerialPortLib.inf [LibraryClasses.common.PEIM] PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf @@ -252,6 +264,11 @@ ## InOsEmuPkg/Unix/Sec/SecMain.inf !else + # + # Generic SEC + # + InOsEmuPkg/Sec/Sec.inf + ## # PEI Phase modules ## @@ -261,10 +278,7 @@ PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf } MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouterPei.inf - MdeModulePkg/Universal/StatusCodeHandler/Pei/StatusCodeHandlerPei.inf { - - SerialPortLib|InOsEmuPkg/Library/PeiEmuSerialPortLib/PeiEmuSerialPortLib.inf - } + MdeModulePkg/Universal/StatusCodeHandler/Pei/StatusCodeHandlerPei.inf IntelFrameworkModulePkg/Universal/StatusCode/Pei/StatusCodePei.inf InOsEmuPkg/BootModePei/BootModePei.inf diff --git a/InOsEmuPkg/Unix/UnixX64.fdf b/InOsEmuPkg/Unix/UnixX64.fdf index 48d9179c9c..4b0e683ea0 100644 --- a/InOsEmuPkg/Unix/UnixX64.fdf +++ b/InOsEmuPkg/Unix/UnixX64.fdf @@ -167,6 +167,7 @@ APRIORI DXE { INF MdeModulePkg/Universal/PCD/Dxe/Pcd.inf INF InOsEmuPkg/MetronomeDxe/Metronome.inf } +INF InOsEmuPkg/Sec/Sec.inf INF MdeModulePkg/Core/Pei/PeiMain.inf INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf INF MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouterPei.inf @@ -293,6 +294,13 @@ FILE FREEFORM = PCD(gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdLogoFile) { # } # ############################################################################ +[Rule.Common.SEC] + FILE SEC = $(NAMED_GUID) { + PE32 PE32 Align=32 $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING ="$(MODULE_NAME)" Optional + VERSION STRING ="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER) + } + [Rule.Common.PEI_CORE] FILE PEI_CORE = $(NAMED_GUID) { -- 2.39.2