diff options
author | andrewfish <andrewfish@6f19259b-4bc3-4df7-8a09-765794883524> | 2011-05-14 16:00:22 +0000 |
---|---|---|
committer | andrewfish <andrewfish@6f19259b-4bc3-4df7-8a09-765794883524> | 2011-05-14 16:00:22 +0000 |
commit | 65e3f333b3b97c8098e95ff27b3292b5c1dc31d1 (patch) | |
tree | d96ae19b9c0ba3158f12bcfde463162015862f86 /InOsEmuPkg/Sec | |
parent | 960212a3e43df72f26f17cb12d9c6bf149440a05 (diff) | |
download | edk2-platforms-65e3f333b3b97c8098e95ff27b3292b5c1dc31d1.tar.xz |
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
Diffstat (limited to 'InOsEmuPkg/Sec')
-rw-r--r-- | InOsEmuPkg/Sec/Sec.c | 149 | ||||
-rw-r--r-- | InOsEmuPkg/Sec/Sec.h | 51 | ||||
-rw-r--r-- | InOsEmuPkg/Sec/Sec.inf | 44 | ||||
-rw-r--r-- | InOsEmuPkg/Sec/X64/SwitchRam.S | 68 |
4 files changed, 312 insertions, 0 deletions
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.<BR> +This program and the accompanying materials +are licensed and made available under the terms and conditions of the BSD License +which accompanies this distribution. The full text of the license may be found at +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.<BR> +This program and the accompanying materials +are licensed and made available under the terms and conditions of the BSD License +which accompanies this distribution. The full text of the license may be found at +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 <PiPei.h> +#include <Library/DebugLib.h> +#include <Library/PeiServicesLib.h> +#include <Library/PeCoffGetEntryPointLib.h> +#include <Library/BaseMemoryLib.h> +#include <Library/PpiListLib.h> + +#include <Ppi/TemporaryRamSupport.h> + + +// +// 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.<BR>
+#
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# 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.<BR>
+# 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
+
+
|