3 Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR>
4 SPDX-License-Identifier: BSD-2-Clause-Patent
11 EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI gSecTemporaryRamSupportPpi
= {
12 SecTemporaryRamSupport
15 EFI_PEI_PPI_DESCRIPTOR mPeiSecPlatformInformationPpi
[] = {
17 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
18 &gEfiTemporaryRamSupportPpiGuid
,
19 &gSecTemporaryRamSupportPpi
24 // These are IDT entries pointing to 08:FFFFFFE4h.
26 UINT64 mIdtEntryTemplate
= 0xffff8e000008ffe4ULL
;
30 Entry point to the C language phase of SEC. After the SEC assembly
31 code has initialized some temporary memory and set up the stack,
32 the control is transferred to this function.
35 @param[in] SizeOfRam Size of the temporary memory available for use.
36 @param[in] TempRamBase Base address of temporary ram
37 @param[in] BootFirmwareVolume Base address of the Boot Firmware Volume.
38 @param[in] PeiCore PeiCore entry point.
39 @param[in] BootLoaderStack BootLoader stack.
40 @param[in] ApiIdx the index of API.
42 @return This function never returns.
49 IN UINT32 TempRamBase
,
50 IN VOID
*BootFirmwareVolume
,
51 IN PEI_CORE_ENTRY PeiCore
,
52 IN UINT32 BootLoaderStack
,
56 EFI_SEC_PEI_HAND_OFF SecCoreData
;
57 IA32_DESCRIPTOR IdtDescriptor
;
58 SEC_IDT_TABLE IdtTableInStack
;
60 FSP_GLOBAL_DATA PeiFspData
;
61 UINT64 ExceptionHandler
;
64 // Process all libraries constructor function linked to SecCore.
66 ProcessLibraryConstructorList ();
69 // Initialize floating point operating environment
70 // to be compliant with UEFI spec.
72 InitializeFloatingPointUnits ();
75 // |-------------------|---->
77 // |-------------------|
78 // |PeiService Pointer | PeiStackSize
79 // |-------------------|
82 // |-------------------|---->
85 // | Heap | PeiTemporayRamSize
88 // |-------------------|----> TempRamBase
89 IdtTableInStack
.PeiService
= NULL
;
90 ExceptionHandler
= FspGetExceptionHandler(mIdtEntryTemplate
);
91 for (Index
= 0; Index
< SEC_IDT_ENTRY_COUNT
; Index
++) {
92 CopyMem ((VOID
*)&IdtTableInStack
.IdtTable
[Index
], (VOID
*)&ExceptionHandler
, sizeof (UINT64
));
95 IdtDescriptor
.Base
= (UINTN
) &IdtTableInStack
.IdtTable
;
96 IdtDescriptor
.Limit
= (UINT16
)(sizeof (IdtTableInStack
.IdtTable
) - 1);
98 AsmWriteIdtr (&IdtDescriptor
);
101 // Initialize the global FSP data region
103 FspGlobalDataInit (&PeiFspData
, BootLoaderStack
, (UINT8
)ApiIdx
);
106 // Update the base address and length of Pei temporary memory
108 SecCoreData
.DataSize
= sizeof (EFI_SEC_PEI_HAND_OFF
);
109 SecCoreData
.BootFirmwareVolumeBase
= BootFirmwareVolume
;
110 SecCoreData
.BootFirmwareVolumeSize
= (UINT32
)((EFI_FIRMWARE_VOLUME_HEADER
*)BootFirmwareVolume
)->FvLength
;
111 SecCoreData
.TemporaryRamBase
= (VOID
*)(UINTN
) TempRamBase
;
112 SecCoreData
.TemporaryRamSize
= SizeOfRam
;
113 SecCoreData
.PeiTemporaryRamBase
= SecCoreData
.TemporaryRamBase
;
114 SecCoreData
.PeiTemporaryRamSize
= SizeOfRam
>> 1;
115 SecCoreData
.StackBase
= (VOID
*)(UINTN
)(TempRamBase
+ SecCoreData
.PeiTemporaryRamSize
);
116 SecCoreData
.StackSize
= SizeOfRam
>> 1;
119 // Call PeiCore Entry
121 PeiCore (&SecCoreData
, mPeiSecPlatformInformationPpi
);
124 // Should never be here
130 This service of the TEMPORARY_RAM_SUPPORT_PPI that migrates temporary RAM into
133 @param[in] PeiServices Pointer to the PEI Services Table.
134 @param[in] TemporaryMemoryBase Source Address in temporary memory from which the SEC or PEIM will copy the
135 Temporary RAM contents.
136 @param[in] PermanentMemoryBase Destination Address in permanent memory into which the SEC or PEIM will copy the
137 Temporary RAM contents.
138 @param[in] CopySize Amount of memory to migrate from temporary to permanent memory.
140 @retval EFI_SUCCESS The data was successfully returned.
141 @retval EFI_INVALID_PARAMETER PermanentMemoryBase + CopySize > TemporaryMemoryBase when
142 TemporaryMemoryBase > PermanentMemoryBase.
147 SecTemporaryRamSupport (
148 IN CONST EFI_PEI_SERVICES
**PeiServices
,
149 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase
,
150 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase
,
154 IA32_DESCRIPTOR IdtDescriptor
;
160 OldHeap
= (VOID
*)(UINTN
)TemporaryMemoryBase
;
161 NewHeap
= (VOID
*)((UINTN
)PermanentMemoryBase
+ CopySize
/ 2);
163 OldStack
= (VOID
*)((UINTN
)TemporaryMemoryBase
+ CopySize
/ 2);
164 NewStack
= (VOID
*)(UINTN
)PermanentMemoryBase
;
169 CopyMem (NewHeap
, OldHeap
, CopySize
/ 2);
174 CopyMem (NewStack
, OldStack
, CopySize
/ 2);
178 // We need *not* fix the return address because currently,
179 // The PeiCore is executed in flash.
183 // Rebase IDT table in permanent memory
185 AsmReadIdtr (&IdtDescriptor
);
186 IdtDescriptor
.Base
= IdtDescriptor
.Base
- (UINTN
)OldStack
+ (UINTN
)NewStack
;
188 AsmWriteIdtr (&IdtDescriptor
);
191 // Fixed the FSP data pointer
193 FspDataPointerFixUp ((UINTN
)NewStack
- (UINTN
)OldStack
);
196 // SecSwitchStack function must be invoked after the memory migration
197 // immediately, also we need fixup the stack change caused by new call into
201 (UINT32
) (UINTN
) OldStack
,
202 (UINT32
) (UINTN
) NewStack