]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c
MdeModulePkg/Core/Dxe: log memory base and length, after lib ctors again
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / DxeMain / DxeMain.c
index ed5a3c9e177a66d744c1fac4728b49bd5a70b0c3..db21311f93529ea6ebbdb2756cdafd213525dec6 100644 (file)
@@ -1,14 +1,8 @@
 /** @file\r
   DXE Core Main Entry Point\r
 \r
-Copyright (c) 2006 - 2012, 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
-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 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -123,6 +117,7 @@ EFI_DXE_SERVICES mDxeServices = {
   (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
@@ -206,6 +201,7 @@ EFI_SYSTEM_TABLE      *gDxeCoreST = NULL;
 EFI_RUNTIME_SERVICES  *gDxeCoreRT = &mEfiRuntimeServicesTableTemplate;\r
 EFI_HANDLE            gDxeCoreImageHandle = NULL;\r
 \r
+BOOLEAN               gMemoryMapTerminated = FALSE;\r
 \r
 //\r
 // EFI Decompress Protocol\r
@@ -242,12 +238,23 @@ DxeMain (
   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
-  SetupCpuExceptionHandlers ();\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 = InitializeCpuExceptionHandlersEx (VectorInfoList, NULL);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
   //\r
   // Initialize Debug Agent to support source level debug in DXE phase\r
   //\r
@@ -258,6 +265,8 @@ DxeMain (
   //\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
@@ -276,25 +285,41 @@ DxeMain (
   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   (NULL,"PEI", NULL, 0) ;\r
-  PERF_START (NULL,"DXE", NULL, 0) ;\r
+  PERF_CROSSMODULE_END   ("PEI");\r
+  PERF_CROSSMODULE_BEGIN ("DXE");\r
 \r
   //\r
-  // Report DXE Core image information to the PE/COFF Extra Action Library\r
+  // Log MemoryBaseAddress and MemoryLength again (from\r
+  // CoreInitializeMemoryServices()), now that library constructors have\r
+  // executed.\r
   //\r
-  ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)gDxeCoreLoadedImage->ImageBase;\r
-  ImageContext.PdbPointer = PeCoffLoaderGetPdbPointer ((VOID*) (UINTN) ImageContext.ImageAddress);\r
-  PeCoffLoaderRelocateImageExtraAction (&ImageContext);\r
+  DEBUG ((DEBUG_INFO, "%a: MemoryBaseAddress=0x%Lx MemoryLength=0x%Lx\n",\r
+    __FUNCTION__, MemoryBaseAddress, MemoryLength));\r
 \r
   //\r
-  // Initialize the Global Coherency Domain Services\r
+  // Report DXE Core image information to the PE/COFF Extra Action Library\r
   //\r
-  Status = CoreInitializeGcdServices (&HobStart, MemoryBaseAddress, MemoryLength);\r
-  ASSERT_EFI_ERROR (Status);\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
+  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
@@ -357,10 +382,43 @@ DxeMain (
       }\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_FV2) {\r
-        DEBUG ((DEBUG_INFO | DEBUG_LOAD, "FV2 Hob           0x%0lx - 0x%0lx\n", Hob.FirmwareVolume2->BaseAddress, Hob.FirmwareVolume2->BaseAddress + Hob.FirmwareVolume2->Length - 1));\r
-      } else if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV) {\r
-        DEBUG ((DEBUG_INFO | DEBUG_LOAD, "FV Hob            0x%0lx - 0x%0lx\n", Hob.FirmwareVolume->BaseAddress, Hob.FirmwareVolume->BaseAddress + Hob.FirmwareVolume2->Length - 1));\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
   DEBUG_CODE_END ();\r
@@ -371,6 +429,29 @@ DxeMain (
   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
+    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
@@ -419,16 +500,12 @@ DxeMain (
   //\r
   // Initialize the DXE Dispatcher\r
   //\r
-  PERF_START (NULL,"CoreInitializeDispatcher", "DxeMain", 0) ;\r
   CoreInitializeDispatcher ();\r
-  PERF_END (NULL,"CoreInitializeDispatcher", "DxeMain", 0) ;\r
 \r
   //\r
   // Invoke the DXE Dispatcher\r
   //\r
-  PERF_START (NULL, "CoreDispatcher", "DxeMain", 0);\r
   CoreDispatcher ();\r
-  PERF_END (NULL, "CoreDispatcher", "DxeMain", 0);\r
 \r
   //\r
   // Display Architectural protocols that were not loaded if this is DEBUG build\r
@@ -456,7 +533,7 @@ DxeMain (
     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
@@ -478,31 +555,11 @@ DxeMain (
   //\r
   ASSERT (FALSE);\r
   CpuDeadLoop ();\r
-}\r
-\r
-\r
-\r
-/**\r
-  Place holder function until all the Boot Services and Runtime Services are\r
-  available.\r
 \r
-  @return EFI_NOT_AVAILABLE_YET\r
+  UNREACHABLE ();\r
+}\r
 \r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-CoreEfiNotAvailableYetArg0 (\r
-  VOID\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
 \r
-  return EFI_NOT_AVAILABLE_YET;\r
-}\r
 \r
 \r
 /**\r
@@ -702,17 +759,29 @@ CoreExitBootServices (
   Status = CoreTerminateMemoryMap (MapKey);\r
   if (EFI_ERROR (Status)) {\r
     //\r
-    // Notify other drivers that ExitBootServices fail \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
+  // 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
+  MemoryProtectionExitBootServicesCallback();\r
+\r
   //\r
   // Disable interrupt of Debug timer.\r
   //\r
@@ -723,14 +792,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
@@ -828,7 +889,7 @@ DxeMainUefiDecompressGetInfo (
   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
-  sucessfully decompressed into Destination, then EFI_SUCCESS is returned. If\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