]> git.proxmox.com Git - mirror_edk2.git/blame - EmulatorPkg/Sec/Sec.c
EmulatorPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / EmulatorPkg / Sec / Sec.c
CommitLineData
79e4f2a5
RN
1/*++ @file\r
2 Stub SEC that is called from the OS appliation that is the root of the emulator.\r
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
78\r
79 EMU_MAGIC_PAGE()->PpiList = PpiList;\r
80 ProcessLibraryConstructorList ();\r
81\r
82 DEBUG ((EFI_D_ERROR, "SEC Has Started\n"));\r
83\r
84 //\r
85 // Add Our PPIs to the list\r
86 //\r
87 SecReseveredMemorySize = sizeof (gPrivateDispatchTable);\r
88 for (Ppi = PpiList, Index = 1; ; Ppi++, Index++) {\r
89 SecReseveredMemorySize += sizeof (EFI_PEI_PPI_DESCRIPTOR);\r
90\r
91 if ((Ppi->Flags & EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) == EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) {\r
92 // Since we are appending, need to clear out privious list terminator.\r
93 Ppi->Flags &= ~EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;\r
94 break;\r
95 }\r
96 }\r
97\r
98 // Keep everything on a good alignment\r
99 SecReseveredMemorySize = ALIGN_VALUE (SecReseveredMemorySize, CPU_STACK_ALIGNMENT);\r
100\r
101#if 0\r
102 // Tell the PEI Core to not use our buffer in temp RAM\r
103 SecPpiList = (EFI_PEI_PPI_DESCRIPTOR *)SecCoreData->PeiTemporaryRamBase;\r
104 SecCoreData->PeiTemporaryRamBase = (VOID *)((UINTN)SecCoreData->PeiTemporaryRamBase + SecReseveredMemorySize);\r
105 SecCoreData->PeiTemporaryRamSize -= SecReseveredMemorySize;\r
106#else\r
107 {\r
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 EFI_PEI_PPI_DESCRIPTOR PpiArray[10];\r
113\r
114 SecPpiList = &PpiArray[0];\r
115 ASSERT (sizeof (PpiArray) >= SecReseveredMemorySize);\r
116 }\r
117#endif\r
118 // Copy existing list, and append our entries.\r
119 CopyMem (SecPpiList, PpiList, sizeof (EFI_PEI_PPI_DESCRIPTOR) * Index);\r
120 CopyMem (&SecPpiList[Index], gPrivateDispatchTable, sizeof (gPrivateDispatchTable));\r
121\r
122 // Find PEI Core and transfer control\r
123 VolumeHandle = (EFI_PEI_FV_HANDLE)(UINTN)SecCoreData->BootFirmwareVolumeBase;\r
124 FileHandle = NULL;\r
125 Status = PeiServicesFfsFindNextFile (EFI_FV_FILETYPE_PEI_CORE, VolumeHandle, &FileHandle);\r
126 ASSERT_EFI_ERROR (Status);\r
127\r
128 Status = PeiServicesFfsFindSectionData (EFI_SECTION_PE32, FileHandle, &PeCoffImage);\r
129 ASSERT_EFI_ERROR (Status);\r
130\r
131 Status = PeCoffLoaderGetEntryPoint (PeCoffImage, (VOID **)&EntryPoint);\r
132 ASSERT_EFI_ERROR (Status);\r
133\r
134 // Transfer control to PEI Core\r
135 EntryPoint (SecCoreData, SecPpiList);\r
136\r
137 // PEI Core never returns\r
138 ASSERT (FALSE);\r
139 return;\r
140}\r
141\r
142\r
143\r