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