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