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