The global variable mSystemMemoryEnd is initialized by PrePi only if
it has not been initialized by ArmPlatformPeiBootAction(). This allows
platforms executing under, e.g., ARM Trusted Firmware to dynamically
reserve a window at the top of memory that will be used by the secure
firmware.
However, PrePi is a SEC module, and writing to a global variable
violates the SEC constraints, since SEC and PEI may execute from NOR
flash.
So instead, initialize mSystemMemoryEnd statically. This will ensure
it holds the correct value for all implementations where the value
is not overridden, but still allows it to be overridden during the
call to ArmPlatformPeiBootAction().
Note that this patch also fixes a latent bug on 32-bit platforms where
a value of mSystemMemoryEnd exceeding 4 GB would be truncated to 32-bits
rather than limited to (4 GB - 1)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Acked-by: Laszlo Ersek <lersek@redhat.com>
Tested-by: Ryan Harkin <ryan.harkin@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
\r
#include <AsmMacroIoLibV8.h>\r
\r
\r
#include <AsmMacroIoLibV8.h>\r
\r
-ASM_GLOBAL ASM_PFX(mSystemMemoryEnd)\r
-\r
ASM_FUNC(_ModuleEntryPoint)\r
// Do early platform specific actions\r
bl ASM_PFX(ArmPlatformPeiBootAction)\r
ASM_FUNC(_ModuleEntryPoint)\r
// Do early platform specific actions\r
bl ASM_PFX(ArmPlatformPeiBootAction)\r
_SystemMemoryEndInit:\r
ldr x1, mSystemMemoryEnd\r
\r
_SystemMemoryEndInit:\r
ldr x1, mSystemMemoryEnd\r
\r
- // Is mSystemMemoryEnd initialized?\r
- cmp x1, #0\r
- bne _SetupStackPosition\r
-\r
- MOV64 (x1, FixedPcdGet64(PcdSystemMemoryBase) + FixedPcdGet64(PcdSystemMemorySize) - 1)\r
-\r
- // Update the global variable\r
- adr x2, mSystemMemoryEnd\r
- str x1, [x2]\r
-\r
_SetupStackPosition:\r
// r1 = SystemMemoryTop\r
\r
_SetupStackPosition:\r
// r1 = SystemMemoryTop\r
\r
\r
_NeverReturn:\r
b _NeverReturn\r
\r
_NeverReturn:\r
b _NeverReturn\r
-\r
-ASM_PFX(mSystemMemoryEnd): .8byte 0\r
\r
#include <Chipset/ArmV7.h>\r
\r
\r
#include <Chipset/ArmV7.h>\r
\r
-GCC_ASM_EXPORT(mSystemMemoryEnd)\r
-\r
ASM_FUNC(_ModuleEntryPoint)\r
// Do early platform specific actions\r
bl ASM_PFX(ArmPlatformPeiBootAction)\r
ASM_FUNC(_ModuleEntryPoint)\r
// Do early platform specific actions\r
bl ASM_PFX(ArmPlatformPeiBootAction)\r
// to install the stacks at the bottom of the Firmware Device (case the FD is located\r
// at the top of the DRAM)\r
_SystemMemoryEndInit:\r
// to install the stacks at the bottom of the Firmware Device (case the FD is located\r
// at the top of the DRAM)\r
_SystemMemoryEndInit:\r
- ldr r1, mSystemMemoryEnd\r
-\r
- // Is mSystemMemoryEnd initialized?\r
- cmp r1, #0\r
- bne _SetupStackPosition\r
-\r
- MOV32 (r1, FixedPcdGet32(PcdSystemMemoryBase) + FixedPcdGet32(PcdSystemMemorySize) - 1)\r
-\r
- // Update the global variable\r
- adr r2, mSystemMemoryEnd\r
- str r1, [r2]\r
+ ADRL (r1, mSystemMemoryEnd)\r
+ ldrd r2, r3, [r1]\r
+ teq r3, #0\r
+ moveq r1, r2\r
+ mvnne r1, #0\r
\r
_SetupStackPosition:\r
// r1 = SystemMemoryTop\r
\r
_SetupStackPosition:\r
// r1 = SystemMemoryTop\r
\r
_NeverReturn:\r
b _NeverReturn\r
\r
_NeverReturn:\r
b _NeverReturn\r
-\r
-ASM_PFX(mSystemMemoryEnd): .8byte 0\r
IMPORT ArmReadMpidr\r
IMPORT ArmPlatformPeiBootAction\r
IMPORT ArmPlatformStackSet\r
IMPORT ArmReadMpidr\r
IMPORT ArmPlatformPeiBootAction\r
IMPORT ArmPlatformStackSet\r
+ IMPORT mSystemMemoryEnd\r
\r
EXPORT _ModuleEntryPoint\r
\r
EXPORT _ModuleEntryPoint\r
- EXPORT mSystemMemoryEnd\r
\r
PRESERVE8\r
AREA PrePiCoreEntryPoint, CODE, READONLY\r
\r
StartupAddr DCD CEntryPoint\r
\r
PRESERVE8\r
AREA PrePiCoreEntryPoint, CODE, READONLY\r
\r
StartupAddr DCD CEntryPoint\r
-mSystemMemoryEnd DCQ 0\r
\r
_ModuleEntryPoint\r
// Do early platform specific actions\r
\r
_ModuleEntryPoint\r
// Do early platform specific actions\r
// to install the stacks at the bottom of the Firmware Device (case the FD is located\r
// at the top of the DRAM)\r
_SystemMemoryEndInit\r
// to install the stacks at the bottom of the Firmware Device (case the FD is located\r
// at the top of the DRAM)\r
_SystemMemoryEndInit\r
- ldr r1, mSystemMemoryEnd\r
-\r
- // Is mSystemMemoryEnd initialized?\r
- cmp r1, #0\r
- bne _SetupStackPosition\r
-\r
- mov32 r1, FixedPcdGet32(PcdSystemMemoryBase)\r
- mov32 r2, FixedPcdGet32(PcdSystemMemorySize)\r
- sub r2, r2, #1\r
- add r1, r1, r2\r
- // Update the global variable\r
- adr r2, mSystemMemoryEnd\r
- str r1, [r2]\r
+ mov32 r1, mSystemMemoryEnd\r
+ ldrd r2, r3, [r1]\r
+ teq r3, #0\r
+ moveq r1, r2\r
+ mvnne r1, #0\r
\r
_SetupStackPosition\r
// r1 = SystemMemoryTop\r
\r
_SetupStackPosition\r
// r1 = SystemMemoryTop\r
#define IS_XIP() (((UINT64)FixedPcdGet64 (PcdFdBaseAddress) > mSystemMemoryEnd) || \\r
((FixedPcdGet64 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) < FixedPcdGet64 (PcdSystemMemoryBase)))\r
\r
#define IS_XIP() (((UINT64)FixedPcdGet64 (PcdFdBaseAddress) > mSystemMemoryEnd) || \\r
((FixedPcdGet64 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) < FixedPcdGet64 (PcdSystemMemoryBase)))\r
\r
+UINT64 mSystemMemoryEnd = FixedPcdGet64(PcdSystemMemoryBase) +\r
+ FixedPcdGet64(PcdSystemMemorySize) - 1;\r
+\r
EFI_STATUS\r
EFIAPI\r
ExtractGuidedSectionLibConstructor (\r
EFI_STATUS\r
EFIAPI\r
ExtractGuidedSectionLibConstructor (\r