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