]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFspPkg/FspSecCore/SecMain.c
Rollback file GUID change, because it is VTF file and GUID is predefined.
[mirror_edk2.git] / IntelFspPkg / FspSecCore / SecMain.c
CommitLineData
c8ec22a2
JY
1/** @file\r
2\r
3 Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>\r
4 This program and the accompanying materials\r
5 are licensed and made available under the terms and conditions of the BSD License\r
6 which accompanies this distribution. The full text of the license may be found at\r
7 http://opensource.org/licenses/bsd-license.php.\r
8\r
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12**/\r
13\r
14#include "SecMain.h"\r
15#include "SecFsp.h"\r
16\r
17EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI gSecTemporaryRamSupportPpi = {\r
18 SecTemporaryRamSupport\r
19};\r
20\r
21EFI_PEI_PPI_DESCRIPTOR mPeiSecPlatformInformationPpi[] = {\r
22 {\r
23 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
24 &gEfiTemporaryRamSupportPpiGuid,\r
25 &gSecTemporaryRamSupportPpi\r
26 }\r
27};\r
28\r
29//\r
30// These are IDT entries pointing to 08:FFFFFFE4h.\r
31//\r
32UINT64 mIdtEntryTemplate = 0xffff8e000008ffe4ULL;\r
33\r
34/**\r
35\r
36 Entry point to the C language phase of SEC. After the SEC assembly\r
37 code has initialized some temporary memory and set up the stack,\r
38 the control is transferred to this function.\r
39\r
40\r
41 @param[in] SizeOfRam Size of the temporary memory available for use.\r
42 @param[in] TempRamBase Base address of tempory ram\r
43 @param[in] BootFirmwareVolume Base address of the Boot Firmware Volume.\r
a0e0fb6d 44 @param[in] PeiCoreEntry Pei Core entrypoint.\r
c8ec22a2
JY
45\r
46 @return This function never returns.\r
47\r
48**/\r
49VOID\r
50EFIAPI\r
51SecStartup (\r
52 IN UINT32 SizeOfRam,\r
53 IN UINT32 TempRamBase,\r
a0e0fb6d
JY
54 IN VOID *BootFirmwareVolume,\r
55 IN UINTN PeiCoreEntry\r
c8ec22a2
JY
56 )\r
57{\r
58 EFI_SEC_PEI_HAND_OFF SecCoreData;\r
59 IA32_DESCRIPTOR IdtDescriptor;\r
60 SEC_IDT_TABLE IdtTableInStack;\r
61 UINT32 Index;\r
62 FSP_GLOBAL_DATA PeiFspData;\r
63 PEI_CORE_ENTRY PeiCore;\r
64 UINT64 ExceptionHandler;\r
65\r
66 //\r
67 // Process all libraries constructor function linked to SecCore.\r
68 //\r
69 ProcessLibraryConstructorList ();\r
70\r
71 //\r
72 // Initialize floating point operating environment\r
73 // to be compliant with UEFI spec.\r
74 //\r
75 InitializeFloatingPointUnits ();\r
76\r
77\r
78 // |-------------------|---->\r
79 // |Idt Table |\r
80 // |-------------------|\r
81 // |PeiService Pointer | PeiStackSize\r
82 // |-------------------|\r
83 // | |\r
84 // | Stack |\r
85 // |-------------------|---->\r
86 // | |\r
87 // | |\r
88 // | Heap | PeiTemporayRamSize\r
89 // | |\r
90 // | |\r
91 // |-------------------|----> TempRamBase\r
92 IdtTableInStack.PeiService = NULL;\r
93 ExceptionHandler = FspGetExceptionHandler(mIdtEntryTemplate);\r
94 for (Index = 0; Index < SEC_IDT_ENTRY_COUNT; Index ++) {\r
95 CopyMem ((VOID*)&IdtTableInStack.IdtTable[Index], (VOID*)&ExceptionHandler, sizeof (UINT64));\r
96 }\r
97\r
98 IdtDescriptor.Base = (UINTN) &IdtTableInStack.IdtTable;\r
99 IdtDescriptor.Limit = (UINT16)(sizeof (IdtTableInStack.IdtTable) - 1);\r
100\r
101 AsmWriteIdtr (&IdtDescriptor);\r
102\r
103 //\r
104 // Iniitalize the global FSP data region\r
105 //\r
106 FspGlobalDataInit (&PeiFspData, &BootFirmwareVolume);\r
107\r
108 //\r
109 // Update the base address and length of Pei temporary memory\r
110 //\r
111 SecCoreData.DataSize = sizeof (EFI_SEC_PEI_HAND_OFF);\r
112 SecCoreData.BootFirmwareVolumeBase = BootFirmwareVolume;\r
113 SecCoreData.BootFirmwareVolumeSize = (UINT32)((EFI_FIRMWARE_VOLUME_HEADER *)BootFirmwareVolume)->FvLength;\r
114 SecCoreData.TemporaryRamBase = (VOID*)(UINTN) TempRamBase;\r
115 SecCoreData.TemporaryRamSize = SizeOfRam;\r
116 SecCoreData.PeiTemporaryRamBase = SecCoreData.TemporaryRamBase;\r
117 SecCoreData.PeiTemporaryRamSize = SizeOfRam >> 1;\r
118 SecCoreData.StackBase = (VOID*)(UINTN)(TempRamBase + SecCoreData.PeiTemporaryRamSize);\r
119 SecCoreData.StackSize = SizeOfRam >> 1;\r
120\r
121 //\r
122 // Call PeiCore Entry\r
123 //\r
a0e0fb6d 124 PeiCore = (PEI_CORE_ENTRY)(PeiCoreEntry);\r
c8ec22a2
JY
125 PeiCore (&SecCoreData, mPeiSecPlatformInformationPpi);\r
126\r
127 //\r
128 // Should never be here\r
129 //\r
130 CpuDeadLoop ();\r
131}\r
132\r
133/**\r
134 This service of the TEMPORARY_RAM_SUPPORT_PPI that migrates temporary RAM into\r
135 permanent memory.\r
136\r
137 @param[in] PeiServices Pointer to the PEI Services Table.\r
138 @param[in] TemporaryMemoryBase Source Address in temporary memory from which the SEC or PEIM will copy the\r
139 Temporary RAM contents.\r
140 @param[in] PermanentMemoryBase Destination Address in permanent memory into which the SEC or PEIM will copy the\r
141 Temporary RAM contents.\r
142 @param[in] CopySize Amount of memory to migrate from temporary to permanent memory.\r
143\r
144 @retval EFI_SUCCESS The data was successfully returned.\r
145 @retval EFI_INVALID_PARAMETER PermanentMemoryBase + CopySize > TemporaryMemoryBase when\r
146 TemporaryMemoryBase > PermanentMemoryBase.\r
147\r
148**/\r
149EFI_STATUS\r
150EFIAPI\r
151SecTemporaryRamSupport (\r
152 IN CONST EFI_PEI_SERVICES **PeiServices,\r
153 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase,\r
154 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase,\r
155 IN UINTN CopySize\r
156 )\r
157{\r
158 IA32_DESCRIPTOR IdtDescriptor;\r
159 VOID* OldHeap;\r
160 VOID* NewHeap;\r
161 VOID* OldStack;\r
162 VOID* NewStack;\r
163\r
164 OldHeap = (VOID*)(UINTN)TemporaryMemoryBase;\r
165 NewHeap = (VOID*)((UINTN)PermanentMemoryBase + CopySize / 2);\r
166\r
167 OldStack = (VOID*)((UINTN)TemporaryMemoryBase + CopySize / 2);\r
168 NewStack = (VOID*)(UINTN)PermanentMemoryBase;\r
169\r
170 //\r
171 // Migrate Heap\r
172 //\r
173 CopyMem (NewHeap, OldHeap, CopySize / 2);\r
174\r
175 //\r
176 // Migrate Stack\r
177 //\r
178 CopyMem (NewStack, OldStack, CopySize / 2);\r
179\r
180\r
181 //\r
182 // We need *not* fix the return address because currently,\r
183 // The PeiCore is executed in flash.\r
184 //\r
185\r
186 //\r
187 // Rebase IDT table in permanent memory\r
188 //\r
189 AsmReadIdtr (&IdtDescriptor);\r
190 IdtDescriptor.Base = IdtDescriptor.Base - (UINTN)OldStack + (UINTN)NewStack;\r
191\r
192 AsmWriteIdtr (&IdtDescriptor);\r
193\r
194 //\r
195 // Fixed the FSP data pointer\r
196 //\r
197 FspDataPointerFixUp ((UINTN)NewStack - (UINTN)OldStack);\r
198\r
199 //\r
200 // SecSwitchStack function must be invoked after the memory migration\r
201 // immediatly, also we need fixup the stack change caused by new call into\r
202 // permenent memory.\r
203 //\r
204 SecSwitchStack (\r
205 (UINT32) (UINTN) OldStack,\r
206 (UINT32) (UINTN) NewStack\r
207 );\r
208\r
209 return EFI_SUCCESS;\r
210}\r