4 Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
12 EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI gSecTemporaryRamSupportPpi
= {
13 SecTemporaryRamSupport
16 EFI_PEI_PPI_DESCRIPTOR mPeiSecPlatformInformationPpi
[] = {
18 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
19 &gEfiTemporaryRamSupportPpiGuid
,
20 &gSecTemporaryRamSupportPpi
25 // These are IDT entries pointing to 10:FFFFFFE4h.
27 UINT64 mIdtEntryTemplate
= 0xffff8e000010ffe4ULL
;
30 Caller provided function to be invoked at the end of InitializeDebugAgent().
32 Entry point to the C language phase of SEC. After the SEC assembly
33 code has initialized some temporary memory and set up the stack,
34 the control is transferred to this function.
36 @param[in] Context The first input parameter of InitializeDebugAgent().
48 Entry point to the C language phase of SEC. After the SEC assembly
49 code has initialized some temporary memory and set up the stack,
50 the control is transferred to this function.
53 @param SizeOfRam Size of the temporary memory available for use.
54 @param TempRamBase Base address of temporary ram
55 @param BootFirmwareVolume Base address of the Boot Firmware Volume.
61 IN UINT32 TempRamBase
,
62 IN VOID
*BootFirmwareVolume
65 EFI_SEC_PEI_HAND_OFF SecCoreData
;
66 IA32_DESCRIPTOR IdtDescriptor
;
67 SEC_IDT_TABLE IdtTableInStack
;
71 PeiStackSize
= (SizeOfRam
>> 1);
73 ASSERT (PeiStackSize
< SizeOfRam
);
76 // Process all libraries constructor function linked to SecCore.
78 ProcessLibraryConstructorList ();
81 // Initialize floating point operating environment
82 // to be compliant with UEFI spec.
84 InitializeFloatingPointUnits ();
87 // |-------------------|---->
89 // |-------------------|
90 // |PeiService Pointer | PeiStackSize
91 // |-------------------|
94 // |-------------------|---->
97 // | Heap | PeiTemporaryRamSize
100 // |-------------------|----> TempRamBase
102 IdtTableInStack
.PeiService
= 0;
103 for (Index
= 0; Index
< SEC_IDT_ENTRY_COUNT
; Index
++) {
104 CopyMem ((VOID
*)&IdtTableInStack
.IdtTable
[Index
], (VOID
*)&mIdtEntryTemplate
, sizeof (UINT64
));
107 IdtDescriptor
.Base
= (UINTN
) &IdtTableInStack
.IdtTable
;
108 IdtDescriptor
.Limit
= (UINT16
)(sizeof (IdtTableInStack
.IdtTable
) - 1);
110 AsmWriteIdtr (&IdtDescriptor
);
113 // Update the base address and length of Pei temporary memory
115 SecCoreData
.DataSize
= (UINT16
) sizeof (EFI_SEC_PEI_HAND_OFF
);
116 SecCoreData
.BootFirmwareVolumeBase
= BootFirmwareVolume
;
117 SecCoreData
.BootFirmwareVolumeSize
= (UINTN
)(0x100000000ULL
- (UINTN
) BootFirmwareVolume
);
118 SecCoreData
.TemporaryRamBase
= (VOID
*)(UINTN
) TempRamBase
;
119 SecCoreData
.TemporaryRamSize
= SizeOfRam
;
120 SecCoreData
.PeiTemporaryRamBase
= SecCoreData
.TemporaryRamBase
;
121 SecCoreData
.PeiTemporaryRamSize
= SizeOfRam
- PeiStackSize
;
122 SecCoreData
.StackBase
= (VOID
*)(UINTN
)(TempRamBase
+ SecCoreData
.PeiTemporaryRamSize
);
123 SecCoreData
.StackSize
= PeiStackSize
;
126 // Initialize Debug Agent to support source level debug in SEC/PEI phases before memory ready.
128 InitializeDebugAgent (DEBUG_AGENT_INIT_PREMEM_SEC
, &SecCoreData
, SecStartupPhase2
);
133 Caller provided function to be invoked at the end of InitializeDebugAgent().
135 Entry point to the C language phase of SEC. After the SEC assembly
136 code has initialized some temporary memory and set up the stack,
137 the control is transferred to this function.
139 @param[in] Context The first input parameter of InitializeDebugAgent().
148 EFI_SEC_PEI_HAND_OFF
*SecCoreData
;
149 EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint
;
151 SecCoreData
= (EFI_SEC_PEI_HAND_OFF
*) Context
;
153 // Find Pei Core entry point. It will report SEC and Pei Core debug information if remote debug
156 FindAndReportEntryPoints ((EFI_FIRMWARE_VOLUME_HEADER
*) SecCoreData
->BootFirmwareVolumeBase
, &PeiCoreEntryPoint
);
157 if (PeiCoreEntryPoint
== NULL
)
163 // Transfer the control to the PEI core
165 ASSERT (PeiCoreEntryPoint
!= NULL
);
166 (*PeiCoreEntryPoint
) (SecCoreData
, (EFI_PEI_PPI_DESCRIPTOR
*)&mPeiSecPlatformInformationPpi
);
169 // Should not come here.
175 This service of the TEMPORARY_RAM_SUPPORT_PPI that migrates temporary RAM into
178 @param PeiServices Pointer to the PEI Services Table.
179 @param TemporaryMemoryBase Source Address in temporary memory from which the SEC or PEIM will copy the
180 Temporary RAM contents.
181 @param PermanentMemoryBase Destination Address in permanent memory into which the SEC or PEIM will copy the
182 Temporary RAM contents.
183 @param CopySize Amount of memory to migrate from temporary to permanent memory.
185 @retval EFI_SUCCESS The data was successfully returned.
186 @retval EFI_INVALID_PARAMETER PermanentMemoryBase + CopySize > TemporaryMemoryBase when
187 TemporaryMemoryBase > PermanentMemoryBase.
192 SecTemporaryRamSupport (
193 IN CONST EFI_PEI_SERVICES
**PeiServices
,
194 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase
,
195 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase
,
199 IA32_DESCRIPTOR IdtDescriptor
;
204 DEBUG_AGENT_CONTEXT_POSTMEM_SEC DebugAgentContext
;
208 PeiStackSize
= (CopySize
>> 1);
210 ASSERT (PeiStackSize
< CopySize
);
213 // |-------------------|---->
214 // | Stack | PeiStackSize
215 // |-------------------|---->
216 // | Heap | PeiTemporaryRamSize
217 // |-------------------|----> TempRamBase
219 // |-------------------|---->
220 // | Heap | PeiTemporaryRamSize
221 // |-------------------|---->
222 // | Stack | PeiStackSize
223 // |-------------------|----> PermanentMemoryBase
226 OldHeap
= (VOID
*)(UINTN
)TemporaryMemoryBase
;
227 NewHeap
= (VOID
*)((UINTN
)PermanentMemoryBase
+ PeiStackSize
);
229 OldStack
= (VOID
*)((UINTN
)TemporaryMemoryBase
+ CopySize
- PeiStackSize
);
230 NewStack
= (VOID
*)(UINTN
)PermanentMemoryBase
;
232 DebugAgentContext
.HeapMigrateOffset
= (UINTN
)NewHeap
- (UINTN
)OldHeap
;
233 DebugAgentContext
.StackMigrateOffset
= (UINTN
)NewStack
- (UINTN
)OldStack
;
235 OldStatus
= SaveAndSetDebugTimerInterrupt (FALSE
);
237 // Initialize Debug Agent to support source level debug in PEI phase after memory ready.
238 // It will build HOB and fix up the pointer in IDT table.
240 InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC
, (VOID
*) &DebugAgentContext
, NULL
);
245 CopyMem (NewHeap
, OldHeap
, CopySize
- PeiStackSize
);
250 CopyMem (NewStack
, OldStack
, PeiStackSize
);
254 // We need *not* fix the return address because currently,
255 // The PeiCore is executed in flash.
259 // Rebase IDT table in permanent memory
261 AsmReadIdtr (&IdtDescriptor
);
262 IdtDescriptor
.Base
= IdtDescriptor
.Base
- (UINTN
)OldStack
+ (UINTN
)NewStack
;
264 AsmWriteIdtr (&IdtDescriptor
);
272 // SecSwitchStack function must be invoked after the memory migration
273 // immediately, also we need fixup the stack change caused by new call into
277 (UINT32
) (UINTN
) OldStack
,
278 (UINT32
) (UINTN
) NewStack
281 SaveAndSetDebugTimerInterrupt (OldStatus
);