]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c
Code Scrub for Dxe Core.
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / DxeMain / DxeMain.c
CommitLineData
162ed594 1/** @file\r
797a9d67 2 DXE Core Main Entry Point\r
23c98c94 3\r
4Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r
28a00297 5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
797a9d67 13**/\r
28a00297 14\r
15#include <DxeMain.h>\r
16\r
17//\r
18// DXE Core Global Variables for Protocols from PEI\r
19//\r
20EFI_HANDLE mDecompressHandle = NULL;\r
28a00297 21\r
22//\r
23// DXE Core globals for Architecture Protocols\r
24//\r
25EFI_SECURITY_ARCH_PROTOCOL *gSecurity = NULL;\r
26EFI_CPU_ARCH_PROTOCOL *gCpu = NULL;\r
27EFI_METRONOME_ARCH_PROTOCOL *gMetronome = NULL;\r
28EFI_TIMER_ARCH_PROTOCOL *gTimer = NULL;\r
29EFI_BDS_ARCH_PROTOCOL *gBds = NULL;\r
30EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *gWatchdogTimer = NULL;\r
31\r
e94a9ff7 32//\r
33// DXE Core Global used to update core loaded image protocol handle\r
34//\r
35EFI_GUID *gDxeCoreFileName;\r
36EFI_LOADED_IMAGE_PROTOCOL *gDxeCoreLoadedImage;\r
28a00297 37\r
38//\r
39// BugBug: I'n not runtime, but is the PPI?\r
40//\r
41EFI_STATUS_CODE_PROTOCOL gStatusCodeInstance = {\r
42 NULL\r
43};\r
44\r
45EFI_STATUS_CODE_PROTOCOL *gStatusCode = &gStatusCodeInstance;\r
46\r
28a00297 47//\r
48// DXE Core Module Variables\r
49//\r
50\r
51EFI_BOOT_SERVICES mBootServices = {\r
52 {\r
53 EFI_BOOT_SERVICES_SIGNATURE, // Signature\r
54 EFI_BOOT_SERVICES_REVISION, // Revision\r
55 sizeof (EFI_BOOT_SERVICES), // HeaderSize\r
56 0, // CRC32\r
57 0 // Reserved\r
58 },\r
59 (EFI_RAISE_TPL) CoreRaiseTpl, // RaiseTPL\r
60 (EFI_RESTORE_TPL) CoreRestoreTpl, // RestoreTPL\r
61 (EFI_ALLOCATE_PAGES) CoreAllocatePages, // AllocatePages\r
62 (EFI_FREE_PAGES) CoreFreePages, // FreePages\r
63 (EFI_GET_MEMORY_MAP) CoreGetMemoryMap, // GetMemoryMap\r
64 (EFI_ALLOCATE_POOL) CoreAllocatePool, // AllocatePool\r
65 (EFI_FREE_POOL) CoreFreePool, // FreePool\r
66 (EFI_CREATE_EVENT) CoreCreateEvent, // CreateEvent\r
67 (EFI_SET_TIMER) CoreSetTimer, // SetTimer\r
68 (EFI_WAIT_FOR_EVENT) CoreWaitForEvent, // WaitForEvent\r
69 (EFI_SIGNAL_EVENT) CoreSignalEvent, // SignalEvent\r
70 (EFI_CLOSE_EVENT) CoreCloseEvent, // CloseEvent\r
71 (EFI_CHECK_EVENT) CoreCheckEvent, // CheckEvent\r
72 (EFI_INSTALL_PROTOCOL_INTERFACE) CoreInstallProtocolInterface, // InstallProtocolInterface\r
73 (EFI_REINSTALL_PROTOCOL_INTERFACE) CoreReinstallProtocolInterface, // ReinstallProtocolInterface\r
74 (EFI_UNINSTALL_PROTOCOL_INTERFACE) CoreUninstallProtocolInterface, // UninstallProtocolInterface\r
75 (EFI_HANDLE_PROTOCOL) CoreHandleProtocol, // HandleProtocol\r
76 (VOID *) NULL, // Reserved\r
77 (EFI_REGISTER_PROTOCOL_NOTIFY) CoreRegisterProtocolNotify, // RegisterProtocolNotify\r
78 (EFI_LOCATE_HANDLE) CoreLocateHandle, // LocateHandle\r
79 (EFI_LOCATE_DEVICE_PATH) CoreLocateDevicePath, // LocateDevicePath\r
80 (EFI_INSTALL_CONFIGURATION_TABLE) CoreInstallConfigurationTable, // InstallConfigurationTable\r
81 (EFI_IMAGE_LOAD) CoreLoadImage, // LoadImage\r
82 (EFI_IMAGE_START) CoreStartImage, // StartImage\r
83 (EFI_EXIT) CoreExit, // Exit\r
84 (EFI_IMAGE_UNLOAD) CoreUnloadImage, // UnloadImage\r
85 (EFI_EXIT_BOOT_SERVICES) CoreExitBootServices, // ExitBootServices\r
86 (EFI_GET_NEXT_MONOTONIC_COUNT) CoreEfiNotAvailableYetArg1, // GetNextMonotonicCount\r
87 (EFI_STALL) CoreStall, // Stall\r
88 (EFI_SET_WATCHDOG_TIMER) CoreSetWatchdogTimer, // SetWatchdogTimer\r
89 (EFI_CONNECT_CONTROLLER) CoreConnectController, // ConnectController\r
90 (EFI_DISCONNECT_CONTROLLER) CoreDisconnectController, // DisconnectController\r
91 (EFI_OPEN_PROTOCOL) CoreOpenProtocol, // OpenProtocol\r
92 (EFI_CLOSE_PROTOCOL) CoreCloseProtocol, // CloseProtocol\r
93 (EFI_OPEN_PROTOCOL_INFORMATION) CoreOpenProtocolInformation, // OpenProtocolInformation\r
94 (EFI_PROTOCOLS_PER_HANDLE) CoreProtocolsPerHandle, // ProtocolsPerHandle\r
95 (EFI_LOCATE_HANDLE_BUFFER) CoreLocateHandleBuffer, // LocateHandleBuffer\r
96 (EFI_LOCATE_PROTOCOL) CoreLocateProtocol, // LocateProtocol\r
97 (EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES) CoreInstallMultipleProtocolInterfaces, // InstallMultipleProtocolInterfaces\r
98 (EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES) CoreUninstallMultipleProtocolInterfaces, // UninstallMultipleProtocolInterfaces\r
99 (EFI_CALCULATE_CRC32) CoreEfiNotAvailableYetArg3, // CalculateCrc32\r
100 (EFI_COPY_MEM) CopyMem, // CopyMem\r
101 (EFI_SET_MEM) SetMem, // SetMem\r
102 (EFI_CREATE_EVENT_EX) CoreCreateEventEx // CreateEventEx\r
103};\r
104\r
105EFI_DXE_SERVICES mDxeServices = {\r
106 {\r
107 DXE_SERVICES_SIGNATURE, // Signature\r
108 DXE_SERVICES_REVISION, // Revision\r
109 sizeof (DXE_SERVICES), // HeaderSize\r
110 0, // CRC32\r
111 0 // Reserved\r
112 },\r
113 (EFI_ADD_MEMORY_SPACE) CoreAddMemorySpace, // AddMemorySpace\r
114 (EFI_ALLOCATE_MEMORY_SPACE) CoreAllocateMemorySpace, // AllocateMemorySpace\r
115 (EFI_FREE_MEMORY_SPACE) CoreFreeMemorySpace, // FreeMemorySpace\r
116 (EFI_REMOVE_MEMORY_SPACE) CoreRemoveMemorySpace, // RemoveMemorySpace\r
117 (EFI_GET_MEMORY_SPACE_DESCRIPTOR) CoreGetMemorySpaceDescriptor, // GetMemorySpaceDescriptor\r
118 (EFI_SET_MEMORY_SPACE_ATTRIBUTES) CoreSetMemorySpaceAttributes, // SetMemorySpaceAttributes\r
119 (EFI_GET_MEMORY_SPACE_MAP) CoreGetMemorySpaceMap, // GetMemorySpaceMap\r
120 (EFI_ADD_IO_SPACE) CoreAddIoSpace, // AddIoSpace\r
121 (EFI_ALLOCATE_IO_SPACE) CoreAllocateIoSpace, // AllocateIoSpace\r
122 (EFI_FREE_IO_SPACE) CoreFreeIoSpace, // FreeIoSpace\r
123 (EFI_REMOVE_IO_SPACE) CoreRemoveIoSpace, // RemoveIoSpace\r
124 (EFI_GET_IO_SPACE_DESCRIPTOR) CoreGetIoSpaceDescriptor, // GetIoSpaceDescriptor\r
125 (EFI_GET_IO_SPACE_MAP) CoreGetIoSpaceMap, // GetIoSpaceMap\r
126 (EFI_DISPATCH) CoreDispatcher, // Dispatch\r
127 (EFI_SCHEDULE) CoreSchedule, // Schedule\r
128 (EFI_TRUST) CoreTrust, // Trust\r
129 (EFI_PROCESS_FIRMWARE_VOLUME) CoreProcessFirmwareVolume, // ProcessFirmwareVolume\r
130};\r
131\r
132EFI_SYSTEM_TABLE mEfiSystemTableTemplate = {\r
133 {\r
134 EFI_SYSTEM_TABLE_SIGNATURE, // Signature\r
135 EFI_SYSTEM_TABLE_REVISION, // Revision\r
136 sizeof (EFI_SYSTEM_TABLE), // HeaderSize\r
137 0, // CRC32\r
138 0 // Reserved\r
139 },\r
140 NULL, // FirmwareVendor\r
141 0, // FirmwareRevision\r
142 NULL, // ConsoleInHandle\r
143 NULL, // ConIn\r
144 NULL, // ConsoleOutHandle\r
145 NULL, // ConOut\r
146 NULL, // StandardErrorHandle\r
147 NULL, // StdErr\r
148 NULL, // RuntimeServices\r
149 &mBootServices, // BootServices\r
150 0, // NumberOfConfigurationTableEntries\r
151 NULL // ConfigurationTable\r
152};\r
153\r
154EFI_RUNTIME_SERVICES mEfiRuntimeServicesTableTemplate = {\r
155 {\r
156 EFI_RUNTIME_SERVICES_SIGNATURE, // Signature\r
157 EFI_RUNTIME_SERVICES_REVISION, // Revision\r
158 sizeof (EFI_RUNTIME_SERVICES), // HeaderSize\r
159 0, // CRC32\r
160 0 // Reserved\r
161 },\r
162 (EFI_GET_TIME) CoreEfiNotAvailableYetArg2, // GetTime\r
163 (EFI_SET_TIME) CoreEfiNotAvailableYetArg1, // SetTime\r
164 (EFI_GET_WAKEUP_TIME) CoreEfiNotAvailableYetArg3, // GetWakeupTime\r
165 (EFI_SET_WAKEUP_TIME) CoreEfiNotAvailableYetArg2, // SetWakeupTime\r
166 (EFI_SET_VIRTUAL_ADDRESS_MAP) CoreEfiNotAvailableYetArg4, // SetVirtualAddressMap\r
167 (EFI_CONVERT_POINTER) CoreEfiNotAvailableYetArg2, // ConvertPointer\r
168 (EFI_GET_VARIABLE) CoreEfiNotAvailableYetArg5, // GetVariable\r
169 (EFI_GET_NEXT_VARIABLE_NAME) CoreEfiNotAvailableYetArg3, // GetNextVariableName\r
170 (EFI_SET_VARIABLE) CoreEfiNotAvailableYetArg5, // SetVariable\r
171 (EFI_GET_NEXT_HIGH_MONO_COUNT) CoreEfiNotAvailableYetArg1, // GetNextHighMonotonicCount\r
172 (EFI_RESET_SYSTEM) CoreEfiNotAvailableYetArg4, // ResetSystem\r
173 (EFI_UPDATE_CAPSULE) CoreEfiNotAvailableYetArg3, // UpdateCapsule\r
174 (EFI_QUERY_CAPSULE_CAPABILITIES) CoreEfiNotAvailableYetArg4, // QueryCapsuleCapabilities\r
175 (EFI_QUERY_VARIABLE_INFO) CoreEfiNotAvailableYetArg4 // QueryVariableInfo\r
176};\r
177\r
178EFI_RUNTIME_ARCH_PROTOCOL gRuntimeTemplate = {\r
179 INITIALIZE_LIST_HEAD_VARIABLE (gRuntimeTemplate.ImageHead),\r
180 INITIALIZE_LIST_HEAD_VARIABLE (gRuntimeTemplate.EventHead),\r
181\r
182 //\r
183 // Make sure Size != sizeof (EFI_MEMORY_DESCRIPTOR). This will\r
184 // prevent people from having pointer math bugs in their code.\r
185 // now you have to use *DescriptorSize to make things work.\r
186 //\r
187 sizeof (EFI_MEMORY_DESCRIPTOR) + sizeof (UINT64) - (sizeof (EFI_MEMORY_DESCRIPTOR) % sizeof (UINT64)),\r
188 EFI_MEMORY_DESCRIPTOR_VERSION,\r
189 0,\r
190 NULL,\r
191 NULL,\r
192 FALSE,\r
193 FALSE\r
194};\r
195\r
196EFI_RUNTIME_ARCH_PROTOCOL *gRuntime = &gRuntimeTemplate;\r
197\r
198//\r
199// DXE Core Global Variables for the EFI System Table, Boot Services Table,\r
200// DXE Services Table, and Runtime Services Table\r
201//\r
202EFI_BOOT_SERVICES *gDxeCoreBS = &mBootServices;\r
203EFI_DXE_SERVICES *gDxeCoreDS = &mDxeServices;\r
204EFI_SYSTEM_TABLE *gDxeCoreST = NULL;\r
205\r
206//\r
207// For debug initialize gDxeCoreRT to template. gDxeCoreRT must be allocated from RT memory\r
208// but gDxeCoreRT is used for ASSERT () and DEBUG () type macros so lets give it\r
209// a value that will not cause debug infrastructure to crash early on.\r
210//\r
211EFI_RUNTIME_SERVICES *gDxeCoreRT = &mEfiRuntimeServicesTableTemplate;\r
212EFI_HANDLE gDxeCoreImageHandle = NULL;\r
213\r
28a00297 214\r
215//\r
216// EFI Decompress Protocol\r
217//\r
218EFI_DECOMPRESS_PROTOCOL gEfiDecompress = {\r
219 DxeMainUefiDecompressGetInfo,\r
220 DxeMainUefiDecompress\r
221};\r
222\r
223//\r
224// Main entry point to the DXE Core\r
225//\r
28a00297 226\r
162ed594 227/**\r
28a00297 228 Main entry point to DXE Core.\r
229\r
022c6d45 230 @param HobStart Pointer to the beginning of the HOB List from PEI.\r
28a00297 231\r
e94a9ff7 232 @return This function should never return.\r
28a00297 233\r
162ed594 234**/\r
235VOID\r
236EFIAPI\r
237DxeMain (\r
238 IN VOID *HobStart\r
239 )\r
28a00297 240{\r
241 EFI_STATUS Status;\r
242 EFI_PHYSICAL_ADDRESS MemoryBaseAddress;\r
243 UINT64 MemoryLength;\r
244\r
28a00297 245 //\r
246 // Initialize Memory Services\r
247 //\r
248 CoreInitializeMemoryServices (&HobStart, &MemoryBaseAddress, &MemoryLength);\r
249\r
250 //\r
251 // Allocate the EFI System Table and EFI Runtime Service Table from EfiRuntimeServicesData\r
252 // Use the templates to initialize the contents of the EFI System Table and EFI Runtime Services Table\r
253 //\r
254 gDxeCoreST = CoreAllocateRuntimeCopyPool (sizeof (EFI_SYSTEM_TABLE), &mEfiSystemTableTemplate);\r
255 ASSERT (gDxeCoreST != NULL);\r
256\r
257 gDxeCoreRT = CoreAllocateRuntimeCopyPool (sizeof (EFI_RUNTIME_SERVICES), &mEfiRuntimeServicesTableTemplate);\r
258 ASSERT (gDxeCoreRT != NULL);\r
259\r
260 gDxeCoreST->RuntimeServices = gDxeCoreRT;\r
261\r
262 //\r
263 // Start the Image Services.\r
264 //\r
265 Status = CoreInitializeImageServices (HobStart);\r
266 ASSERT_EFI_ERROR (Status);\r
267\r
268 //\r
269 // Call constructor for all libraries\r
270 //\r
271 ProcessLibraryConstructorList (gDxeCoreImageHandle, gDxeCoreST);\r
272 PERF_END (0,PEI_TOK, NULL, 0) ;\r
273 PERF_START (0,DXE_TOK, NULL, 0) ;\r
274\r
275 //\r
276 // Initialize the Global Coherency Domain Services\r
277 //\r
278 Status = CoreInitializeGcdServices (&HobStart, MemoryBaseAddress, MemoryLength);\r
279 ASSERT_EFI_ERROR (Status);\r
280\r
281 //\r
282 // Install the DXE Services Table into the EFI System Tables's Configuration Table\r
283 //\r
284 Status = CoreInstallConfigurationTable (&gEfiDxeServicesTableGuid, gDxeCoreDS);\r
285 ASSERT_EFI_ERROR (Status);\r
286\r
287 //\r
288 // Install the HOB List into the EFI System Tables's Configuration Table\r
289 //\r
290 Status = CoreInstallConfigurationTable (&gEfiHobListGuid, HobStart);\r
291 ASSERT_EFI_ERROR (Status);\r
292\r
293 //\r
294 // Install Memory Type Information Table into the EFI System Tables's Configuration Table\r
295 //\r
296 Status = CoreInstallConfigurationTable (&gEfiMemoryTypeInformationGuid, &gMemoryTypeInformation);\r
297 ASSERT_EFI_ERROR (Status);\r
298\r
299 //\r
300 // Initialize the ReportStatusCode with PEI version, if available\r
301 //\r
e94a9ff7 302 CoreGetPeiProtocol (&gEfiStatusCodeRuntimeProtocolGuid, (VOID **) &gStatusCode->ReportStatusCode);\r
28a00297 303\r
304 //\r
305 // Report Status Code here for DXE_ENTRY_POINT once it is available\r
306 //\r
797a9d67 307 CoreReportProgressCode (FixedPcdGet32(PcdStatusCodeValueDxeCoreEntry));\r
28a00297 308\r
309 //\r
310 // Create the aligned system table pointer structure that is used by external\r
311 // debuggers to locate the system table... Also, install debug image info\r
312 // configuration table.\r
313 //\r
314 CoreInitializeDebugImageInfoTable ();\r
315 CoreNewDebugImageInfoEntry (\r
316 EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL,\r
317 gDxeCoreLoadedImage,\r
318 gDxeCoreImageHandle\r
319 );\r
320\r
e94a9ff7 321 DEBUG ((DEBUG_INFO | DEBUG_LOAD, "HOBLIST address in DXE = 0x%p\n", HobStart));\r
28a00297 322\r
323 //\r
324 // Initialize the Event Services\r
325 //\r
326 Status = CoreInitializeEventServices ();\r
327 ASSERT_EFI_ERROR (Status);\r
328\r
329\r
330 //\r
331 // Get the Protocols that were passed in from PEI to DXE through GUIDed HOBs\r
332 //\r
333 // These Protocols are not architectural. This implementation is sharing code between\r
334 // PEI and DXE in order to save FLASH space. These Protocols could also be implemented\r
335 // as part of the DXE Core. However, that would also require the DXE Core to be ported\r
336 // each time a different CPU is used, a different Decompression algorithm is used, or a\r
337 // different Image type is used. By placing these Protocols in PEI, the DXE Core remains\r
338 // generic, and only PEI and the Arch Protocols need to be ported from Platform to Platform,\r
339 // and from CPU to CPU.\r
340 //\r
341\r
342 //\r
343 // Publish the EFI, Tiano, and Custom Decompress protocols for use by other DXE components\r
344 //\r
345 Status = CoreInstallMultipleProtocolInterfaces (\r
e94a9ff7 346 &mDecompressHandle,\r
347 &gEfiDecompressProtocolGuid, &gEfiDecompress,\r
348 NULL\r
349 );\r
28a00297 350 ASSERT_EFI_ERROR (Status);\r
351\r
28a00297 352 //\r
353 // Register for the GUIDs of the Architectural Protocols, so the rest of the\r
354 // EFI Boot Services and EFI Runtime Services tables can be filled in.\r
355 //\r
356 CoreNotifyOnArchProtocolInstallation ();\r
357\r
358 //\r
359 // Produce Firmware Volume Protocols, one for each FV in the HOB list.\r
360 //\r
361 Status = FwVolBlockDriverInit (gDxeCoreImageHandle, gDxeCoreST);\r
362 ASSERT_EFI_ERROR (Status);\r
363\r
364 Status = FwVolDriverInit (gDxeCoreImageHandle, gDxeCoreST);\r
365 ASSERT_EFI_ERROR (Status);\r
366\r
367 //\r
368 // Produce the Section Extraction Protocol\r
369 //\r
370 Status = InitializeSectionExtraction (gDxeCoreImageHandle, gDxeCoreST);\r
371 ASSERT_EFI_ERROR (Status);\r
372\r
373 //\r
374 // Initialize the DXE Dispatcher\r
375 //\r
376 PERF_START (0,"CoreInitializeDispatcher", "DxeMain", 0) ;\r
377 CoreInitializeDispatcher ();\r
378 PERF_END (0,"CoreInitializeDispatcher", "DxeMain", 0) ;\r
379\r
380 //\r
381 // Invoke the DXE Dispatcher\r
382 //\r
383 PERF_START (0, "CoreDispatcher", "DxeMain", 0);\r
384 CoreDispatcher ();\r
385 PERF_END (0, "CoreDispatcher", "DxeMain", 0);\r
386\r
387 //\r
388 // Display Architectural protocols that were not loaded if this is DEBUG build\r
389 //\r
390 DEBUG_CODE_BEGIN ();\r
391 CoreDisplayMissingArchProtocols ();\r
392 DEBUG_CODE_END ();\r
393\r
394 //\r
395 // Assert if the Architectural Protocols are not present.\r
396 //\r
397 ASSERT_EFI_ERROR (CoreAllEfiServicesAvailable ());\r
398\r
399 //\r
400 // Report Status code before transfer control to BDS\r
401 //\r
797a9d67 402 CoreReportProgressCode (FixedPcdGet32 (PcdStatusCodeValueDxeCoreHandoffToBds));\r
022c6d45 403\r
28a00297 404 //\r
405 // Display any drivers that were not dispatched because dependency expression\r
406 // evaluated to false if this is a debug build\r
407 //\r
408 DEBUG_CODE_BEGIN ();\r
409 CoreDisplayDiscoveredNotDispatched ();\r
410 DEBUG_CODE_END ();\r
411\r
412 //\r
413 // Transfer control to the BDS Architectural Protocol\r
414 //\r
415 gBds->Entry (gBds);\r
416\r
417 //\r
418 // BDS should never return\r
419 //\r
420 ASSERT (FALSE);\r
421 CpuDeadLoop ();\r
422}\r
423\r
424\r
162ed594 425\r
426/**\r
427 Place holder function until all the Boot Services and Runtime Services are\r
428 available.\r
429\r
430 @return EFI_NOT_AVAILABLE_YET\r
431\r
432**/\r
28a00297 433EFI_STATUS\r
434EFIAPI\r
435CoreEfiNotAvailableYetArg0 (\r
436 VOID\r
437 )\r
28a00297 438{\r
439 //\r
440 // This function should never be executed. If it does, then the architectural protocols\r
441 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the\r
442 // DXE Core and all the Architectural Protocols are complete.\r
443 //\r
444\r
445 return EFI_NOT_AVAILABLE_YET;\r
446}\r
447\r
162ed594 448\r
449/**\r
450 Place holder function until all the Boot Services and Runtime Services are\r
451 available.\r
452\r
022c6d45 453 @param Arg1 Undefined\r
162ed594 454\r
455 @return EFI_NOT_AVAILABLE_YET\r
456\r
457**/\r
28a00297 458EFI_STATUS\r
459EFIAPI\r
460CoreEfiNotAvailableYetArg1 (\r
461 UINTN Arg1\r
462 )\r
28a00297 463{\r
464 //\r
465 // This function should never be executed. If it does, then the architectural protocols\r
466 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the\r
467 // DXE Core and all the Architectural Protocols are complete.\r
468 //\r
469\r
470 return EFI_NOT_AVAILABLE_YET;\r
471}\r
472\r
162ed594 473\r
474/**\r
475 Place holder function until all the Boot Services and Runtime Services are available.\r
476\r
022c6d45 477 @param Arg1 Undefined\r
478 @param Arg2 Undefined\r
162ed594 479\r
480 @return EFI_NOT_AVAILABLE_YET\r
481\r
482**/\r
28a00297 483EFI_STATUS\r
484EFIAPI\r
485CoreEfiNotAvailableYetArg2 (\r
486 UINTN Arg1,\r
487 UINTN Arg2\r
488 )\r
28a00297 489{\r
490 //\r
491 // This function should never be executed. If it does, then the architectural protocols\r
492 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the\r
493 // DXE Core and all the Architectural Protocols are complete.\r
494 //\r
495\r
496 return EFI_NOT_AVAILABLE_YET;\r
497}\r
498\r
162ed594 499\r
500/**\r
501 Place holder function until all the Boot Services and Runtime Services are available.\r
502\r
022c6d45 503 @param Arg1 Undefined\r
504 @param Arg2 Undefined\r
505 @param Arg3 Undefined\r
162ed594 506\r
507 @return EFI_NOT_AVAILABLE_YET\r
508\r
509**/\r
28a00297 510EFI_STATUS\r
511EFIAPI\r
512CoreEfiNotAvailableYetArg3 (\r
513 UINTN Arg1,\r
514 UINTN Arg2,\r
515 UINTN Arg3\r
516 )\r
28a00297 517{\r
518 //\r
519 // This function should never be executed. If it does, then the architectural protocols\r
520 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the\r
521 // DXE Core and all the Architectural Protocols are complete.\r
522 //\r
523\r
524 return EFI_NOT_AVAILABLE_YET;\r
525}\r
526\r
162ed594 527\r
528/**\r
529 Place holder function until all the Boot Services and Runtime Services are available.\r
530\r
022c6d45 531 @param Arg1 Undefined\r
532 @param Arg2 Undefined\r
533 @param Arg3 Undefined\r
534 @param Arg4 Undefined\r
162ed594 535\r
536 @return EFI_NOT_AVAILABLE_YET\r
537\r
538**/\r
28a00297 539EFI_STATUS\r
540EFIAPI\r
541CoreEfiNotAvailableYetArg4 (\r
542 UINTN Arg1,\r
543 UINTN Arg2,\r
544 UINTN Arg3,\r
545 UINTN Arg4\r
546 )\r
28a00297 547{\r
548 //\r
549 // This function should never be executed. If it does, then the architectural protocols\r
550 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the\r
551 // DXE Core and all the Architectural Protocols are complete.\r
552 //\r
553\r
554 return EFI_NOT_AVAILABLE_YET;\r
555}\r
556\r
162ed594 557\r
558/**\r
559 Place holder function until all the Boot Services and Runtime Services are available.\r
560\r
022c6d45 561 @param Arg1 Undefined\r
562 @param Arg2 Undefined\r
563 @param Arg3 Undefined\r
564 @param Arg4 Undefined\r
565 @param Arg5 Undefined\r
162ed594 566\r
567 @return EFI_NOT_AVAILABLE_YET\r
568\r
569**/\r
28a00297 570EFI_STATUS\r
571EFIAPI\r
572CoreEfiNotAvailableYetArg5 (\r
573 UINTN Arg1,\r
574 UINTN Arg2,\r
575 UINTN Arg3,\r
576 UINTN Arg4,\r
577 UINTN Arg5\r
578 )\r
28a00297 579{\r
580 //\r
581 // This function should never be executed. If it does, then the architectural protocols\r
582 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the\r
583 // DXE Core and all the Architectural Protocols are complete.\r
584 //\r
585\r
586 return EFI_NOT_AVAILABLE_YET;\r
587}\r
588\r
589\r
162ed594 590\r
591/**\r
592 Searches for a Protocol Interface passed from PEI through a HOB.\r
593\r
022c6d45 594 @param ProtocolGuid The Protocol GUID to search for in the HOB List\r
595 @param Interface A pointer to the interface for the Protocol GUID\r
162ed594 596\r
022c6d45 597 @retval EFI_SUCCESS The Protocol GUID was found and its interface is\r
598 returned in Interface\r
162ed594 599 @retval EFI_NOT_FOUND The Protocol GUID was not found in the HOB List\r
600\r
601**/\r
28a00297 602EFI_STATUS\r
603CoreGetPeiProtocol (\r
604 IN EFI_GUID *ProtocolGuid,\r
605 IN VOID **Interface\r
606 )\r
28a00297 607{\r
608 EFI_HOB_GUID_TYPE *GuidHob;\r
609 VOID *Buffer;\r
610\r
e94a9ff7 611 GuidHob = GetFirstGuidHob (ProtocolGuid);\r
28a00297 612 if (GuidHob == NULL) {\r
613 return EFI_NOT_FOUND;\r
614 }\r
615\r
616 Buffer = GET_GUID_HOB_DATA (GuidHob);\r
617 ASSERT (Buffer != NULL);\r
618\r
619 *Interface = (VOID *)(*(UINTN *)(Buffer));\r
620\r
621 return EFI_SUCCESS;\r
622}\r
623\r
624\r
28a00297 625\r
162ed594 626/**\r
28a00297 627 Calcualte the 32-bit CRC in a EFI table using the service provided by the\r
628 gRuntime service.\r
629\r
162ed594 630 @param Hdr Pointer to an EFI standard header\r
28a00297 631\r
162ed594 632**/\r
633VOID\r
634CalculateEfiHdrCrc (\r
635 IN OUT EFI_TABLE_HEADER *Hdr\r
636 )\r
28a00297 637{\r
638 UINT32 Crc;\r
639\r
640 Hdr->CRC32 = 0;\r
641\r
642 //\r
643 // If gDxeCoreBS->CalculateCrce32 () == CoreEfiNotAvailableYet () then\r
644 // Crc will come back as zero if we set it to zero here\r
645 //\r
646 Crc = 0;\r
647 gDxeCoreBS->CalculateCrc32 ((UINT8 *)Hdr, Hdr->HeaderSize, &Crc);\r
648 Hdr->CRC32 = Crc;\r
649}\r
650\r
651\r
652\r
162ed594 653\r
654/**\r
655 Terminates all boot services.\r
656\r
022c6d45 657 @param ImageHandle Handle that identifies the exiting image.\r
162ed594 658 @param MapKey Key to the latest memory map.\r
659\r
022c6d45 660 @retval EFI_SUCCESS Boot Services terminated\r
162ed594 661 @retval EFI_INVALID_PARAMETER MapKey is incorrect.\r
662\r
663**/\r
28a00297 664EFI_STATUS\r
665EFIAPI\r
666CoreExitBootServices (\r
667 IN EFI_HANDLE ImageHandle,\r
668 IN UINTN MapKey\r
669 )\r
28a00297 670{\r
e94a9ff7 671 EFI_STATUS Status;\r
672 EFI_STATUS StatusTemp;\r
822360ee
LG
673 EFI_TCG_PLATFORM_PROTOCOL *TcgPlatformProtocol;\r
674\r
675 //\r
022c6d45 676 // Measure invocation of ExitBootServices,\r
822360ee
LG
677 // which is defined by TCG_EFI_Platform_1_20_Final Specification\r
678 //\r
679 TcgPlatformProtocol = NULL;\r
680 Status = CoreLocateProtocol (\r
681 &gEfiTcgPlatformProtocolGuid,\r
682 NULL,\r
683 (VOID **) &TcgPlatformProtocol\r
684 );\r
685 if (!EFI_ERROR (Status)) {\r
686 Status = TcgPlatformProtocol->MeasureAction (EFI_EXIT_BOOT_SERVICES_INVOCATION);\r
687 ASSERT_EFI_ERROR (Status);\r
688 }\r
28a00297 689\r
690 //\r
691 // Terminate memory services if the MapKey matches\r
692 //\r
693 Status = CoreTerminateMemoryMap (MapKey);\r
694 if (EFI_ERROR (Status)) {\r
822360ee
LG
695 //\r
696 // Measure failure of ExitBootServices\r
697 //\r
698 if (TcgPlatformProtocol != NULL) {\r
699 StatusTemp = TcgPlatformProtocol->MeasureAction (EFI_EXIT_BOOT_SERVICES_FAILED);\r
700 ASSERT_EFI_ERROR (StatusTemp);\r
701 }\r
702\r
28a00297 703 return Status;\r
704 }\r
705\r
706 //\r
707 // Notify other drivers that we are exiting boot services.\r
708 //\r
709 CoreNotifySignalList (&gEfiEventExitBootServicesGuid);\r
710\r
711 //\r
712 // Disable Timer\r
713 //\r
714 gTimer->SetTimerPeriod (gTimer, 0);\r
715\r
716 //\r
717 // Disable CPU Interrupts\r
718 //\r
719 gCpu->DisableInterrupt (gCpu);\r
720\r
721 //\r
722 // Report that ExitBootServices() has been called\r
723 //\r
eba54e17 724 // We are using gEfiCallerIdGuid as the caller ID for Dxe Core\r
28a00297 725 //\r
797a9d67 726 CoreReportProgressCode (FixedPcdGet32 (PcdStatusCodeValueBootServiceExit));\r
28a00297 727\r
728 //\r
729 // Clear the non-runtime values of the EFI System Table\r
730 //\r
731 gDxeCoreST->BootServices = NULL;\r
732 gDxeCoreST->ConIn = NULL;\r
733 gDxeCoreST->ConsoleInHandle = NULL;\r
734 gDxeCoreST->ConOut = NULL;\r
735 gDxeCoreST->ConsoleOutHandle = NULL;\r
736 gDxeCoreST->StdErr = NULL;\r
737 gDxeCoreST->StandardErrorHandle = NULL;\r
738\r
739 //\r
740 // Recompute the 32-bit CRC of the EFI System Table\r
741 //\r
742 CalculateEfiHdrCrc (&gDxeCoreST->Hdr);\r
743\r
744 //\r
745 // Zero out the Boot Service Table\r
746 //\r
e94a9ff7 747 ZeroMem (gDxeCoreBS, sizeof (EFI_BOOT_SERVICES));\r
28a00297 748 gDxeCoreBS = NULL;\r
749\r
750 //\r
751 // Update the AtRuntime field in Runtiem AP.\r
752 //\r
753 gRuntime->AtRuntime = TRUE;\r
754\r
822360ee
LG
755 //\r
756 // Measure success of ExitBootServices\r
757 //\r
758 if (TcgPlatformProtocol != NULL) {\r
759 StatusTemp = TcgPlatformProtocol->MeasureAction (EFI_EXIT_BOOT_SERVICES_SUCCEEDED);\r
760 ASSERT_EFI_ERROR (StatusTemp);\r
761 }\r
022c6d45 762\r
28a00297 763 return Status;\r
764}\r
765\r
162ed594 766\r
767/**\r
768 Given a compressed source buffer, this function retrieves the size of the\r
769 uncompressed buffer and the size of the scratch buffer required to decompress\r
770 the compressed source buffer.\r
771\r
772 The GetInfo() function retrieves the size of the uncompressed buffer and the\r
773 temporary scratch buffer required to decompress the buffer specified by Source\r
774 and SourceSize. If the size of the uncompressed buffer or the size of the\r
775 scratch buffer cannot be determined from the compressed data specified by\r
776 Source and SourceData, then EFI_INVALID_PARAMETER is returned. Otherwise, the\r
777 size of the uncompressed buffer is returned in DestinationSize, the size of\r
778 the scratch buffer is returned in ScratchSize, and EFI_SUCCESS is returned.\r
779 The GetInfo() function does not have scratch buffer available to perform a\r
780 thorough checking of the validity of the source data. It just retrieves the\r
781 "Original Size" field from the beginning bytes of the source data and output\r
782 it as DestinationSize. And ScratchSize is specific to the decompression\r
783 implementation.\r
784\r
785 @param This A pointer to the EFI_DECOMPRESS_PROTOCOL instance.\r
786 @param Source The source buffer containing the compressed data.\r
787 @param SourceSize The size, in bytes, of the source buffer.\r
788 @param DestinationSize A pointer to the size, in bytes, of the\r
789 uncompressed buffer that will be generated when the\r
790 compressed buffer specified by Source and\r
791 SourceSize is decompressed.\r
792 @param ScratchSize A pointer to the size, in bytes, of the scratch\r
793 buffer that is required to decompress the\r
794 compressed buffer specified by Source and\r
795 SourceSize.\r
022c6d45 796\r
162ed594 797 @retval EFI_SUCCESS The size of the uncompressed data was returned in\r
798 DestinationSize and the size of the scratch buffer\r
799 was returned in ScratchSize.\r
800 @retval EFI_INVALID_PARAMETER The size of the uncompressed data or the size of\r
801 the scratch buffer cannot be determined from the\r
802 compressed data specified by Source and\r
803 SourceSize.\r
804\r
805**/\r
28a00297 806EFI_STATUS\r
162ed594 807EFIAPI\r
28a00297 808DxeMainUefiDecompressGetInfo (\r
809 IN EFI_DECOMPRESS_PROTOCOL *This,\r
810 IN VOID *Source,\r
811 IN UINT32 SourceSize,\r
812 OUT UINT32 *DestinationSize,\r
813 OUT UINT32 *ScratchSize\r
814 )\r
815{\r
e94a9ff7 816 if (Source == NULL || DestinationSize == NULL || ScratchSize == NULL) {\r
28a00297 817 return EFI_INVALID_PARAMETER;\r
818 }\r
819 return UefiDecompressGetInfo (Source, SourceSize, DestinationSize, ScratchSize);\r
820}\r
821\r
162ed594 822\r
823/**\r
824 Decompresses a compressed source buffer.\r
825\r
826 The Decompress() function extracts decompressed data to its original form.\r
827 This protocol is designed so that the decompression algorithm can be\r
828 implemented without using any memory services. As a result, the Decompress()\r
829 Function is not allowed to call AllocatePool() or AllocatePages() in its\r
db405d1b 830 implementation. It is the caller's responsibility to allocate and free the\r
162ed594 831 Destination and Scratch buffers.\r
832 If the compressed source data specified by Source and SourceSize is\r
833 sucessfully decompressed into Destination, then EFI_SUCCESS is returned. If\r
834 the compressed source data specified by Source and SourceSize is not in a\r
835 valid compressed data format, then EFI_INVALID_PARAMETER is returned.\r
836\r
837 @param This A pointer to the EFI_DECOMPRESS_PROTOCOL instance.\r
838 @param Source The source buffer containing the compressed data.\r
839 @param SourceSize SourceSizeThe size of source data.\r
840 @param Destination On output, the destination buffer that contains\r
841 the uncompressed data.\r
842 @param DestinationSize The size of the destination buffer. The size of\r
843 the destination buffer needed is obtained from\r
844 EFI_DECOMPRESS_PROTOCOL.GetInfo().\r
845 @param Scratch A temporary scratch buffer that is used to perform\r
846 the decompression.\r
847 @param ScratchSize The size of scratch buffer. The size of the\r
848 scratch buffer needed is obtained from GetInfo().\r
022c6d45 849\r
162ed594 850 @retval EFI_SUCCESS Decompression completed successfully, and the\r
851 uncompressed buffer is returned in Destination.\r
852 @retval EFI_INVALID_PARAMETER The source buffer specified by Source and\r
853 SourceSize is corrupted (not in a valid\r
854 compressed format).\r
855\r
856**/\r
28a00297 857EFI_STATUS\r
858EFIAPI\r
859DxeMainUefiDecompress (\r
e94a9ff7 860 IN EFI_DECOMPRESS_PROTOCOL *This,\r
28a00297 861 IN VOID *Source,\r
862 IN UINT32 SourceSize,\r
863 IN OUT VOID *Destination,\r
864 IN UINT32 DestinationSize,\r
865 IN OUT VOID *Scratch,\r
866 IN UINT32 ScratchSize\r
867 )\r
868{\r
869 EFI_STATUS Status;\r
870 UINT32 TestDestinationSize;\r
871 UINT32 TestScratchSize;\r
022c6d45 872\r
e94a9ff7 873 if (Source == NULL || Destination== NULL || Scratch == NULL) {\r
28a00297 874 return EFI_INVALID_PARAMETER;\r
875 }\r
022c6d45 876\r
28a00297 877 Status = UefiDecompressGetInfo (Source, SourceSize, &TestDestinationSize, &TestScratchSize);\r
878 if (EFI_ERROR (Status)) {\r
879 return Status;\r
880 }\r
881\r
882 if (ScratchSize < TestScratchSize || DestinationSize < TestDestinationSize) {\r
883 return RETURN_INVALID_PARAMETER;\r
884 }\r
885\r
886 return UefiDecompress (Source, Destination, Scratch);\r
887}\r