4 Copyright (c) 2013, 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_TEMPORARY_RAM_SUPPORT_PPI gSecTemporaryRamSupportPpi
= {
19 SecTemporaryRamSupport
22 EFI_PEI_PPI_DESCRIPTOR mPeiSecPlatformInformationPpi
[] = {
24 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
25 &gEfiTemporaryRamSupportPpiGuid
,
26 &gSecTemporaryRamSupportPpi
31 // These are IDT entries pointing to 10:FFFFFFE4h.
33 UINT64 mIdtEntryTemplate
= 0xffff8e000010ffe4ULL
;
36 Caller provided function to be invoked at the end of InitializeDebugAgent().
38 Entry point to the C language phase of SEC. After the SEC assembly
39 code has initialized some temporary memory and set up the stack,
40 the control is transferred to this function.
42 @param[in] Context The first input parameter of InitializeDebugAgent().
54 Entry point to the C language phase of SEC. After the SEC assembly
55 code has initialized some temporary memory and set up the stack,
56 the control is transferred to this function.
59 @param SizeOfRam Size of the temporary memory available for use.
60 @param TempRamBase Base address of tempory ram
61 @param 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
= (SizeOfRam
>> 1);
79 ASSERT (PeiStackSize
< SizeOfRam
);
82 // Process all libraries constructor function linked to SecCore.
84 ProcessLibraryConstructorList ();
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
)(0x100000000ULL
- (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
;
132 // Initialize Debug Agent to support source level debug in SEC/PEI phases before memory ready.
134 InitializeDebugAgent (DEBUG_AGENT_INIT_PREMEM_SEC
, &SecCoreData
, SecStartupPhase2
);
139 Caller provided function to be invoked at the end of InitializeDebugAgent().
141 Entry point to the C language phase of SEC. After the SEC assembly
142 code has initialized some temporary memory and set up the stack,
143 the control is transferred to this function.
145 @param[in] Context The first input parameter of InitializeDebugAgent().
154 EFI_SEC_PEI_HAND_OFF
*SecCoreData
;
155 EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint
;
157 SecCoreData
= (EFI_SEC_PEI_HAND_OFF
*) Context
;
159 // Find Pei Core entry point. It will report SEC and Pei Core debug information if remote debug
162 FindAndReportEntryPoints ((EFI_FIRMWARE_VOLUME_HEADER
*) SecCoreData
->BootFirmwareVolumeBase
, &PeiCoreEntryPoint
);
163 if (PeiCoreEntryPoint
== NULL
)
169 // Transfer the control to the PEI core
171 ASSERT (PeiCoreEntryPoint
!= NULL
);
172 (*PeiCoreEntryPoint
) (SecCoreData
, (EFI_PEI_PPI_DESCRIPTOR
*)&mPeiSecPlatformInformationPpi
);
175 // Should not come here.
181 This service of the TEMPORARY_RAM_SUPPORT_PPI that migrates temporary RAM into
184 @param PeiServices Pointer to the PEI Services Table.
185 @param TemporaryMemoryBase Source Address in temporary memory from which the SEC or PEIM will copy the
186 Temporary RAM contents.
187 @param PermanentMemoryBase Destination Address in permanent memory into which the SEC or PEIM will copy the
188 Temporary RAM contents.
189 @param CopySize Amount of memory to migrate from temporary to permanent memory.
191 @retval EFI_SUCCESS The data was successfully returned.
192 @retval EFI_INVALID_PARAMETER PermanentMemoryBase + CopySize > TemporaryMemoryBase when
193 TemporaryMemoryBase > PermanentMemoryBase.
198 SecTemporaryRamSupport (
199 IN CONST EFI_PEI_SERVICES
**PeiServices
,
200 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase
,
201 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase
,
205 IA32_DESCRIPTOR IdtDescriptor
;
210 DEBUG_AGENT_CONTEXT_POSTMEM_SEC DebugAgentContext
;
214 PeiStackSize
= (CopySize
>> 1);
216 ASSERT (PeiStackSize
< CopySize
);
219 // |-------------------|---->
220 // | Stack | PeiStackSize
221 // |-------------------|---->
222 // | Heap | PeiTemporayRamSize
223 // |-------------------|----> TempRamBase
225 // |-------------------|---->
226 // | Heap | PeiTemporayRamSize
227 // |-------------------|---->
228 // | Stack | PeiStackSize
229 // |-------------------|----> PermanentMemoryBase
232 OldHeap
= (VOID
*)(UINTN
)TemporaryMemoryBase
;
233 NewHeap
= (VOID
*)((UINTN
)PermanentMemoryBase
+ PeiStackSize
);
235 OldStack
= (VOID
*)((UINTN
)TemporaryMemoryBase
+ CopySize
- PeiStackSize
);
236 NewStack
= (VOID
*)(UINTN
)PermanentMemoryBase
;
238 DebugAgentContext
.HeapMigrateOffset
= (UINTN
)NewHeap
- (UINTN
)OldHeap
;
239 DebugAgentContext
.StackMigrateOffset
= (UINTN
)NewStack
- (UINTN
)OldStack
;
241 OldStatus
= SaveAndSetDebugTimerInterrupt (FALSE
);
243 // Initialize Debug Agent to support source level debug in PEI phase after memory ready.
244 // It will build HOB and fix up the pointer in IDT table.
246 InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC
, (VOID
*) &DebugAgentContext
, NULL
);
251 CopyMem (NewHeap
, OldHeap
, CopySize
- PeiStackSize
);
256 CopyMem (NewStack
, OldStack
, PeiStackSize
);
260 // We need *not* fix the return address because currently,
261 // The PeiCore is executed in flash.
265 // Rebase IDT table in permanent memory
267 AsmReadIdtr (&IdtDescriptor
);
268 IdtDescriptor
.Base
= IdtDescriptor
.Base
- (UINTN
)OldStack
+ (UINTN
)NewStack
;
270 AsmWriteIdtr (&IdtDescriptor
);
278 // SecSwitchStack function must be invoked after the memory migration
279 // immediatly, also we need fixup the stack change caused by new call into
283 (UINT32
) (UINTN
) OldStack
,
284 (UINT32
) (UINTN
) NewStack
287 SaveAndSetDebugTimerInterrupt (OldStatus
);