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().
60 Entry point to the C language phase of SEC. After the SEC assembly
61 code has initialized some temporary memory and set up the stack,
62 the control is transferred to this function.
65 @param SizeOfRam Size of the temporary memory available for use.
66 @param TempRamBase Base address of temporary ram
67 @param BootFirmwareVolume Base address of the Boot Firmware Volume.
73 IN UINT32 TempRamBase
,
74 IN VOID
*BootFirmwareVolume
77 EFI_SEC_PEI_HAND_OFF SecCoreData
;
78 IA32_DESCRIPTOR IdtDescriptor
;
79 SEC_IDT_TABLE IdtTableInStack
;
85 // Report Status Code to indicate entering SEC core
89 EFI_SOFTWARE_SEC
| EFI_SW_SEC_PC_ENTRY_POINT
92 PeiStackSize
= PcdGet32 (PcdPeiTemporaryRamStackSize
);
93 if (PeiStackSize
== 0) {
94 PeiStackSize
= (SizeOfRam
>> 1);
97 ASSERT (PeiStackSize
< SizeOfRam
);
100 // Process all libraries constructor function linked to SecCore.
102 ProcessLibraryConstructorList ();
105 // Initialize floating point operating environment
106 // to be compliant with UEFI spec.
108 InitializeFloatingPointUnits ();
110 // |-------------------|---->
112 // |-------------------|
113 // |PeiService Pointer | PeiStackSize
114 // |-------------------|
117 // |-------------------|---->
120 // | Heap | PeiTemporayRamSize
123 // |-------------------|----> TempRamBase
125 IdtTableInStack
.PeiService
= 0;
126 for (Index
= 0; Index
< SEC_IDT_ENTRY_COUNT
; Index
++) {
127 CopyMem ((VOID
*)&IdtTableInStack
.IdtTable
[Index
], (VOID
*)&mIdtEntryTemplate
, sizeof (UINT64
));
130 IdtDescriptor
.Base
= (UINTN
) &IdtTableInStack
.IdtTable
;
131 IdtDescriptor
.Limit
= (UINT16
)(sizeof (IdtTableInStack
.IdtTable
) - 1);
133 AsmWriteIdtr (&IdtDescriptor
);
136 // Setup the default exception handlers
138 Status
= InitializeCpuExceptionHandlers (NULL
);
139 ASSERT_EFI_ERROR (Status
);
142 // Update the base address and length of Pei temporary memory
144 SecCoreData
.DataSize
= (UINT16
) sizeof (EFI_SEC_PEI_HAND_OFF
);
145 SecCoreData
.BootFirmwareVolumeBase
= BootFirmwareVolume
;
146 SecCoreData
.BootFirmwareVolumeSize
= (UINTN
)(0x100000000ULL
- (UINTN
) BootFirmwareVolume
);
147 SecCoreData
.TemporaryRamBase
= (VOID
*)(UINTN
) TempRamBase
;
148 SecCoreData
.TemporaryRamSize
= SizeOfRam
;
149 SecCoreData
.PeiTemporaryRamBase
= SecCoreData
.TemporaryRamBase
;
150 SecCoreData
.PeiTemporaryRamSize
= SizeOfRam
- PeiStackSize
;
151 SecCoreData
.StackBase
= (VOID
*)(UINTN
)(TempRamBase
+ SecCoreData
.PeiTemporaryRamSize
);
152 SecCoreData
.StackSize
= PeiStackSize
;
155 // Initialize Debug Agent to support source level debug in SEC/PEI phases before memory ready.
157 InitializeDebugAgent (DEBUG_AGENT_INIT_PREMEM_SEC
, &SecCoreData
, SecStartupPhase2
);
161 Caller provided function to be invoked at the end of InitializeDebugAgent().
163 Entry point to the C language phase of SEC. After the SEC assembly
164 code has initialized some temporary memory and set up the stack,
165 the control is transferred to this function.
167 @param[in] Context The first input parameter of InitializeDebugAgent().
177 EFI_SEC_PEI_HAND_OFF
*SecCoreData
;
178 EFI_PEI_PPI_DESCRIPTOR
*PpiList
;
180 EFI_PEI_PPI_DESCRIPTOR
*AllSecPpiList
;
181 EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint
;
183 SecCoreData
= (EFI_SEC_PEI_HAND_OFF
*) Context
;
184 AllSecPpiList
= (EFI_PEI_PPI_DESCRIPTOR
*) SecCoreData
->PeiTemporaryRamBase
;
186 // Find Pei Core entry point. It will report SEC and Pei Core debug information if remote debug
189 FindAndReportEntryPoints ((EFI_FIRMWARE_VOLUME_HEADER
*) SecCoreData
->BootFirmwareVolumeBase
, &PeiCoreEntryPoint
);
190 if (PeiCoreEntryPoint
== NULL
)
196 // Perform platform specific initialization before entering PeiCore.
198 PpiList
= SecPlatformMain (SecCoreData
);
199 if (PpiList
!= NULL
) {
201 // Remove the terminal flag from the terminal PPI
203 CopyMem (AllSecPpiList
, mPeiSecPlatformInformationPpi
, sizeof (mPeiSecPlatformInformationPpi
));
204 Index
= sizeof (mPeiSecPlatformInformationPpi
) / sizeof (EFI_PEI_PPI_DESCRIPTOR
) - 1;
205 AllSecPpiList
[Index
].Flags
= AllSecPpiList
[Index
].Flags
& (~EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
);
208 // Append the platform additional PPI list
211 while (((PpiList
->Flags
& EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
) != EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
)) {
212 CopyMem (&AllSecPpiList
[Index
], PpiList
, sizeof (EFI_PEI_PPI_DESCRIPTOR
));
218 // Add the terminal PPI
220 CopyMem (&AllSecPpiList
[Index
++], PpiList
, sizeof (EFI_PEI_PPI_DESCRIPTOR
));
223 // Set PpiList to the total PPI
225 PpiList
= AllSecPpiList
;
228 // Adjust PEI TEMP RAM Range.
230 ASSERT (SecCoreData
->PeiTemporaryRamSize
> Index
* sizeof (EFI_PEI_PPI_DESCRIPTOR
));
231 SecCoreData
->PeiTemporaryRamBase
= (VOID
*)((UINTN
) SecCoreData
->PeiTemporaryRamBase
+ Index
* sizeof (EFI_PEI_PPI_DESCRIPTOR
));
232 SecCoreData
->PeiTemporaryRamSize
= SecCoreData
->PeiTemporaryRamSize
- Index
* sizeof (EFI_PEI_PPI_DESCRIPTOR
);
235 // No addition PPI, PpiList directly point to the common PPI list.
237 PpiList
= &mPeiSecPlatformInformationPpi
[0];
241 // Report Status Code to indicate transferring to PEI core
245 EFI_SOFTWARE_SEC
| EFI_SW_SEC_PC_HANDOFF_TO_NEXT
249 // Transfer the control to the PEI core
251 ASSERT (PeiCoreEntryPoint
!= NULL
);
252 (*PeiCoreEntryPoint
) (SecCoreData
, PpiList
);
255 // Should not come here.
261 TemporaryRamDone() disables the use of Temporary RAM. If present, this service is invoked
262 by the PEI Foundation after the EFI_PEI_PERMANANT_MEMORY_INSTALLED_PPI is installed.
264 @retval EFI_SUCCESS Use of Temporary RAM was disabled.
265 @retval EFI_INVALID_PARAMETER Temporary RAM could not be disabled.
270 SecTemporaryRamDone (
277 // Republish Sec Platform Information(2) PPI
279 RepublishSecPlatformInformationPpi ();
282 // Migrate DebugAgentContext.
284 InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC
, NULL
, NULL
);
287 // Disable interrupts and save current interrupt state
289 State
= SaveAndDisableInterrupts();
292 // Disable Temporary RAM after Stack and Heap have been migrated at this point.
294 SecPlatformDisableTemporaryMemory ();
297 // Restore original interrupt state
299 SetInterruptState (State
);