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
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
,
21 &gTopOfTemporaryRamPpiGuid
,
22 NULL
// To be patched later.
27 // These are IDT entries pointing to 10:FFFFFFE4h.
29 UINT64 mIdtEntryTemplate
= 0xffff8e000010ffe4ULL
;
32 Caller provided function to be invoked at the end of InitializeDebugAgent().
34 Entry point to the C language phase of SEC. After the SEC assembly
35 code has initialized some temporary memory and set up the stack,
36 the control is transferred to this function.
38 @param[in] Context The first input parameter of InitializeDebugAgent().
50 Entry point to the C language phase of SEC. After the SEC assembly
51 code has initialized some temporary memory and set up the stack,
52 the control is transferred to this function.
54 @param[in] SizeOfRam Size of the temporary memory available for use.
55 @param[in] TempRamBase Base address of tempory ram
56 @param[in] BootFirmwareVolume Base address of the Boot Firmware Volume.
62 IN UINT32 TempRamBase
,
63 IN VOID
*BootFirmwareVolume
66 EFI_SEC_PEI_HAND_OFF SecCoreData
;
67 IA32_DESCRIPTOR IdtDescriptor
;
68 SEC_IDT_TABLE IdtTableInStack
;
72 PeiStackSize
= PcdGet32 (PcdPeiTemporaryRamStackSize
);
73 if (PeiStackSize
== 0) {
74 PeiStackSize
= (SizeOfRam
>> 1);
77 ASSERT (PeiStackSize
< SizeOfRam
);
80 // Process all libraries constructor function linked to SecCore.
82 ProcessLibraryConstructorList ();
84 DEBUG ((DEBUG_INFO
, "SecCore - SecStartup\n"));
87 // Initialize floating point operating environment
88 // to be compliant with UEFI spec.
90 InitializeFloatingPointUnits ();
93 // |-------------------|---->
95 // |-------------------|
96 // |PeiService Pointer | PeiStackSize
97 // |-------------------|
100 // |-------------------|---->
103 // | Heap | PeiTemporayRamSize
106 // |-------------------|----> TempRamBase
108 IdtTableInStack
.PeiService
= 0;
109 for (Index
= 0; Index
< SEC_IDT_ENTRY_COUNT
; Index
++) {
110 CopyMem ((VOID
*)&IdtTableInStack
.IdtTable
[Index
], (VOID
*)&mIdtEntryTemplate
, sizeof (UINT64
));
113 IdtDescriptor
.Base
= (UINTN
) &IdtTableInStack
.IdtTable
;
114 IdtDescriptor
.Limit
= (UINT16
)(sizeof (IdtTableInStack
.IdtTable
) - 1);
116 AsmWriteIdtr (&IdtDescriptor
);
119 // Update the base address and length of Pei temporary memory
121 SecCoreData
.DataSize
= (UINT16
) sizeof (EFI_SEC_PEI_HAND_OFF
);
122 SecCoreData
.BootFirmwareVolumeBase
= BootFirmwareVolume
;
123 SecCoreData
.BootFirmwareVolumeSize
= (UINTN
)(SIZE_4GB
- (UINTN
) BootFirmwareVolume
);
124 SecCoreData
.TemporaryRamBase
= (VOID
*)(UINTN
) TempRamBase
;
125 SecCoreData
.TemporaryRamSize
= SizeOfRam
;
126 SecCoreData
.PeiTemporaryRamBase
= SecCoreData
.TemporaryRamBase
;
127 SecCoreData
.PeiTemporaryRamSize
= SizeOfRam
- PeiStackSize
;
128 SecCoreData
.StackBase
= (VOID
*)(UINTN
)(TempRamBase
+ SecCoreData
.PeiTemporaryRamSize
);
129 SecCoreData
.StackSize
= PeiStackSize
;
131 DEBUG ((DEBUG_INFO
, "BootFirmwareVolumeBase - 0x%x\n", SecCoreData
.BootFirmwareVolumeBase
));
132 DEBUG ((DEBUG_INFO
, "BootFirmwareVolumeSize - 0x%x\n", SecCoreData
.BootFirmwareVolumeSize
));
133 DEBUG ((DEBUG_INFO
, "TemporaryRamBase - 0x%x\n", SecCoreData
.TemporaryRamBase
));
134 DEBUG ((DEBUG_INFO
, "TemporaryRamSize - 0x%x\n", SecCoreData
.TemporaryRamSize
));
135 DEBUG ((DEBUG_INFO
, "PeiTemporaryRamBase - 0x%x\n", SecCoreData
.PeiTemporaryRamBase
));
136 DEBUG ((DEBUG_INFO
, "PeiTemporaryRamSize - 0x%x\n", SecCoreData
.PeiTemporaryRamSize
));
137 DEBUG ((DEBUG_INFO
, "StackBase - 0x%x\n", SecCoreData
.StackBase
));
138 DEBUG ((DEBUG_INFO
, "StackSize - 0x%x\n", SecCoreData
.StackSize
));
141 // Initialize Debug Agent to support source level debug in SEC/PEI phases before memory ready.
143 InitializeDebugAgent (DEBUG_AGENT_INIT_PREMEM_SEC
, &SecCoreData
, SecStartupPhase2
);
148 This API patch the TopOfTemporaryRam value in SecPpiList.
150 @param[in,out] SecPpiList PPI list to be patched.
151 @param[in] TopOfTemporaryRam The top of CAR.
155 PatchTopOfTemporaryRamPpi (
156 IN OUT EFI_PEI_PPI_DESCRIPTOR
*SecPpiList
,
157 IN VOID
*TopOfTemporaryRam
160 SecPpiList
[0].Ppi
= TopOfTemporaryRam
;
164 Caller provided function to be invoked at the end of InitializeDebugAgent().
166 Entry point to the C language phase of SEC. After the SEC assembly
167 code has initialized some temporary memory and set up the stack,
168 the control is transferred to this function.
170 @param[in] Context The first input parameter of InitializeDebugAgent().
179 EFI_SEC_PEI_HAND_OFF
*SecCoreData
;
180 EFI_PEI_PPI_DESCRIPTOR
*PpiList
;
182 EFI_PEI_PPI_DESCRIPTOR LocalSecPpiList
[sizeof(mPeiSecMainPpi
)/sizeof(mPeiSecMainPpi
[0])];
183 EFI_PEI_PPI_DESCRIPTOR AllSecPpiList
[FixedPcdGet32(PcdSecCoreMaxPpiSupported
)];
184 EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint
;
186 SecCoreData
= (EFI_SEC_PEI_HAND_OFF
*) Context
;
188 // Find Pei Core entry point. It will report SEC and Pei Core debug information if remote debug
191 FindAndReportEntryPoints ((EFI_FIRMWARE_VOLUME_HEADER
*) SecCoreData
->BootFirmwareVolumeBase
, &PeiCoreEntryPoint
);
192 if (PeiCoreEntryPoint
== NULL
)
197 CopyMem (LocalSecPpiList
, mPeiSecMainPpi
, sizeof(mPeiSecMainPpi
));
198 PatchTopOfTemporaryRamPpi (LocalSecPpiList
, (VOID
*)((UINTN
)SecCoreData
->TemporaryRamBase
+ SecCoreData
->TemporaryRamSize
));
201 // Perform platform specific initialization before entering PeiCore.
203 PpiList
= SecPlatformMain (SecCoreData
);
204 if (PpiList
!= NULL
) {
206 // Remove the terminal flag from the terminal Ppi
208 CopyMem (AllSecPpiList
, LocalSecPpiList
, sizeof (LocalSecPpiList
));
209 for (Index
= 0; Index
< PcdGet32 (PcdSecCoreMaxPpiSupported
); Index
++) {
210 if ((AllSecPpiList
[Index
].Flags
& EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
) == EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
) {
214 AllSecPpiList
[Index
].Flags
= AllSecPpiList
[Index
].Flags
& (~EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
);
217 // Append the platform additional Ppi list
220 while (Index
< PcdGet32 (PcdSecCoreMaxPpiSupported
) &&
221 ((PpiList
->Flags
& EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
) != EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
)) {
222 CopyMem (&AllSecPpiList
[Index
], PpiList
, sizeof (EFI_PEI_PPI_DESCRIPTOR
));
228 // Check whether the total Ppis exceeds the max supported Ppi.
230 if (Index
>= PcdGet32 (PcdSecCoreMaxPpiSupported
)) {
232 // the total Ppi is larger than the supported Max
233 // PcdSecCoreMaxPpiSupported can be enlarged to solve it.
238 // Add the terminal Ppi
240 CopyMem (&AllSecPpiList
[Index
], PpiList
, sizeof (EFI_PEI_PPI_DESCRIPTOR
));
244 // Set PpiList to the total Ppi
246 PpiList
= &AllSecPpiList
[0];
249 // No addition Ppi, PpiList directly point to the common Ppi list.
251 PpiList
= &LocalSecPpiList
[0];
255 // Transfer the control to the PEI core
257 ASSERT (PeiCoreEntryPoint
!= NULL
);
258 (*PeiCoreEntryPoint
) (SecCoreData
, PpiList
);
261 // Should not come here.