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