]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFspPkg/FspSecCore/SecMain.c
Add IntelFspPkg to support create FSP bin based on EDKII.
[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
44\r
45 @return This function never returns.\r
46\r
47**/\r
48VOID\r
49EFIAPI\r
50SecStartup (\r
51 IN UINT32 SizeOfRam,\r
52 IN UINT32 TempRamBase,\r
53 IN VOID *BootFirmwareVolume\r
54 )\r
55{\r
56 EFI_SEC_PEI_HAND_OFF SecCoreData;\r
57 IA32_DESCRIPTOR IdtDescriptor;\r
58 SEC_IDT_TABLE IdtTableInStack;\r
59 UINT32 Index;\r
60 FSP_GLOBAL_DATA PeiFspData;\r
61 PEI_CORE_ENTRY PeiCore;\r
62 UINT64 ExceptionHandler;\r
63\r
64 //\r
65 // Process all libraries constructor function linked to SecCore.\r
66 //\r
67 ProcessLibraryConstructorList ();\r
68\r
69 //\r
70 // Initialize floating point operating environment\r
71 // to be compliant with UEFI spec.\r
72 //\r
73 InitializeFloatingPointUnits ();\r
74\r
75\r
76 // |-------------------|---->\r
77 // |Idt Table |\r
78 // |-------------------|\r
79 // |PeiService Pointer | PeiStackSize\r
80 // |-------------------|\r
81 // | |\r
82 // | Stack |\r
83 // |-------------------|---->\r
84 // | |\r
85 // | |\r
86 // | Heap | PeiTemporayRamSize\r
87 // | |\r
88 // | |\r
89 // |-------------------|----> TempRamBase\r
90 IdtTableInStack.PeiService = NULL;\r
91 ExceptionHandler = FspGetExceptionHandler(mIdtEntryTemplate);\r
92 for (Index = 0; Index < SEC_IDT_ENTRY_COUNT; Index ++) {\r
93 CopyMem ((VOID*)&IdtTableInStack.IdtTable[Index], (VOID*)&ExceptionHandler, sizeof (UINT64));\r
94 }\r
95\r
96 IdtDescriptor.Base = (UINTN) &IdtTableInStack.IdtTable;\r
97 IdtDescriptor.Limit = (UINT16)(sizeof (IdtTableInStack.IdtTable) - 1);\r
98\r
99 AsmWriteIdtr (&IdtDescriptor);\r
100\r
101 //\r
102 // Iniitalize the global FSP data region\r
103 //\r
104 FspGlobalDataInit (&PeiFspData, &BootFirmwareVolume);\r
105\r
106 //\r
107 // Update the base address and length of Pei temporary memory\r
108 //\r
109 SecCoreData.DataSize = sizeof (EFI_SEC_PEI_HAND_OFF);\r
110 SecCoreData.BootFirmwareVolumeBase = BootFirmwareVolume;\r
111 SecCoreData.BootFirmwareVolumeSize = (UINT32)((EFI_FIRMWARE_VOLUME_HEADER *)BootFirmwareVolume)->FvLength;\r
112 SecCoreData.TemporaryRamBase = (VOID*)(UINTN) TempRamBase;\r
113 SecCoreData.TemporaryRamSize = SizeOfRam;\r
114 SecCoreData.PeiTemporaryRamBase = SecCoreData.TemporaryRamBase;\r
115 SecCoreData.PeiTemporaryRamSize = SizeOfRam >> 1;\r
116 SecCoreData.StackBase = (VOID*)(UINTN)(TempRamBase + SecCoreData.PeiTemporaryRamSize);\r
117 SecCoreData.StackSize = SizeOfRam >> 1;\r
118\r
119 //\r
120 // Call PeiCore Entry\r
121 //\r
122 PeiCore = (PEI_CORE_ENTRY)(*(UINTN *)((&BootFirmwareVolume) + 1));\r
123 PeiCore (&SecCoreData, mPeiSecPlatformInformationPpi);\r
124\r
125 //\r
126 // Should never be here\r
127 //\r
128 CpuDeadLoop ();\r
129}\r
130\r
131/**\r
132 This service of the TEMPORARY_RAM_SUPPORT_PPI that migrates temporary RAM into\r
133 permanent memory.\r
134\r
135 @param[in] PeiServices Pointer to the PEI Services Table.\r
136 @param[in] TemporaryMemoryBase Source Address in temporary memory from which the SEC or PEIM will copy the\r
137 Temporary RAM contents.\r
138 @param[in] PermanentMemoryBase Destination Address in permanent memory into which the SEC or PEIM will copy the\r
139 Temporary RAM contents.\r
140 @param[in] CopySize Amount of memory to migrate from temporary to permanent memory.\r
141\r
142 @retval EFI_SUCCESS The data was successfully returned.\r
143 @retval EFI_INVALID_PARAMETER PermanentMemoryBase + CopySize > TemporaryMemoryBase when\r
144 TemporaryMemoryBase > PermanentMemoryBase.\r
145\r
146**/\r
147EFI_STATUS\r
148EFIAPI\r
149SecTemporaryRamSupport (\r
150 IN CONST EFI_PEI_SERVICES **PeiServices,\r
151 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase,\r
152 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase,\r
153 IN UINTN CopySize\r
154 )\r
155{\r
156 IA32_DESCRIPTOR IdtDescriptor;\r
157 VOID* OldHeap;\r
158 VOID* NewHeap;\r
159 VOID* OldStack;\r
160 VOID* NewStack;\r
161\r
162 OldHeap = (VOID*)(UINTN)TemporaryMemoryBase;\r
163 NewHeap = (VOID*)((UINTN)PermanentMemoryBase + CopySize / 2);\r
164\r
165 OldStack = (VOID*)((UINTN)TemporaryMemoryBase + CopySize / 2);\r
166 NewStack = (VOID*)(UINTN)PermanentMemoryBase;\r
167\r
168 //\r
169 // Migrate Heap\r
170 //\r
171 CopyMem (NewHeap, OldHeap, CopySize / 2);\r
172\r
173 //\r
174 // Migrate Stack\r
175 //\r
176 CopyMem (NewStack, OldStack, CopySize / 2);\r
177\r
178\r
179 //\r
180 // We need *not* fix the return address because currently,\r
181 // The PeiCore is executed in flash.\r
182 //\r
183\r
184 //\r
185 // Rebase IDT table in permanent memory\r
186 //\r
187 AsmReadIdtr (&IdtDescriptor);\r
188 IdtDescriptor.Base = IdtDescriptor.Base - (UINTN)OldStack + (UINTN)NewStack;\r
189\r
190 AsmWriteIdtr (&IdtDescriptor);\r
191\r
192 //\r
193 // Fixed the FSP data pointer\r
194 //\r
195 FspDataPointerFixUp ((UINTN)NewStack - (UINTN)OldStack);\r
196\r
197 //\r
198 // SecSwitchStack function must be invoked after the memory migration\r
199 // immediatly, also we need fixup the stack change caused by new call into\r
200 // permenent memory.\r
201 //\r
202 SecSwitchStack (\r
203 (UINT32) (UINTN) OldStack,\r
204 (UINT32) (UINTN) NewStack\r
205 );\r
206\r
207 return EFI_SUCCESS;\r
208}\r