]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c
Clean up DxeCore to use report status code macros in ReportStatusCode to retire CoreR...
[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
9c4ac31c 15#include "DxeMain.h"\r
28a00297 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
28a00297 202EFI_DXE_SERVICES *gDxeCoreDS = &mDxeServices;\r
203EFI_SYSTEM_TABLE *gDxeCoreST = NULL;\r
204\r
205//\r
206// For debug initialize gDxeCoreRT to template. gDxeCoreRT must be allocated from RT memory\r
207// but gDxeCoreRT is used for ASSERT () and DEBUG () type macros so lets give it\r
208// a value that will not cause debug infrastructure to crash early on.\r
209//\r
210EFI_RUNTIME_SERVICES *gDxeCoreRT = &mEfiRuntimeServicesTableTemplate;\r
211EFI_HANDLE gDxeCoreImageHandle = NULL;\r
212\r
28a00297 213\r
214//\r
215// EFI Decompress Protocol\r
216//\r
217EFI_DECOMPRESS_PROTOCOL gEfiDecompress = {\r
218 DxeMainUefiDecompressGetInfo,\r
219 DxeMainUefiDecompress\r
220};\r
221\r
222//\r
223// Main entry point to the DXE Core\r
224//\r
28a00297 225\r
162ed594 226/**\r
28a00297 227 Main entry point to DXE Core.\r
228\r
022c6d45 229 @param HobStart Pointer to the beginning of the HOB List from PEI.\r
28a00297 230\r
e94a9ff7 231 @return This function should never return.\r
28a00297 232\r
162ed594 233**/\r
234VOID\r
235EFIAPI\r
236DxeMain (\r
237 IN VOID *HobStart\r
238 )\r
28a00297 239{\r
240 EFI_STATUS Status;\r
241 EFI_PHYSICAL_ADDRESS MemoryBaseAddress;\r
242 UINT64 MemoryLength;\r
243\r
28a00297 244 //\r
245 // Initialize Memory Services\r
246 //\r
247 CoreInitializeMemoryServices (&HobStart, &MemoryBaseAddress, &MemoryLength);\r
248\r
249 //\r
250 // Allocate the EFI System Table and EFI Runtime Service Table from EfiRuntimeServicesData\r
251 // Use the templates to initialize the contents of the EFI System Table and EFI Runtime Services Table\r
252 //\r
9c4ac31c 253 gDxeCoreST = AllocateRuntimeCopyPool (sizeof (EFI_SYSTEM_TABLE), &mEfiSystemTableTemplate);\r
28a00297 254 ASSERT (gDxeCoreST != NULL);\r
255\r
9c4ac31c 256 gDxeCoreRT = AllocateRuntimeCopyPool (sizeof (EFI_RUNTIME_SERVICES), &mEfiRuntimeServicesTableTemplate);\r
28a00297 257 ASSERT (gDxeCoreRT != NULL);\r
258\r
259 gDxeCoreST->RuntimeServices = gDxeCoreRT;\r
260\r
261 //\r
262 // Start the Image Services.\r
263 //\r
264 Status = CoreInitializeImageServices (HobStart);\r
265 ASSERT_EFI_ERROR (Status);\r
266\r
267 //\r
268 // Call constructor for all libraries\r
269 //\r
270 ProcessLibraryConstructorList (gDxeCoreImageHandle, gDxeCoreST);\r
271 PERF_END (0,PEI_TOK, NULL, 0) ;\r
272 PERF_START (0,DXE_TOK, NULL, 0) ;\r
273\r
274 //\r
275 // Initialize the Global Coherency Domain Services\r
276 //\r
277 Status = CoreInitializeGcdServices (&HobStart, MemoryBaseAddress, MemoryLength);\r
278 ASSERT_EFI_ERROR (Status);\r
279\r
280 //\r
281 // Install the DXE Services Table into the EFI System Tables's Configuration Table\r
282 //\r
283 Status = CoreInstallConfigurationTable (&gEfiDxeServicesTableGuid, gDxeCoreDS);\r
284 ASSERT_EFI_ERROR (Status);\r
285\r
286 //\r
287 // Install the HOB List into the EFI System Tables's Configuration Table\r
288 //\r
289 Status = CoreInstallConfigurationTable (&gEfiHobListGuid, HobStart);\r
290 ASSERT_EFI_ERROR (Status);\r
291\r
292 //\r
293 // Install Memory Type Information Table into the EFI System Tables's Configuration Table\r
294 //\r
295 Status = CoreInstallConfigurationTable (&gEfiMemoryTypeInformationGuid, &gMemoryTypeInformation);\r
296 ASSERT_EFI_ERROR (Status);\r
297\r
298 //\r
299 // Initialize the ReportStatusCode with PEI version, if available\r
300 //\r
e94a9ff7 301 CoreGetPeiProtocol (&gEfiStatusCodeRuntimeProtocolGuid, (VOID **) &gStatusCode->ReportStatusCode);\r
28a00297 302\r
303 //\r
304 // Report Status Code here for DXE_ENTRY_POINT once it is available\r
305 //\r
2680a308 306 REPORT_STATUS_CODE (\r
307 EFI_PROGRESS_CODE,\r
308 FixedPcdGet32(PcdStatusCodeValueDxeCoreEntry)\r
309 );\r
28a00297 310\r
311 //\r
312 // Create the aligned system table pointer structure that is used by external\r
313 // debuggers to locate the system table... Also, install debug image info\r
314 // configuration table.\r
315 //\r
316 CoreInitializeDebugImageInfoTable ();\r
317 CoreNewDebugImageInfoEntry (\r
318 EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL,\r
319 gDxeCoreLoadedImage,\r
320 gDxeCoreImageHandle\r
321 );\r
322\r
e94a9ff7 323 DEBUG ((DEBUG_INFO | DEBUG_LOAD, "HOBLIST address in DXE = 0x%p\n", HobStart));\r
28a00297 324\r
325 //\r
326 // Initialize the Event Services\r
327 //\r
328 Status = CoreInitializeEventServices ();\r
329 ASSERT_EFI_ERROR (Status);\r
330\r
331\r
332 //\r
333 // Get the Protocols that were passed in from PEI to DXE through GUIDed HOBs\r
334 //\r
335 // These Protocols are not architectural. This implementation is sharing code between\r
336 // PEI and DXE in order to save FLASH space. These Protocols could also be implemented\r
337 // as part of the DXE Core. However, that would also require the DXE Core to be ported\r
338 // each time a different CPU is used, a different Decompression algorithm is used, or a\r
339 // different Image type is used. By placing these Protocols in PEI, the DXE Core remains\r
340 // generic, and only PEI and the Arch Protocols need to be ported from Platform to Platform,\r
341 // and from CPU to CPU.\r
342 //\r
343\r
344 //\r
345 // Publish the EFI, Tiano, and Custom Decompress protocols for use by other DXE components\r
346 //\r
347 Status = CoreInstallMultipleProtocolInterfaces (\r
e94a9ff7 348 &mDecompressHandle,\r
349 &gEfiDecompressProtocolGuid, &gEfiDecompress,\r
350 NULL\r
351 );\r
28a00297 352 ASSERT_EFI_ERROR (Status);\r
353\r
28a00297 354 //\r
355 // Register for the GUIDs of the Architectural Protocols, so the rest of the\r
356 // EFI Boot Services and EFI Runtime Services tables can be filled in.\r
357 //\r
358 CoreNotifyOnArchProtocolInstallation ();\r
359\r
360 //\r
361 // Produce Firmware Volume Protocols, one for each FV in the HOB list.\r
362 //\r
363 Status = FwVolBlockDriverInit (gDxeCoreImageHandle, gDxeCoreST);\r
364 ASSERT_EFI_ERROR (Status);\r
365\r
366 Status = FwVolDriverInit (gDxeCoreImageHandle, gDxeCoreST);\r
367 ASSERT_EFI_ERROR (Status);\r
368\r
369 //\r
370 // Produce the Section Extraction Protocol\r
371 //\r
372 Status = InitializeSectionExtraction (gDxeCoreImageHandle, gDxeCoreST);\r
373 ASSERT_EFI_ERROR (Status);\r
374\r
375 //\r
376 // Initialize the DXE Dispatcher\r
377 //\r
378 PERF_START (0,"CoreInitializeDispatcher", "DxeMain", 0) ;\r
379 CoreInitializeDispatcher ();\r
380 PERF_END (0,"CoreInitializeDispatcher", "DxeMain", 0) ;\r
381\r
382 //\r
383 // Invoke the DXE Dispatcher\r
384 //\r
385 PERF_START (0, "CoreDispatcher", "DxeMain", 0);\r
386 CoreDispatcher ();\r
387 PERF_END (0, "CoreDispatcher", "DxeMain", 0);\r
388\r
389 //\r
390 // Display Architectural protocols that were not loaded if this is DEBUG build\r
391 //\r
392 DEBUG_CODE_BEGIN ();\r
393 CoreDisplayMissingArchProtocols ();\r
394 DEBUG_CODE_END ();\r
395\r
396 //\r
397 // Assert if the Architectural Protocols are not present.\r
398 //\r
399 ASSERT_EFI_ERROR (CoreAllEfiServicesAvailable ());\r
400\r
401 //\r
402 // Report Status code before transfer control to BDS\r
403 //\r
2680a308 404 REPORT_STATUS_CODE (\r
405 EFI_PROGRESS_CODE,\r
406 FixedPcdGet32 (PcdStatusCodeValueDxeCoreHandoffToBds)\r
407 );\r
022c6d45 408\r
28a00297 409 //\r
410 // Display any drivers that were not dispatched because dependency expression\r
411 // evaluated to false if this is a debug build\r
412 //\r
413 DEBUG_CODE_BEGIN ();\r
414 CoreDisplayDiscoveredNotDispatched ();\r
415 DEBUG_CODE_END ();\r
416\r
417 //\r
418 // Transfer control to the BDS Architectural Protocol\r
419 //\r
420 gBds->Entry (gBds);\r
421\r
422 //\r
423 // BDS should never return\r
424 //\r
425 ASSERT (FALSE);\r
426 CpuDeadLoop ();\r
427}\r
428\r
429\r
162ed594 430\r
431/**\r
432 Place holder function until all the Boot Services and Runtime Services are\r
433 available.\r
434\r
435 @return EFI_NOT_AVAILABLE_YET\r
436\r
437**/\r
28a00297 438EFI_STATUS\r
439EFIAPI\r
440CoreEfiNotAvailableYetArg0 (\r
441 VOID\r
442 )\r
28a00297 443{\r
444 //\r
445 // This function should never be executed. If it does, then the architectural protocols\r
446 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the\r
447 // DXE Core and all the Architectural Protocols are complete.\r
448 //\r
449\r
450 return EFI_NOT_AVAILABLE_YET;\r
451}\r
452\r
162ed594 453\r
454/**\r
455 Place holder function until all the Boot Services and Runtime Services are\r
456 available.\r
457\r
022c6d45 458 @param Arg1 Undefined\r
162ed594 459\r
460 @return EFI_NOT_AVAILABLE_YET\r
461\r
462**/\r
28a00297 463EFI_STATUS\r
464EFIAPI\r
465CoreEfiNotAvailableYetArg1 (\r
466 UINTN Arg1\r
467 )\r
28a00297 468{\r
469 //\r
470 // This function should never be executed. If it does, then the architectural protocols\r
471 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the\r
472 // DXE Core and all the Architectural Protocols are complete.\r
473 //\r
474\r
475 return EFI_NOT_AVAILABLE_YET;\r
476}\r
477\r
162ed594 478\r
479/**\r
480 Place holder function until all the Boot Services and Runtime Services are available.\r
481\r
022c6d45 482 @param Arg1 Undefined\r
483 @param Arg2 Undefined\r
162ed594 484\r
485 @return EFI_NOT_AVAILABLE_YET\r
486\r
487**/\r
28a00297 488EFI_STATUS\r
489EFIAPI\r
490CoreEfiNotAvailableYetArg2 (\r
491 UINTN Arg1,\r
492 UINTN Arg2\r
493 )\r
28a00297 494{\r
495 //\r
496 // This function should never be executed. If it does, then the architectural protocols\r
497 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the\r
498 // DXE Core and all the Architectural Protocols are complete.\r
499 //\r
500\r
501 return EFI_NOT_AVAILABLE_YET;\r
502}\r
503\r
162ed594 504\r
505/**\r
506 Place holder function until all the Boot Services and Runtime Services are available.\r
507\r
022c6d45 508 @param Arg1 Undefined\r
509 @param Arg2 Undefined\r
510 @param Arg3 Undefined\r
162ed594 511\r
512 @return EFI_NOT_AVAILABLE_YET\r
513\r
514**/\r
28a00297 515EFI_STATUS\r
516EFIAPI\r
517CoreEfiNotAvailableYetArg3 (\r
518 UINTN Arg1,\r
519 UINTN Arg2,\r
520 UINTN Arg3\r
521 )\r
28a00297 522{\r
523 //\r
524 // This function should never be executed. If it does, then the architectural protocols\r
525 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the\r
526 // DXE Core and all the Architectural Protocols are complete.\r
527 //\r
528\r
529 return EFI_NOT_AVAILABLE_YET;\r
530}\r
531\r
162ed594 532\r
533/**\r
534 Place holder function until all the Boot Services and Runtime Services are available.\r
535\r
022c6d45 536 @param Arg1 Undefined\r
537 @param Arg2 Undefined\r
538 @param Arg3 Undefined\r
539 @param Arg4 Undefined\r
162ed594 540\r
541 @return EFI_NOT_AVAILABLE_YET\r
542\r
543**/\r
28a00297 544EFI_STATUS\r
545EFIAPI\r
546CoreEfiNotAvailableYetArg4 (\r
547 UINTN Arg1,\r
548 UINTN Arg2,\r
549 UINTN Arg3,\r
550 UINTN Arg4\r
551 )\r
28a00297 552{\r
553 //\r
554 // This function should never be executed. If it does, then the architectural protocols\r
555 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the\r
556 // DXE Core and all the Architectural Protocols are complete.\r
557 //\r
558\r
559 return EFI_NOT_AVAILABLE_YET;\r
560}\r
561\r
162ed594 562\r
563/**\r
564 Place holder function until all the Boot Services and Runtime Services are available.\r
565\r
022c6d45 566 @param Arg1 Undefined\r
567 @param Arg2 Undefined\r
568 @param Arg3 Undefined\r
569 @param Arg4 Undefined\r
570 @param Arg5 Undefined\r
162ed594 571\r
572 @return EFI_NOT_AVAILABLE_YET\r
573\r
574**/\r
28a00297 575EFI_STATUS\r
576EFIAPI\r
577CoreEfiNotAvailableYetArg5 (\r
578 UINTN Arg1,\r
579 UINTN Arg2,\r
580 UINTN Arg3,\r
581 UINTN Arg4,\r
582 UINTN Arg5\r
583 )\r
28a00297 584{\r
585 //\r
586 // This function should never be executed. If it does, then the architectural protocols\r
587 // have not been designed correctly. The CpuBreakpoint () is commented out for now until the\r
588 // DXE Core and all the Architectural Protocols are complete.\r
589 //\r
590\r
591 return EFI_NOT_AVAILABLE_YET;\r
592}\r
593\r
594\r
162ed594 595\r
596/**\r
597 Searches for a Protocol Interface passed from PEI through a HOB.\r
598\r
022c6d45 599 @param ProtocolGuid The Protocol GUID to search for in the HOB List\r
600 @param Interface A pointer to the interface for the Protocol GUID\r
162ed594 601\r
022c6d45 602 @retval EFI_SUCCESS The Protocol GUID was found and its interface is\r
603 returned in Interface\r
162ed594 604 @retval EFI_NOT_FOUND The Protocol GUID was not found in the HOB List\r
605\r
606**/\r
28a00297 607EFI_STATUS\r
608CoreGetPeiProtocol (\r
609 IN EFI_GUID *ProtocolGuid,\r
610 IN VOID **Interface\r
611 )\r
28a00297 612{\r
613 EFI_HOB_GUID_TYPE *GuidHob;\r
614 VOID *Buffer;\r
615\r
e94a9ff7 616 GuidHob = GetFirstGuidHob (ProtocolGuid);\r
28a00297 617 if (GuidHob == NULL) {\r
618 return EFI_NOT_FOUND;\r
619 }\r
620\r
621 Buffer = GET_GUID_HOB_DATA (GuidHob);\r
622 ASSERT (Buffer != NULL);\r
623\r
624 *Interface = (VOID *)(*(UINTN *)(Buffer));\r
625\r
626 return EFI_SUCCESS;\r
627}\r
628\r
629\r
28a00297 630\r
162ed594 631/**\r
28a00297 632 Calcualte the 32-bit CRC in a EFI table using the service provided by the\r
633 gRuntime service.\r
634\r
162ed594 635 @param Hdr Pointer to an EFI standard header\r
28a00297 636\r
162ed594 637**/\r
638VOID\r
639CalculateEfiHdrCrc (\r
640 IN OUT EFI_TABLE_HEADER *Hdr\r
641 )\r
28a00297 642{\r
643 UINT32 Crc;\r
644\r
645 Hdr->CRC32 = 0;\r
646\r
647 //\r
0e9b156d 648 // If gBS->CalculateCrce32 () == CoreEfiNotAvailableYet () then\r
28a00297 649 // Crc will come back as zero if we set it to zero here\r
650 //\r
651 Crc = 0;\r
0e9b156d 652 gBS->CalculateCrc32 ((UINT8 *)Hdr, Hdr->HeaderSize, &Crc);\r
28a00297 653 Hdr->CRC32 = Crc;\r
654}\r
655\r
656\r
657\r
162ed594 658\r
659/**\r
660 Terminates all boot services.\r
661\r
022c6d45 662 @param ImageHandle Handle that identifies the exiting image.\r
162ed594 663 @param MapKey Key to the latest memory map.\r
664\r
022c6d45 665 @retval EFI_SUCCESS Boot Services terminated\r
162ed594 666 @retval EFI_INVALID_PARAMETER MapKey is incorrect.\r
667\r
668**/\r
28a00297 669EFI_STATUS\r
670EFIAPI\r
671CoreExitBootServices (\r
672 IN EFI_HANDLE ImageHandle,\r
673 IN UINTN MapKey\r
674 )\r
28a00297 675{\r
e94a9ff7 676 EFI_STATUS Status;\r
677 EFI_STATUS StatusTemp;\r
822360ee
LG
678 EFI_TCG_PLATFORM_PROTOCOL *TcgPlatformProtocol;\r
679\r
680 //\r
022c6d45 681 // Measure invocation of ExitBootServices,\r
822360ee
LG
682 // which is defined by TCG_EFI_Platform_1_20_Final Specification\r
683 //\r
684 TcgPlatformProtocol = NULL;\r
685 Status = CoreLocateProtocol (\r
686 &gEfiTcgPlatformProtocolGuid,\r
687 NULL,\r
688 (VOID **) &TcgPlatformProtocol\r
689 );\r
690 if (!EFI_ERROR (Status)) {\r
691 Status = TcgPlatformProtocol->MeasureAction (EFI_EXIT_BOOT_SERVICES_INVOCATION);\r
692 ASSERT_EFI_ERROR (Status);\r
693 }\r
28a00297 694\r
695 //\r
696 // Terminate memory services if the MapKey matches\r
697 //\r
698 Status = CoreTerminateMemoryMap (MapKey);\r
699 if (EFI_ERROR (Status)) {\r
822360ee
LG
700 //\r
701 // Measure failure of ExitBootServices\r
702 //\r
703 if (TcgPlatformProtocol != NULL) {\r
704 StatusTemp = TcgPlatformProtocol->MeasureAction (EFI_EXIT_BOOT_SERVICES_FAILED);\r
705 ASSERT_EFI_ERROR (StatusTemp);\r
706 }\r
707\r
28a00297 708 return Status;\r
709 }\r
710\r
711 //\r
712 // Notify other drivers that we are exiting boot services.\r
713 //\r
714 CoreNotifySignalList (&gEfiEventExitBootServicesGuid);\r
715\r
716 //\r
717 // Disable Timer\r
718 //\r
719 gTimer->SetTimerPeriod (gTimer, 0);\r
720\r
721 //\r
722 // Disable CPU Interrupts\r
723 //\r
724 gCpu->DisableInterrupt (gCpu);\r
725\r
726 //\r
727 // Report that ExitBootServices() has been called\r
728 //\r
2680a308 729 REPORT_STATUS_CODE (\r
730 EFI_PROGRESS_CODE,\r
731 FixedPcdGet32 (PcdStatusCodeValueBootServiceExit)\r
732 );\r
28a00297 733\r
734 //\r
735 // Clear the non-runtime values of the EFI System Table\r
736 //\r
737 gDxeCoreST->BootServices = NULL;\r
738 gDxeCoreST->ConIn = NULL;\r
739 gDxeCoreST->ConsoleInHandle = NULL;\r
740 gDxeCoreST->ConOut = NULL;\r
741 gDxeCoreST->ConsoleOutHandle = NULL;\r
742 gDxeCoreST->StdErr = NULL;\r
743 gDxeCoreST->StandardErrorHandle = NULL;\r
744\r
745 //\r
746 // Recompute the 32-bit CRC of the EFI System Table\r
747 //\r
748 CalculateEfiHdrCrc (&gDxeCoreST->Hdr);\r
749\r
750 //\r
751 // Zero out the Boot Service Table\r
752 //\r
0e9b156d 753 ZeroMem (gBS, sizeof (EFI_BOOT_SERVICES));\r
754 gBS = NULL;\r
28a00297 755\r
756 //\r
757 // Update the AtRuntime field in Runtiem AP.\r
758 //\r
759 gRuntime->AtRuntime = TRUE;\r
760\r
822360ee
LG
761 //\r
762 // Measure success of ExitBootServices\r
763 //\r
764 if (TcgPlatformProtocol != NULL) {\r
765 StatusTemp = TcgPlatformProtocol->MeasureAction (EFI_EXIT_BOOT_SERVICES_SUCCEEDED);\r
766 ASSERT_EFI_ERROR (StatusTemp);\r
767 }\r
022c6d45 768\r
28a00297 769 return Status;\r
770}\r
771\r
162ed594 772\r
773/**\r
774 Given a compressed source buffer, this function retrieves the size of the\r
775 uncompressed buffer and the size of the scratch buffer required to decompress\r
776 the compressed source buffer.\r
777\r
778 The GetInfo() function retrieves the size of the uncompressed buffer and the\r
779 temporary scratch buffer required to decompress the buffer specified by Source\r
780 and SourceSize. If the size of the uncompressed buffer or the size of the\r
781 scratch buffer cannot be determined from the compressed data specified by\r
782 Source and SourceData, then EFI_INVALID_PARAMETER is returned. Otherwise, the\r
783 size of the uncompressed buffer is returned in DestinationSize, the size of\r
784 the scratch buffer is returned in ScratchSize, and EFI_SUCCESS is returned.\r
785 The GetInfo() function does not have scratch buffer available to perform a\r
786 thorough checking of the validity of the source data. It just retrieves the\r
787 "Original Size" field from the beginning bytes of the source data and output\r
788 it as DestinationSize. And ScratchSize is specific to the decompression\r
789 implementation.\r
790\r
791 @param This A pointer to the EFI_DECOMPRESS_PROTOCOL instance.\r
792 @param Source The source buffer containing the compressed data.\r
793 @param SourceSize The size, in bytes, of the source buffer.\r
794 @param DestinationSize A pointer to the size, in bytes, of the\r
795 uncompressed buffer that will be generated when the\r
796 compressed buffer specified by Source and\r
797 SourceSize is decompressed.\r
798 @param ScratchSize A pointer to the size, in bytes, of the scratch\r
799 buffer that is required to decompress the\r
800 compressed buffer specified by Source and\r
801 SourceSize.\r
022c6d45 802\r
162ed594 803 @retval EFI_SUCCESS The size of the uncompressed data was returned in\r
804 DestinationSize and the size of the scratch buffer\r
805 was returned in ScratchSize.\r
806 @retval EFI_INVALID_PARAMETER The size of the uncompressed data or the size of\r
807 the scratch buffer cannot be determined from the\r
808 compressed data specified by Source and\r
809 SourceSize.\r
810\r
811**/\r
28a00297 812EFI_STATUS\r
162ed594 813EFIAPI\r
28a00297 814DxeMainUefiDecompressGetInfo (\r
815 IN EFI_DECOMPRESS_PROTOCOL *This,\r
816 IN VOID *Source,\r
817 IN UINT32 SourceSize,\r
818 OUT UINT32 *DestinationSize,\r
819 OUT UINT32 *ScratchSize\r
820 )\r
821{\r
e94a9ff7 822 if (Source == NULL || DestinationSize == NULL || ScratchSize == NULL) {\r
28a00297 823 return EFI_INVALID_PARAMETER;\r
824 }\r
825 return UefiDecompressGetInfo (Source, SourceSize, DestinationSize, ScratchSize);\r
826}\r
827\r
162ed594 828\r
829/**\r
830 Decompresses a compressed source buffer.\r
831\r
832 The Decompress() function extracts decompressed data to its original form.\r
833 This protocol is designed so that the decompression algorithm can be\r
834 implemented without using any memory services. As a result, the Decompress()\r
835 Function is not allowed to call AllocatePool() or AllocatePages() in its\r
db405d1b 836 implementation. It is the caller's responsibility to allocate and free the\r
162ed594 837 Destination and Scratch buffers.\r
838 If the compressed source data specified by Source and SourceSize is\r
839 sucessfully decompressed into Destination, then EFI_SUCCESS is returned. If\r
840 the compressed source data specified by Source and SourceSize is not in a\r
841 valid compressed data format, then EFI_INVALID_PARAMETER is returned.\r
842\r
843 @param This A pointer to the EFI_DECOMPRESS_PROTOCOL instance.\r
844 @param Source The source buffer containing the compressed data.\r
845 @param SourceSize SourceSizeThe size of source data.\r
846 @param Destination On output, the destination buffer that contains\r
847 the uncompressed data.\r
848 @param DestinationSize The size of the destination buffer. The size of\r
849 the destination buffer needed is obtained from\r
850 EFI_DECOMPRESS_PROTOCOL.GetInfo().\r
851 @param Scratch A temporary scratch buffer that is used to perform\r
852 the decompression.\r
853 @param ScratchSize The size of scratch buffer. The size of the\r
854 scratch buffer needed is obtained from GetInfo().\r
022c6d45 855\r
162ed594 856 @retval EFI_SUCCESS Decompression completed successfully, and the\r
857 uncompressed buffer is returned in Destination.\r
858 @retval EFI_INVALID_PARAMETER The source buffer specified by Source and\r
859 SourceSize is corrupted (not in a valid\r
860 compressed format).\r
861\r
862**/\r
28a00297 863EFI_STATUS\r
864EFIAPI\r
865DxeMainUefiDecompress (\r
e94a9ff7 866 IN EFI_DECOMPRESS_PROTOCOL *This,\r
28a00297 867 IN VOID *Source,\r
868 IN UINT32 SourceSize,\r
869 IN OUT VOID *Destination,\r
870 IN UINT32 DestinationSize,\r
871 IN OUT VOID *Scratch,\r
872 IN UINT32 ScratchSize\r
873 )\r
874{\r
875 EFI_STATUS Status;\r
876 UINT32 TestDestinationSize;\r
877 UINT32 TestScratchSize;\r
022c6d45 878\r
e94a9ff7 879 if (Source == NULL || Destination== NULL || Scratch == NULL) {\r
28a00297 880 return EFI_INVALID_PARAMETER;\r
881 }\r
022c6d45 882\r
28a00297 883 Status = UefiDecompressGetInfo (Source, SourceSize, &TestDestinationSize, &TestScratchSize);\r
884 if (EFI_ERROR (Status)) {\r
885 return Status;\r
886 }\r
887\r
888 if (ScratchSize < TestScratchSize || DestinationSize < TestDestinationSize) {\r
889 return RETURN_INVALID_PARAMETER;\r
890 }\r
891\r
892 return UefiDecompress (Source, Destination, Scratch);\r
893}\r