diff --git a/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatformGlobalVariableLib.c b/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatformGlobalVariableLib.c index 41af1836e1..db69ba047d 100644 --- a/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatformGlobalVariableLib.c +++ b/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatformGlobalVariableLib.c @@ -1,6 +1,6 @@ /** @file * -* Copyright (c) 2011-2012, ARM Limited. All rights reserved. +* Copyright (c) 2011-2015, ARM Limited. All rights reserved. * * This program and the accompanying materials * are licensed and made available under the terms and conditions of the BSD License @@ -19,7 +19,9 @@ #include #include -#define IS_XIP() (((UINT32)PcdGet64 (PcdFdBaseAddress) > (UINT32)(PcdGet64 (PcdSystemMemoryBase) + PcdGet64 (PcdSystemMemorySize))) || \ +extern UINT64 mSystemMemoryEnd; + +#define IS_XIP() (((UINT32)PcdGet64 (PcdFdBaseAddress) > (UINT32)(mSystemMemoryEnd)) || \ ((PcdGet64 (PcdFdBaseAddress) + PcdGet32 (PcdFdSize)) < PcdGet64 (PcdSystemMemoryBase))) // Declared by ArmPlatformPkg/PrePi Module @@ -40,7 +42,7 @@ ArmPlatformGetGlobalVariable ( if (IS_XIP()) { // In Case of XIP, we expect the Primary Stack at the top of the System Memory // The size must be 64bit aligned to allow 64bit variable to be aligned - GlobalVariableBase = PcdGet64 (PcdSystemMemoryBase) + PcdGet64 (PcdSystemMemorySize) - ALIGN_VALUE(PcdGet32 (PcdPeiGlobalVariableSize),0x8); + GlobalVariableBase = mSystemMemoryEnd + 1 - ALIGN_VALUE (PcdGet32 (PcdPeiGlobalVariableSize), 0x8); } else { GlobalVariableBase = mGlobalVariableBase; } @@ -69,7 +71,7 @@ ArmPlatformSetGlobalVariable ( if (IS_XIP()) { // In Case of XIP, we expect the Primary Stack at the top of the System Memory // The size must be 64bit aligned to allow 64bit variable to be aligned - GlobalVariableBase = PcdGet64 (PcdSystemMemoryBase) + PcdGet64 (PcdSystemMemorySize) - ALIGN_VALUE(PcdGet32 (PcdPeiGlobalVariableSize),0x8); + GlobalVariableBase = mSystemMemoryEnd + 1 - ALIGN_VALUE (PcdGet32 (PcdPeiGlobalVariableSize), 0x8); } else { GlobalVariableBase = mGlobalVariableBase; } @@ -96,7 +98,7 @@ ArmPlatformGetGlobalVariableAddress ( if (IS_XIP()) { // In Case of XIP, we expect the Primary Stack at the top of the System Memory // The size must be 64bit aligned to allow 64bit variable to be aligned - GlobalVariableBase = PcdGet64 (PcdSystemMemoryBase) + PcdGet64 (PcdSystemMemorySize) - ALIGN_VALUE(PcdGet32 (PcdPeiGlobalVariableSize),0x8); + GlobalVariableBase = mSystemMemoryEnd + 1 - ALIGN_VALUE (PcdGet32 (PcdPeiGlobalVariableSize), 0x8); } else { GlobalVariableBase = mGlobalVariableBase; } diff --git a/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatformGlobalVariableLib.inf b/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatformGlobalVariableLib.inf index 37de35e7d0..1b5b8fcbee 100644 --- a/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatformGlobalVariableLib.inf +++ b/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatformGlobalVariableLib.inf @@ -1,6 +1,6 @@ #/** @file # -# Copyright (c) 2011-2012, ARM Ltd. All rights reserved.
+# Copyright (c) 2011-2015, ARM Ltd. All rights reserved.
# # This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD License @@ -41,6 +41,4 @@ [Pcd] gArmTokenSpaceGuid.PcdSystemMemoryBase - gArmTokenSpaceGuid.PcdSystemMemorySize gArmTokenSpaceGuid.PcdFdBaseAddress - diff --git a/ArmPlatformPkg/PrePi/AArch64/ModuleEntryPoint.S b/ArmPlatformPkg/PrePi/AArch64/ModuleEntryPoint.S index fcea9496cb..2c4a7e5324 100644 --- a/ArmPlatformPkg/PrePi/AArch64/ModuleEntryPoint.S +++ b/ArmPlatformPkg/PrePi/AArch64/ModuleEntryPoint.S @@ -1,5 +1,5 @@ // -// Copyright (c) 2011-2013, ARM Limited. All rights reserved. +// Copyright (c) 2011-2015, ARM Limited. All rights reserved. // // This program and the accompanying materials // are licensed and made available under the terms and conditions of the BSD License @@ -24,8 +24,10 @@ GCC_ASM_IMPORT(ArmReadMpidr) GCC_ASM_IMPORT(ArmPlatformPeiBootAction) GCC_ASM_IMPORT(ArmPlatformStackSet) GCC_ASM_EXPORT(_ModuleEntryPoint) +GCC_ASM_EXPORT(mSystemMemoryEnd) -StartupAddr: .8byte ASM_PFX(CEntryPoint) +StartupAddr: .8byte ASM_PFX(CEntryPoint) +mSystemMemoryEnd: .8byte 0 ASM_PFX(_ModuleEntryPoint): // Do early platform specific actions @@ -40,12 +42,23 @@ _SetSVCMode: // Check if we can install the stack at the top of the System Memory or if we need // to install the stacks at the bottom of the Firmware Device (case the FD is located // at the top of the DRAM) -_SetupStackPosition: - // Compute Top of System Memory - LoadConstantToReg (FixedPcdGet64 (PcdSystemMemoryBase), x1) - LoadConstantToReg (FixedPcdGet64 (PcdSystemMemorySize), x2) +_SystemMemoryEndInit: + ldr x1, mSystemMemoryEnd + + // Is mSystemMemoryEnd initialized? + cmp x1, #0 + bne _SetupStackPosition + + LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryBase), x1) + LoadConstantToReg (FixedPcdGet32(PcdSystemMemorySize), x2) sub x2, x2, #1 - add x1, x1, x2 // x1 = SystemMemoryTop = PcdSystemMemoryBase + PcdSystemMemorySize + add x1, x1, x2 + // Update the global variable + adr x2, mSystemMemoryEnd + str x1, [x2] + +_SetupStackPosition: + // r1 = SystemMemoryTop // Calculate Top of the Firmware Device LoadConstantToReg (FixedPcdGet32(PcdFdBaseAddress), x2) diff --git a/ArmPlatformPkg/PrePi/Arm/ModuleEntryPoint.S b/ArmPlatformPkg/PrePi/Arm/ModuleEntryPoint.S index f00960f166..f64934480f 100644 --- a/ArmPlatformPkg/PrePi/Arm/ModuleEntryPoint.S +++ b/ArmPlatformPkg/PrePi/Arm/ModuleEntryPoint.S @@ -1,5 +1,5 @@ // -// Copyright (c) 2011-2014, ARM Limited. All rights reserved. +// Copyright (c) 2011-2015, ARM Limited. All rights reserved. // // This program and the accompanying materials // are licensed and made available under the terms and conditions of the BSD License @@ -27,8 +27,10 @@ GCC_ASM_IMPORT(ArmReadMpidr) GCC_ASM_IMPORT(ArmPlatformPeiBootAction) GCC_ASM_IMPORT(ArmPlatformStackSet) GCC_ASM_EXPORT(_ModuleEntryPoint) +GCC_ASM_EXPORT(mSystemMemoryEnd) -StartupAddr: .word CEntryPoint +StartupAddr: .word CEntryPoint +mSystemMemoryEnd: .8byte 0 ASM_PFX(_ModuleEntryPoint): @@ -48,12 +50,23 @@ _SetSVCMode: // Check if we can install the stack at the top of the System Memory or if we need // to install the stacks at the bottom of the Firmware Device (case the FD is located // at the top of the DRAM) -_SetupStackPosition: - // Compute Top of System Memory - LoadConstantToReg (FixedPcdGet64 (PcdSystemMemoryBase), r1) - LoadConstantToReg (FixedPcdGet64 (PcdSystemMemorySize), r2) +_SystemMemoryEndInit: + ldr r1, mSystemMemoryEnd + + // Is mSystemMemoryEnd initialized? + cmp r1, #0 + bne _SetupStackPosition + + LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryBase), r1) + LoadConstantToReg (FixedPcdGet32(PcdSystemMemorySize), r2) sub r2, r2, #1 - add r1, r1, r2 // r1 = SystemMemoryTop = PcdSystemMemoryBase + PcdSystemMemorySize + add r1, r1, r2 + // Update the global variable + adr r2, mSystemMemoryEnd + str r1, [r2] + +_SetupStackPosition: + // r1 = SystemMemoryTop // Calculate Top of the Firmware Device LoadConstantToReg (FixedPcdGet32(PcdFdBaseAddress), r2) diff --git a/ArmPlatformPkg/PrePi/Arm/ModuleEntryPoint.asm b/ArmPlatformPkg/PrePi/Arm/ModuleEntryPoint.asm index cbb3a08008..f73c56850d 100644 --- a/ArmPlatformPkg/PrePi/Arm/ModuleEntryPoint.asm +++ b/ArmPlatformPkg/PrePi/Arm/ModuleEntryPoint.asm @@ -1,5 +1,5 @@ // -// Copyright (c) 2011-2014, ARM Limited. All rights reserved. +// Copyright (c) 2011-2015, ARM Limited. All rights reserved. // // This program and the accompanying materials // are licensed and made available under the terms and conditions of the BSD License @@ -27,11 +27,13 @@ IMPORT ArmPlatformStackSet EXPORT _ModuleEntryPoint + EXPORT mSystemMemoryEnd PRESERVE8 AREA PrePiCoreEntryPoint, CODE, READONLY StartupAddr DCD CEntryPoint +mSystemMemoryEnd DCQ 0 _ModuleEntryPoint // Do early platform specific actions @@ -50,12 +52,23 @@ _SetSVCMode // Check if we can install the stack at the top of the System Memory or if we need // to install the stacks at the bottom of the Firmware Device (case the FD is located // at the top of the DRAM) -_SetupStackPosition - // Compute Top of System Memory - LoadConstantToReg (FixedPcdGet64 (PcdSystemMemoryBase), r1) - LoadConstantToReg (FixedPcdGet64 (PcdSystemMemorySize), r2) +_SystemMemoryEndInit + ldr r1, mSystemMemoryEnd + + // Is mSystemMemoryEnd initialized? + cmp r1, #0 + bne _SetupStackPosition + + LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryBase), r1) + LoadConstantToReg (FixedPcdGet32(PcdSystemMemorySize), r2) sub r2, r2, #1 - add r1, r1, r2 // r1 = SystemMemoryTop = PcdSystemMemoryBase + PcdSystemMemorySize + add r1, r1, r2 + // Update the global variable + adr r2, mSystemMemoryEnd + str r1, [r2] + +_SetupStackPosition + // r1 = SystemMemoryTop // Calculate Top of the Firmware Device LoadConstantToReg (FixedPcdGet32(PcdFdBaseAddress), r2) diff --git a/ArmPlatformPkg/PrePi/PrePi.c b/ArmPlatformPkg/PrePi/PrePi.c index 9a5e067ef5..99afe6fa90 100755 --- a/ArmPlatformPkg/PrePi/PrePi.c +++ b/ArmPlatformPkg/PrePi/PrePi.c @@ -30,7 +30,7 @@ #include "PrePi.h" #include "LzmaDecompress.h" -#define IS_XIP() (((UINT32)FixedPcdGet32 (PcdFdBaseAddress) > (UINT32)(FixedPcdGet64 (PcdSystemMemoryBase) + FixedPcdGet32 (PcdSystemMemorySize))) || \ +#define IS_XIP() (((UINT32)FixedPcdGet32 (PcdFdBaseAddress) > mSystemMemoryEnd) || \ ((FixedPcdGet32 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) < FixedPcdGet64 (PcdSystemMemoryBase))) // Not used when PrePi in run in XIP mode @@ -109,7 +109,7 @@ PrePiMain ( // If ensure the FD is either part of the System Memory or totally outside of the System Memory (XIP) ASSERT (IS_XIP() || ((FixedPcdGet32 (PcdFdBaseAddress) >= FixedPcdGet64 (PcdSystemMemoryBase)) && - ((UINT32)(FixedPcdGet32 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) <= (UINT32)(FixedPcdGet64 (PcdSystemMemoryBase) + FixedPcdGet64 (PcdSystemMemorySize))))); + ((UINT32)(FixedPcdGet32 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) <= (UINT32)mSystemMemoryEnd))); // Initialize the architecture specific bits ArchInitialize (); diff --git a/ArmPlatformPkg/PrePi/PrePi.h b/ArmPlatformPkg/PrePi/PrePi.h index e67795f449..6e90c2afc8 100644 --- a/ArmPlatformPkg/PrePi/PrePi.h +++ b/ArmPlatformPkg/PrePi/PrePi.h @@ -1,6 +1,6 @@ /** @file * -* Copyright (c) 2011-2012, ARM Limited. All rights reserved. +* Copyright (c) 2011-2015, ARM Limited. All rights reserved. * * This program and the accompanying materials * are licensed and made available under the terms and conditions of the BSD License @@ -29,6 +29,8 @@ #define SerialPrint(txt) SerialPortWrite (txt, AsciiStrLen(txt)+1); +extern UINT64 mSystemMemoryEnd; + RETURN_STATUS EFIAPI TimerConstructor (