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