From c5e702e45ad4e71e1bfc710c9db0826c1c893b18 Mon Sep 17 00:00:00 2001 From: Michael D Kinney Date: Tue, 9 Jan 2024 10:13:12 -0800 Subject: MdeModulePkg/Core/Dxe: Initialize GCD before RT memory allocations Update the DxeMain initialization order to initialize GCD services before any runtime allocations are performed. This is required to prevent runtime data fragmentation when the UEFI System Table and UEFI Runtime Service Table are allocated before both the memory and GCD services are initialized. Cc: Liming Gao Cc: Aaron Li Cc: Liu Yun Cc: Andrew Fish Cc: Laszlo Ersek Signed-off-by: Michael D Kinney Reviewed-by: Liming Gao Reviewed-by: Laszlo Ersek --- MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c | 23 ++++++++++++++--------- MdeModulePkg/Core/Dxe/Image/Image.c | 13 ++++++------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c b/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c index 0e0f976..17d510a 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c +++ b/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c @@ -277,6 +277,18 @@ DxeMain ( MemoryProfileInit (HobStart); // + // Start the Image Services. + // + Status = CoreInitializeImageServices (HobStart); + ASSERT_EFI_ERROR (Status); + + // + // Initialize the Global Coherency Domain Services + // + Status = CoreInitializeGcdServices (&HobStart, MemoryBaseAddress, MemoryLength); + ASSERT_EFI_ERROR (Status); + + // // Allocate the EFI System Table and EFI Runtime Service Table from EfiRuntimeServicesData // Use the templates to initialize the contents of the EFI System Table and EFI Runtime Services Table // @@ -289,16 +301,9 @@ DxeMain ( gDxeCoreST->RuntimeServices = gDxeCoreRT; // - // Start the Image Services. - // - Status = CoreInitializeImageServices (HobStart); - ASSERT_EFI_ERROR (Status); - - // - // Initialize the Global Coherency Domain Services + // Update DXE Core Loaded Image Protocol with allocated UEFI System Table // - Status = CoreInitializeGcdServices (&HobStart, MemoryBaseAddress, MemoryLength); - ASSERT_EFI_ERROR (Status); + gDxeCoreLoadedImage->SystemTable = gDxeCoreST; // // Call constructor for all libraries diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Image/Image.c index 6bc3a54..f520c48 100644 --- a/MdeModulePkg/Core/Dxe/Image/Image.c +++ b/MdeModulePkg/Core/Dxe/Image/Image.c @@ -218,13 +218,12 @@ CoreInitializeImageServices ( // Image = &mCorePrivateImage; - Image->EntryPoint = (EFI_IMAGE_ENTRY_POINT)(UINTN)DxeCoreEntryPoint; - Image->ImageBasePage = DxeCoreImageBaseAddress; - Image->NumberOfPages = (UINTN)(EFI_SIZE_TO_PAGES ((UINTN)(DxeCoreImageLength))); - Image->Tpl = gEfiCurrentTpl; - Image->Info.SystemTable = gDxeCoreST; - Image->Info.ImageBase = (VOID *)(UINTN)DxeCoreImageBaseAddress; - Image->Info.ImageSize = DxeCoreImageLength; + Image->EntryPoint = (EFI_IMAGE_ENTRY_POINT)(UINTN)DxeCoreEntryPoint; + Image->ImageBasePage = DxeCoreImageBaseAddress; + Image->NumberOfPages = (UINTN)(EFI_SIZE_TO_PAGES ((UINTN)(DxeCoreImageLength))); + Image->Tpl = gEfiCurrentTpl; + Image->Info.ImageBase = (VOID *)(UINTN)DxeCoreImageBaseAddress; + Image->Info.ImageSize = DxeCoreImageLength; // // Install the protocol interfaces for this image -- cgit v1.1