- if (PcdGet32 (PcdStandalone)) {\r
- // In case of standalone UEFI, we set the UEFI memory region at the top of the DRAM\r
- UefiMemoryBase = SystemMemoryTop - FixedPcdGet32 (PcdSystemMemoryUefiRegionSize);\r
+\r
+ // In case the firmware has been shadowed in the System Memory\r
+ if ((FdBase >= SystemMemoryBase) && (FdTop <= SystemMemoryTop)) {\r
+ // Check if there is enough space between the top of the system memory and the top of the\r
+ // firmware to place the UEFI memory (for PEI & DXE phases)\r
+ if (SystemMemoryTop - FdTop >= FixedPcdGet32 (PcdSystemMemoryUefiRegionSize)) {\r
+ UefiMemoryBase = SystemMemoryTop - FixedPcdGet32 (PcdSystemMemoryUefiRegionSize);\r
+ } else {\r
+ // Check there is enough space for the UEFI memory\r
+ ASSERT (SystemMemoryBase + FixedPcdGet32 (PcdSystemMemoryUefiRegionSize) <= FdBase);\r
+\r
+ UefiMemoryBase = FdBase - FixedPcdGet32 (PcdSystemMemoryUefiRegionSize);\r
+ }\r