]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EdkModulePkg/Core/Dxe/DxeMain/DxeMain.c
1) Initialize gBS, gST, gImageHandle in UefiBootServicesTableLib.c to NULL
[mirror_edk2.git] / EdkModulePkg / Core / Dxe / DxeMain / DxeMain.c
index 24568ea334456141f08d306c05ce489712aa1139..1e31a8899e753e33737722b7bb73f49a805af4e7 100644 (file)
@@ -1,13 +1,13 @@
 /*++\r
 \r
-Copyright (c) 2006, 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
+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
@@ -21,127 +21,6 @@ Abstract:
 \r
 #include <DxeMain.h>\r
 \r
-VOID\r
-EFIAPI\r
-DxeMain (\r
-  IN  VOID *HobStart\r
-  );\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-CoreEfiNotAvailableYetArg0 (\r
-  VOID\r
-  );\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-CoreEfiNotAvailableYetArg1 (\r
-  UINTN Arg1\r
-  );\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-CoreEfiNotAvailableYetArg2 (\r
-  UINTN Arg1,\r
-  UINTN Arg2\r
-  );\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-CoreEfiNotAvailableYetArg3 (\r
-  UINTN Arg1,\r
-  UINTN Arg2,\r
-  UINTN Arg3\r
-  );\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-CoreEfiNotAvailableYetArg4 (\r
-  UINTN Arg1,\r
-  UINTN Arg2,\r
-  UINTN Arg3,\r
-  UINTN Arg4\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
-  );\r
-\r
-EFI_STATUS\r
-CoreGetPeiProtocol (\r
-  IN EFI_GUID  *ProtocolGuid,\r
-  IN VOID      **Interface\r
-  );\r
-  \r
-EFI_STATUS\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
-  );\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
-  );\r
-\r
-EFI_STATUS\r
-DxeMainTianoDecompressGetInfo (\r
-  IN EFI_TIANO_DECOMPRESS_PROTOCOL      *This,\r
-  IN   VOID                             *Source,\r
-  IN   UINT32                           SourceSize,\r
-  OUT  UINT32                           *DestinationSize,\r
-  OUT  UINT32                           *ScratchSize\r
-  );\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-DxeMainTianoDecompress (\r
-  IN EFI_TIANO_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\r
-DxeMainCustomDecompressGetInfo (\r
-  IN EFI_CUSTOMIZED_DECOMPRESS_PROTOCOL  *This,\r
-  IN   VOID                              *Source,\r
-  IN   UINT32                            SourceSize,\r
-  OUT  UINT32                            *DestinationSize,\r
-  OUT  UINT32                            *ScratchSize\r
-  );\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-DxeMainCustomDecompress (\r
-  IN EFI_CUSTOMIZED_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
 //\r
 // DXE Core Global Variables for Protocols from PEI\r
 //\r
@@ -157,7 +36,7 @@ EFI_METRONOME_ARCH_PROTOCOL       *gMetronome     = NULL;
 EFI_TIMER_ARCH_PROTOCOL           *gTimer         = NULL;\r
 EFI_BDS_ARCH_PROTOCOL             *gBds           = NULL;\r
 EFI_WATCHDOG_TIMER_ARCH_PROTOCOL  *gWatchdogTimer = NULL;\r
-EFI_RUNTIME_ARCH_PROTOCOL         *gRuntime       = NULL;\r
+\r
 \r
 //\r
 // BugBug: I'n not runtime, but is the PPI?\r
@@ -188,7 +67,7 @@ EFI_BOOT_SERVICES mBootServices = {
     sizeof (EFI_BOOT_SERVICES),                                                           // HeaderSize\r
     0,                                                                                    // CRC32\r
     0                                                                                     // Reserved\r
-  },                                                                                      \r
+  },\r
   (EFI_RAISE_TPL)                               CoreRaiseTpl,                             // RaiseTPL\r
   (EFI_RESTORE_TPL)                             CoreRestoreTpl,                           // RestoreTPL\r
   (EFI_ALLOCATE_PAGES)                          CoreAllocatePages,                        // AllocatePages\r
@@ -231,11 +110,8 @@ EFI_BOOT_SERVICES mBootServices = {
   (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
-#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
-  ,                                   \r
-  (EFI_CREATE_EVENT_EX)                          CoreCreateEventEx                         // CreateEventEx\r
-#endif\r
+  (EFI_SET_MEM)                                 SetMem,                                   // SetMem\r
+  (EFI_CREATE_EVENT_EX)                         CoreCreateEventEx                         // CreateEventEx\r
 };\r
 \r
 EFI_DXE_SERVICES mDxeServices = {\r
@@ -295,49 +171,56 @@ 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
-#if ((EDK_RELEASE_VERSION != 0) && (EFI_SPECIFICATION_VERSION <  0x00020000))\r
-  //\r
-  // This Tiano extension was removed when UEFI 2.0 support was added. \r
-  // It's now just a protocol.\r
-  //\r
-  ,\r
-  (EFI_REPORT_STATUS_CODE)       CoreEfiNotAvailableYetArg5       // ReportStatusCode\r
-#elif (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
-  //\r
-  // New runtime services added by UEFI 2.0\r
-  //\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
-#endif\r
 };\r
 \r
+EFI_RUNTIME_ARCH_PROTOCOL gRuntimeTemplate = {\r
+  INITIALIZE_LIST_HEAD_VARIABLE (gRuntimeTemplate.ImageHead),\r
+  INITIALIZE_LIST_HEAD_VARIABLE (gRuntimeTemplate.EventHead),\r
+\r
+  //\r
+  // Make sure Size != sizeof (EFI_MEMORY_DESCRIPTOR). This will\r
+  // prevent people from having pointer math bugs in their code.\r
+  // now you have to use *DescriptorSize to make things work.\r
+  //\r
+  sizeof (EFI_MEMORY_DESCRIPTOR) + sizeof (UINT64) - (sizeof (EFI_MEMORY_DESCRIPTOR) % sizeof (UINT64)),\r
+  EFI_MEMORY_DESCRIPTOR_VERSION,\r
+  0,\r
+  NULL,\r
+  NULL,\r
+  FALSE,\r
+  FALSE\r
+};\r
+\r
+EFI_RUNTIME_ARCH_PROTOCOL *gRuntime = &gRuntimeTemplate;\r
+\r
 //\r
-// DXE Core Global Variables for the EFI System Table, Boot Services Table, \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     *gBS = &mBootServices;\r
-EFI_DXE_SERVICES      *gDS = &mDxeServices;\r
-EFI_SYSTEM_TABLE      *gST = NULL;\r
+EFI_BOOT_SERVICES     *gDxeCoreBS = &mBootServices;\r
+EFI_DXE_SERVICES      *gDxeCoreDS = &mDxeServices;\r
+EFI_SYSTEM_TABLE      *gDxeCoreST = NULL;\r
 \r
 //\r
-// For debug initialize gRT to template. gRT must be allocated from RT memory\r
-//  but gRT is used for ASSERT () and DEBUG () type macros so lets give it\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  *gRT = &mEfiRuntimeServicesTableTemplate;\r
+EFI_RUNTIME_SERVICES  *gDxeCoreRT = &mEfiRuntimeServicesTableTemplate;\r
 EFI_HANDLE            gDxeCoreImageHandle = NULL;\r
 \r
 VOID  *mHobStart;\r
@@ -394,12 +277,6 @@ Returns:
   EFI_PHYSICAL_ADDRESS               MemoryBaseAddress;\r
   UINT64                             MemoryLength;\r
 \r
-#ifdef EFI_DXE_PERFORMANCE\r
-  UINT64                             Tick;\r
-\r
-  GetTimerValue (&Tick);\r
-#endif\r
-\r
   mHobStart = HobStart;\r
 \r
   //\r
@@ -411,14 +288,14 @@ Returns:
   // 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
-  gST = CoreAllocateRuntimeCopyPool (sizeof (EFI_SYSTEM_TABLE), &mEfiSystemTableTemplate);\r
-  ASSERT (gST != NULL);\r
+  gDxeCoreST = CoreAllocateRuntimeCopyPool (sizeof (EFI_SYSTEM_TABLE), &mEfiSystemTableTemplate);\r
+  ASSERT (gDxeCoreST != NULL);\r
 \r
-  gRT = CoreAllocateRuntimeCopyPool (sizeof (EFI_RUNTIME_SERVICES), &mEfiRuntimeServicesTableTemplate);\r
-  ASSERT (gRT != NULL);\r
+  gDxeCoreRT = CoreAllocateRuntimeCopyPool (sizeof (EFI_RUNTIME_SERVICES), &mEfiRuntimeServicesTableTemplate);\r
+  ASSERT (gDxeCoreRT != NULL);\r
+\r
+  gDxeCoreST->RuntimeServices = gDxeCoreRT;\r
 \r
-  gST->RuntimeServices = gRT;\r
-  \r
   //\r
   // Start the Image Services.\r
   //\r
@@ -428,7 +305,9 @@ Returns:
   //\r
   // Call constructor for all libraries\r
   //\r
-  ProcessLibraryConstructorList (gDxeCoreImageHandle, gST);\r
+  ProcessLibraryConstructorList (gDxeCoreImageHandle, gDxeCoreST);\r
+  PERF_END   (0,PEI_TOK, NULL, 0) ;\r
+  PERF_START (0,DXE_TOK, NULL, 0) ;\r
 \r
   //\r
   // Initialize the Global Coherency Domain Services\r
@@ -439,7 +318,7 @@ Returns:
   //\r
   // Install the DXE Services Table into the EFI System Tables's Configuration Table\r
   //\r
-  Status = CoreInstallConfigurationTable (&gEfiDxeServicesTableGuid, gDS);\r
+  Status = CoreInstallConfigurationTable (&gEfiDxeServicesTableGuid, gDxeCoreDS);\r
   ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
@@ -455,16 +334,9 @@ Returns:
   ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
-  // Initialize the ReportStatusCode with PEI version, if availible\r
+  // Initialize the ReportStatusCode with PEI version, if available\r
   //\r
   CoreGetPeiProtocol (&gEfiStatusCodeRuntimeProtocolGuid, (VOID **)&gStatusCode->ReportStatusCode);\r
-#if ((EDK_RELEASE_VERSION != 0) && (EFI_SPECIFICATION_VERSION < 0x00020000))\r
-  //\r
-  // This Tiano extension was removed when UEFI 2.0 support was added. \r
-  // It's now just a protocol.\r
-  //\r
-  gRT->ReportStatusCode = gStatusCode->ReportStatusCode;\r
-#endif\r
 \r
   //\r
   // Report Status Code here for DXE_ENTRY_POINT once it is available\r
@@ -491,22 +363,22 @@ Returns:
   Status = CoreInitializeEventServices ();\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-   \r
+\r
   //\r
   // Get the Protocols that were passed in from PEI to DXE through GUIDed HOBs\r
   //\r
-  // These Protocols are not architectural. This implementation is sharing code between \r
-  // PEI and DXE in order to save FLASH space. These Protocols could also be implemented \r
-  // as part of the DXE Core. However, that would also require the DXE Core to be ported \r
-  // each time a different CPU is used, a different Decompression algorithm is used, or a \r
-  // different Image type is used. By placing these Protocols in PEI, the DXE Core remains \r
-  // generic, and only PEI and the Arch Protocols need to be ported from Platform to Platform, \r
+  // These Protocols are not architectural. This implementation is sharing code between\r
+  // PEI and DXE in order to save FLASH space. These Protocols could also be implemented\r
+  // as part of the DXE Core. However, that would also require the DXE Core to be ported\r
+  // each time a different CPU is used, a different Decompression algorithm is used, or a\r
+  // different Image type is used. By placing these Protocols in PEI, the DXE Core remains\r
+  // generic, and only PEI and the Arch Protocols need to be ported from Platform to Platform,\r
   // and from CPU to CPU.\r
   //\r
 \r
   //\r
   // Publish the EFI, Tiano, and Custom Decompress protocols for use by other DXE components\r
-  //   \r
+  //\r
   Status = CoreInstallMultipleProtocolInterfaces (\r
               &mDecompressHandle,\r
               &gEfiDecompressProtocolGuid,           &gEfiDecompress,\r
@@ -528,16 +400,16 @@ Returns:
   //\r
   // Produce Firmware Volume Protocols, one for each FV in the HOB list.\r
   //\r
-  Status = FwVolBlockDriverInit (gDxeCoreImageHandle, gST);\r
+  Status = FwVolBlockDriverInit (gDxeCoreImageHandle, gDxeCoreST);\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-  Status = FwVolDriverInit (gDxeCoreImageHandle, gST);\r
+  Status = FwVolDriverInit (gDxeCoreImageHandle, gDxeCoreST);\r
   ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
-  // Produce the Section Extraction Protocol \r
+  // Produce the Section Extraction Protocol\r
   //\r
-  Status = InitializeSectionExtraction (gDxeCoreImageHandle, gST);\r
+  Status = InitializeSectionExtraction (gDxeCoreImageHandle, gDxeCoreST);\r
   ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
@@ -557,10 +429,10 @@ Returns:
   //\r
   // Display Architectural protocols that were not loaded if this is DEBUG build\r
   //\r
-  DEBUG_CODE (\r
+  DEBUG_CODE_BEGIN ();\r
     CoreDisplayMissingArchProtocols ();\r
-  );\r
-  \r
+  DEBUG_CODE_END ();\r
+\r
   //\r
   // Assert if the Architectural Protocols are not present.\r
   //\r
@@ -574,15 +446,15 @@ Returns:
   // Display any drivers that were not dispatched because dependency expression\r
   // evaluated to false if this is a debug build\r
   //\r
-  DEBUG_CODE (\r
+  DEBUG_CODE_BEGIN ();\r
     CoreDisplayDiscoveredNotDispatched ();\r
-  );\r
+  DEBUG_CODE_END ();\r
 \r
   //\r
   // Transfer control to the BDS Architectural Protocol\r
   //\r
   gBds->Entry (gBds);\r
-  \r
+\r
   //\r
   // BDS should never return\r
   //\r
@@ -666,7 +538,7 @@ Routine Description:
 Arguments:\r
 \r
   Arg1        - Undefined\r
-  \r
+\r
   Arg2        - Undefined\r
 \r
 Returns:\r
@@ -700,9 +572,9 @@ Routine Description:
 Arguments:\r
 \r
   Arg1        - Undefined\r
-  \r
+\r
   Arg2        - Undefined\r
-  \r
+\r
   Arg3        - Undefined\r
 \r
 Returns:\r
@@ -737,11 +609,11 @@ Routine Description:
 Arguments:\r
 \r
   Arg1        - Undefined\r
-  \r
+\r
   Arg2        - Undefined\r
-  \r
+\r
   Arg3        - Undefined\r
-  \r
+\r
   Arg4        - Undefined\r
 \r
 Returns:\r
@@ -777,13 +649,13 @@ Routine Description:
 Arguments:\r
 \r
   Arg1        - Undefined\r
-  \r
+\r
   Arg2        - Undefined\r
-  \r
+\r
   Arg3        - Undefined\r
-  \r
+\r
   Arg4        - Undefined\r
-  \r
+\r
   Arg5        - Undefined\r
 \r
 Returns:\r
@@ -834,7 +706,7 @@ Returns:
   if (GuidHob == NULL) {\r
     return EFI_NOT_FOUND;\r
   }\r
-  \r
+\r
   Buffer = GET_GUID_HOB_DATA (GuidHob);\r
   ASSERT (Buffer != NULL);\r
 \r
@@ -868,14 +740,14 @@ Returns:
   UINT32 Crc;\r
 \r
   Hdr->CRC32 = 0;\r
-  \r
+\r
   //\r
-  // If gBS->CalculateCrce32 () == CoreEfiNotAvailableYet () then\r
+  // If gDxeCoreBS->CalculateCrce32 () == CoreEfiNotAvailableYet () then\r
   //  Crc will come back as zero if we set it to zero here\r
   //\r
   Crc = 0;\r
-  gBS->CalculateCrc32 ((UINT8 *)Hdr, Hdr->HeaderSize, &Crc);\r
-  Hdr->CRC32 = Crc; \r
+  gDxeCoreBS->CalculateCrc32 ((UINT8 *)Hdr, Hdr->HeaderSize, &Crc);\r
+  Hdr->CRC32 = Crc;\r
 }\r
 \r
 \r
@@ -890,11 +762,11 @@ CoreExitBootServices (
 \r
 Routine Description:\r
 \r
-  EFI 1.0 API to terminate Boot Services\r
+  Terminates all boot services.\r
 \r
 Arguments:\r
 \r
-  ImageHandle  - Handle that represents the identity of the calling image\r
+  ImageHandle   - Handle that identifies the exiting image.\r
 \r
   MapKey -Key to the latest memory map.\r
 \r
@@ -930,16 +802,6 @@ Returns:
   //\r
   gCpu->DisableInterrupt (gCpu);\r
 \r
-  //\r
-  // Register Runtime events with the Runtime Architectural Protocol\r
-  //\r
-  CoreShutdownEventServices ();\r
-\r
-  //\r
-  // Register Runtime images with the Runtime Architectural Protocol\r
-  //\r
-  CoreShutdownImageServices ();\r
-\r
   //\r
   // Report that ExitBootServices() has been called\r
   //\r
@@ -950,24 +812,29 @@ Returns:
   //\r
   // Clear the non-runtime values of the EFI System Table\r
   //\r
-  gST->BootServices        = NULL;\r
-  gST->ConIn               = NULL;\r
-  gST->ConsoleInHandle     = NULL;\r
-  gST->ConOut              = NULL;\r
-  gST->ConsoleOutHandle    = NULL;\r
-  gST->StdErr              = NULL;\r
-  gST->StandardErrorHandle = NULL;\r
+  gDxeCoreST->BootServices        = NULL;\r
+  gDxeCoreST->ConIn               = NULL;\r
+  gDxeCoreST->ConsoleInHandle     = NULL;\r
+  gDxeCoreST->ConOut              = NULL;\r
+  gDxeCoreST->ConsoleOutHandle    = NULL;\r
+  gDxeCoreST->StdErr              = NULL;\r
+  gDxeCoreST->StandardErrorHandle = NULL;\r
 \r
   //\r
   // Recompute the 32-bit CRC of the EFI System Table\r
   //\r
-  CalculateEfiHdrCrc (&gST->Hdr);\r
+  CalculateEfiHdrCrc (&gDxeCoreST->Hdr);\r
 \r
   //\r
   // Zero out the Boot Service Table\r
   //\r
-  SetMem (gBS, sizeof (EFI_BOOT_SERVICES), 0);\r
-  gBS = NULL;\r
+  SetMem (gDxeCoreBS, sizeof (EFI_BOOT_SERVICES), 0);\r
+  gDxeCoreBS = NULL;\r
+\r
+  //\r
+  // Update the AtRuntime field in Runtiem AP.\r
+  //\r
+  gRuntime->AtRuntime = TRUE;\r
 \r
   return Status;\r
 }\r
@@ -981,6 +848,11 @@ DxeMainUefiDecompressGetInfo (
   OUT  UINT32                           *ScratchSize\r
   )\r
 {\r
+  if (Source == NULL \r
+        || DestinationSize == NULL \r
+        || ScratchSize == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
   return UefiDecompressGetInfo (Source, SourceSize, DestinationSize, ScratchSize);\r
 }\r
 \r
@@ -999,7 +871,13 @@ DxeMainUefiDecompress (
   EFI_STATUS  Status;\r
   UINT32      TestDestinationSize;\r
   UINT32      TestScratchSize;\r
-\r
+  \r
+  if (Source == NULL \r
+        || Destination== NULL \r
+        || Scratch == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  \r
   Status = UefiDecompressGetInfo (Source, SourceSize, &TestDestinationSize, &TestScratchSize);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
@@ -1021,6 +899,12 @@ DxeMainTianoDecompressGetInfo (
   OUT  UINT32                           *ScratchSize\r
   )\r
 {\r
+  if (Source == NULL \r
+        || DestinationSize == NULL \r
+        || ScratchSize == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
   return TianoDecompressGetInfo (Source, SourceSize, DestinationSize, ScratchSize);\r
 }\r
 \r
@@ -1039,7 +923,13 @@ DxeMainTianoDecompress (
   EFI_STATUS  Status;\r
   UINT32      TestDestinationSize;\r
   UINT32      TestScratchSize;\r
-\r
+  \r
+  if (Source == NULL \r
+        || Destination== NULL \r
+        || Scratch == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  \r
   Status = TianoDecompressGetInfo (Source, SourceSize, &TestDestinationSize, &TestScratchSize);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
@@ -1061,6 +951,12 @@ DxeMainCustomDecompressGetInfo (
   OUT  UINT32                            *ScratchSize\r
   )\r
 {\r
+  if (Source == NULL \r
+        || DestinationSize == NULL \r
+        || ScratchSize == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  \r
   return CustomDecompressGetInfo (Source, SourceSize, DestinationSize, ScratchSize);\r
 }\r
 \r
@@ -1080,6 +976,12 @@ DxeMainCustomDecompress (
   UINT32      TestDestinationSize;\r
   UINT32      TestScratchSize;\r
 \r
+  if (Source == NULL \r
+        || Destination== NULL \r
+        || Scratch == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
   Status = CustomDecompressGetInfo (Source, SourceSize, &TestDestinationSize, &TestScratchSize);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r