4 Copyright (c) 2008 - 2015, 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.
17 EFI_PEI_TEMPORARY_RAM_DONE_PPI gSecTemporaryRamDonePpi
= {
21 EFI_SEC_PLATFORM_INFORMATION_PPI mSecPlatformInformationPpi
= { SecPlatformInformation
};
23 EFI_PEI_PPI_DESCRIPTOR mPeiSecPlatformInformationPpi
[] = {
25 EFI_PEI_PPI_DESCRIPTOR_PPI
,
26 &gEfiTemporaryRamDonePpiGuid
,
27 &gSecTemporaryRamDonePpi
30 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
31 &gEfiSecPlatformInformationPpiGuid
,
32 &mSecPlatformInformationPpi
37 // These are IDT entries pointing to 10:FFFFFFE4h.
39 UINT64 mIdtEntryTemplate
= 0xffff8e000010ffe4ULL
;
42 Caller provided function to be invoked at the end of InitializeDebugAgent().
44 Entry point to the C language phase of SEC. After the SEC assembly
45 code has initialized some temporary memory and set up the stack,
46 the control is transferred to this function.
48 @param[in] Context The first input parameter of InitializeDebugAgent().
59 Entry point to the C language phase of SEC. After the SEC assembly
60 code has initialized some temporary memory and set up the stack,
61 the control is transferred to this function.
64 @param SizeOfRam Size of the temporary memory available for use.
65 @param TempRamBase Base address of temporary ram
66 @param BootFirmwareVolume Base address of the Boot Firmware Volume.
72 IN UINT32 TempRamBase
,
73 IN VOID
*BootFirmwareVolume
76 EFI_SEC_PEI_HAND_OFF SecCoreData
;
77 IA32_DESCRIPTOR IdtDescriptor
;
78 SEC_IDT_TABLE IdtTableInStack
;
84 // Report Status Code to indicate entering SEC core
88 EFI_SOFTWARE_SEC
| EFI_SW_SEC_PC_ENTRY_POINT
91 PeiStackSize
= PcdGet32 (PcdPeiTemporaryRamStackSize
);
92 if (PeiStackSize
== 0) {
93 PeiStackSize
= (SizeOfRam
>> 1);
96 ASSERT (PeiStackSize
< SizeOfRam
);
99 // Process all libraries constructor function linked to SecCore.
101 ProcessLibraryConstructorList ();
104 // Initialize floating point operating environment
105 // to be compliant with UEFI spec.
107 InitializeFloatingPointUnits ();
109 // |-------------------|---->
111 // |-------------------|
112 // |PeiService Pointer | PeiStackSize
113 // |-------------------|
116 // |-------------------|---->
119 // | Heap | PeiTemporayRamSize
122 // |-------------------|----> TempRamBase
124 IdtTableInStack
.PeiService
= 0;
125 for (Index
= 0; Index
< SEC_IDT_ENTRY_COUNT
; Index
++) {
126 CopyMem ((VOID
*)&IdtTableInStack
.IdtTable
[Index
], (VOID
*)&mIdtEntryTemplate
, sizeof (UINT64
));
129 IdtDescriptor
.Base
= (UINTN
) &IdtTableInStack
.IdtTable
;
130 IdtDescriptor
.Limit
= (UINT16
)(sizeof (IdtTableInStack
.IdtTable
) - 1);
132 AsmWriteIdtr (&IdtDescriptor
);
135 // Setup the default exception handlers
137 Status
= InitializeCpuExceptionHandlers (NULL
);
138 ASSERT_EFI_ERROR (Status
);
141 // Update the base address and length of Pei temporary memory
143 SecCoreData
.DataSize
= (UINT16
) sizeof (EFI_SEC_PEI_HAND_OFF
);
144 SecCoreData
.BootFirmwareVolumeBase
= BootFirmwareVolume
;
145 SecCoreData
.BootFirmwareVolumeSize
= (UINTN
)(0x100000000ULL
- (UINTN
) BootFirmwareVolume
);
146 SecCoreData
.TemporaryRamBase
= (VOID
*)(UINTN
) TempRamBase
;
147 SecCoreData
.TemporaryRamSize
= SizeOfRam
;
148 SecCoreData
.PeiTemporaryRamBase
= SecCoreData
.TemporaryRamBase
;
149 SecCoreData
.PeiTemporaryRamSize
= SizeOfRam
- PeiStackSize
;
150 SecCoreData
.StackBase
= (VOID
*)(UINTN
)(TempRamBase
+ SecCoreData
.PeiTemporaryRamSize
);
151 SecCoreData
.StackSize
= PeiStackSize
;
154 // Initialize Debug Agent to support source level debug in SEC/PEI phases before memory ready.
156 InitializeDebugAgent (DEBUG_AGENT_INIT_PREMEM_SEC
, &SecCoreData
, SecStartupPhase2
);
160 Caller provided function to be invoked at the end of InitializeDebugAgent().
162 Entry point to the C language phase of SEC. After the SEC assembly
163 code has initialized some temporary memory and set up the stack,
164 the control is transferred to this function.
166 @param[in] Context The first input parameter of InitializeDebugAgent().
175 EFI_SEC_PEI_HAND_OFF
*SecCoreData
;
176 EFI_PEI_PPI_DESCRIPTOR
*PpiList
;
178 EFI_PEI_PPI_DESCRIPTOR
*AllSecPpiList
;
179 EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint
;
181 SecCoreData
= (EFI_SEC_PEI_HAND_OFF
*) Context
;
182 AllSecPpiList
= (EFI_PEI_PPI_DESCRIPTOR
*) SecCoreData
->PeiTemporaryRamBase
;
184 // Find Pei Core entry point. It will report SEC and Pei Core debug information if remote debug
187 FindAndReportEntryPoints ((EFI_FIRMWARE_VOLUME_HEADER
*) SecCoreData
->BootFirmwareVolumeBase
, &PeiCoreEntryPoint
);
188 if (PeiCoreEntryPoint
== NULL
)
194 // Perform platform specific initialization before entering PeiCore.
196 PpiList
= SecPlatformMain (SecCoreData
);
197 if (PpiList
!= NULL
) {
199 // Remove the terminal flag from the terminal PPI
201 CopyMem (AllSecPpiList
, mPeiSecPlatformInformationPpi
, sizeof (mPeiSecPlatformInformationPpi
));
202 Index
= sizeof (mPeiSecPlatformInformationPpi
) / sizeof (EFI_PEI_PPI_DESCRIPTOR
) - 1;
203 AllSecPpiList
[Index
].Flags
= AllSecPpiList
[Index
].Flags
& (~EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
);
206 // Append the platform additional PPI list
209 while (((PpiList
->Flags
& EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
) != EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
)) {
210 CopyMem (&AllSecPpiList
[Index
], PpiList
, sizeof (EFI_PEI_PPI_DESCRIPTOR
));
216 // Add the terminal PPI
218 CopyMem (&AllSecPpiList
[Index
++], PpiList
, sizeof (EFI_PEI_PPI_DESCRIPTOR
));
221 // Set PpiList to the total PPI
223 PpiList
= AllSecPpiList
;
226 // Adjust PEI TEMP RAM Range.
228 ASSERT (SecCoreData
->PeiTemporaryRamSize
> Index
* sizeof (EFI_PEI_PPI_DESCRIPTOR
));
229 SecCoreData
->PeiTemporaryRamBase
= (VOID
*)((UINTN
) SecCoreData
->PeiTemporaryRamBase
+ Index
* sizeof (EFI_PEI_PPI_DESCRIPTOR
));
230 SecCoreData
->PeiTemporaryRamSize
= SecCoreData
->PeiTemporaryRamSize
- Index
* sizeof (EFI_PEI_PPI_DESCRIPTOR
);
233 // No addition PPI, PpiList directly point to the common PPI list.
235 PpiList
= &mPeiSecPlatformInformationPpi
[0];
239 // Report Status Code to indicate transferring to PEI core
243 EFI_SOFTWARE_SEC
| EFI_SW_SEC_PC_HANDOFF_TO_NEXT
247 // Transfer the control to the PEI core
249 ASSERT (PeiCoreEntryPoint
!= NULL
);
250 (*PeiCoreEntryPoint
) (SecCoreData
, PpiList
);
253 // Should not come here.
259 TemporaryRamDone() disables the use of Temporary RAM. If present, this service is invoked
260 by the PEI Foundation after the EFI_PEI_PERMANANT_MEMORY_INSTALLED_PPI is installed.
262 @retval EFI_SUCCESS Use of Temporary RAM was disabled.
263 @retval EFI_INVALID_PARAMETER Temporary RAM could not be disabled.
268 SecTemporaryRamDone (
275 // Migrate DebugAgentContext.
277 InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC
, NULL
, NULL
);
280 // Disable interrupts and save current interrupt state
282 State
= SaveAndDisableInterrupts();
285 // Disable Temporary RAM after Stack and Heap have been migrated at this point.
287 SecPlatformDisableTemporaryMemory ();
290 // Restore original interrupt state
292 SetInterruptState (State
);