The build tools write the fixed load address into the section header
of the first non-code section. While PeiCore and PiSmmCore correctly
load it from there, DxeCore uses ImageBase from the PE/COFF Optional
Header instead.

Align the behaviour of DxeCore with the other dispatchers.

Cc: Jian J Wang <jian.j.w...@intel.com>
Cc: Hao A Wu <hao.a...@intel.com>
Cc: Dandan Bi <dandan...@intel.com>
Cc: Liming Gao <gaolim...@byosoft.com.cn>
Cc: Vitaly Cheptsov <vit9...@protonmail.com>
Signed-off-by: Marvin Häuser <mhaeu...@posteo.de>
---
 MdeModulePkg/Core/Dxe/Image/Image.c | 30 ++++++++++++++------
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c 
b/MdeModulePkg/Core/Dxe/Image/Image.c
index 641a5715b112..9455c2fa45ad 100644
--- a/MdeModulePkg/Core/Dxe/Image/Image.c
+++ b/MdeModulePkg/Core/Dxe/Image/Image.c
@@ -416,6 +416,7 @@ GetPeCoffImageFixLoadingAssignedAddress(
    EFI_STATUS                         Status;

    EFI_IMAGE_SECTION_HEADER           SectionHeader;

    EFI_IMAGE_OPTIONAL_HEADER_UNION    *ImgHdr;

+   EFI_PHYSICAL_ADDRESS               FixLoadingAddress;

    UINT16                             Index;

    UINTN                              Size;

    UINT16                             NumberOfSections;

@@ -468,24 +469,35 @@ GetPeCoffImageFixLoadingAssignedAddress(
        //

        ValueInSectionHeader = 
ReadUnaligned64((UINT64*)&SectionHeader.PointerToRelocations);

        if (ValueInSectionHeader != 0) {

-         //

-         // When the feature is configured as load module at fixed absolute 
address, the ImageAddress field of ImageContext

-         // hold the specified address. If the feature is configured as load 
module at fixed offset, ImageAddress hold an offset

-         // relative to top address

-         //

-         if ((INT64)PcdGet64(PcdLoadModuleAtFixAddressEnable) < 0) {

-            ImageContext->ImageAddress = 
gLoadModuleAtFixAddressConfigurationTable.DxeCodeTopAddress + 
(INT64)(INTN)ImageContext->ImageAddress;

+          if ((INT64)PcdGet64(PcdLoadModuleAtFixAddressEnable) > 0) {

+           //

+           // When LMFA feature is configured as Load Module at Fixed Absolute 
Address mode, PointerToRelocations & PointerToLineNumbers field

+           // hold the absolute address of image base running in memory

+           //

+           FixLoadingAddress = ValueInSectionHeader;

+         } else {

+           //

+           // When LMFA feature is configured as Load Module at Fixed offset 
mode, PointerToRelocations & PointerToLineNumbers field

+           // hold the offset relative to a platform-specific top address.

+           //

+           FixLoadingAddress = 
gLoadModuleAtFixAddressConfigurationTable.DxeCodeTopAddress + 
ValueInSectionHeader;

          }

          //

          // Check if the memory range is available.

          //

-         Status = CheckAndMarkFixLoadingMemoryUsageBitMap 
(ImageContext->ImageAddress, (UINTN)(ImageContext->ImageSize + 
ImageContext->SectionAlignment));

+         Status = CheckAndMarkFixLoadingMemoryUsageBitMap (FixLoadingAddress, 
(UINTN)(ImageContext->ImageSize + ImageContext->SectionAlignment));

+         if (!EFI_ERROR(Status)) {

+           //

+           // The assigned address is valid. Return the specified loading 
address

+           //

+           ImageContext->ImageAddress = FixLoadingAddress;

+         }

        }

        break;

      }

      SectionHeaderOffset += sizeof (EFI_IMAGE_SECTION_HEADER);

    }

-   DEBUG ((EFI_D_INFO|EFI_D_LOAD, "LOADING MODULE FIXED INFO: Loading module 
at fixed address 0x%11p. Status = %r \n", (VOID 
*)(UINTN)(ImageContext->ImageAddress), Status));

+   DEBUG ((EFI_D_INFO|EFI_D_LOAD, "LOADING MODULE FIXED INFO: Loading module 
at fixed address 0x%11p. Status = %r \n", (VOID *)(UINTN)FixLoadingAddress, 
Status));

    return Status;

 }

 

-- 
2.31.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#78884): https://edk2.groups.io/g/devel/message/78884
Mute This Topic: https://groups.io/mt/84754057/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to