TianoCore EDK2 master
Loading...
Searching...
No Matches
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
6Copyright (c) 2011, Apple Inc. All rights reserved.<BR>
7SPDX-License-Identifier: BSD-2-Clause-Patent
8
9**/
10
11#include "Sec.h"
12
13EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI mSecTemporaryRamSupportPpi = {
15};
16
17EFI_PEI_PPI_DESCRIPTOR gPrivateDispatchTable[] = {
18 {
19 EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
20 &gEfiTemporaryRamSupportPpiGuid,
21 &mSecTemporaryRamSupportPpi
22 }
23};
24
57VOID
58EFIAPI
59_ModuleEntryPoint (
60 IN EFI_SEC_PEI_HAND_OFF *SecCoreData,
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;
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}
UINT64 UINTN
#define CPU_STACK_ALIGNMENT
STATIC EFI_STATUS EFIAPI SecTemporaryRamSupport(IN CONST EFI_PEI_SERVICES **PeiServices, IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase, IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase, IN UINTN CopySize)
Definition: Sec.c:35
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
EFI_STATUS EFIAPI PeiServicesFfsFindSectionData(IN EFI_SECTION_TYPE SectionType, IN EFI_PEI_FILE_HANDLE FileHandle, OUT VOID **SectionData)
EFI_STATUS EFIAPI PeiServicesFfsFindNextFile(IN EFI_FV_FILETYPE SearchType, IN EFI_PEI_FV_HANDLE VolumeHandle, IN OUT EFI_PEI_FILE_HANDLE *FileHandle)
#define NULL
Definition: Base.h:319
#define ALIGN_VALUE(Value, Alignment)
Definition: Base.h:948
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define EFI_SECTION_PE32
VOID * EFI_PEI_FILE_HANDLE
Definition: PiPeiCis.h:26
VOID * EFI_PEI_FV_HANDLE
Definition: PiPeiCis.h:21
VOID(EFIAPI * EFI_PEI_CORE_ENTRY_POINT)(IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData, IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList)
Definition: PiPeiCis.h:1051
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29