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