2011-05-14 18:00:22 +02:00
|
|
|
/*++ @file
|
|
|
|
Stub SEC that is called from the OS appliation that is the root of the emulator.
|
2011-06-28 18:50:26 +02:00
|
|
|
|
|
|
|
The OS application will call the SEC with the PEI Entry Point API.
|
2011-05-14 18:00:22 +02:00
|
|
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-06-28 18:50:26 +02:00
|
|
|
EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI mSecTemporaryRamSupportPpi = {
|
2011-05-14 18:00:22 +02:00
|
|
|
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
|
2011-06-28 18:50:26 +02:00
|
|
|
SEC that sits on top of an OS application. So the entry and exit of this module
|
|
|
|
has the same API.
|
2011-05-14 18:00:22 +02:00
|
|
|
|
|
|
|
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
|
2011-06-28 18:50:26 +02:00
|
|
|
temporary RAM, the stack location and the BFV location.
|
2011-05-14 18:00:22 +02:00
|
|
|
|
|
|
|
@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.
|
|
|
|
|
|
|
|
**/
|
2011-06-28 18:50:26 +02:00
|
|
|
VOID
|
2011-05-14 18:00:22 +02:00
|
|
|
EFIAPI
|
|
|
|
_ModuleEntryPoint (
|
|
|
|
IN EFI_SEC_PEI_HAND_OFF *SecCoreData,
|
2011-06-28 18:50:26 +02:00
|
|
|
IN EFI_PEI_PPI_DESCRIPTOR *PpiList
|
2011-05-14 18:00:22 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
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;
|
2011-06-28 18:50:26 +02:00
|
|
|
|
2011-06-08 23:52:21 +02:00
|
|
|
EMU_MAGIC_PAGE()->PpiList = PpiList;
|
2011-05-14 18:00:22 +02:00
|
|
|
ProcessLibraryConstructorList ();
|
2011-06-28 18:50:26 +02:00
|
|
|
|
2011-05-14 18:00:22 +02:00
|
|
|
DEBUG ((EFI_D_ERROR, "SEC Has Started\n"));
|
2011-06-28 18:50:26 +02:00
|
|
|
|
2011-05-14 18:00:22 +02:00
|
|
|
//
|
|
|
|
// Add Our PPIs to the list
|
|
|
|
//
|
|
|
|
SecReseveredMemorySize = sizeof (gPrivateDispatchTable);
|
|
|
|
for (Ppi = PpiList, Index = 1; ; Ppi++, Index++) {
|
|
|
|
SecReseveredMemorySize += sizeof (EFI_PEI_PPI_DESCRIPTOR);
|
2011-06-28 18:50:26 +02:00
|
|
|
|
2011-05-14 18:00:22 +02:00
|
|
|
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.
|
2011-06-28 18:50:26 +02:00
|
|
|
Ppi->Flags &= ~EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;
|
2011-05-14 18:00:22 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-06-28 18:50:26 +02:00
|
|
|
|
2011-05-14 18:00:22 +02:00
|
|
|
// Keep everything on a good alignment
|
|
|
|
SecReseveredMemorySize = ALIGN_VALUE (SecReseveredMemorySize, CPU_STACK_ALIGNMENT);
|
2011-06-28 18:50:26 +02:00
|
|
|
|
2011-05-14 18:00:22 +02:00
|
|
|
#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];
|
2011-06-28 18:50:26 +02:00
|
|
|
|
2011-05-14 18:00:22 +02:00
|
|
|
SecPpiList = &PpiArray[0];
|
|
|
|
ASSERT (sizeof (PpiArray) >= SecReseveredMemorySize);
|
|
|
|
}
|
|
|
|
#endif
|
2011-06-28 18:50:26 +02:00
|
|
|
// Copy existing list, and append our entries.
|
2011-05-14 18:00:22 +02:00
|
|
|
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);
|
2011-06-28 18:50:26 +02:00
|
|
|
|
2011-05-14 18:00:22 +02:00
|
|
|
Status = PeiServicesFfsFindSectionData (EFI_SECTION_PE32, FileHandle, &PeCoffImage);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
|
|
Status = PeCoffLoaderGetEntryPoint (PeCoffImage, (VOID **)&EntryPoint);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
2011-06-28 18:50:26 +02:00
|
|
|
|
2011-05-14 18:00:22 +02:00
|
|
|
// Transfer control to PEI Core
|
|
|
|
EntryPoint (SecCoreData, SecPpiList);
|
2011-06-28 18:50:26 +02:00
|
|
|
|
2011-05-14 18:00:22 +02:00
|
|
|
// PEI Core never returns
|
|
|
|
ASSERT (FALSE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|