]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c
DxeMain: Fix the bug that StackGuard is not enabled
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / DxeMain / DxeMain.c
index 0324901ef9a80a2ef129b2cef1d22b4da83d1b81..0a1f3d79e2420eb1e7a224efdbceaddf5224e740 100644 (file)
@@ -1,66 +1,44 @@
-/*++\r
-\r
-Copyright (c) 2006 - 2007, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution.  The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-Module Name:\r
-\r
-  DxeMain.c\r
-\r
-Abstract:\r
-\r
+/** @file\r
   DXE Core Main Entry Point\r
 \r
---*/\r
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
-#include <DxeMain.h>\r
+**/\r
+\r
+#include "DxeMain.h"\r
 \r
 //\r
 // DXE Core Global Variables for Protocols from PEI\r
 //\r
-EFI_HANDLE                                mDecompressHandle = NULL;\r
-EFI_PEI_PE_COFF_LOADER_PROTOCOL           *gEfiPeiPeCoffLoader          = NULL;\r
+EFI_HANDLE  mDecompressHandle = NULL;\r
 \r
 //\r
 // DXE Core globals for Architecture Protocols\r
 //\r
 EFI_SECURITY_ARCH_PROTOCOL        *gSecurity      = NULL;\r
+EFI_SECURITY2_ARCH_PROTOCOL       *gSecurity2     = NULL;\r
 EFI_CPU_ARCH_PROTOCOL             *gCpu           = NULL;\r
 EFI_METRONOME_ARCH_PROTOCOL       *gMetronome     = NULL;\r
 EFI_TIMER_ARCH_PROTOCOL           *gTimer         = NULL;\r
 EFI_BDS_ARCH_PROTOCOL             *gBds           = NULL;\r
 EFI_WATCHDOG_TIMER_ARCH_PROTOCOL  *gWatchdogTimer = NULL;\r
 \r
-\r
 //\r
-// BugBug: I'n not runtime, but is the PPI?\r
+// DXE Core globals for optional protocol dependencies\r
 //\r
-EFI_STATUS_CODE_PROTOCOL     gStatusCodeInstance = {\r
-  NULL\r
-};\r
-\r
-EFI_STATUS_CODE_PROTOCOL     *gStatusCode    = &gStatusCodeInstance;\r
-\r
+EFI_SMM_BASE2_PROTOCOL  *gSmmBase2 = NULL;\r
 \r
 //\r
 // DXE Core Global used to update core loaded image protocol handle\r
 //\r
-EFI_GUID                           *gDxeCoreFileName;\r
-EFI_LOADED_IMAGE_PROTOCOL          *gDxeCoreLoadedImage;\r
-\r
-\r
+EFI_GUID                   *gDxeCoreFileName;\r
+EFI_LOADED_IMAGE_PROTOCOL  *gDxeCoreLoadedImage;\r
 \r
 //\r
 // DXE Core Module Variables\r
 //\r
-\r
-EFI_BOOT_SERVICES mBootServices = {\r
+EFI_BOOT_SERVICES  mBootServices = {\r
   {\r
     EFI_BOOT_SERVICES_SIGNATURE,                                                          // Signature\r
     EFI_BOOT_SERVICES_REVISION,                                                           // Revision\r
@@ -68,80 +46,81 @@ EFI_BOOT_SERVICES mBootServices = {
     0,                                                                                    // CRC32\r
     0                                                                                     // Reserved\r
   },\r
-  (EFI_RAISE_TPL)                               CoreRaiseTpl,                             // RaiseTPL\r
-  (EFI_RESTORE_TPL)                             CoreRestoreTpl,                           // RestoreTPL\r
-  (EFI_ALLOCATE_PAGES)                          CoreAllocatePages,                        // AllocatePages\r
-  (EFI_FREE_PAGES)                              CoreFreePages,                            // FreePages\r
-  (EFI_GET_MEMORY_MAP)                          CoreGetMemoryMap,                         // GetMemoryMap\r
-  (EFI_ALLOCATE_POOL)                           CoreAllocatePool,                         // AllocatePool\r
-  (EFI_FREE_POOL)                               CoreFreePool,                             // FreePool\r
-  (EFI_CREATE_EVENT)                            CoreCreateEvent,                          // CreateEvent\r
-  (EFI_SET_TIMER)                               CoreSetTimer,                             // SetTimer\r
-  (EFI_WAIT_FOR_EVENT)                          CoreWaitForEvent,                         // WaitForEvent\r
-  (EFI_SIGNAL_EVENT)                            CoreSignalEvent,                          // SignalEvent\r
-  (EFI_CLOSE_EVENT)                             CoreCloseEvent,                           // CloseEvent\r
-  (EFI_CHECK_EVENT)                             CoreCheckEvent,                           // CheckEvent\r
-  (EFI_INSTALL_PROTOCOL_INTERFACE)              CoreInstallProtocolInterface,             // InstallProtocolInterface\r
-  (EFI_REINSTALL_PROTOCOL_INTERFACE)            CoreReinstallProtocolInterface,           // ReinstallProtocolInterface\r
-  (EFI_UNINSTALL_PROTOCOL_INTERFACE)            CoreUninstallProtocolInterface,           // UninstallProtocolInterface\r
-  (EFI_HANDLE_PROTOCOL)                         CoreHandleProtocol,                       // HandleProtocol\r
-  (VOID *)                                      NULL,                                     // Reserved\r
-  (EFI_REGISTER_PROTOCOL_NOTIFY)                CoreRegisterProtocolNotify,               // RegisterProtocolNotify\r
-  (EFI_LOCATE_HANDLE)                           CoreLocateHandle,                         // LocateHandle\r
-  (EFI_LOCATE_DEVICE_PATH)                      CoreLocateDevicePath,                     // LocateDevicePath\r
-  (EFI_INSTALL_CONFIGURATION_TABLE)             CoreInstallConfigurationTable,            // InstallConfigurationTable\r
-  (EFI_IMAGE_LOAD)                              CoreLoadImage,                            // LoadImage\r
-  (EFI_IMAGE_START)                             CoreStartImage,                           // StartImage\r
-  (EFI_EXIT)                                    CoreExit,                                 // Exit\r
-  (EFI_IMAGE_UNLOAD)                            CoreUnloadImage,                          // UnloadImage\r
-  (EFI_EXIT_BOOT_SERVICES)                      CoreExitBootServices,                     // ExitBootServices\r
-  (EFI_GET_NEXT_MONOTONIC_COUNT)                CoreEfiNotAvailableYetArg1,               // GetNextMonotonicCount\r
-  (EFI_STALL)                                   CoreStall,                                // Stall\r
-  (EFI_SET_WATCHDOG_TIMER)                      CoreSetWatchdogTimer,                     // SetWatchdogTimer\r
-  (EFI_CONNECT_CONTROLLER)                      CoreConnectController,                    // ConnectController\r
-  (EFI_DISCONNECT_CONTROLLER)                   CoreDisconnectController,                 // DisconnectController\r
-  (EFI_OPEN_PROTOCOL)                           CoreOpenProtocol,                         // OpenProtocol\r
-  (EFI_CLOSE_PROTOCOL)                          CoreCloseProtocol,                        // CloseProtocol\r
-  (EFI_OPEN_PROTOCOL_INFORMATION)               CoreOpenProtocolInformation,              // OpenProtocolInformation\r
-  (EFI_PROTOCOLS_PER_HANDLE)                    CoreProtocolsPerHandle,                   // ProtocolsPerHandle\r
-  (EFI_LOCATE_HANDLE_BUFFER)                    CoreLocateHandleBuffer,                   // LocateHandleBuffer\r
-  (EFI_LOCATE_PROTOCOL)                         CoreLocateProtocol,                       // LocateProtocol\r
-  (EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES)    CoreInstallMultipleProtocolInterfaces,    // InstallMultipleProtocolInterfaces\r
-  (EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES)  CoreUninstallMultipleProtocolInterfaces,  // UninstallMultipleProtocolInterfaces\r
-  (EFI_CALCULATE_CRC32)                         CoreEfiNotAvailableYetArg3,               // CalculateCrc32\r
-  (EFI_COPY_MEM)                                CopyMem,                                  // CopyMem\r
-  (EFI_SET_MEM)                                 SetMem,                                   // SetMem\r
-  (EFI_CREATE_EVENT_EX)                         CoreCreateEventEx                         // CreateEventEx\r
+  (EFI_RAISE_TPL)CoreRaiseTpl,                                                            // RaiseTPL\r
+  (EFI_RESTORE_TPL)CoreRestoreTpl,                                                        // RestoreTPL\r
+  (EFI_ALLOCATE_PAGES)CoreAllocatePages,                                                  // AllocatePages\r
+  (EFI_FREE_PAGES)CoreFreePages,                                                          // FreePages\r
+  (EFI_GET_MEMORY_MAP)CoreGetMemoryMap,                                                   // GetMemoryMap\r
+  (EFI_ALLOCATE_POOL)CoreAllocatePool,                                                    // AllocatePool\r
+  (EFI_FREE_POOL)CoreFreePool,                                                            // FreePool\r
+  (EFI_CREATE_EVENT)CoreCreateEvent,                                                      // CreateEvent\r
+  (EFI_SET_TIMER)CoreSetTimer,                                                            // SetTimer\r
+  (EFI_WAIT_FOR_EVENT)CoreWaitForEvent,                                                   // WaitForEvent\r
+  (EFI_SIGNAL_EVENT)CoreSignalEvent,                                                      // SignalEvent\r
+  (EFI_CLOSE_EVENT)CoreCloseEvent,                                                        // CloseEvent\r
+  (EFI_CHECK_EVENT)CoreCheckEvent,                                                        // CheckEvent\r
+  (EFI_INSTALL_PROTOCOL_INTERFACE)CoreInstallProtocolInterface,                           // InstallProtocolInterface\r
+  (EFI_REINSTALL_PROTOCOL_INTERFACE)CoreReinstallProtocolInterface,                       // ReinstallProtocolInterface\r
+  (EFI_UNINSTALL_PROTOCOL_INTERFACE)CoreUninstallProtocolInterface,                       // UninstallProtocolInterface\r
+  (EFI_HANDLE_PROTOCOL)CoreHandleProtocol,                                                // HandleProtocol\r
+  (VOID *)NULL,                                                                           // Reserved\r
+  (EFI_REGISTER_PROTOCOL_NOTIFY)CoreRegisterProtocolNotify,                               // RegisterProtocolNotify\r
+  (EFI_LOCATE_HANDLE)CoreLocateHandle,                                                    // LocateHandle\r
+  (EFI_LOCATE_DEVICE_PATH)CoreLocateDevicePath,                                           // LocateDevicePath\r
+  (EFI_INSTALL_CONFIGURATION_TABLE)CoreInstallConfigurationTable,                         // InstallConfigurationTable\r
+  (EFI_IMAGE_LOAD)CoreLoadImage,                                                          // LoadImage\r
+  (EFI_IMAGE_START)CoreStartImage,                                                        // StartImage\r
+  (EFI_EXIT)CoreExit,                                                                     // Exit\r
+  (EFI_IMAGE_UNLOAD)CoreUnloadImage,                                                      // UnloadImage\r
+  (EFI_EXIT_BOOT_SERVICES)CoreExitBootServices,                                           // ExitBootServices\r
+  (EFI_GET_NEXT_MONOTONIC_COUNT)CoreEfiNotAvailableYetArg1,                               // GetNextMonotonicCount\r
+  (EFI_STALL)CoreStall,                                                                   // Stall\r
+  (EFI_SET_WATCHDOG_TIMER)CoreSetWatchdogTimer,                                           // SetWatchdogTimer\r
+  (EFI_CONNECT_CONTROLLER)CoreConnectController,                                          // ConnectController\r
+  (EFI_DISCONNECT_CONTROLLER)CoreDisconnectController,                                    // DisconnectController\r
+  (EFI_OPEN_PROTOCOL)CoreOpenProtocol,                                                    // OpenProtocol\r
+  (EFI_CLOSE_PROTOCOL)CoreCloseProtocol,                                                  // CloseProtocol\r
+  (EFI_OPEN_PROTOCOL_INFORMATION)CoreOpenProtocolInformation,                             // OpenProtocolInformation\r
+  (EFI_PROTOCOLS_PER_HANDLE)CoreProtocolsPerHandle,                                       // ProtocolsPerHandle\r
+  (EFI_LOCATE_HANDLE_BUFFER)CoreLocateHandleBuffer,                                       // LocateHandleBuffer\r
+  (EFI_LOCATE_PROTOCOL)CoreLocateProtocol,                                                // LocateProtocol\r
+  (EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES)CoreInstallMultipleProtocolInterfaces,        // InstallMultipleProtocolInterfaces\r
+  (EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES)CoreUninstallMultipleProtocolInterfaces,    // UninstallMultipleProtocolInterfaces\r
+  (EFI_CALCULATE_CRC32)CoreEfiNotAvailableYetArg3,                                        // CalculateCrc32\r
+  (EFI_COPY_MEM)CopyMem,                                                                  // CopyMem\r
+  (EFI_SET_MEM)SetMem,                                                                    // SetMem\r
+  (EFI_CREATE_EVENT_EX)CoreCreateEventEx                                                  // CreateEventEx\r
 };\r
 \r
-EFI_DXE_SERVICES mDxeServices = {\r
+EFI_DXE_SERVICES  mDxeServices = {\r
   {\r
     DXE_SERVICES_SIGNATURE,                                           // Signature\r
     DXE_SERVICES_REVISION,                                            // Revision\r
     sizeof (DXE_SERVICES),                                            // HeaderSize\r
-    0,                                                                    // CRC32\r
-    0                                                                     // Reserved\r
+    0,                                                                // CRC32\r
+    0                                                                 // Reserved\r
   },\r
-  (EFI_ADD_MEMORY_SPACE)             CoreAddMemorySpace,                  // AddMemorySpace\r
-  (EFI_ALLOCATE_MEMORY_SPACE)        CoreAllocateMemorySpace,             // AllocateMemorySpace\r
-  (EFI_FREE_MEMORY_SPACE)            CoreFreeMemorySpace,                 // FreeMemorySpace\r
-  (EFI_REMOVE_MEMORY_SPACE)          CoreRemoveMemorySpace,               // RemoveMemorySpace\r
-  (EFI_GET_MEMORY_SPACE_DESCRIPTOR)  CoreGetMemorySpaceDescriptor,        // GetMemorySpaceDescriptor\r
-  (EFI_SET_MEMORY_SPACE_ATTRIBUTES)  CoreSetMemorySpaceAttributes,        // SetMemorySpaceAttributes\r
-  (EFI_GET_MEMORY_SPACE_MAP)         CoreGetMemorySpaceMap,               // GetMemorySpaceMap\r
-  (EFI_ADD_IO_SPACE)                 CoreAddIoSpace,                      // AddIoSpace\r
-  (EFI_ALLOCATE_IO_SPACE)            CoreAllocateIoSpace,                 // AllocateIoSpace\r
-  (EFI_FREE_IO_SPACE)                CoreFreeIoSpace,                     // FreeIoSpace\r
-  (EFI_REMOVE_IO_SPACE)              CoreRemoveIoSpace,                   // RemoveIoSpace\r
-  (EFI_GET_IO_SPACE_DESCRIPTOR)      CoreGetIoSpaceDescriptor,            // GetIoSpaceDescriptor\r
-  (EFI_GET_IO_SPACE_MAP)             CoreGetIoSpaceMap,                   // GetIoSpaceMap\r
-  (EFI_DISPATCH)                     CoreDispatcher,                      // Dispatch\r
-  (EFI_SCHEDULE)                     CoreSchedule,                        // Schedule\r
-  (EFI_TRUST)                        CoreTrust,                           // Trust\r
-  (EFI_PROCESS_FIRMWARE_VOLUME)      CoreProcessFirmwareVolume,           // ProcessFirmwareVolume\r
+  (EFI_ADD_MEMORY_SPACE)CoreAddMemorySpace,                               // AddMemorySpace\r
+  (EFI_ALLOCATE_MEMORY_SPACE)CoreAllocateMemorySpace,                     // AllocateMemorySpace\r
+  (EFI_FREE_MEMORY_SPACE)CoreFreeMemorySpace,                             // FreeMemorySpace\r
+  (EFI_REMOVE_MEMORY_SPACE)CoreRemoveMemorySpace,                         // RemoveMemorySpace\r
+  (EFI_GET_MEMORY_SPACE_DESCRIPTOR)CoreGetMemorySpaceDescriptor,          // GetMemorySpaceDescriptor\r
+  (EFI_SET_MEMORY_SPACE_ATTRIBUTES)CoreSetMemorySpaceAttributes,          // SetMemorySpaceAttributes\r
+  (EFI_GET_MEMORY_SPACE_MAP)CoreGetMemorySpaceMap,                        // GetMemorySpaceMap\r
+  (EFI_ADD_IO_SPACE)CoreAddIoSpace,                                       // AddIoSpace\r
+  (EFI_ALLOCATE_IO_SPACE)CoreAllocateIoSpace,                             // AllocateIoSpace\r
+  (EFI_FREE_IO_SPACE)CoreFreeIoSpace,                                     // FreeIoSpace\r
+  (EFI_REMOVE_IO_SPACE)CoreRemoveIoSpace,                                 // RemoveIoSpace\r
+  (EFI_GET_IO_SPACE_DESCRIPTOR)CoreGetIoSpaceDescriptor,                  // GetIoSpaceDescriptor\r
+  (EFI_GET_IO_SPACE_MAP)CoreGetIoSpaceMap,                                // GetIoSpaceMap\r
+  (EFI_DISPATCH)CoreDispatcher,                                           // Dispatch\r
+  (EFI_SCHEDULE)CoreSchedule,                                             // Schedule\r
+  (EFI_TRUST)CoreTrust,                                                   // Trust\r
+  (EFI_PROCESS_FIRMWARE_VOLUME)CoreProcessFirmwareVolume,                 // ProcessFirmwareVolume\r
+  (EFI_SET_MEMORY_SPACE_CAPABILITIES)CoreSetMemorySpaceCapabilities,      // SetMemorySpaceCapabilities\r
 };\r
 \r
-EFI_SYSTEM_TABLE mEfiSystemTableTemplate = {\r
+EFI_SYSTEM_TABLE  mEfiSystemTableTemplate = {\r
   {\r
     EFI_SYSTEM_TABLE_SIGNATURE,                                           // Signature\r
     EFI_SYSTEM_TABLE_REVISION,                                            // Revision\r
@@ -163,7 +142,7 @@ EFI_SYSTEM_TABLE mEfiSystemTableTemplate = {
   NULL                                                                    // ConfigurationTable\r
 };\r
 \r
-EFI_RUNTIME_SERVICES mEfiRuntimeServicesTableTemplate = {\r
+EFI_RUNTIME_SERVICES  mEfiRuntimeServicesTableTemplate = {\r
   {\r
     EFI_RUNTIME_SERVICES_SIGNATURE,                               // Signature\r
     EFI_RUNTIME_SERVICES_REVISION,                                // Revision\r
@@ -171,23 +150,23 @@ EFI_RUNTIME_SERVICES mEfiRuntimeServicesTableTemplate = {
     0,                                                            // CRC32\r
     0                                                             // Reserved\r
   },\r
-  (EFI_GET_TIME)                    CoreEfiNotAvailableYetArg2,   // GetTime\r
-  (EFI_SET_TIME)                    CoreEfiNotAvailableYetArg1,   // SetTime\r
-  (EFI_GET_WAKEUP_TIME)             CoreEfiNotAvailableYetArg3,   // GetWakeupTime\r
-  (EFI_SET_WAKEUP_TIME)             CoreEfiNotAvailableYetArg2,   // SetWakeupTime\r
-  (EFI_SET_VIRTUAL_ADDRESS_MAP)     CoreEfiNotAvailableYetArg4,   // SetVirtualAddressMap\r
-  (EFI_CONVERT_POINTER)             CoreEfiNotAvailableYetArg2,   // ConvertPointer\r
-  (EFI_GET_VARIABLE)                CoreEfiNotAvailableYetArg5,   // GetVariable\r
-  (EFI_GET_NEXT_VARIABLE_NAME)      CoreEfiNotAvailableYetArg3,   // GetNextVariableName\r
-  (EFI_SET_VARIABLE)                CoreEfiNotAvailableYetArg5,   // SetVariable\r
-  (EFI_GET_NEXT_HIGH_MONO_COUNT)    CoreEfiNotAvailableYetArg1,   // GetNextHighMonotonicCount\r
-  (EFI_RESET_SYSTEM)                CoreEfiNotAvailableYetArg4,   // ResetSystem\r
-  (EFI_UPDATE_CAPSULE)              CoreEfiNotAvailableYetArg3,   // UpdateCapsule\r
-  (EFI_QUERY_CAPSULE_CAPABILITIES)  CoreEfiNotAvailableYetArg4,   // QueryCapsuleCapabilities\r
-  (EFI_QUERY_VARIABLE_INFO)         CoreEfiNotAvailableYetArg4    // QueryVariableInfo\r
+  (EFI_GET_TIME)CoreEfiNotAvailableYetArg2,                       // GetTime\r
+  (EFI_SET_TIME)CoreEfiNotAvailableYetArg1,                       // SetTime\r
+  (EFI_GET_WAKEUP_TIME)CoreEfiNotAvailableYetArg3,                // GetWakeupTime\r
+  (EFI_SET_WAKEUP_TIME)CoreEfiNotAvailableYetArg2,                // SetWakeupTime\r
+  (EFI_SET_VIRTUAL_ADDRESS_MAP)CoreEfiNotAvailableYetArg4,        // SetVirtualAddressMap\r
+  (EFI_CONVERT_POINTER)CoreEfiNotAvailableYetArg2,                // ConvertPointer\r
+  (EFI_GET_VARIABLE)CoreEfiNotAvailableYetArg5,                   // GetVariable\r
+  (EFI_GET_NEXT_VARIABLE_NAME)CoreEfiNotAvailableYetArg3,         // GetNextVariableName\r
+  (EFI_SET_VARIABLE)CoreEfiNotAvailableYetArg5,                   // SetVariable\r
+  (EFI_GET_NEXT_HIGH_MONO_COUNT)CoreEfiNotAvailableYetArg1,       // GetNextHighMonotonicCount\r
+  (EFI_RESET_SYSTEM)CoreEfiNotAvailableYetArg4,                   // ResetSystem\r
+  (EFI_UPDATE_CAPSULE)CoreEfiNotAvailableYetArg3,                 // UpdateCapsule\r
+  (EFI_QUERY_CAPSULE_CAPABILITIES)CoreEfiNotAvailableYetArg4,     // QueryCapsuleCapabilities\r
+  (EFI_QUERY_VARIABLE_INFO)CoreEfiNotAvailableYetArg4             // QueryVariableInfo\r
 };\r
 \r
-EFI_RUNTIME_ARCH_PROTOCOL gRuntimeTemplate = {\r
+EFI_RUNTIME_ARCH_PROTOCOL  gRuntimeTemplate = {\r
   INITIALIZE_LIST_HEAD_VARIABLE (gRuntimeTemplate.ImageHead),\r
   INITIALIZE_LIST_HEAD_VARIABLE (gRuntimeTemplate.EventHead),\r
 \r
@@ -205,25 +184,24 @@ EFI_RUNTIME_ARCH_PROTOCOL gRuntimeTemplate = {
   FALSE\r
 };\r
 \r
-EFI_RUNTIME_ARCH_PROTOCOL *gRuntime = &gRuntimeTemplate;\r
+EFI_RUNTIME_ARCH_PROTOCOL  *gRuntime = &gRuntimeTemplate;\r
 \r
 //\r
 // DXE Core Global Variables for the EFI System Table, Boot Services Table,\r
 // DXE Services Table, and Runtime Services Table\r
 //\r
-EFI_BOOT_SERVICES     *gDxeCoreBS = &mBootServices;\r
-EFI_DXE_SERVICES      *gDxeCoreDS = &mDxeServices;\r
-EFI_SYSTEM_TABLE      *gDxeCoreST = NULL;\r
+EFI_DXE_SERVICES  *gDxeCoreDS = &mDxeServices;\r
+EFI_SYSTEM_TABLE  *gDxeCoreST = NULL;\r
 \r
 //\r
 // For debug initialize gDxeCoreRT to template. gDxeCoreRT must be allocated from RT memory\r
 //  but gDxeCoreRT is used for ASSERT () and DEBUG () type macros so lets give it\r
 //  a value that will not cause debug infrastructure to crash early on.\r
 //\r
-EFI_RUNTIME_SERVICES  *gDxeCoreRT = &mEfiRuntimeServicesTableTemplate;\r
+EFI_RUNTIME_SERVICES  *gDxeCoreRT         = &mEfiRuntimeServicesTableTemplate;\r
 EFI_HANDLE            gDxeCoreImageHandle = NULL;\r
 \r
-VOID  *mHobStart;\r
+BOOLEAN  gMemoryMapTerminated = FALSE;\r
 \r
 //\r
 // EFI Decompress Protocol\r
@@ -234,48 +212,78 @@ EFI_DECOMPRESS_PROTOCOL  gEfiDecompress = {
 };\r
 \r
 //\r
-// Main entry point to the DXE Core\r
+// For Loading modules at fixed address feature, the configuration table is to cache the top address below which to load\r
+// Runtime code&boot time code\r
 //\r
-VOID\r
-EFIAPI\r
-DxeMain (\r
-  IN  VOID *HobStart\r
-  )\r
-/*++\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_LOAD_FIXED_ADDRESS_CONFIGURATION_TABLE  gLoadModuleAtFixAddressConfigurationTable = { 0, 0 };\r
 \r
-Routine Description:\r
+// Main entry point to the DXE Core\r
+//\r
 \r
+/**\r
   Main entry point to DXE Core.\r
 \r
-Arguments:\r
+  @param  HobStart               Pointer to the beginning of the HOB List from PEI.\r
 \r
-  HobStart - Pointer to the beginning of the HOB List from PEI\r
+  @return This function should never return.\r
 \r
-Returns:\r
+**/\r
+VOID\r
+EFIAPI\r
+DxeMain (\r
+  IN  VOID  *HobStart\r
+  )\r
+{\r
+  EFI_STATUS                    Status;\r
+  EFI_PHYSICAL_ADDRESS          MemoryBaseAddress;\r
+  UINT64                        MemoryLength;\r
+  PE_COFF_LOADER_IMAGE_CONTEXT  ImageContext;\r
+  UINTN                         Index;\r
+  EFI_HOB_GUID_TYPE             *GuidHob;\r
+  EFI_VECTOR_HANDOFF_INFO       *VectorInfoList;\r
+  EFI_VECTOR_HANDOFF_INFO       *VectorInfo;\r
+  VOID                          *EntryPoint;\r
+\r
+  //\r
+  // Setup the default exception handlers\r
+  //\r
+  VectorInfoList = NULL;\r
+  GuidHob        = GetNextGuidHob (&gEfiVectorHandoffInfoPpiGuid, HobStart);\r
+  if (GuidHob != NULL) {\r
+    VectorInfoList = (EFI_VECTOR_HANDOFF_INFO *)(GET_GUID_HOB_DATA (GuidHob));\r
+  }\r
 \r
-  This function should never return\r
+  Status = InitializeCpuExceptionHandlers (VectorInfoList);\r
+  ASSERT_EFI_ERROR (Status);\r
 \r
---*/\r
-{\r
-  EFI_STATUS                         Status;\r
-  EFI_PHYSICAL_ADDRESS               MemoryBaseAddress;\r
-  UINT64                             MemoryLength;\r
+  //\r
+  // Setup Stack Guard\r
+  //\r
+  if (PcdGetBool (PcdCpuStackGuard)) {\r
+    Status = InitializeSeparateExceptionStacks (NULL);\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
 \r
-  mHobStart = HobStart;\r
+  //\r
+  // Initialize Debug Agent to support source level debug in DXE phase\r
+  //\r
+  InitializeDebugAgent (DEBUG_AGENT_INIT_DXE_CORE, HobStart, NULL);\r
 \r
   //\r
   // Initialize Memory Services\r
   //\r
   CoreInitializeMemoryServices (&HobStart, &MemoryBaseAddress, &MemoryLength);\r
 \r
+  MemoryProfileInit (HobStart);\r
+\r
   //\r
   // Allocate the EFI System Table and EFI Runtime Service Table from EfiRuntimeServicesData\r
   // Use the templates to initialize the contents of the EFI System Table and EFI Runtime Services Table\r
   //\r
-  gDxeCoreST = CoreAllocateRuntimeCopyPool (sizeof (EFI_SYSTEM_TABLE), &mEfiSystemTableTemplate);\r
+  gDxeCoreST = AllocateRuntimeCopyPool (sizeof (EFI_SYSTEM_TABLE), &mEfiSystemTableTemplate);\r
   ASSERT (gDxeCoreST != NULL);\r
 \r
-  gDxeCoreRT = CoreAllocateRuntimeCopyPool (sizeof (EFI_RUNTIME_SERVICES), &mEfiRuntimeServicesTableTemplate);\r
+  gDxeCoreRT = AllocateRuntimeCopyPool (sizeof (EFI_RUNTIME_SERVICES), &mEfiRuntimeServicesTableTemplate);\r
   ASSERT (gDxeCoreRT != NULL);\r
 \r
   gDxeCoreST->RuntimeServices = gDxeCoreRT;\r
@@ -286,18 +294,47 @@ Returns:
   Status = CoreInitializeImageServices (HobStart);\r
   ASSERT_EFI_ERROR (Status);\r
 \r
+  //\r
+  // Initialize the Global Coherency Domain Services\r
+  //\r
+  Status = CoreInitializeGcdServices (&HobStart, MemoryBaseAddress, MemoryLength);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
   //\r
   // Call constructor for all libraries\r
   //\r
   ProcessLibraryConstructorList (gDxeCoreImageHandle, gDxeCoreST);\r
-  PERF_END   (0,PEI_TOK, NULL, 0) ;\r
-  PERF_START (0,DXE_TOK, NULL, 0) ;\r
+  PERF_CROSSMODULE_END ("PEI");\r
+  PERF_CROSSMODULE_BEGIN ("DXE");\r
 \r
   //\r
-  // Initialize the Global Coherency Domain Services\r
+  // Log MemoryBaseAddress and MemoryLength again (from\r
+  // CoreInitializeMemoryServices()), now that library constructors have\r
+  // executed.\r
   //\r
-  Status = CoreInitializeGcdServices (&HobStart, MemoryBaseAddress, MemoryLength);\r
-  ASSERT_EFI_ERROR (Status);\r
+  DEBUG ((\r
+    DEBUG_INFO,\r
+    "%a: MemoryBaseAddress=0x%Lx MemoryLength=0x%Lx\n",\r
+    __FUNCTION__,\r
+    MemoryBaseAddress,\r
+    MemoryLength\r
+    ));\r
+\r
+  //\r
+  // Report DXE Core image information to the PE/COFF Extra Action Library\r
+  //\r
+  ZeroMem (&ImageContext, sizeof (ImageContext));\r
+  ImageContext.ImageAddress  = (EFI_PHYSICAL_ADDRESS)(UINTN)gDxeCoreLoadedImage->ImageBase;\r
+  ImageContext.PdbPointer    = PeCoffLoaderGetPdbPointer ((VOID *)(UINTN)ImageContext.ImageAddress);\r
+  ImageContext.SizeOfHeaders = PeCoffGetSizeOfHeaders ((VOID *)(UINTN)ImageContext.ImageAddress);\r
+  Status                     = PeCoffLoaderGetEntryPoint ((VOID *)(UINTN)ImageContext.ImageAddress, &EntryPoint);\r
+  if (Status == EFI_SUCCESS) {\r
+    ImageContext.EntryPoint = (EFI_PHYSICAL_ADDRESS)(UINTN)EntryPoint;\r
+  }\r
+\r
+  ImageContext.Handle    = (VOID *)(UINTN)gDxeCoreLoadedImage->ImageBase;\r
+  ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory;\r
+  PeCoffLoaderRelocateImageExtraAction (&ImageContext);\r
 \r
   //\r
   // Install the DXE Services Table into the EFI System Tables's Configuration Table\r
@@ -318,14 +355,22 @@ Returns:
   ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
-  // Initialize the ReportStatusCode with PEI version, if available\r
+  // If Loading modules At fixed address feature is enabled, install Load moduels at fixed address\r
+  // Configuration Table so that user could easily to retrieve the top address to load Dxe and PEI\r
+  // Code and Tseg base to load SMM driver.\r
   //\r
-  CoreGetPeiProtocol (&gEfiStatusCodeRuntimeProtocolGuid, (VOID **)&gStatusCode->ReportStatusCode);\r
+  if (PcdGet64 (PcdLoadModuleAtFixAddressEnable) != 0) {\r
+    Status = CoreInstallConfigurationTable (&gLoadFixedAddressConfigurationTableGuid, &gLoadModuleAtFixAddressConfigurationTable);\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
 \r
   //\r
   // Report Status Code here for DXE_ENTRY_POINT once it is available\r
   //\r
-  CoreReportProgressCode ((EFI_SOFTWARE_DXE_CORE | EFI_SW_DXE_CORE_PC_ENTRY_POINT));\r
+  REPORT_STATUS_CODE (\r
+    EFI_PROGRESS_CODE,\r
+    (EFI_SOFTWARE_DXE_CORE | EFI_SW_DXE_CORE_PC_ENTRY_POINT)\r
+    );\r
 \r
   //\r
   // Create the aligned system table pointer structure that is used by external\r
@@ -339,7 +384,65 @@ Returns:
     gDxeCoreImageHandle\r
     );\r
 \r
-  DEBUG ((EFI_D_INFO | EFI_D_LOAD, "HOBLIST address in DXE = 0x%08x\n", HobStart));\r
+  DEBUG ((DEBUG_INFO | DEBUG_LOAD, "HOBLIST address in DXE = 0x%p\n", HobStart));\r
+\r
+  DEBUG_CODE_BEGIN ();\r
+  EFI_PEI_HOB_POINTERS  Hob;\r
+\r
+  for (Hob.Raw = HobStart; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) {\r
+    if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_MEMORY_ALLOCATION) {\r
+      DEBUG ((\r
+        DEBUG_INFO | DEBUG_LOAD,\r
+        "Memory Allocation 0x%08x 0x%0lx - 0x%0lx\n", \\r
+        Hob.MemoryAllocation->AllocDescriptor.MemoryType,                      \\r
+        Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress,               \\r
+        Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress + Hob.MemoryAllocation->AllocDescriptor.MemoryLength - 1\r
+        ));\r
+    }\r
+  }\r
+\r
+  for (Hob.Raw = HobStart; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) {\r
+    if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV) {\r
+      DEBUG ((\r
+        DEBUG_INFO | DEBUG_LOAD,\r
+        "FV Hob            0x%0lx - 0x%0lx\n",\r
+        Hob.FirmwareVolume->BaseAddress,\r
+        Hob.FirmwareVolume->BaseAddress + Hob.FirmwareVolume->Length - 1\r
+        ));\r
+    } else if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV2) {\r
+      DEBUG ((\r
+        DEBUG_INFO | DEBUG_LOAD,\r
+        "FV2 Hob           0x%0lx - 0x%0lx\n",\r
+        Hob.FirmwareVolume2->BaseAddress,\r
+        Hob.FirmwareVolume2->BaseAddress + Hob.FirmwareVolume2->Length - 1\r
+        ));\r
+      DEBUG ((\r
+        DEBUG_INFO | DEBUG_LOAD,\r
+        "                  %g - %g\n",\r
+        &Hob.FirmwareVolume2->FvName,\r
+        &Hob.FirmwareVolume2->FileName\r
+        ));\r
+    } else if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV3) {\r
+      DEBUG ((\r
+        DEBUG_INFO | DEBUG_LOAD,\r
+        "FV3 Hob           0x%0lx - 0x%0lx - 0x%x - 0x%x\n",\r
+        Hob.FirmwareVolume3->BaseAddress,\r
+        Hob.FirmwareVolume3->BaseAddress + Hob.FirmwareVolume3->Length - 1,\r
+        Hob.FirmwareVolume3->AuthenticationStatus,\r
+        Hob.FirmwareVolume3->ExtractedFv\r
+        ));\r
+      if (Hob.FirmwareVolume3->ExtractedFv) {\r
+        DEBUG ((\r
+          DEBUG_INFO | DEBUG_LOAD,\r
+          "                  %g - %g\n",\r
+          &Hob.FirmwareVolume3->FvName,\r
+          &Hob.FirmwareVolume3->FileName\r
+          ));\r
+      }\r
+    }\r
+  }\r
+\r
+  DEBUG_CODE_END ();\r
 \r
   //\r
   // Initialize the Event Services\r
@@ -347,6 +450,30 @@ Returns:
   Status = CoreInitializeEventServices ();\r
   ASSERT_EFI_ERROR (Status);\r
 \r
+  MemoryProfileInstallProtocol ();\r
+\r
+  CoreInitializeMemoryAttributesTable ();\r
+  CoreInitializeMemoryProtection ();\r
+\r
+  //\r
+  // Get persisted vector hand-off info from GUIDeed HOB again due to HobStart may be updated,\r
+  // and install configuration table\r
+  //\r
+  GuidHob = GetNextGuidHob (&gEfiVectorHandoffInfoPpiGuid, HobStart);\r
+  if (GuidHob != NULL) {\r
+    VectorInfoList = (EFI_VECTOR_HANDOFF_INFO *)(GET_GUID_HOB_DATA (GuidHob));\r
+    VectorInfo     = VectorInfoList;\r
+    Index          = 1;\r
+    while (VectorInfo->Attribute != EFI_VECTOR_HANDOFF_LAST_ENTRY) {\r
+      VectorInfo++;\r
+      Index++;\r
+    }\r
+\r
+    VectorInfo = AllocateCopyPool (sizeof (EFI_VECTOR_HANDOFF_INFO) * Index, (VOID *)VectorInfoList);\r
+    ASSERT (VectorInfo != NULL);\r
+    Status = CoreInstallConfigurationTable (&gEfiVectorHandoffTableGuid, (VOID *)VectorInfo);\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
 \r
   //\r
   // Get the Protocols that were passed in from PEI to DXE through GUIDed HOBs\r
@@ -364,20 +491,19 @@ Returns:
   // Publish the EFI, Tiano, and Custom Decompress protocols for use by other DXE components\r
   //\r
   Status = CoreInstallMultipleProtocolInterfaces (\r
-              &mDecompressHandle,\r
-              &gEfiDecompressProtocolGuid,           &gEfiDecompress,\r
-              NULL\r
-              );\r
+             &mDecompressHandle,\r
+             &gEfiDecompressProtocolGuid,\r
+             &gEfiDecompress,\r
+             NULL\r
+             );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-  gEfiPeiPeCoffLoader = GetPeCoffLoaderProtocol ();\r
-  ASSERT (gEfiPeiPeCoffLoader != NULL);\r
-\r
   //\r
   // Register for the GUIDs of the Architectural Protocols, so the rest of the\r
   // EFI Boot Services and EFI Runtime Services tables can be filled in.\r
+  // Also register for the GUIDs of optional protocols.\r
   //\r
-  CoreNotifyOnArchProtocolInstallation ();\r
+  CoreNotifyOnProtocolInstallation ();\r
 \r
   //\r
   // Produce Firmware Volume Protocols, one for each FV in the HOB list.\r
@@ -397,40 +523,51 @@ Returns:
   //\r
   // Initialize the DXE Dispatcher\r
   //\r
-  PERF_START (0,"CoreInitializeDispatcher", "DxeMain", 0) ;\r
   CoreInitializeDispatcher ();\r
-  PERF_END (0,"CoreInitializeDispatcher", "DxeMain", 0) ;\r
 \r
   //\r
   // Invoke the DXE Dispatcher\r
   //\r
-  PERF_START (0, "CoreDispatcher", "DxeMain", 0);\r
   CoreDispatcher ();\r
-  PERF_END (0, "CoreDispatcher", "DxeMain", 0);\r
 \r
   //\r
   // Display Architectural protocols that were not loaded if this is DEBUG build\r
   //\r
   DEBUG_CODE_BEGIN ();\r
-    CoreDisplayMissingArchProtocols ();\r
+  CoreDisplayMissingArchProtocols ();\r
   DEBUG_CODE_END ();\r
 \r
   //\r
-  // Assert if the Architectural Protocols are not present.\r
+  // Display any drivers that were not dispatched because dependency expression\r
+  // evaluated to false if this is a debug build\r
   //\r
-  ASSERT_EFI_ERROR (CoreAllEfiServicesAvailable ());\r
+  DEBUG_CODE_BEGIN ();\r
+  CoreDisplayDiscoveredNotDispatched ();\r
+  DEBUG_CODE_END ();\r
 \r
   //\r
-  // Report Status code before transfer control to BDS\r
+  // Assert if the Architectural Protocols are not present.\r
   //\r
-  CoreReportProgressCode ((EFI_SOFTWARE_DXE_CORE | EFI_SW_DXE_CORE_PC_HANDOFF_TO_NEXT));\r
+  Status = CoreAllEfiServicesAvailable ();\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // Report Status code that some Architectural Protocols are not present.\r
+    //\r
+    REPORT_STATUS_CODE (\r
+      EFI_ERROR_CODE | EFI_ERROR_MAJOR,\r
+      (EFI_SOFTWARE_DXE_CORE | EFI_SW_DXE_CORE_EC_NO_ARCH)\r
+      );\r
+  }\r
+\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
   //\r
-  // Display any drivers that were not dispatched because dependency expression\r
-  // evaluated to false if this is a debug build\r
+  // Report Status code before transfer control to BDS\r
   //\r
-  DEBUG_CODE_BEGIN ();\r
-    CoreDisplayDiscoveredNotDispatched ();\r
-  DEBUG_CODE_END ();\r
+  REPORT_STATUS_CODE (\r
+    EFI_PROGRESS_CODE,\r
+    (EFI_SOFTWARE_DXE_CORE | EFI_SW_DXE_CORE_PC_HANDOFF_TO_NEXT)\r
+    );\r
 \r
   //\r
   // Transfer control to the BDS Architectural Protocol\r
@@ -442,59 +579,24 @@ Returns:
   //\r
   ASSERT (FALSE);\r
   CpuDeadLoop ();\r
-}\r
-\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-CoreEfiNotAvailableYetArg0 (\r
-  VOID\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
 \r
-  Place holder function until all the Boot Services and Runtime Services are available\r
-\r
-Arguments:\r
-\r
-  None\r
-\r
-Returns:\r
+  UNREACHABLE ();\r
+}\r
 \r
-  EFI_NOT_AVAILABLE_YET\r
+/**\r
+  Place holder function until all the Boot Services and Runtime Services are\r
+  available.\r
 \r
---*/\r
-{\r
-  //\r
-  // This function should never be executed.  If it does, then the architectural protocols\r
-  // have not been designed correctly.  The CpuBreakpoint () is commented out for now until the\r
-  // DXE Core and all the Architectural Protocols are complete.\r
-  //\r
+  @param  Arg1                   Undefined\r
 \r
-  return EFI_NOT_AVAILABLE_YET;\r
-}\r
+  @return EFI_NOT_AVAILABLE_YET\r
 \r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 CoreEfiNotAvailableYetArg1 (\r
-  UINTN Arg1\r
+  UINTN  Arg1\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Place holder function until all the Boot Services and Runtime Services are available\r
-\r
-Arguments:\r
-\r
-  Arg1        - Undefined\r
-\r
-Returns:\r
-\r
-  EFI_NOT_AVAILABLE_YET\r
-\r
---*/\r
 {\r
   //\r
   // This function should never be executed.  If it does, then the architectural protocols\r
@@ -505,29 +607,21 @@ Returns:
   return EFI_NOT_AVAILABLE_YET;\r
 }\r
 \r
+/**\r
+  Place holder function until all the Boot Services and Runtime Services are available.\r
+\r
+  @param  Arg1                   Undefined\r
+  @param  Arg2                   Undefined\r
+\r
+  @return EFI_NOT_AVAILABLE_YET\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 CoreEfiNotAvailableYetArg2 (\r
-  UINTN Arg1,\r
-  UINTN Arg2\r
+  UINTN  Arg1,\r
+  UINTN  Arg2\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Place holder function until all the Boot Services and Runtime Services are available\r
-\r
-Arguments:\r
-\r
-  Arg1        - Undefined\r
-\r
-  Arg2        - Undefined\r
-\r
-Returns:\r
-\r
-  EFI_NOT_AVAILABLE_YET\r
-\r
---*/\r
 {\r
   //\r
   // This function should never be executed.  If it does, then the architectural protocols\r
@@ -538,32 +632,23 @@ Returns:
   return EFI_NOT_AVAILABLE_YET;\r
 }\r
 \r
+/**\r
+  Place holder function until all the Boot Services and Runtime Services are available.\r
+\r
+  @param  Arg1                   Undefined\r
+  @param  Arg2                   Undefined\r
+  @param  Arg3                   Undefined\r
+\r
+  @return EFI_NOT_AVAILABLE_YET\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 CoreEfiNotAvailableYetArg3 (\r
-  UINTN Arg1,\r
-  UINTN Arg2,\r
-  UINTN Arg3\r
+  UINTN  Arg1,\r
+  UINTN  Arg2,\r
+  UINTN  Arg3\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Place holder function until all the Boot Services and Runtime Services are available\r
-\r
-Arguments:\r
-\r
-  Arg1        - Undefined\r
-\r
-  Arg2        - Undefined\r
-\r
-  Arg3        - Undefined\r
-\r
-Returns:\r
-\r
-  EFI_NOT_AVAILABLE_YET\r
-\r
---*/\r
 {\r
   //\r
   // This function should never be executed.  If it does, then the architectural protocols\r
@@ -574,35 +659,25 @@ Returns:
   return EFI_NOT_AVAILABLE_YET;\r
 }\r
 \r
+/**\r
+  Place holder function until all the Boot Services and Runtime Services are available.\r
+\r
+  @param  Arg1                   Undefined\r
+  @param  Arg2                   Undefined\r
+  @param  Arg3                   Undefined\r
+  @param  Arg4                   Undefined\r
+\r
+  @return EFI_NOT_AVAILABLE_YET\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 CoreEfiNotAvailableYetArg4 (\r
-  UINTN Arg1,\r
-  UINTN Arg2,\r
-  UINTN Arg3,\r
-  UINTN Arg4\r
+  UINTN  Arg1,\r
+  UINTN  Arg2,\r
+  UINTN  Arg3,\r
+  UINTN  Arg4\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Place holder function until all the Boot Services and Runtime Services are available\r
-\r
-Arguments:\r
-\r
-  Arg1        - Undefined\r
-\r
-  Arg2        - Undefined\r
-\r
-  Arg3        - Undefined\r
-\r
-  Arg4        - Undefined\r
-\r
-Returns:\r
-\r
-  EFI_NOT_AVAILABLE_YET\r
-\r
---*/\r
 {\r
   //\r
   // This function should never be executed.  If it does, then the architectural protocols\r
@@ -613,38 +688,27 @@ Returns:
   return EFI_NOT_AVAILABLE_YET;\r
 }\r
 \r
+/**\r
+  Place holder function until all the Boot Services and Runtime Services are available.\r
+\r
+  @param  Arg1                   Undefined\r
+  @param  Arg2                   Undefined\r
+  @param  Arg3                   Undefined\r
+  @param  Arg4                   Undefined\r
+  @param  Arg5                   Undefined\r
+\r
+  @return EFI_NOT_AVAILABLE_YET\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 CoreEfiNotAvailableYetArg5 (\r
-  UINTN Arg1,\r
-  UINTN Arg2,\r
-  UINTN Arg3,\r
-  UINTN Arg4,\r
-  UINTN Arg5\r
+  UINTN  Arg1,\r
+  UINTN  Arg2,\r
+  UINTN  Arg3,\r
+  UINTN  Arg4,\r
+  UINTN  Arg5\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Place holder function until all the Boot Services and Runtime Services are available\r
-\r
-Arguments:\r
-\r
-  Arg1        - Undefined\r
-\r
-  Arg2        - Undefined\r
-\r
-  Arg3        - Undefined\r
-\r
-  Arg4        - Undefined\r
-\r
-  Arg5        - Undefined\r
-\r
-Returns:\r
-\r
-  EFI_NOT_AVAILABLE_YET\r
-\r
---*/\r
 {\r
   //\r
   // This function should never be executed.  If it does, then the architectural protocols\r
@@ -655,141 +719,93 @@ Returns:
   return EFI_NOT_AVAILABLE_YET;\r
 }\r
 \r
+/**\r
+  Calcualte the 32-bit CRC in a EFI table using the service provided by the\r
+  gRuntime service.\r
 \r
-EFI_STATUS\r
-CoreGetPeiProtocol (\r
-  IN EFI_GUID  *ProtocolGuid,\r
-  IN VOID      **Interface\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Searches for a Protocol Interface passed from PEI through a HOB\r
-\r
-Arguments:\r
-\r
-  ProtocolGuid - The Protocol GUID to search for in the HOB List\r
-\r
-  Interface    - A pointer to the interface for the Protocol GUID\r
-\r
-Returns:\r
-\r
-  EFI_SUCCESS   - The Protocol GUID was found and its interface is returned in Interface\r
-\r
-  EFI_NOT_FOUND - The Protocol GUID was not found in the HOB List\r
-\r
---*/\r
-{\r
-  EFI_HOB_GUID_TYPE   *GuidHob;\r
-  VOID                *Buffer;\r
-\r
-  GuidHob = GetNextGuidHob (ProtocolGuid, mHobStart);\r
-  if (GuidHob == NULL) {\r
-    return EFI_NOT_FOUND;\r
-  }\r
-\r
-  Buffer = GET_GUID_HOB_DATA (GuidHob);\r
-  ASSERT (Buffer != NULL);\r
-\r
-  *Interface = (VOID *)(*(UINTN *)(Buffer));\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
+  @param  Hdr                    Pointer to an EFI standard header\r
 \r
+**/\r
 VOID\r
 CalculateEfiHdrCrc (\r
-  IN  OUT EFI_TABLE_HEADER    *Hdr\r
+  IN  OUT EFI_TABLE_HEADER  *Hdr\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Calcualte the 32-bit CRC in a EFI table using the service provided by the\r
-  gRuntime service.\r
-\r
-Arguments:\r
-\r
-  Hdr  - Pointer to an EFI standard header\r
-\r
-Returns:\r
-\r
-  None\r
-\r
---*/\r
 {\r
-  UINT32 Crc;\r
+  UINT32  Crc;\r
 \r
   Hdr->CRC32 = 0;\r
 \r
   //\r
-  // If gDxeCoreBS->CalculateCrce32 () == CoreEfiNotAvailableYet () then\r
+  // If gBS->CalculateCrce32 () == CoreEfiNotAvailableYet () then\r
   //  Crc will come back as zero if we set it to zero here\r
   //\r
   Crc = 0;\r
-  gDxeCoreBS->CalculateCrc32 ((UINT8 *)Hdr, Hdr->HeaderSize, &Crc);\r
+  gBS->CalculateCrc32 ((UINT8 *)Hdr, Hdr->HeaderSize, &Crc);\r
   Hdr->CRC32 = Crc;\r
 }\r
 \r
+/**\r
+  Terminates all boot services.\r
+\r
+  @param  ImageHandle            Handle that identifies the exiting image.\r
+  @param  MapKey                 Key to the latest memory map.\r
 \r
+  @retval EFI_SUCCESS            Boot Services terminated\r
+  @retval EFI_INVALID_PARAMETER  MapKey is incorrect.\r
 \r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 CoreExitBootServices (\r
-  IN EFI_HANDLE   ImageHandle,\r
-  IN UINTN        MapKey\r
+  IN EFI_HANDLE  ImageHandle,\r
+  IN UINTN       MapKey\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Terminates all boot services.\r
-\r
-Arguments:\r
-\r
-  ImageHandle   - Handle that identifies the exiting image.\r
-\r
-  MapKey -Key to the latest memory map.\r
-\r
-Returns:\r
-\r
-  EFI_SUCCESS - Boot Services terminated\r
-  EFI_INVALID_PARAMETER - MapKey is incorrect.\r
-\r
---*/\r
 {\r
-  EFI_STATUS    Status;\r
+  EFI_STATUS  Status;\r
+\r
+  //\r
+  // Disable Timer\r
+  //\r
+  gTimer->SetTimerPeriod (gTimer, 0);\r
 \r
   //\r
   // Terminate memory services if the MapKey matches\r
   //\r
   Status = CoreTerminateMemoryMap (MapKey);\r
   if (EFI_ERROR (Status)) {\r
+    //\r
+    // Notify other drivers that ExitBootServices fail\r
+    //\r
+    CoreNotifySignalList (&gEventExitBootServicesFailedGuid);\r
     return Status;\r
   }\r
 \r
+  gMemoryMapTerminated = TRUE;\r
+\r
   //\r
   // Notify other drivers that we are exiting boot services.\r
   //\r
   CoreNotifySignalList (&gEfiEventExitBootServicesGuid);\r
 \r
   //\r
-  // Disable Timer\r
+  // Report that ExitBootServices() has been called\r
   //\r
-  gTimer->SetTimerPeriod (gTimer, 0);\r
+  REPORT_STATUS_CODE (\r
+    EFI_PROGRESS_CODE,\r
+    (EFI_SOFTWARE_EFI_BOOT_SERVICE | EFI_SW_BS_PC_EXIT_BOOT_SERVICES)\r
+    );\r
+\r
+  MemoryProtectionExitBootServicesCallback ();\r
 \r
   //\r
-  // Disable CPU Interrupts\r
+  // Disable interrupt of Debug timer.\r
   //\r
-  gCpu->DisableInterrupt (gCpu);\r
+  SaveAndSetDebugTimerInterrupt (FALSE);\r
 \r
   //\r
-  // Report that ExitBootServices() has been called\r
-  //\r
-  // We are using gEfiDxeServicesTableGuid as the caller ID for Dxe Core\r
+  // Disable CPU Interrupts\r
   //\r
-  CoreReportProgressCode ((EFI_SOFTWARE_EFI_BOOT_SERVICE | EFI_SW_BS_PC_EXIT_BOOT_SERVICES));\r
+  gCpu->DisableInterrupt (gCpu);\r
 \r
   //\r
   // Clear the non-runtime values of the EFI System Table\r
@@ -810,8 +826,8 @@ Returns:
   //\r
   // Zero out the Boot Service Table\r
   //\r
-  SetMem (gDxeCoreBS, sizeof (EFI_BOOT_SERVICES), 0);\r
-  gDxeCoreBS = NULL;\r
+  ZeroMem (gBS, sizeof (EFI_BOOT_SERVICES));\r
+  gBS = NULL;\r
 \r
   //\r
   // Update the AtRuntime field in Runtiem AP.\r
@@ -821,54 +837,124 @@ Returns:
   return Status;\r
 }\r
 \r
+/**\r
+  Given a compressed source buffer, this function retrieves the size of the\r
+  uncompressed buffer and the size of the scratch buffer required to decompress\r
+  the compressed source buffer.\r
+\r
+  The GetInfo() function retrieves the size of the uncompressed buffer and the\r
+  temporary scratch buffer required to decompress the buffer specified by Source\r
+  and SourceSize. If the size of the uncompressed buffer or the size of the\r
+  scratch buffer cannot be determined from the compressed data specified by\r
+  Source and SourceData, then EFI_INVALID_PARAMETER is returned. Otherwise, the\r
+  size of the uncompressed buffer is returned in DestinationSize, the size of\r
+  the scratch buffer is returned in ScratchSize, and EFI_SUCCESS is returned.\r
+  The GetInfo() function does not have scratch buffer available to perform a\r
+  thorough checking of the validity of the source data. It just retrieves the\r
+  "Original Size" field from the beginning bytes of the source data and output\r
+  it as DestinationSize. And ScratchSize is specific to the decompression\r
+  implementation.\r
+\r
+  @param  This               A pointer to the EFI_DECOMPRESS_PROTOCOL instance.\r
+  @param  Source             The source buffer containing the compressed data.\r
+  @param  SourceSize         The size, in bytes, of the source buffer.\r
+  @param  DestinationSize    A pointer to the size, in bytes, of the\r
+                             uncompressed buffer that will be generated when the\r
+                             compressed buffer specified by Source and\r
+                             SourceSize is decompressed.\r
+  @param  ScratchSize        A pointer to the size, in bytes, of the scratch\r
+                             buffer that is required to decompress the\r
+                             compressed buffer specified by Source and\r
+                             SourceSize.\r
+\r
+  @retval EFI_SUCCESS        The size of the uncompressed data was returned in\r
+                             DestinationSize and the size of the scratch buffer\r
+                             was returned in ScratchSize.\r
+  @retval EFI_INVALID_PARAMETER The size of the uncompressed data or the size of\r
+                                the scratch buffer cannot be determined from the\r
+                                compressed data specified by Source and\r
+                                SourceSize.\r
+\r
+**/\r
 EFI_STATUS\r
+EFIAPI\r
 DxeMainUefiDecompressGetInfo (\r
-  IN EFI_DECOMPRESS_PROTOCOL            *This,\r
-  IN   VOID                             *Source,\r
-  IN   UINT32                           SourceSize,\r
-  OUT  UINT32                           *DestinationSize,\r
-  OUT  UINT32                           *ScratchSize\r
+  IN EFI_DECOMPRESS_PROTOCOL  *This,\r
+  IN   VOID                   *Source,\r
+  IN   UINT32                 SourceSize,\r
+  OUT  UINT32                 *DestinationSize,\r
+  OUT  UINT32                 *ScratchSize\r
   )\r
 {\r
-  if (Source == NULL \r
-        || DestinationSize == NULL \r
-        || ScratchSize == NULL) {\r
+  if ((Source == NULL) || (DestinationSize == NULL) || (ScratchSize == NULL)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
+\r
   return UefiDecompressGetInfo (Source, SourceSize, DestinationSize, ScratchSize);\r
 }\r
 \r
+/**\r
+  Decompresses a compressed source buffer.\r
+\r
+  The Decompress() function extracts decompressed data to its original form.\r
+  This protocol is designed so that the decompression algorithm can be\r
+  implemented without using any memory services. As a result, the Decompress()\r
+  Function is not allowed to call AllocatePool() or AllocatePages() in its\r
+  implementation. It is the caller's responsibility to allocate and free the\r
+  Destination and Scratch buffers.\r
+  If the compressed source data specified by Source and SourceSize is\r
+  successfully decompressed into Destination, then EFI_SUCCESS is returned. If\r
+  the compressed source data specified by Source and SourceSize is not in a\r
+  valid compressed data format, then EFI_INVALID_PARAMETER is returned.\r
+\r
+  @param  This                A pointer to the EFI_DECOMPRESS_PROTOCOL instance.\r
+  @param  Source              The source buffer containing the compressed data.\r
+  @param  SourceSize          SourceSizeThe size of source data.\r
+  @param  Destination         On output, the destination buffer that contains\r
+                              the uncompressed data.\r
+  @param  DestinationSize     The size of the destination buffer.  The size of\r
+                              the destination buffer needed is obtained from\r
+                              EFI_DECOMPRESS_PROTOCOL.GetInfo().\r
+  @param  Scratch             A temporary scratch buffer that is used to perform\r
+                              the decompression.\r
+  @param  ScratchSize         The size of scratch buffer. The size of the\r
+                              scratch buffer needed is obtained from GetInfo().\r
+\r
+  @retval EFI_SUCCESS         Decompression completed successfully, and the\r
+                              uncompressed buffer is returned in Destination.\r
+  @retval EFI_INVALID_PARAMETER  The source buffer specified by Source and\r
+                                 SourceSize is corrupted (not in a valid\r
+                                 compressed format).\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 DxeMainUefiDecompress (\r
-  IN EFI_DECOMPRESS_PROTOCOL              *This,\r
-  IN     VOID                             *Source,\r
-  IN     UINT32                           SourceSize,\r
-  IN OUT VOID                             *Destination,\r
-  IN     UINT32                           DestinationSize,\r
-  IN OUT VOID                             *Scratch,\r
-  IN     UINT32                           ScratchSize\r
+  IN     EFI_DECOMPRESS_PROTOCOL  *This,\r
+  IN     VOID                     *Source,\r
+  IN     UINT32                   SourceSize,\r
+  IN OUT VOID                     *Destination,\r
+  IN     UINT32                   DestinationSize,\r
+  IN OUT VOID                     *Scratch,\r
+  IN     UINT32                   ScratchSize\r
   )\r
 {\r
   EFI_STATUS  Status;\r
   UINT32      TestDestinationSize;\r
   UINT32      TestScratchSize;\r
-  \r
-  if (Source == NULL \r
-        || Destination== NULL \r
-        || Scratch == NULL) {\r
+\r
+  if ((Source == NULL) || (Destination == NULL) || (Scratch == NULL)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  \r
+\r
   Status = UefiDecompressGetInfo (Source, SourceSize, &TestDestinationSize, &TestScratchSize);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
 \r
-  if (ScratchSize < TestScratchSize || DestinationSize < TestDestinationSize) {\r
+  if ((ScratchSize < TestScratchSize) || (DestinationSize < TestDestinationSize)) {\r
     return RETURN_INVALID_PARAMETER;\r
   }\r
 \r
   return UefiDecompress (Source, Destination, Scratch);\r
 }\r
-\r