diff options
author | andrewfish <andrewfish@6f19259b-4bc3-4df7-8a09-765794883524> | 2011-06-08 21:52:21 +0000 |
---|---|---|
committer | andrewfish <andrewfish@6f19259b-4bc3-4df7-8a09-765794883524> | 2011-06-08 21:52:21 +0000 |
commit | 946bfba2c321425f22fecb53349b779594543919 (patch) | |
tree | edfc9766a6eadf3fd14f0d5555d92ffd43505d46 /InOsEmuPkg/Unix | |
parent | f65dc3bebd97e5b9951fa44bb6365275f7f00791 (diff) | |
download | edk2-platforms-946bfba2c321425f22fecb53349b779594543919.tar.xz |
InOsEmuPkg: Make XIP work properly
Update the InOsEmuPkg to properly function with XIP. Make the Recovery FV read only. Remove the use of global variable writes from XIP code. Add a new global page that can be used in place of writting to the FD by XIP code. Think of this global page as a system SRAM.
igned-off-by: andrewfish
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11771 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'InOsEmuPkg/Unix')
-rw-r--r-- | InOsEmuPkg/Unix/Sec/SecMain.c | 64 | ||||
-rw-r--r-- | InOsEmuPkg/Unix/Sec/SecMain.h | 2 | ||||
-rw-r--r-- | InOsEmuPkg/Unix/Sec/SecMain.inf | 2 | ||||
-rw-r--r-- | InOsEmuPkg/Unix/UnixX64.dsc | 5 |
4 files changed, 61 insertions, 12 deletions
diff --git a/InOsEmuPkg/Unix/Sec/SecMain.c b/InOsEmuPkg/Unix/Sec/SecMain.c index 1771f36132..5dcb44523e 100644 --- a/InOsEmuPkg/Unix/Sec/SecMain.c +++ b/InOsEmuPkg/Unix/Sec/SecMain.c @@ -57,7 +57,7 @@ EMU_SYSTEM_MEMORY *gSystemMemory; UINTN mImageContextModHandleArraySize = 0; IMAGE_CONTEXT_TO_MOD_HANDLE *mImageContextModHandleArray = NULL; - +EFI_PEI_PPI_DESCRIPTOR *gPpiList; /*++ @@ -127,7 +127,6 @@ main ( // EmuSecLibConstructor (); - gPpiList = GetThunkPpiList (); @@ -371,7 +370,7 @@ MapFile ( 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); @@ -394,9 +393,10 @@ MapFd0 ( ) { int fd; - VOID *res, *res2; + void *res, *res2, *res3; UINTN FileSize; UINTN FvSize; + void *EmuMagicPage; fd = open (FileName, O_RDWR); if (fd < 0) { @@ -410,15 +410,31 @@ MapFd0 ( 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 @@ -432,10 +448,32 @@ MapFd0 ( ); 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; @@ -631,6 +669,7 @@ SecPeCoffGetEntryPoint ( return Status; } + if (ImageContext.ImageAddress != (UINTN)Pe32Data) { // // Relocate image to match the address where it resides // @@ -644,6 +683,17 @@ SecPeCoffGetEntryPoint ( 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); diff --git a/InOsEmuPkg/Unix/Sec/SecMain.h b/InOsEmuPkg/Unix/Sec/SecMain.h index af88d06837..cbe98de648 100644 --- a/InOsEmuPkg/Unix/Sec/SecMain.h +++ b/InOsEmuPkg/Unix/Sec/SecMain.h @@ -29,9 +29,9 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include <Library/ThunkPpiList.h>
#include <Library/ThunkProtocolList.h>
-#include <Library/PpiListLib.h>
#include <Library/PeiServicesLib.h>
#include <Library/PeCoffGetEntryPointLib.h>
+#include <Library/EmuMagicPageLib.h>
#include <Ppi/EmuThunk.h>
#include <Ppi/StatusCode.h>
diff --git a/InOsEmuPkg/Unix/Sec/SecMain.inf b/InOsEmuPkg/Unix/Sec/SecMain.inf index 0e494e76bb..da4714e2a6 100644 --- a/InOsEmuPkg/Unix/Sec/SecMain.inf +++ b/InOsEmuPkg/Unix/Sec/SecMain.inf @@ -101,7 +101,7 @@ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize
gInOsEmuPkgTokenSpaceGuid.PcdEmuFlashNvStorageFtwSpareBase
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
-
+ gInOsEmuPkgTokenSpaceGuid.PcdPeiServicesTablePage
[BuildOptions]
diff --git a/InOsEmuPkg/Unix/UnixX64.dsc b/InOsEmuPkg/Unix/UnixX64.dsc index 8bb1391af9..ce9b088f2a 100644 --- a/InOsEmuPkg/Unix/UnixX64.dsc +++ b/InOsEmuPkg/Unix/UnixX64.dsc @@ -109,7 +109,8 @@ DebugAgentLib|MdeModulePkg/Library/DebugAgentLibNull/DebugAgentLibNull.inf
DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
-##### DevicePathTextLib|InOsEmuPkg/Library/DevicePathTextLib/DevicePathTextLib.inf
+#### DevicePathTextLib|InOsEmuPkg/Library/DevicePathTextLib/DevicePathTextLib.inf
+ PeiServicesTablePointerLib|InOsEmuPkg/Library/PeiServicesTablePointerLibMagicPage/PeiServicesTablePointerLibMagicPage.inf
[LibraryClasses.common.SEC]
PeiServicesLib|InOsEmuPkg/Library/SecPeiServicesLib/SecPeiServicesLib.inf
@@ -145,11 +146,9 @@ [LibraryClasses.common.PEI_CORE]
PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
- PeiServicesTablePointerLib|InOsEmuPkg/Library/PeiCoreServicesTablePointerLib/PeiCoreServicesTablePointerLib.inf
[LibraryClasses.common.PEIM]
PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf
- PeiServicesTablePointerLib|InOsEmuPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf
[LibraryClasses.common.DXE_CORE]
HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf
|