ArmPlatformPkg/PrePi: avoid global variable write to mSystemMemoryEnd

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>
This commit is contained in:
Ard Biesheuvel
2016-10-24 09:48:32 +01:00
parent 5b005a6b32
commit 4aae7419ee
4 changed files with 14 additions and 44 deletions

View File

@@ -13,8 +13,6 @@
#include <AsmMacroIoLibV8.h>
ASM_GLOBAL ASM_PFX(mSystemMemoryEnd)
ASM_FUNC(_ModuleEntryPoint)
// Do early platform specific actions
bl ASM_PFX(ArmPlatformPeiBootAction)
@@ -31,16 +29,6 @@ _SetSVCMode:
_SystemMemoryEndInit:
ldr x1, mSystemMemoryEnd
// Is mSystemMemoryEnd initialized?
cmp x1, #0
bne _SetupStackPosition
MOV64 (x1, FixedPcdGet64(PcdSystemMemoryBase) + FixedPcdGet64(PcdSystemMemorySize) - 1)
// Update the global variable
adr x2, mSystemMemoryEnd
str x1, [x2]
_SetupStackPosition:
// r1 = SystemMemoryTop
@@ -129,5 +117,3 @@ _PrepareArguments:
_NeverReturn:
b _NeverReturn
ASM_PFX(mSystemMemoryEnd): .8byte 0