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