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