]>
Commit | Line | Data |
---|---|---|
1921695e MK |
1 | /** @file\r |
2 | C functions in SEC\r | |
3 | \r | |
af34c106 | 4 | Copyright (c) 2008 - 2016, Intel Corporation. All rights reserved.<BR>\r |
1921695e MK |
5 | This program and the accompanying materials\r |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #include "SecMain.h"\r | |
16 | \r | |
17 | EFI_PEI_TEMPORARY_RAM_DONE_PPI gSecTemporaryRamDonePpi = {\r | |
18 | SecTemporaryRamDone\r | |
19 | };\r | |
20 | \r | |
21 | EFI_SEC_PLATFORM_INFORMATION_PPI mSecPlatformInformationPpi = { SecPlatformInformation };\r | |
22 | \r | |
23 | EFI_PEI_PPI_DESCRIPTOR mPeiSecPlatformInformationPpi[] = {\r | |
24 | {\r | |
25 | EFI_PEI_PPI_DESCRIPTOR_PPI,\r | |
26 | &gEfiTemporaryRamDonePpiGuid,\r | |
27 | &gSecTemporaryRamDonePpi\r | |
28 | },\r | |
29 | {\r | |
30 | (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r | |
31 | &gEfiSecPlatformInformationPpiGuid,\r | |
32 | &mSecPlatformInformationPpi\r | |
33 | }\r | |
34 | };\r | |
35 | \r | |
36 | //\r | |
37 | // These are IDT entries pointing to 10:FFFFFFE4h.\r | |
38 | //\r | |
39 | UINT64 mIdtEntryTemplate = 0xffff8e000010ffe4ULL;\r | |
40 | \r | |
41 | /**\r | |
42 | Caller provided function to be invoked at the end of InitializeDebugAgent().\r | |
43 | \r | |
44 | Entry point to the C language phase of SEC. After the SEC assembly\r | |
45 | code has initialized some temporary memory and set up the stack,\r | |
46 | the control is transferred to this function.\r | |
47 | \r | |
48 | @param[in] Context The first input parameter of InitializeDebugAgent().\r | |
49 | \r | |
50 | **/\r | |
51 | VOID\r | |
61257251 | 52 | NORETURN\r |
1921695e MK |
53 | EFIAPI\r |
54 | SecStartupPhase2(\r | |
55 | IN VOID *Context\r | |
56 | );\r | |
57 | \r | |
58 | /**\r | |
59 | \r | |
60 | Entry point to the C language phase of SEC. After the SEC assembly\r | |
61 | code has initialized some temporary memory and set up the stack,\r | |
62 | the control is transferred to this function.\r | |
63 | \r | |
64 | \r | |
65 | @param SizeOfRam Size of the temporary memory available for use.\r | |
66 | @param TempRamBase Base address of temporary ram\r | |
67 | @param BootFirmwareVolume Base address of the Boot Firmware Volume.\r | |
68 | **/\r | |
69 | VOID\r | |
70 | EFIAPI\r | |
71 | SecStartup (\r | |
72 | IN UINT32 SizeOfRam,\r | |
73 | IN UINT32 TempRamBase,\r | |
74 | IN VOID *BootFirmwareVolume\r | |
75 | )\r | |
76 | {\r | |
77 | EFI_SEC_PEI_HAND_OFF SecCoreData;\r | |
78 | IA32_DESCRIPTOR IdtDescriptor;\r | |
79 | SEC_IDT_TABLE IdtTableInStack;\r | |
80 | UINT32 Index;\r | |
81 | UINT32 PeiStackSize;\r | |
82 | EFI_STATUS Status;\r | |
83 | \r | |
84 | //\r | |
85 | // Report Status Code to indicate entering SEC core\r | |
86 | //\r | |
87 | REPORT_STATUS_CODE (\r | |
88 | EFI_PROGRESS_CODE,\r | |
89 | EFI_SOFTWARE_SEC | EFI_SW_SEC_PC_ENTRY_POINT\r | |
90 | );\r | |
91 | \r | |
92 | PeiStackSize = PcdGet32 (PcdPeiTemporaryRamStackSize);\r | |
93 | if (PeiStackSize == 0) {\r | |
94 | PeiStackSize = (SizeOfRam >> 1);\r | |
95 | }\r | |
96 | \r | |
97 | ASSERT (PeiStackSize < SizeOfRam);\r | |
98 | \r | |
99 | //\r | |
100 | // Process all libraries constructor function linked to SecCore.\r | |
101 | //\r | |
102 | ProcessLibraryConstructorList ();\r | |
103 | \r | |
104 | //\r | |
105 | // Initialize floating point operating environment\r | |
106 | // to be compliant with UEFI spec.\r | |
107 | //\r | |
108 | InitializeFloatingPointUnits ();\r | |
109 | \r | |
110 | // |-------------------|---->\r | |
111 | // |IDT Table |\r | |
112 | // |-------------------|\r | |
113 | // |PeiService Pointer | PeiStackSize\r | |
114 | // |-------------------|\r | |
115 | // | |\r | |
116 | // | Stack |\r | |
117 | // |-------------------|---->\r | |
118 | // | |\r | |
119 | // | |\r | |
120 | // | Heap | PeiTemporayRamSize\r | |
121 | // | |\r | |
122 | // | |\r | |
123 | // |-------------------|----> TempRamBase\r | |
124 | \r | |
125 | IdtTableInStack.PeiService = 0;\r | |
126 | for (Index = 0; Index < SEC_IDT_ENTRY_COUNT; Index ++) {\r | |
127 | CopyMem ((VOID*)&IdtTableInStack.IdtTable[Index], (VOID*)&mIdtEntryTemplate, sizeof (UINT64));\r | |
128 | }\r | |
129 | \r | |
130 | IdtDescriptor.Base = (UINTN) &IdtTableInStack.IdtTable;\r | |
131 | IdtDescriptor.Limit = (UINT16)(sizeof (IdtTableInStack.IdtTable) - 1);\r | |
132 | \r | |
133 | AsmWriteIdtr (&IdtDescriptor);\r | |
134 | \r | |
135 | //\r | |
136 | // Setup the default exception handlers\r | |
137 | //\r | |
138 | Status = InitializeCpuExceptionHandlers (NULL);\r | |
139 | ASSERT_EFI_ERROR (Status);\r | |
140 | \r | |
141 | //\r | |
142 | // Update the base address and length of Pei temporary memory\r | |
143 | //\r | |
144 | SecCoreData.DataSize = (UINT16) sizeof (EFI_SEC_PEI_HAND_OFF);\r | |
145 | SecCoreData.BootFirmwareVolumeBase = BootFirmwareVolume;\r | |
146 | SecCoreData.BootFirmwareVolumeSize = (UINTN)(0x100000000ULL - (UINTN) BootFirmwareVolume);\r | |
147 | SecCoreData.TemporaryRamBase = (VOID*)(UINTN) TempRamBase;\r | |
148 | SecCoreData.TemporaryRamSize = SizeOfRam;\r | |
149 | SecCoreData.PeiTemporaryRamBase = SecCoreData.TemporaryRamBase;\r | |
150 | SecCoreData.PeiTemporaryRamSize = SizeOfRam - PeiStackSize;\r | |
151 | SecCoreData.StackBase = (VOID*)(UINTN)(TempRamBase + SecCoreData.PeiTemporaryRamSize);\r | |
152 | SecCoreData.StackSize = PeiStackSize;\r | |
153 | \r | |
154 | //\r | |
155 | // Initialize Debug Agent to support source level debug in SEC/PEI phases before memory ready.\r | |
156 | //\r | |
157 | InitializeDebugAgent (DEBUG_AGENT_INIT_PREMEM_SEC, &SecCoreData, SecStartupPhase2);\r | |
158 | }\r | |
159 | \r | |
160 | /**\r | |
161 | Caller provided function to be invoked at the end of InitializeDebugAgent().\r | |
162 | \r | |
163 | Entry point to the C language phase of SEC. After the SEC assembly\r | |
164 | code has initialized some temporary memory and set up the stack,\r | |
165 | the control is transferred to this function.\r | |
166 | \r | |
167 | @param[in] Context The first input parameter of InitializeDebugAgent().\r | |
168 | \r | |
169 | **/\r | |
170 | VOID\r | |
61257251 | 171 | NORETURN\r |
1921695e MK |
172 | EFIAPI\r |
173 | SecStartupPhase2(\r | |
174 | IN VOID *Context\r | |
175 | )\r | |
176 | {\r | |
177 | EFI_SEC_PEI_HAND_OFF *SecCoreData;\r | |
178 | EFI_PEI_PPI_DESCRIPTOR *PpiList;\r | |
179 | UINT32 Index;\r | |
180 | EFI_PEI_PPI_DESCRIPTOR *AllSecPpiList;\r | |
181 | EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint;\r | |
182 | \r | |
183 | SecCoreData = (EFI_SEC_PEI_HAND_OFF *) Context;\r | |
184 | AllSecPpiList = (EFI_PEI_PPI_DESCRIPTOR *) SecCoreData->PeiTemporaryRamBase;\r | |
185 | //\r | |
186 | // Find Pei Core entry point. It will report SEC and Pei Core debug information if remote debug\r | |
187 | // is enabled.\r | |
188 | //\r | |
189 | FindAndReportEntryPoints ((EFI_FIRMWARE_VOLUME_HEADER *) SecCoreData->BootFirmwareVolumeBase, &PeiCoreEntryPoint);\r | |
190 | if (PeiCoreEntryPoint == NULL)\r | |
191 | {\r | |
192 | CpuDeadLoop ();\r | |
193 | }\r | |
194 | \r | |
195 | //\r | |
196 | // Perform platform specific initialization before entering PeiCore.\r | |
197 | //\r | |
198 | PpiList = SecPlatformMain (SecCoreData);\r | |
199 | if (PpiList != NULL) {\r | |
200 | //\r | |
201 | // Remove the terminal flag from the terminal PPI\r | |
202 | //\r | |
203 | CopyMem (AllSecPpiList, mPeiSecPlatformInformationPpi, sizeof (mPeiSecPlatformInformationPpi));\r | |
204 | Index = sizeof (mPeiSecPlatformInformationPpi) / sizeof (EFI_PEI_PPI_DESCRIPTOR) - 1;\r | |
205 | AllSecPpiList[Index].Flags = AllSecPpiList[Index].Flags & (~EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);\r | |
206 | \r | |
207 | //\r | |
208 | // Append the platform additional PPI list\r | |
209 | //\r | |
210 | Index += 1;\r | |
211 | while (((PpiList->Flags & EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) != EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST)) {\r | |
212 | CopyMem (&AllSecPpiList[Index], PpiList, sizeof (EFI_PEI_PPI_DESCRIPTOR));\r | |
213 | Index++;\r | |
214 | PpiList++;\r | |
215 | }\r | |
216 | \r | |
217 | //\r | |
218 | // Add the terminal PPI\r | |
219 | //\r | |
220 | CopyMem (&AllSecPpiList[Index ++], PpiList, sizeof (EFI_PEI_PPI_DESCRIPTOR));\r | |
221 | \r | |
222 | //\r | |
223 | // Set PpiList to the total PPI\r | |
224 | //\r | |
225 | PpiList = AllSecPpiList;\r | |
226 | \r | |
227 | //\r | |
228 | // Adjust PEI TEMP RAM Range.\r | |
229 | //\r | |
230 | ASSERT (SecCoreData->PeiTemporaryRamSize > Index * sizeof (EFI_PEI_PPI_DESCRIPTOR));\r | |
231 | SecCoreData->PeiTemporaryRamBase = (VOID *)((UINTN) SecCoreData->PeiTemporaryRamBase + Index * sizeof (EFI_PEI_PPI_DESCRIPTOR));\r | |
232 | SecCoreData->PeiTemporaryRamSize = SecCoreData->PeiTemporaryRamSize - Index * sizeof (EFI_PEI_PPI_DESCRIPTOR);\r | |
233 | } else {\r | |
234 | //\r | |
235 | // No addition PPI, PpiList directly point to the common PPI list.\r | |
236 | //\r | |
237 | PpiList = &mPeiSecPlatformInformationPpi[0];\r | |
238 | }\r | |
239 | \r | |
af34c106 JF |
240 | DEBUG ((\r |
241 | DEBUG_INFO,\r | |
ec16deea | 242 | "%a() Stack Base: 0x%p, Stack Size: 0x%x\n",\r |
af34c106 JF |
243 | __FUNCTION__,\r |
244 | SecCoreData->StackBase,\r | |
ec16deea | 245 | (UINT32) SecCoreData->StackSize\r |
af34c106 JF |
246 | ));\r |
247 | \r | |
1921695e MK |
248 | //\r |
249 | // Report Status Code to indicate transferring to PEI core\r | |
250 | //\r | |
251 | REPORT_STATUS_CODE (\r | |
252 | EFI_PROGRESS_CODE,\r | |
253 | EFI_SOFTWARE_SEC | EFI_SW_SEC_PC_HANDOFF_TO_NEXT\r | |
254 | );\r | |
255 | \r | |
256 | //\r | |
257 | // Transfer the control to the PEI core\r | |
258 | //\r | |
259 | ASSERT (PeiCoreEntryPoint != NULL);\r | |
260 | (*PeiCoreEntryPoint) (SecCoreData, PpiList);\r | |
261 | \r | |
262 | //\r | |
263 | // Should not come here.\r | |
264 | //\r | |
61257251 | 265 | UNREACHABLE ();\r |
1921695e MK |
266 | }\r |
267 | \r | |
268 | /**\r | |
269 | TemporaryRamDone() disables the use of Temporary RAM. If present, this service is invoked\r | |
270 | by the PEI Foundation after the EFI_PEI_PERMANANT_MEMORY_INSTALLED_PPI is installed.\r | |
271 | \r | |
272 | @retval EFI_SUCCESS Use of Temporary RAM was disabled.\r | |
273 | @retval EFI_INVALID_PARAMETER Temporary RAM could not be disabled.\r | |
274 | \r | |
275 | **/\r | |
276 | EFI_STATUS\r | |
277 | EFIAPI\r | |
278 | SecTemporaryRamDone (\r | |
279 | VOID\r | |
280 | )\r | |
281 | {\r | |
282 | BOOLEAN State;\r | |
283 | \r | |
8a5b8cef JF |
284 | //\r |
285 | // Republish Sec Platform Information(2) PPI\r | |
286 | //\r | |
287 | RepublishSecPlatformInformationPpi ();\r | |
288 | \r | |
1921695e MK |
289 | //\r |
290 | // Migrate DebugAgentContext.\r | |
291 | //\r | |
292 | InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC, NULL, NULL);\r | |
293 | \r | |
294 | //\r | |
295 | // Disable interrupts and save current interrupt state\r | |
296 | //\r | |
297 | State = SaveAndDisableInterrupts();\r | |
298 | \r | |
299 | //\r | |
300 | // Disable Temporary RAM after Stack and Heap have been migrated at this point.\r | |
301 | //\r | |
302 | SecPlatformDisableTemporaryMemory ();\r | |
303 | \r | |
304 | //\r | |
305 | // Restore original interrupt state\r | |
306 | //\r | |
307 | SetInterruptState (State);\r | |
308 | \r | |
309 | return EFI_SUCCESS;\r | |
310 | }\r |