4 Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php.
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 EFI_PEI_PPI_DESCRIPTOR mPeiSecMainPpi
[] = {
20 EFI_PEI_PPI_DESCRIPTOR_PPI
,
21 &gTopOfTemporaryRamPpiGuid
,
22 NULL
// To be patched later.
25 EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
,
32 // These are IDT entries pointing to 10:FFFFFFE4h.
34 UINT64 mIdtEntryTemplate
= 0xffff8e000010ffe4ULL
;
37 Caller provided function to be invoked at the end of InitializeDebugAgent().
39 Entry point to the C language phase of SEC. After the SEC assembly
40 code has initialized some temporary memory and set up the stack,
41 the control is transferred to this function.
43 @param[in] Context The first input parameter of InitializeDebugAgent().
55 Entry point to the C language phase of SEC. After the SEC assembly
56 code has initialized some temporary memory and set up the stack,
57 the control is transferred to this function.
59 @param[in] SizeOfRam Size of the temporary memory available for use.
60 @param[in] TempRamBase Base address of tempory ram
61 @param[in] BootFirmwareVolume Base address of the Boot Firmware Volume.
67 IN UINT32 TempRamBase
,
68 IN VOID
*BootFirmwareVolume
71 EFI_SEC_PEI_HAND_OFF SecCoreData
;
72 IA32_DESCRIPTOR IdtDescriptor
;
73 SEC_IDT_TABLE IdtTableInStack
;
77 PeiStackSize
= PcdGet32 (PcdPeiTemporaryRamStackSize
);
78 if (PeiStackSize
== 0) {
79 PeiStackSize
= (SizeOfRam
>> 1);
82 ASSERT (PeiStackSize
< SizeOfRam
);
85 // Process all libraries constructor function linked to SecCore.
87 ProcessLibraryConstructorList ();
89 DEBUG ((DEBUG_INFO
, "FspPei - SecStartup\n"));
92 // Initialize floating point operating environment
93 // to be compliant with UEFI spec.
95 InitializeFloatingPointUnits ();
98 // |-------------------|---->
100 // |-------------------|
101 // |PeiService Pointer | PeiStackSize
102 // |-------------------|
105 // |-------------------|---->
108 // | Heap | PeiTemporayRamSize
111 // |-------------------|----> TempRamBase
113 IdtTableInStack
.PeiService
= 0;
114 for (Index
= 0; Index
< SEC_IDT_ENTRY_COUNT
; Index
++) {
115 CopyMem ((VOID
*)&IdtTableInStack
.IdtTable
[Index
], (VOID
*)&mIdtEntryTemplate
, sizeof (UINT64
));
118 IdtDescriptor
.Base
= (UINTN
) &IdtTableInStack
.IdtTable
;
119 IdtDescriptor
.Limit
= (UINT16
)(sizeof (IdtTableInStack
.IdtTable
) - 1);
121 AsmWriteIdtr (&IdtDescriptor
);
124 // Update the base address and length of Pei temporary memory
126 SecCoreData
.DataSize
= (UINT16
) sizeof (EFI_SEC_PEI_HAND_OFF
);
127 SecCoreData
.BootFirmwareVolumeBase
= BootFirmwareVolume
;
128 SecCoreData
.BootFirmwareVolumeSize
= (UINTN
)(SIZE_4GB
- (UINTN
) BootFirmwareVolume
);
129 SecCoreData
.TemporaryRamBase
= (VOID
*)(UINTN
) TempRamBase
;
130 SecCoreData
.TemporaryRamSize
= SizeOfRam
;
131 SecCoreData
.PeiTemporaryRamBase
= SecCoreData
.TemporaryRamBase
;
132 SecCoreData
.PeiTemporaryRamSize
= SizeOfRam
- PeiStackSize
;
133 SecCoreData
.StackBase
= (VOID
*)(UINTN
)(TempRamBase
+ SecCoreData
.PeiTemporaryRamSize
);
134 SecCoreData
.StackSize
= PeiStackSize
;
136 DEBUG ((DEBUG_INFO
, "BootFirmwareVolumeBase - 0x%x\n", SecCoreData
.BootFirmwareVolumeBase
));
137 DEBUG ((DEBUG_INFO
, "BootFirmwareVolumeSize - 0x%x\n", SecCoreData
.BootFirmwareVolumeSize
));
138 DEBUG ((DEBUG_INFO
, "TemporaryRamBase - 0x%x\n", SecCoreData
.TemporaryRamBase
));
139 DEBUG ((DEBUG_INFO
, "TemporaryRamSize - 0x%x\n", SecCoreData
.TemporaryRamSize
));
140 DEBUG ((DEBUG_INFO
, "PeiTemporaryRamBase - 0x%x\n", SecCoreData
.PeiTemporaryRamBase
));
141 DEBUG ((DEBUG_INFO
, "PeiTemporaryRamSize - 0x%x\n", SecCoreData
.PeiTemporaryRamSize
));
142 DEBUG ((DEBUG_INFO
, "StackBase - 0x%x\n", SecCoreData
.StackBase
));
143 DEBUG ((DEBUG_INFO
, "StackSize - 0x%x\n", SecCoreData
.StackSize
));
146 // Initialize Debug Agent to support source level debug in SEC/PEI phases before memory ready.
148 InitializeDebugAgent (DEBUG_AGENT_INIT_PREMEM_SEC
, &SecCoreData
, SecStartupPhase2
);
153 This API patch the TopOfTemporaryRam value in SecPpiList.
155 @param[in,out] SecPpiList PPI list to be patched.
156 @param[in] TopOfTemporaryRam The top of Temporary Ram.
160 PatchTopOfTemporaryRamPpi (
161 IN OUT EFI_PEI_PPI_DESCRIPTOR
*SecPpiList
,
162 IN VOID
*TopOfTemporaryRam
165 SecPpiList
[0].Ppi
= TopOfTemporaryRam
;
169 Caller provided function to be invoked at the end of InitializeDebugAgent().
171 Entry point to the C language phase of SEC. After the SEC assembly
172 code has initialized some temporary memory and set up the stack,
173 the control is transferred to this function.
175 @param[in] Context The first input parameter of InitializeDebugAgent().
184 EFI_SEC_PEI_HAND_OFF
*SecCoreData
;
185 EFI_PEI_PPI_DESCRIPTOR
*PpiList
;
187 EFI_PEI_PPI_DESCRIPTOR LocalSecPpiList
[sizeof(mPeiSecMainPpi
)/sizeof(mPeiSecMainPpi
[0])];
188 EFI_PEI_PPI_DESCRIPTOR AllSecPpiList
[FixedPcdGet32(PcdSecCoreMaxPpiSupported
)];
189 EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint
;
191 SecCoreData
= (EFI_SEC_PEI_HAND_OFF
*) Context
;
193 // Find Pei Core entry point. It will report SEC and Pei Core debug information if remote debug
196 FindAndReportEntryPoints ((EFI_FIRMWARE_VOLUME_HEADER
*) SecCoreData
->BootFirmwareVolumeBase
, &PeiCoreEntryPoint
);
197 if (PeiCoreEntryPoint
== NULL
)
202 CopyMem (LocalSecPpiList
, mPeiSecMainPpi
, sizeof(mPeiSecMainPpi
));
203 PatchTopOfTemporaryRamPpi (LocalSecPpiList
, (VOID
*)((UINTN
)SecCoreData
->TemporaryRamBase
+ SecCoreData
->TemporaryRamSize
));
206 // Perform platform specific initialization before entering PeiCore.
208 PpiList
= SecPlatformMain (SecCoreData
);
209 if (PpiList
!= NULL
) {
211 // Remove the terminal flag from the terminal Ppi
213 CopyMem (AllSecPpiList
, LocalSecPpiList
, sizeof (LocalSecPpiList
));
214 for (Index
= 0; Index
< PcdGet32 (PcdSecCoreMaxPpiSupported
); Index
++) {
215 if ((AllSecPpiList
[Index
].Flags
& EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
) == EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
) {
219 AllSecPpiList
[Index
].Flags
= AllSecPpiList
[Index
].Flags
& (~EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
);
222 // Append the platform additional Ppi list
225 while (Index
< PcdGet32 (PcdSecCoreMaxPpiSupported
) &&
226 ((PpiList
->Flags
& EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
) != EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
)) {
227 CopyMem (&AllSecPpiList
[Index
], PpiList
, sizeof (EFI_PEI_PPI_DESCRIPTOR
));
233 // Check whether the total Ppis exceeds the max supported Ppi.
235 if (Index
>= PcdGet32 (PcdSecCoreMaxPpiSupported
)) {
237 // the total Ppi is larger than the supported Max
238 // PcdSecCoreMaxPpiSupported can be enlarged to solve it.
243 // Add the terminal Ppi
245 CopyMem (&AllSecPpiList
[Index
], PpiList
, sizeof (EFI_PEI_PPI_DESCRIPTOR
));
249 // Set PpiList to the total Ppi
251 PpiList
= &AllSecPpiList
[0];
254 // No addition Ppi, PpiList directly point to the common Ppi list.
256 PpiList
= &LocalSecPpiList
[0];
260 // Transfer the control to the PEI core
262 ASSERT (PeiCoreEntryPoint
!= NULL
);
263 (*PeiCoreEntryPoint
) (SecCoreData
, PpiList
);
266 // Should not come here.