Sec.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*++ @file
  2. Stub SEC that is called from the OS application that is the root of the emulator.
  3. The OS application will call the SEC with the PEI Entry Point API.
  4. Copyright (c) 2011, Apple Inc. All rights reserved.<BR>
  5. SPDX-License-Identifier: BSD-2-Clause-Patent
  6. **/
  7. #include "Sec.h"
  8. EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI mSecTemporaryRamSupportPpi = {
  9. SecTemporaryRamSupport
  10. };
  11. EFI_PEI_PPI_DESCRIPTOR gPrivateDispatchTable[] = {
  12. {
  13. EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
  14. &gEfiTemporaryRamSupportPpiGuid,
  15. &mSecTemporaryRamSupportPpi
  16. }
  17. };
  18. /**
  19. The entry point of PE/COFF Image for the PEI Core, that has been hijacked by this
  20. SEC that sits on top of an OS application. So the entry and exit of this module
  21. has the same API.
  22. This function is the entry point for the PEI Foundation, which allows the SEC phase
  23. to pass information about the stack, temporary RAM and the Boot Firmware Volume.
  24. In addition, it also allows the SEC phase to pass services and data forward for use
  25. during the PEI phase in the form of one or more PPIs.
  26. There is no limit to the number of additional PPIs that can be passed from SEC into
  27. the PEI Foundation. As part of its initialization phase, the PEI Foundation will add
  28. these SEC-hosted PPIs to its PPI database such that both the PEI Foundation and any
  29. modules can leverage the associated service calls and/or code in these early PPIs.
  30. This function is required to call ProcessModuleEntryPointList() with the Context
  31. parameter set to NULL. ProcessModuleEntryPoint() is never expected to return.
  32. The PEI Core is responsible for calling ProcessLibraryConstructorList() as soon as
  33. the PEI Services Table and the file handle for the PEI Core itself have been established.
  34. If ProcessModuleEntryPointList() returns, then ASSERT() and halt the system.
  35. @param SecCoreData Points to a data structure containing information about the PEI
  36. core's operating environment, such as the size and location of
  37. temporary RAM, the stack location and the BFV location.
  38. @param PpiList Points to a list of one or more PPI descriptors to be installed
  39. initially by the PEI core. An empty PPI list consists of a single
  40. descriptor with the end-tag EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST.
  41. As part of its initialization phase, the PEI Foundation will add
  42. these SEC-hosted PPIs to its PPI database such that both the PEI
  43. Foundation and any modules can leverage the associated service calls
  44. and/or code in these early PPIs.
  45. **/
  46. VOID
  47. EFIAPI
  48. _ModuleEntryPoint (
  49. IN EFI_SEC_PEI_HAND_OFF *SecCoreData,
  50. IN EFI_PEI_PPI_DESCRIPTOR *PpiList
  51. )
  52. {
  53. EFI_STATUS Status;
  54. EFI_PEI_FV_HANDLE VolumeHandle;
  55. EFI_PEI_FILE_HANDLE FileHandle;
  56. VOID *PeCoffImage;
  57. EFI_PEI_CORE_ENTRY_POINT EntryPoint;
  58. EFI_PEI_PPI_DESCRIPTOR *Ppi;
  59. EFI_PEI_PPI_DESCRIPTOR *SecPpiList;
  60. UINTN SecReseveredMemorySize;
  61. UINTN Index;
  62. EFI_PEI_PPI_DESCRIPTOR PpiArray[10];
  63. EMU_MAGIC_PAGE ()->PpiList = PpiList;
  64. ProcessLibraryConstructorList ();
  65. DEBUG ((DEBUG_ERROR, "SEC Has Started\n"));
  66. //
  67. // Add Our PPIs to the list
  68. //
  69. SecReseveredMemorySize = sizeof (gPrivateDispatchTable);
  70. for (Ppi = PpiList, Index = 1; ; Ppi++, Index++) {
  71. SecReseveredMemorySize += sizeof (EFI_PEI_PPI_DESCRIPTOR);
  72. if ((Ppi->Flags & EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) == EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) {
  73. // Since we are appending, need to clear out previous list terminator.
  74. Ppi->Flags &= ~EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;
  75. break;
  76. }
  77. }
  78. // Keep everything on a good alignment
  79. SecReseveredMemorySize = ALIGN_VALUE (SecReseveredMemorySize, CPU_STACK_ALIGNMENT);
  80. #if 0
  81. // Tell the PEI Core to not use our buffer in temp RAM
  82. SecPpiList = (EFI_PEI_PPI_DESCRIPTOR *)SecCoreData->PeiTemporaryRamBase;
  83. SecCoreData->PeiTemporaryRamBase = (VOID *)((UINTN)SecCoreData->PeiTemporaryRamBase + SecReseveredMemorySize);
  84. SecCoreData->PeiTemporaryRamSize -= SecReseveredMemorySize;
  85. #else
  86. //
  87. // When I subtrack from SecCoreData->PeiTemporaryRamBase PEI Core crashes? Either there is a bug
  88. // or I don't understand temp RAM correctly?
  89. //
  90. SecPpiList = &PpiArray[0];
  91. ASSERT (sizeof (PpiArray) >= SecReseveredMemorySize);
  92. #endif
  93. // Copy existing list, and append our entries.
  94. CopyMem (SecPpiList, PpiList, sizeof (EFI_PEI_PPI_DESCRIPTOR) * Index);
  95. CopyMem (&SecPpiList[Index], gPrivateDispatchTable, sizeof (gPrivateDispatchTable));
  96. // Find PEI Core and transfer control
  97. VolumeHandle = (EFI_PEI_FV_HANDLE)(UINTN)SecCoreData->BootFirmwareVolumeBase;
  98. FileHandle = NULL;
  99. Status = PeiServicesFfsFindNextFile (EFI_FV_FILETYPE_PEI_CORE, VolumeHandle, &FileHandle);
  100. ASSERT_EFI_ERROR (Status);
  101. Status = PeiServicesFfsFindSectionData (EFI_SECTION_PE32, FileHandle, &PeCoffImage);
  102. ASSERT_EFI_ERROR (Status);
  103. Status = PeCoffLoaderGetEntryPoint (PeCoffImage, (VOID **)&EntryPoint);
  104. ASSERT_EFI_ERROR (Status);
  105. // Transfer control to PEI Core
  106. EntryPoint (SecCoreData, SecPpiList);
  107. // PEI Core never returns
  108. ASSERT (FALSE);
  109. return;
  110. }