gInOsEmuPkgTokenSpaceGuid.PcdEmuFirmwareFdSize|0x0|UINT32|0x00001012\r
gInOsEmuPkgTokenSpaceGuid.PcdEmuFirmwareBlockSize|0|UINT32|0x00001013\r
\r
+ ## Number of Application Processors (APs) in the system 0 means Uniprocessor mode\r
gInOsEmuPkgTokenSpaceGuid.PcdEmuApCount|L"0"|VOID*|0x00001019\r
\r
+ ## Magic page to implement PEI Services Table Pointer Lib\r
+ gInOsEmuPkgTokenSpaceGuid.PcdPeiServicesTablePage|0x1000000000|UINT64|0x0000101b\r
+\r
[PcdsFixedAtBuild, PcdsPatchableInModule] \r
gInOsEmuPkgTokenSpaceGuid.PcdEmuBootMode|1|UINT32|0x00001006\r
gInOsEmuPkgTokenSpaceGuid.PcdEmuFirmwareVolume|L"..\\Fv\\Fv_Recovery.fd"|VOID*|0x00001009\r
--- /dev/null
+/*++ @file
+The PCD, gInOsEmuPkgTokenSpaceGuid.PcdPeiServicesTablePage, points to a magic page
+of memory that is like SRAM on an embedded system. This file defines what goes
+where in the magic page.
+
+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 __EMU_MAGIC_PAGE_LIB_H__
+#define __EMU_MAGIC_PAGE_LIB_H__
+
+#include <PiPei.h>
+#include <Library/PcdLib.h>
+#include <Protocol/EmuThunk.h>
+
+typedef struct {
+ // Used by PEI Core and PEIMs to store the PEI Services pointer.
+ // Privilege issues prevent using the PI mechanism in the emulator.
+ CONST EFI_PEI_SERVICES **PeiServicesTablePointer;
+
+ // Used by SecPeiServicesLib
+ EFI_PEI_PPI_DESCRIPTOR *PpiList;
+
+ // Needed by PEI PEI PeCoffLoaderExtraActionLib
+ EMU_THUNK_PROTOCOL *Thunk;
+} EMU_MAGIC_PAGE_LAYOUT;
+
+#define EMU_MAGIC_PAGE() ((EMU_MAGIC_PAGE_LAYOUT *)((UINTN)PcdGet64 (PcdPeiServicesTablePage)))
+
+#endif
#include <Library/DebugLib.h>\r
#include <Library/BaseLib.h>\r
#include <Library/PeCoffExtraActionLib.h>\r
+#include <Library/EmuMagicPageLib.h>\r
\r
//\r
// Cache of UnixThunk protocol \r
);\r
ASSERT_EFI_ERROR (Status);\r
\r
- mThunk = (EMU_THUNK_PROTOCOL *) ThunkPpi->Thunk ();\r
+ EMU_MAGIC_PAGE()->Thunk = (EMU_THUNK_PROTOCOL *) ThunkPpi->Thunk ();\r
\r
return EFI_SUCCESS;\r
}\r
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
)\r
{\r
- if (mThunk == NULL) {\r
+ if (EMU_MAGIC_PAGE()->Thunk == NULL) {\r
EmuPeCoffGetThunkStucture ();\r
}\r
- mThunk->PeCoffRelocateImageExtraAction (ImageContext);\r
+ EMU_MAGIC_PAGE()->Thunk->PeCoffRelocateImageExtraAction (ImageContext);\r
}\r
\r
\r
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
)\r
{\r
- if (mThunk == NULL) {\r
+ if (EMU_MAGIC_PAGE()->Thunk == NULL) {\r
EmuPeCoffGetThunkStucture ();\r
}\r
- mThunk->PeCoffUnloadImageExtraAction (ImageContext);\r
+ EMU_MAGIC_PAGE()->Thunk->PeCoffUnloadImageExtraAction (ImageContext);\r
}\r
[Ppis]
gEmuThunkPpiGuid # PPI ALWAYS_CONSUMED
+
+[Pcd]
+ gInOsEmuPkgTokenSpaceGuid.PcdPeiServicesTablePage
--- /dev/null
+/** @file\r
+ PEI Services Table Pointer Library.\r
+ \r
+ Store PEI Services Table pointer via gInOsEmuPkgTokenSpaceGuid.PcdPeiServicesTablePage.\r
+ This emulates a platform SRAM. The PI mechaism does not work in the emulator due to\r
+ lack of privledge.\r
+\r
+ Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+ Portiions copyrigth (c) 2011, Apple Inc. All rights reserved. \r
+ This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution. The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php.\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <PiPei.h>\r
+#include <Library/PeiServicesTablePointerLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/EmuMagicPageLib.h>\r
+\r
+\r
+/**\r
+ Caches a pointer PEI Services Table. \r
+ \r
+ Caches the pointer to the PEI Services Table specified by PeiServicesTablePointer \r
+ in a CPU specific manner as specified in the CPU binding section of the Platform Initialization \r
+ Pre-EFI Initialization Core Interface Specification. \r
+ \r
+ If PeiServicesTablePointer is NULL, then ASSERT().\r
+ \r
+ @param PeiServicesTablePointer The address of PeiServices pointer.\r
+**/\r
+VOID\r
+EFIAPI\r
+SetPeiServicesTablePointer (\r
+ IN CONST EFI_PEI_SERVICES ** PeiServicesTablePointer\r
+ )\r
+{\r
+ ASSERT (PeiServicesTablePointer != NULL);\r
+ ASSERT (*PeiServicesTablePointer != NULL);\r
+ EMU_MAGIC_PAGE()->PeiServicesTablePointer = PeiServicesTablePointer;\r
+}\r
+\r
+/**\r
+ Retrieves the cached value of the PEI Services Table pointer.\r
+\r
+ Returns the cached value of the PEI Services Table pointer in a CPU specific manner \r
+ as specified in the CPU binding section of the Platform Initialization Pre-EFI \r
+ Initialization Core Interface Specification.\r
+ \r
+ If the cached PEI Services Table pointer is NULL, then ASSERT().\r
+\r
+ @return The pointer to PeiServices.\r
+\r
+**/\r
+CONST EFI_PEI_SERVICES **\r
+EFIAPI\r
+GetPeiServicesTablePointer (\r
+ VOID\r
+ )\r
+{\r
+ CONST EFI_PEI_SERVICES **PeiServicesTablePointer;\r
+ \r
+ PeiServicesTablePointer = EMU_MAGIC_PAGE()->PeiServicesTablePointer;\r
+ ASSERT (PeiServicesTablePointer != NULL);\r
+ ASSERT (*PeiServicesTablePointer != NULL);\r
+ return PeiServicesTablePointer;\r
+}\r
+\r
+\r
+\r
--- /dev/null
+## @file\r
+# PEI Services Table Pointer Library.\r
+# \r
+# Store PEI Services Table pointer via gInOsEmuPkgTokenSpaceGuid.PcdPeiServicesTablePage.\r
+# This emulates a platform SRAM. The PI mechaism does not work in the emulator due to\r
+# lack of privledge.\r
+#\r
+# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>\r
+# Portions copyright (c) 2011, Apple Inc. All rights reserved. \r
+#\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution. The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php.\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+##\r
+\r
+[Defines]\r
+ INF_VERSION = 0x00010005\r
+ BASE_NAME = InOsEmuPkgPeiServicesTablePointerLib\r
+ FILE_GUID = 7488FC06-370A-1C41-B05C-7395559A535A\r
+ MODULE_TYPE = PEIM\r
+ VERSION_STRING = 1.0\r
+ LIBRARY_CLASS = PeiServicesTablePointerLib|PEIM PEI_CORE SEC\r
+\r
+#\r
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC (EBC is for build only)\r
+#\r
+\r
+[Sources]\r
+ PeiServicesTablePointer.c\r
+\r
+[Packages]\r
+ MdePkg/MdePkg.dec\r
+ InOsEmuPkg/InOsEmuPkg.dec\r
+\r
+[LibraryClasses]\r
+ DebugLib\r
+\r
+[Pcd]\r
+ gInOsEmuPkgTokenSpaceGuid.PcdPeiServicesTablePage\r
\r
\r
#include <PiPei.h>\r
-\r
+#include <Library/EmuMagicPageLib.h>\r
#include <Library/PeiServicesLib.h>\r
#include <Library/DebugLib.h>\r
#include <Library/BaseMemoryLib.h>\r
-#include <Library/PpiListLib.h>\r
\r
\r
\r
return EFI_NOT_FOUND;\r
}\r
\r
- \r
- for (PpiList = (EFI_PEI_PPI_DESCRIPTOR *)gPpiList; ; PpiList++) {\r
+ for (PpiList = EMU_MAGIC_PAGE()->PpiList; ; PpiList++) {\r
if (CompareGuid (PpiList->Guid, Guid)) {\r
if (PpiDescriptor != NULL) {\r
*PpiDescriptor = PpiList;\r
BaseMemoryLib\r
PpiListLib\r
\r
+[Pcd]\r
+ gInOsEmuPkgTokenSpaceGuid.PcdPeiServicesTablePage\r
+\r
+\r
\r
\r
\r
UINTN SecReseveredMemorySize;
UINTN Index;
- gPpiList = PpiList;
+ EMU_MAGIC_PAGE()->PpiList = PpiList;
ProcessLibraryConstructorList ();
DEBUG ((EFI_D_ERROR, "SEC Has Started\n"));
#include <PiPei.h>
+#include <Library/EmuMagicPageLib.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>
\r
[Ppis]\r
gEfiTemporaryRamSupportPpiGuid\r
-
\ No newline at end of file
+ \r
+[Pcd]\r
+ gInOsEmuPkgTokenSpaceGuid.PcdPeiServicesTablePage\r
UINTN mImageContextModHandleArraySize = 0;
IMAGE_CONTEXT_TO_MOD_HANDLE *mImageContextModHandleArray = NULL;
-
+EFI_PEI_PPI_DESCRIPTOR *gPpiList;
/*++
// EmuSecLibConstructor ();
-
gPpiList = GetThunkPpiList ();
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_EXEC, MAP_PRIVATE);
close (fd);
)
{
int fd;
- VOID *res, *res2;
+ void *res, *res2, *res3;
UINTN FileSize;
UINTN FvSize;
+ void *EmuMagicPage;
fd = open (FileName, O_RDWR);
if (fd < 0) {
res = mmap (
(void *)(UINTN)FixedPcdGet64 (PcdEmuFlashFvRecoveryBase),
FvSize,
- PROT_READ | PROT_WRITE | PROT_EXEC,
+ PROT_READ | PROT_EXEC,
MAP_PRIVATE,
fd,
0
);
if (res == MAP_FAILED) {
- perror ("MapFile() Failed res =");
+ perror ("MapFd0() Failed res =");
close (fd);
return EFI_DEVICE_ERROR;
+ } else if (res != (void *)(UINTN)FixedPcdGet64 (PcdEmuFlashFvRecoveryBase)) {
+ // We could not load at the build address, so we need to allow writes
+ munmap (res, FvSize);
+ res = mmap (
+ (void *)(UINTN)FixedPcdGet64 (PcdEmuFlashFvRecoveryBase),
+ FvSize,
+ PROT_READ | PROT_WRITE | PROT_EXEC,
+ MAP_PRIVATE,
+ fd,
+ 0
+ );
+ if (res == MAP_FAILED) {
+ perror ("MapFd0() Failed res =");
+ close (fd);
+ return EFI_DEVICE_ERROR;
+ }
}
// Map the rest of the FD as read/write
);
close (fd);
if (res2 == MAP_FAILED) {
- perror ("MapFile() Failed res2 =");
+ perror ("MapFd0() Failed res2 =");
return EFI_DEVICE_ERROR;
}
+ //
+ // If enabled use the magic page to communicate between modules
+ // This replaces the PI PeiServicesTable pointer mechanism that
+ // deos not work in the emulator. It also allows the removal of
+ // writable globals from SEC, PEI_CORE (libraries), PEIMs
+ //
+ EmuMagicPage = (void *)(UINTN)FixedPcdGet64 (PcdPeiServicesTablePage);
+ if (EmuMagicPage != NULL) {
+ res3 = mmap (
+ (void *)EmuMagicPage,
+ 4096,
+ PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS,
+ 0,
+ 0
+ );
+ if (res3 != EmuMagicPage) {
+ printf ("MapFd0(): Could not allocate PeiServicesTablePage @ %lx\n", (long unsigned int)EmuMagicPage);
+ return EFI_DEVICE_ERROR;
+ }
+ }
+
*Length = (UINT64) FileSize;
*BaseAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) res;
return Status;
}
+ if (ImageContext.ImageAddress != (UINTN)Pe32Data) {
//
// Relocate image to match the address where it resides
//
if (EFI_ERROR (Status)) {
return Status;
}
+ } else {
+ //
+ // Or just return image entry point
+ //
+ ImageContext.PdbPointer = PeCoffLoaderGetPdbPointer (Pe32Data);
+ Status = PeCoffLoaderGetEntryPoint (Pe32Data, EntryPoint);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+ ImageContext.EntryPoint = (UINTN)*EntryPoint;
+ }
// On Unix a dlopen is done that will change the entry point
SecPeCoffRelocateImageExtraAction (&ImageContext);
\r
#include <Library/ThunkPpiList.h>\r
#include <Library/ThunkProtocolList.h>\r
-#include <Library/PpiListLib.h>\r
#include <Library/PeiServicesLib.h>\r
#include <Library/PeCoffGetEntryPointLib.h>\r
+#include <Library/EmuMagicPageLib.h>\r
\r
#include <Ppi/EmuThunk.h>\r
#include <Ppi/StatusCode.h>\r
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize\r
gInOsEmuPkgTokenSpaceGuid.PcdEmuFlashNvStorageFtwSpareBase\r
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize\r
-\r
+ gInOsEmuPkgTokenSpaceGuid.PcdPeiServicesTablePage\r
\r
\r
[BuildOptions]\r
DebugAgentLib|MdeModulePkg/Library/DebugAgentLibNull/DebugAgentLibNull.inf\r
DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf\r
\r
-##### DevicePathTextLib|InOsEmuPkg/Library/DevicePathTextLib/DevicePathTextLib.inf\r
+#### DevicePathTextLib|InOsEmuPkg/Library/DevicePathTextLib/DevicePathTextLib.inf\r
+ PeiServicesTablePointerLib|InOsEmuPkg/Library/PeiServicesTablePointerLibMagicPage/PeiServicesTablePointerLibMagicPage.inf\r
\r
[LibraryClasses.common.SEC]\r
PeiServicesLib|InOsEmuPkg/Library/SecPeiServicesLib/SecPeiServicesLib.inf\r
\r
[LibraryClasses.common.PEI_CORE]\r
PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf\r
- PeiServicesTablePointerLib|InOsEmuPkg/Library/PeiCoreServicesTablePointerLib/PeiCoreServicesTablePointerLib.inf\r
\r
[LibraryClasses.common.PEIM]\r
PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf\r
- PeiServicesTablePointerLib|InOsEmuPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf\r
\r
[LibraryClasses.common.DXE_CORE]\r
HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf\r