]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPlatformPkg/PrePi: avoid global variable write to mSystemMemoryEnd
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Mon, 24 Oct 2016 08:48:32 +0000 (09:48 +0100)
committerArd Biesheuvel <ard.biesheuvel@linaro.org>
Mon, 24 Oct 2016 14:57:25 +0000 (15:57 +0100)
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>
ArmPlatformPkg/PrePi/AArch64/ModuleEntryPoint.S
ArmPlatformPkg/PrePi/Arm/ModuleEntryPoint.S
ArmPlatformPkg/PrePi/Arm/ModuleEntryPoint.asm
ArmPlatformPkg/PrePi/PrePi.c

index d0530a874726752aa50ac9baed8d58f7f4bfc680..a81709d5d12d590ec5cb6e908ea7e0f3a4c52366 100644 (file)
@@ -13,8 +13,6 @@
 \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
@@ -31,16 +29,6 @@ _SetSVCMode:
 _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
@@ -129,5 +117,3 @@ _PrepareArguments:
 \r
 _NeverReturn:\r
   b _NeverReturn\r
-\r
-ASM_PFX(mSystemMemoryEnd):    .8byte 0\r
index 39030da5f2c3d2be26dc7fe1f0f70df1f7df7d0a..212cab62d44b28de71a420057f7fe67b6806ef3d 100644 (file)
@@ -15,8 +15,6 @@
 \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
@@ -35,17 +33,11 @@ _SetSVCMode:
 // 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
@@ -136,5 +128,3 @@ _PrepareArguments:
 \r
 _NeverReturn:\r
   b _NeverReturn\r
-\r
-ASM_PFX(mSystemMemoryEnd):  .8byte 0\r
index 023339841f7529fedc6cdef465ad8261df03ec02..1e9daf563bb659af9e63fd39e799d3b78c8e0658 100644 (file)
   IMPORT  ArmReadMpidr\r
   IMPORT  ArmPlatformPeiBootAction\r
   IMPORT  ArmPlatformStackSet\r
+  IMPORT  mSystemMemoryEnd\r
 \r
   EXPORT  _ModuleEntryPoint\r
-  EXPORT  mSystemMemoryEnd\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
@@ -49,19 +48,11 @@ _SetSVCMode
 // 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
index 36928c65a73bb644ef47a320cb39cbf10a81efcf..e548ccace09730b78851b987d7b902a5bb7a84c5 100644 (file)
@@ -32,6 +32,9 @@
 #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