]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c
Fixed the issue in ExitBootServices() implementation to avoid the potential boot...
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / DxeMain / DxeMain.c
index b18f92d4081066f534be279cab8c3091d253a75c..d8c7cd02491cfcd6a715dcbd1ef01a72c4c26a14 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   DXE Core Main Entry Point\r
 \r
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
 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
@@ -23,6 +23,7 @@ EFI_HANDLE                                mDecompressHandle = NULL;
 // 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
@@ -237,10 +238,26 @@ DxeMain (
   IN  VOID *HobStart\r
   )\r
 {\r
-  EFI_STATUS                         Status;\r
-  EFI_PHYSICAL_ADDRESS               MemoryBaseAddress;\r
-  UINT64                             MemoryLength;\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
+\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
+  Status = InitializeCpuExceptionHandlers (VectorInfoList);\r
+  ASSERT_EFI_ERROR (Status);\r
+  \r
   //\r
   // Initialize Debug Agent to support source level debug in DXE phase\r
   //\r
@@ -276,6 +293,13 @@ DxeMain (
   PERF_END   (NULL,"PEI", NULL, 0) ;\r
   PERF_START (NULL,"DXE", NULL, 0) ;\r
 \r
+  //\r
+  // Report DXE Core image information to the PE/COFF Extra Action Library\r
+  //\r
+  ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)gDxeCoreLoadedImage->ImageBase;\r
+  ImageContext.PdbPointer = PeCoffLoaderGetPdbPointer ((VOID*) (UINTN) ImageContext.ImageAddress);\r
+  PeCoffLoaderRelocateImageExtraAction (&ImageContext);\r
+\r
   //\r
   // Initialize the Global Coherency Domain Services\r
   //\r
@@ -357,6 +381,24 @@ DxeMain (
   Status = CoreInitializeEventServices ();\r
   ASSERT_EFI_ERROR (Status);\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
+    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
@@ -434,7 +476,17 @@ DxeMain (
   //\r
   // Assert if the Architectural Protocols are not present.\r
   //\r
-  ASSERT_EFI_ERROR (CoreAllEfiServicesAvailable ());\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
+  ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
   // Report Status code before transfer control to BDS\r
@@ -667,23 +719,35 @@ CoreExitBootServices (
 {\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
   //\r
-  // Disable Timer\r
+  // Notify other drivers that we are exiting boot services.\r
   //\r
-  gTimer->SetTimerPeriod (gTimer, 0);\r
+  CoreNotifySignalList (&gEfiEventExitBootServicesGuid);\r
 \r
   //\r
-  // Notify other drivers that we are exiting boot services.\r
+  // Report that ExitBootServices() has been called\r
   //\r
-  CoreNotifySignalList (&gEfiEventExitBootServicesGuid);\r
+  REPORT_STATUS_CODE (\r
+    EFI_PROGRESS_CODE,\r
+    (EFI_SOFTWARE_EFI_BOOT_SERVICE | EFI_SW_BS_PC_EXIT_BOOT_SERVICES)\r
+    );\r
 \r
   //\r
   // Disable interrupt of Debug timer.\r
@@ -695,14 +759,6 @@ CoreExitBootServices (
   //\r
   gCpu->DisableInterrupt (gCpu);\r
 \r
-  //\r
-  // Report that ExitBootServices() has been called\r
-  //\r
-  REPORT_STATUS_CODE (\r
-    EFI_PROGRESS_CODE,\r
-    (EFI_SOFTWARE_EFI_BOOT_SERVICE | EFI_SW_BS_PC_EXIT_BOOT_SERVICES)\r
-    );\r
-\r
   //\r
   // Clear the non-runtime values of the EFI System Table\r
   //\r