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