diff mbox

[edk2,07/26] ArmVirtPkg: clean up assembly source files

Message ID 1470842282-8415-8-git-send-email-ard.biesheuvel@linaro.org
State Accepted
Commit dfc2838892e4a69781b06353ef494ba3ddf16488
Headers show

Commit Message

Ard Biesheuvel Aug. 10, 2016, 3:17 p.m. UTC
This updates all assembly source files under ArmVirtPkg to mark
exported functions as ASM_FUNC(), which puts them in a separate
section, allowing the linker to prune code that is left unused.

At the same time, clean up the code to get rid of LoadConstantToReg()
instances involving symbol references, each of which emits an absolute
literal, and hence and entry in the PE/COFF .reloc table.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

---
 ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/AARCH64/RelocatableVirtHelper.S | 36 +++--------
 ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/ARM/RelocatableVirtHelper.S     | 50 +++++----------
 ArmVirtPkg/Library/ArmVirtPlatformLib/AARCH64/VirtHelper.S                       | 30 +++------
 ArmVirtPkg/Library/ArmVirtPlatformLib/ARM/VirtHelper.S                           | 31 +++------
 ArmVirtPkg/Library/ArmVirtPlatformLib/ARM/VirtHelper.asm                         | 10 +--
 ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/AARCH64/RelocatableVirtHelper.S  | 36 +++--------
 ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/ARM/RelocatableVirtHelper.S      | 47 +++++---------
 ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S                                      | 41 ++++--------
 ArmVirtPkg/PrePi/Arm/ModuleEntryPoint.S                                          | 66 ++++++--------------
 9 files changed, 97 insertions(+), 250 deletions(-)

-- 
2.7.4

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
diff mbox

Patch

diff --git a/ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/AARCH64/RelocatableVirtHelper.S b/ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/AARCH64/RelocatableVirtHelper.S
index 27ad07a1a197..ec6955cf0af8 100644
--- a/ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/AARCH64/RelocatableVirtHelper.S
+++ b/ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/AARCH64/RelocatableVirtHelper.S
@@ -1,5 +1,6 @@ 
 #
 #  Copyright (c) 2011-2013, ARM Limited. All rights reserved.
+#  Copyright (c) 2016, Linaro Limited. All rights reserved.
 #
 #  This program and the accompanying materials
 #  are licensed and made available under the terms and conditions of the BSD License
@@ -12,33 +13,14 @@ 
 #
 
 #include <AsmMacroIoLibV8.h>
-#include <Base.h>
 #include <Library/ArmLib.h>
-#include <Library/PcdLib.h>
-#include <AutoGen.h>
-
-.text
-.align 2
-
-GCC_ASM_EXPORT(ArmPlatformPeiBootAction)
-GCC_ASM_EXPORT(ArmPlatformIsPrimaryCore)
-GCC_ASM_EXPORT(ArmPlatformGetPrimaryCoreMpId)
-GCC_ASM_EXPORT(ArmPlatformGetCorePosition)
-GCC_ASM_EXPORT(ArmGetPhysAddrTop)
-
-GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdArmPrimaryCore)
-GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdArmPrimaryCoreMask)
-GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdCoreCount)
-
-.LArm64LinuxMagic:
-  .byte   0x41, 0x52, 0x4d, 0x64
 
 // VOID
 // ArmPlatformPeiBootAction (
 //   VOID   *DeviceTreeBaseAddress,   // passed by loader in x0
 //   VOID   *ImageBase                // passed by FDF trampoline in x1
 //   );
-ASM_PFX(ArmPlatformPeiBootAction):
+ASM_FUNC(ArmPlatformPeiBootAction)
   //
   // If we are booting from RAM using the Linux kernel boot protocol, x0 will
   // point to the DTB image in memory. Otherwise, use the default value defined
@@ -104,20 +86,22 @@  ASM_PFX(ArmPlatformPeiBootAction):
 .Lout:
   ret    x29
 
+.LArm64LinuxMagic:
+  .byte   0x41, 0x52, 0x4d, 0x64
+
 //UINTN
 //ArmPlatformGetPrimaryCoreMpId (
 //  VOID
 //  );
-ASM_PFX(ArmPlatformGetPrimaryCoreMpId):
-  LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCore, x0)
-  ldrh   w0, [x0]
+ASM_FUNC(ArmPlatformGetPrimaryCoreMpId)
+  MOV32  (w0, FixedPcdGet32 (PcdArmPrimaryCore))
   ret
 
 //UINTN
 //ArmPlatformIsPrimaryCore (
 //  IN UINTN MpId
 //  );
-ASM_PFX(ArmPlatformIsPrimaryCore):
+ASM_FUNC(ArmPlatformIsPrimaryCore)
   mov   x0, #1
   ret
 
@@ -126,7 +110,7 @@  ASM_PFX(ArmPlatformIsPrimaryCore):
 //  IN UINTN MpId
 //  );
 // With this function: CorePos = (ClusterId * 4) + CoreId
-ASM_PFX(ArmPlatformGetCorePosition):
+ASM_FUNC(ArmPlatformGetCorePosition)
   and   x1, x0, #ARM_CORE_MASK
   and   x0, x0, #ARM_CLUSTER_MASK
   add   x0, x1, x0, LSR #6
@@ -136,7 +120,7 @@  ASM_PFX(ArmPlatformGetCorePosition):
 //GetPhysAddrTop (
 //  VOID
 //  );
-ASM_PFX(ArmGetPhysAddrTop):
+ASM_FUNC(ArmGetPhysAddrTop)
   mrs   x0, id_aa64mmfr0_el1
   adr   x1, .LPARanges
   and   x0, x0, #7
diff --git a/ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/ARM/RelocatableVirtHelper.S b/ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/ARM/RelocatableVirtHelper.S
index 097038806ecd..27af98970c16 100644
--- a/ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/ARM/RelocatableVirtHelper.S
+++ b/ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/ARM/RelocatableVirtHelper.S
@@ -1,6 +1,6 @@ 
 #
 #  Copyright (c) 2011-2013, ARM Limited. All rights reserved.
-#  Copyright (c) 2014, Linaro Limited. All rights reserved.
+#  Copyright (c) 2014-2016, Linaro Limited. All rights reserved.
 #
 #  This program and the accompanying materials
 #  are licensed and made available under the terms and conditions of the BSD License
@@ -13,28 +13,9 @@ 
 #
 
 #include <AsmMacroIoLib.h>
-#include <Base.h>
 #include <Library/ArmLib.h>
-#include <Library/PcdLib.h>
-#include <AutoGen.h>
 
-.text
-.align 2
-
-GCC_ASM_EXPORT(ArmPlatformPeiBootAction)
-GCC_ASM_EXPORT(ArmPlatformIsPrimaryCore)
-GCC_ASM_EXPORT(ArmPlatformGetPrimaryCoreMpId)
-GCC_ASM_EXPORT(ArmPlatformGetCorePosition)
-GCC_ASM_EXPORT(ArmGetPhysAddrTop)
-
-GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdArmPrimaryCore)
-GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdArmPrimaryCoreMask)
-GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdCoreCount)
-
-.LArm32LinuxMagic:
-  .byte   0x18, 0x28, 0x6f, 0x01
-
-ASM_PFX(ArmPlatformPeiBootAction):
+ASM_FUNC(ArmPlatformPeiBootAction)
   //
   // If we are booting from RAM using the Linux kernel boot protocol, r0 will
   // point to the DTB image in memory. Otherwise, use the default value defined
@@ -42,7 +23,7 @@  ASM_PFX(ArmPlatformPeiBootAction):
   //
   teq   r0, #0
   bne   0f
-  ldr   r0, =PcdGet64 (PcdDeviceTreeInitialBaseAddress)
+  LDRL  (r0, PcdGet64 (PcdDeviceTreeInitialBaseAddress))
 
 0:mov   r11, r14            // preserve LR
   mov   r10, r0             // preserve DTB pointer
@@ -64,8 +45,8 @@  ASM_PFX(ArmPlatformPeiBootAction):
   // to the actual relocated value, and add the shift of PcdFdBaseAddress to
   // PcdFvBaseAddress as well
   //
-  ldr   r8, =PcdGet64 (PcdFdBaseAddress)
-  ldr   r7, =PcdGet64 (PcdFvBaseAddress)
+  ADRL  (r8, PcdGet64 (PcdFdBaseAddress))
+  ADRL  (r7, PcdGet64 (PcdFvBaseAddress))
   ldr   r6, [r8]
   ldr   r5, [r7]
   sub   r5, r5, r6
@@ -79,8 +60,8 @@  ASM_PFX(ArmPlatformPeiBootAction):
   // encountered. Since we are calling a C function, use the window at the
   // beginning of the FD image as a temp stack.
   //
-  ldr   r1, =PcdGet64 (PcdSystemMemoryBase)
-  ldr   r2, =PcdGet64 (PcdSystemMemorySize)
+  ADRL  (r1, PcdGet64 (PcdSystemMemoryBase))
+  ADRL  (r2, PcdGet64 (PcdSystemMemorySize))
   mov   sp, r5
   bl    FindMemnode
   teq   r0, #0
@@ -91,7 +72,7 @@  ASM_PFX(ArmPlatformPeiBootAction):
   // image header at the base of this image (defined in the FDF), and record the
   // pointer in PcdDeviceTreeInitialBaseAddress.
   //
-  ldr   r8, =PcdGet64 (PcdDeviceTreeInitialBaseAddress)
+  ADRL  (r8, PcdGet64 (PcdDeviceTreeInitialBaseAddress))
   add   r9, r9, #0x40
   str   r9, [r8]
 
@@ -102,20 +83,22 @@  ASM_PFX(ArmPlatformPeiBootAction):
 .Lout:
   bx    r11
 
+.LArm32LinuxMagic:
+  .byte   0x18, 0x28, 0x6f, 0x01
+
 //UINTN
 //ArmPlatformGetPrimaryCoreMpId (
 //  VOID
 //  );
-ASM_PFX(ArmPlatformGetPrimaryCoreMpId):
-  LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCore, r0)
-  ldr    r0, [r0]
+ASM_FUNC(ArmPlatformGetPrimaryCoreMpId)
+  MOV32  (r0, FixedPcdGet32 (PcdArmPrimaryCore))
   bx     lr
 
 //UINTN
 //ArmPlatformIsPrimaryCore (
 //  IN UINTN MpId
 //  );
-ASM_PFX(ArmPlatformIsPrimaryCore):
+ASM_FUNC(ArmPlatformIsPrimaryCore)
   mov   r0, #1
   bx    lr
 
@@ -124,7 +107,7 @@  ASM_PFX(ArmPlatformIsPrimaryCore):
 //  IN UINTN MpId
 //  );
 // With this function: CorePos = (ClusterId * 4) + CoreId
-ASM_PFX(ArmPlatformGetCorePosition):
+ASM_FUNC(ArmPlatformGetCorePosition)
   and   r1, r0, #ARM_CORE_MASK
   and   r0, r0, #ARM_CLUSTER_MASK
   add   r0, r1, r0, LSR #6
@@ -134,8 +117,7 @@  ASM_PFX(ArmPlatformGetCorePosition):
 //GetPhysAddrTop (
 //  VOID
 //  );
-ASM_PFX(ArmGetPhysAddrTop):
+ASM_FUNC(ArmGetPhysAddrTop)
   mov   r0, #0x00000000
   mov   r1, #0x10000
   bx    lr
-
diff --git a/ArmVirtPkg/Library/ArmVirtPlatformLib/AARCH64/VirtHelper.S b/ArmVirtPkg/Library/ArmVirtPlatformLib/AARCH64/VirtHelper.S
index 14200fc17b3e..1d8fe25928d8 100644
--- a/ArmVirtPkg/Library/ArmVirtPlatformLib/AARCH64/VirtHelper.S
+++ b/ArmVirtPkg/Library/ArmVirtPlatformLib/AARCH64/VirtHelper.S
@@ -1,5 +1,6 @@ 
 #
 #  Copyright (c) 2011-2013, ARM Limited. All rights reserved.
+#  Copyright (c) 2016, Linaro Limited. All rights reserved.
 #
 #  This program and the accompanying materials
 #  are licensed and made available under the terms and conditions of the BSD License
@@ -12,41 +13,24 @@ 
 #
 
 #include <AsmMacroIoLibV8.h>
-#include <Base.h>
 #include <Library/ArmLib.h>
-#include <Library/PcdLib.h>
-#include <AutoGen.h>
 
-.text
-.align 2
-
-GCC_ASM_EXPORT(ArmPlatformPeiBootAction)
-GCC_ASM_EXPORT(ArmPlatformIsPrimaryCore)
-GCC_ASM_EXPORT(ArmPlatformGetPrimaryCoreMpId)
-GCC_ASM_EXPORT(ArmPlatformGetCorePosition)
-GCC_ASM_EXPORT(ArmGetPhysAddrTop)
-
-GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdArmPrimaryCore)
-GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdArmPrimaryCoreMask)
-GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdCoreCount)
-
-ASM_PFX(ArmPlatformPeiBootAction):
+ASM_FUNC(ArmPlatformPeiBootAction)
   ret
 
 //UINTN
 //ArmPlatformGetPrimaryCoreMpId (
 //  VOID
 //  );
-ASM_PFX(ArmPlatformGetPrimaryCoreMpId):
-  LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCore, x0)
-  ldrh   w0, [x0]
+ASM_FUNC(ArmPlatformGetPrimaryCoreMpId)
+  MOV32  (w0, FixedPcdGet32 (PcdArmPrimaryCore))
   ret
 
 //UINTN
 //ArmPlatformIsPrimaryCore (
 //  IN UINTN MpId
 //  );
-ASM_PFX(ArmPlatformIsPrimaryCore):
+ASM_FUNC(ArmPlatformIsPrimaryCore)
   mov   x0, #1
   ret
 
@@ -55,7 +39,7 @@  ASM_PFX(ArmPlatformIsPrimaryCore):
 //  IN UINTN MpId
 //  );
 // With this function: CorePos = (ClusterId * 4) + CoreId
-ASM_PFX(ArmPlatformGetCorePosition):
+ASM_FUNC(ArmPlatformGetCorePosition)
   and   x1, x0, #ARM_CORE_MASK
   and   x0, x0, #ARM_CLUSTER_MASK
   add   x0, x1, x0, LSR #6
@@ -65,7 +49,7 @@  ASM_PFX(ArmPlatformGetCorePosition):
 //GetPhysAddrTop (
 //  VOID
 //  );
-ASM_PFX(ArmGetPhysAddrTop):
+ASM_FUNC(ArmGetPhysAddrTop)
   mrs   x0, id_aa64mmfr0_el1
   adr   x1, .LPARanges
   and   x0, x0, #7
diff --git a/ArmVirtPkg/Library/ArmVirtPlatformLib/ARM/VirtHelper.S b/ArmVirtPkg/Library/ArmVirtPlatformLib/ARM/VirtHelper.S
index 255f99598740..4a4db3721072 100644
--- a/ArmVirtPkg/Library/ArmVirtPlatformLib/ARM/VirtHelper.S
+++ b/ArmVirtPkg/Library/ArmVirtPlatformLib/ARM/VirtHelper.S
@@ -1,6 +1,6 @@ 
 #
 #  Copyright (c) 2011-2013, ARM Limited. All rights reserved.
-#  Copyright (c) 2014, Linaro Limited. All rights reserved.
+#  Copyright (c) 2014-2016, Linaro Limited. All rights reserved.
 #
 #  This program and the accompanying materials
 #  are licensed and made available under the terms and conditions of the BSD License
@@ -13,41 +13,24 @@ 
 #
 
 #include <AsmMacroIoLib.h>
-#include <Base.h>
 #include <Library/ArmLib.h>
-#include <Library/PcdLib.h>
-#include <AutoGen.h>
 
-.text
-.align 2
-
-GCC_ASM_EXPORT(ArmPlatformPeiBootAction)
-GCC_ASM_EXPORT(ArmPlatformIsPrimaryCore)
-GCC_ASM_EXPORT(ArmPlatformGetPrimaryCoreMpId)
-GCC_ASM_EXPORT(ArmPlatformGetCorePosition)
-GCC_ASM_EXPORT(ArmGetPhysAddrTop)
-
-GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdArmPrimaryCore)
-GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdArmPrimaryCoreMask)
-GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdCoreCount)
-
-ASM_PFX(ArmPlatformPeiBootAction):
+ASM_FUNC(ArmPlatformPeiBootAction)
   bx    lr
 
 //UINTN
 //ArmPlatformGetPrimaryCoreMpId (
 //  VOID
 //  );
-ASM_PFX(ArmPlatformGetPrimaryCoreMpId):
-  LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCore, r0)
-  ldr    r0, [r0]
+ASM_FUNC(ArmPlatformGetPrimaryCoreMpId)
+  MOV32  (r0, FixedPcdGet32 (PcdArmPrimaryCore))
   bx     lr
 
 //UINTN
 //ArmPlatformIsPrimaryCore (
 //  IN UINTN MpId
 //  );
-ASM_PFX(ArmPlatformIsPrimaryCore):
+ASM_FUNC(ArmPlatformIsPrimaryCore)
   mov   r0, #1
   bx    lr
 
@@ -56,7 +39,7 @@  ASM_PFX(ArmPlatformIsPrimaryCore):
 //  IN UINTN MpId
 //  );
 // With this function: CorePos = (ClusterId * 4) + CoreId
-ASM_PFX(ArmPlatformGetCorePosition):
+ASM_FUNC(ArmPlatformGetCorePosition)
   and   r1, r0, #ARM_CORE_MASK
   and   r0, r0, #ARM_CLUSTER_MASK
   add   r0, r1, r0, LSR #6
@@ -66,7 +49,7 @@  ASM_PFX(ArmPlatformGetCorePosition):
 //GetPhysAddrTop (
 //  VOID
 //  );
-ASM_PFX(ArmGetPhysAddrTop):
+ASM_FUNC(ArmGetPhysAddrTop)
   mov   r0, #0x00000000
   mov   r1, #0x10000
   bx    lr
diff --git a/ArmVirtPkg/Library/ArmVirtPlatformLib/ARM/VirtHelper.asm b/ArmVirtPkg/Library/ArmVirtPlatformLib/ARM/VirtHelper.asm
index 7882e63217fc..b476516f2115 100644
--- a/ArmVirtPkg/Library/ArmVirtPlatformLib/ARM/VirtHelper.asm
+++ b/ArmVirtPkg/Library/ArmVirtPlatformLib/ARM/VirtHelper.asm
@@ -11,10 +11,7 @@ 
 //  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 //
 
-#include <AsmMacroIoLib.h>
-#include <Base.h>
 #include <Library/ArmLib.h>
-#include <Library/PcdLib.h>
 #include <AutoGen.h>
 
   INCLUDE AsmMacroIoLib.inc
@@ -25,10 +22,6 @@ 
   EXPORT  ArmPlatformGetCorePosition
   EXPORT  ArmGetPhysAddrTop
 
-  IMPORT  _gPcd_FixedAtBuild_PcdArmPrimaryCore
-  IMPORT  _gPcd_FixedAtBuild_PcdArmPrimaryCoreMask
-  IMPORT  _gPcd_FixedAtBuild_PcdCoreCount
-
   AREA VirtHelper, CODE, READONLY
 
 ArmPlatformPeiBootAction FUNCTION
@@ -40,8 +33,7 @@  ArmPlatformPeiBootAction FUNCTION
 //  VOID
 //  );
 ArmPlatformGetPrimaryCoreMpId FUNCTION
-  LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCore, r0)
-  ldr    r0, [r0]
+  MOV32  r0, FixedPcdGet32 (PcdArmPrimaryCore)
   bx     lr
   ENDFUNC
 
diff --git a/ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/AARCH64/RelocatableVirtHelper.S b/ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/AARCH64/RelocatableVirtHelper.S
index 940bcb2d257a..ce886378eae6 100644
--- a/ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/AARCH64/RelocatableVirtHelper.S
+++ b/ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/AARCH64/RelocatableVirtHelper.S
@@ -1,5 +1,6 @@ 
 #
 #  Copyright (c) 2011-2013, ARM Limited. All rights reserved.
+#  Copyright (c) 2016, Linaro Limited. All rights reserved.
 #
 #  This program and the accompanying materials
 #  are licensed and made available under the terms and conditions of the BSD License
@@ -12,33 +13,14 @@ 
 #
 
 #include <AsmMacroIoLibV8.h>
-#include <Base.h>
 #include <Library/ArmLib.h>
-#include <Library/PcdLib.h>
-#include <AutoGen.h>
-
-.text
-.align 2
-
-GCC_ASM_EXPORT(ArmPlatformPeiBootAction)
-GCC_ASM_EXPORT(ArmPlatformIsPrimaryCore)
-GCC_ASM_EXPORT(ArmPlatformGetPrimaryCoreMpId)
-GCC_ASM_EXPORT(ArmPlatformGetCorePosition)
-GCC_ASM_EXPORT(ArmGetPhysAddrTop)
-
-GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdArmPrimaryCore)
-GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdArmPrimaryCoreMask)
-GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdCoreCount)
-
-.LArm64LinuxMagic:
-  .byte   0x41, 0x52, 0x4d, 0x64
 
 // VOID
 // ArmPlatformPeiBootAction (
 //   VOID   *DeviceTreeBaseAddress,   // passed by loader in x0
 //   VOID   *ImageBase                // passed by FDF trampoline in x1
 //   );
-ASM_PFX(ArmPlatformPeiBootAction):
+ASM_FUNC(ArmPlatformPeiBootAction)
   mov   x29, x30            // preserve LR
   mov   x28, x0             // preserve DTB pointer
   mov   x27, x1             // preserve base of image pointer
@@ -103,20 +85,22 @@  ASM_PFX(ArmPlatformPeiBootAction):
 .Lout:
   ret    x29
 
+.LArm64LinuxMagic:
+  .byte   0x41, 0x52, 0x4d, 0x64
+
 //UINTN
 //ArmPlatformGetPrimaryCoreMpId (
 //  VOID
 //  );
-ASM_PFX(ArmPlatformGetPrimaryCoreMpId):
-  LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCore, x0)
-  ldrh   w0, [x0]
+ASM_FUNC(ArmPlatformGetPrimaryCoreMpId)
+  MOV32  (w0, FixedPcdGet32 (PcdArmPrimaryCore))
   ret
 
 //UINTN
 //ArmPlatformIsPrimaryCore (
 //  IN UINTN MpId
 //  );
-ASM_PFX(ArmPlatformIsPrimaryCore):
+ASM_FUNC(ArmPlatformIsPrimaryCore)
   mov   x0, #1
   ret
 
@@ -125,7 +109,7 @@  ASM_PFX(ArmPlatformIsPrimaryCore):
 //  IN UINTN MpId
 //  );
 // With this function: CorePos = (ClusterId * 4) + CoreId
-ASM_PFX(ArmPlatformGetCorePosition):
+ASM_FUNC(ArmPlatformGetCorePosition)
   and   x1, x0, #ARM_CORE_MASK
   and   x0, x0, #ARM_CLUSTER_MASK
   add   x0, x1, x0, LSR #6
@@ -135,7 +119,7 @@  ASM_PFX(ArmPlatformGetCorePosition):
 //GetPhysAddrTop (
 //  VOID
 //  );
-ASM_PFX(ArmGetPhysAddrTop):
+ASM_FUNC(ArmGetPhysAddrTop)
   mrs   x0, id_aa64mmfr0_el1
   adr   x1, .LPARanges
   and   x0, x0, #7
diff --git a/ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/ARM/RelocatableVirtHelper.S b/ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/ARM/RelocatableVirtHelper.S
index 539426f36f50..f264fa1cf731 100644
--- a/ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/ARM/RelocatableVirtHelper.S
+++ b/ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/ARM/RelocatableVirtHelper.S
@@ -1,6 +1,6 @@ 
 #
 #  Copyright (c) 2011-2013, ARM Limited. All rights reserved.
-#  Copyright (c) 2014, Linaro Limited. All rights reserved.
+#  Copyright (c) 2014-2016, Linaro Limited. All rights reserved.
 #
 #  This program and the accompanying materials
 #  are licensed and made available under the terms and conditions of the BSD License
@@ -13,28 +13,9 @@ 
 #
 
 #include <AsmMacroIoLib.h>
-#include <Base.h>
 #include <Library/ArmLib.h>
-#include <Library/PcdLib.h>
-#include <AutoGen.h>
 
-.text
-.align 2
-
-GCC_ASM_EXPORT(ArmPlatformPeiBootAction)
-GCC_ASM_EXPORT(ArmPlatformIsPrimaryCore)
-GCC_ASM_EXPORT(ArmPlatformGetPrimaryCoreMpId)
-GCC_ASM_EXPORT(ArmPlatformGetCorePosition)
-GCC_ASM_EXPORT(ArmGetPhysAddrTop)
-
-GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdArmPrimaryCore)
-GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdArmPrimaryCoreMask)
-GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdCoreCount)
-
-.LArm32LinuxMagic:
-  .byte   0x18, 0x28, 0x6f, 0x01
-
-ASM_PFX(ArmPlatformPeiBootAction):
+ASM_FUNC(ArmPlatformPeiBootAction)
   mov   r11, r14            // preserve LR
   mov   r10, r0             // preserve DTB pointer
   mov   r9, r1              // preserve base of image pointer
@@ -63,8 +44,8 @@  ASM_PFX(ArmPlatformPeiBootAction):
   // to the actual relocated value, and add the shift of PcdFdBaseAddress to
   // PcdFvBaseAddress as well
   //
-  ldr   r8, =PcdGet64 (PcdFdBaseAddress)
-  ldr   r7, =PcdGet64 (PcdFvBaseAddress)
+  ADRL  (r8, PcdGet64 (PcdFdBaseAddress))
+  ADRL  (r7, PcdGet64 (PcdFvBaseAddress))
   ldr   r6, [r8]
   ldr   r5, [r7]
   sub   r5, r5, r6
@@ -78,8 +59,8 @@  ASM_PFX(ArmPlatformPeiBootAction):
   // encountered. Since we are calling a C function, use the window at the
   // beginning of the FD image as a temp stack.
   //
-  ldr   r1, =PcdGet64 (PcdSystemMemoryBase)
-  ldr   r2, =PcdGet64 (PcdSystemMemorySize)
+  ADRL  (r1, PcdGet64 (PcdSystemMemoryBase))
+  ADRL  (r2, PcdGet64 (PcdSystemMemorySize))
   mov   sp, r5
   bl    FindMemnode
   teq   r0, #0
@@ -90,7 +71,7 @@  ASM_PFX(ArmPlatformPeiBootAction):
   // image header at the base of this image (defined in the FDF), and record the
   // pointer in PcdDeviceTreeInitialBaseAddress.
   //
-  ldr   r8, =PcdGet64 (PcdDeviceTreeInitialBaseAddress)
+  ADRL  (r8, PcdGet64 (PcdDeviceTreeInitialBaseAddress))
   add   r9, r9, #0x40
   str   r9, [r8]
 
@@ -101,20 +82,22 @@  ASM_PFX(ArmPlatformPeiBootAction):
 .Lout:
   bx    r11
 
+.LArm32LinuxMagic:
+  .byte   0x18, 0x28, 0x6f, 0x01
+
 //UINTN
 //ArmPlatformGetPrimaryCoreMpId (
 //  VOID
 //  );
-ASM_PFX(ArmPlatformGetPrimaryCoreMpId):
-  LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCore, r0)
-  ldr    r0, [r0]
+ASM_FUNC(ArmPlatformGetPrimaryCoreMpId)
+  MOV32  (r0, FixedPcdGet32 (PcdArmPrimaryCore))
   bx     lr
 
 //UINTN
 //ArmPlatformIsPrimaryCore (
 //  IN UINTN MpId
 //  );
-ASM_PFX(ArmPlatformIsPrimaryCore):
+ASM_FUNC(ArmPlatformIsPrimaryCore)
   mov   r0, #1
   bx    lr
 
@@ -123,7 +106,7 @@  ASM_PFX(ArmPlatformIsPrimaryCore):
 //  IN UINTN MpId
 //  );
 // With this function: CorePos = (ClusterId * 4) + CoreId
-ASM_PFX(ArmPlatformGetCorePosition):
+ASM_FUNC(ArmPlatformGetCorePosition)
   and   r1, r0, #ARM_CORE_MASK
   and   r0, r0, #ARM_CLUSTER_MASK
   add   r0, r1, r0, LSR #6
@@ -133,7 +116,7 @@  ASM_PFX(ArmPlatformGetCorePosition):
 //GetPhysAddrTop (
 //  VOID
 //  );
-ASM_PFX(ArmGetPhysAddrTop):
+ASM_FUNC(ArmGetPhysAddrTop)
   mov   r0, #0x00000000
   mov   r1, #0x10000
   bx    lr
diff --git a/ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S b/ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S
index 1fed84ed0ac3..9c040b17f253 100644
--- a/ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S
+++ b/ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S
@@ -1,6 +1,6 @@ 
 //
 //  Copyright (c) 2011-2013, ARM Limited. All rights reserved.
-//  Copyright (c) 2015, Linaro Limited. All rights reserved.
+//  Copyright (c) 2015-2016, Linaro Limited. All rights reserved.
 //
 //  This program and the accompanying materials
 //  are licensed and made available under the terms and conditions of the BSD License
@@ -13,23 +13,10 @@ 
 //
 
 #include <AsmMacroIoLibV8.h>
-#include <Base.h>
-#include <Library/PcdLib.h>
-#include <AutoGen.h>
-
-.text
-.align 3
-
-GCC_ASM_IMPORT(ArmPlatformIsPrimaryCore)
-GCC_ASM_IMPORT(ArmReadMpidr)
-GCC_ASM_IMPORT(ArmPlatformPeiBootAction)
-GCC_ASM_IMPORT(ArmPlatformStackSet)
-GCC_ASM_EXPORT(_ModuleEntryPoint)
-ASM_GLOBAL ASM_PFX(mSystemMemoryEnd)
 
-ASM_PFX(mSystemMemoryEnd):    .8byte 0
+ASM_GLOBAL ASM_PFX(mSystemMemoryEnd)
 
-ASM_PFX(_ModuleEntryPoint):
+ASM_FUNC(_ModuleEntryPoint)
   //
   // We are built as a ET_DYN PIE executable, so we need to process all
   // relative relocations regardless of whether or not we are executing from
@@ -86,12 +73,11 @@  _SetupStackPosition:
 
   // Calculate Top of the Firmware Device
   ldr   x2, PcdGet64 (PcdFdBaseAddress)
-  ldr   w3, PcdGet32 (PcdFdSize)
-  sub   x3, x3, #1
+  MOV32 (w3, FixedPcdGet32 (PcdFdSize) - 1)
   add   x3, x3, x2      // x3 = FdTop = PcdFdBaseAddress + PcdFdSize
 
   // UEFI Memory Size (stacks are allocated in this region)
-  LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryUefiRegionSize), x4)
+  MOV32 (x4, FixedPcdGet32(PcdSystemMemoryUefiRegionSize))
 
   //
   // Reserve the memory for the UEFI region (contain stacks on its top)
@@ -122,9 +108,7 @@  _SetupAlignedStack:
 _SetupOverflowStack:
   // Case memory at the top of the address space. Ensure the top of the stack is EFI_PAGE_SIZE
   // aligned (4KB)
-  LoadConstantToReg (EFI_PAGE_MASK, x21)
-  and   x21, x21, x1
-  sub   x1, x1, x21
+  and   x1, x1, ~EFI_PAGE_MASK
 
 _GetBaseUefiMemory:
   // Calculate the Base of the UEFI Memory
@@ -133,22 +117,19 @@  _GetBaseUefiMemory:
 _GetStackBase:
   // r1 = The top of the Mpcore Stacks
   // Stack for the primary core = PrimaryCoreStack
-  LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), x2)
+  MOV32 (x2, FixedPcdGet32(PcdCPUCorePrimaryStackSize))
   sub   x22, x1, x2
 
   // Stack for the secondary core = Number of Cores - 1
-  LoadConstantToReg (FixedPcdGet32(PcdCoreCount), x0)
-  sub   x0, x0, #1
-  LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), x1)
-  mul   x1, x1, x0
+  MOV32 (x1, (FixedPcdGet32(PcdCoreCount) - 1) * FixedPcdGet32(PcdCPUCoreSecondaryStackSize))
   sub   x22, x22, x1
 
   // x22 = The base of the MpCore Stacks (primary stack & secondary stacks)
   mov   x0, x22
   mov   x1, x20
   //ArmPlatformStackSet(StackBase, MpId, PrimaryStackSize, SecondaryStackSize)
-  LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), x2)
-  LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), x3)
+  MOV32 (x2, FixedPcdGet32(PcdCPUCorePrimaryStackSize))
+  MOV32 (x3, FixedPcdGet32(PcdCPUCoreSecondaryStackSize))
   bl    ASM_PFX(ArmPlatformStackSet)
 
   // Is it the Primary Core ?
@@ -170,3 +151,5 @@  _PrepareArguments:
 
 _NeverReturn:
   b _NeverReturn
+
+ASM_PFX(mSystemMemoryEnd):    .8byte 0
diff --git a/ArmVirtPkg/PrePi/Arm/ModuleEntryPoint.S b/ArmVirtPkg/PrePi/Arm/ModuleEntryPoint.S
index a0176af91c8f..e03aeefbb003 100644
--- a/ArmVirtPkg/PrePi/Arm/ModuleEntryPoint.S
+++ b/ArmVirtPkg/PrePi/Arm/ModuleEntryPoint.S
@@ -1,6 +1,6 @@ 
 //
 //  Copyright (c) 2011-2013, ARM Limited. All rights reserved.
-//  Copyright (c) 2015, Linaro Limited. All rights reserved.
+//  Copyright (c) 2015-2016, Linaro Limited. All rights reserved.
 //
 //  This program and the accompanying materials
 //  are licensed and made available under the terms and conditions of the BSD License
@@ -13,41 +13,18 @@ 
 //
 
 #include <AsmMacroIoLib.h>
-#include <Base.h>
-#include <Library/PcdLib.h>
-#include <AutoGen.h>
-
-.text
-.align 3
-
-GCC_ASM_IMPORT(ArmPlatformIsPrimaryCore)
-GCC_ASM_IMPORT(ArmReadMpidr)
-GCC_ASM_IMPORT(ArmPlatformPeiBootAction)
-GCC_ASM_IMPORT(ArmPlatformStackSet)
-GCC_ASM_EXPORT(_ModuleEntryPoint)
-ASM_GLOBAL ASM_PFX(mSystemMemoryEnd)
-
-ASM_PFX(mSystemMemoryEnd):    .quad 0
 
-__relocs:
-  .long   __reloc_base - __relocs
-  .long   __reloc_start - __relocs
-  .long   __reloc_end - __relocs
+ASM_GLOBAL ASM_PFX(mSystemMemoryEnd)
 
-ASM_PFX(_ModuleEntryPoint):
+ASM_FUNC(_ModuleEntryPoint)
   //
   // We are built as a ET_DYN PIE executable, so we need to process all
   // relative relocations if we are executing from a different offset than we
   // were linked at. This is only possible if we are running from RAM.
   //
-
-  adr   r12, __relocs
-  ldrd  r4, r5, [r12]
-  ldr   r6, [r12, #8]
-
-  add   r4, r4, r12
-  add   r5, r5, r12
-  add   r6, r6, r12
+  ADRL  (r4, __reloc_base)
+  ADRL  (r5, __reloc_start)
+  ADRL  (r6, __reloc_end)
 
 .Lreloc_loop:
   cmp   r5, r6
@@ -85,9 +62,8 @@  ASM_PFX(_ModuleEntryPoint):
 // at the top of the DRAM)
 _SetupStackPosition:
   // Compute Top of System Memory
-  ldr   r12, =PcdGet64 (PcdSystemMemoryBase)
-  ldr   r1, [r12]
-  ldr   r12, =PcdGet64 (PcdSystemMemorySize)
+  LDRL  (r1, PcdGet64 (PcdSystemMemoryBase))
+  ADRL  (r12, PcdGet64 (PcdSystemMemorySize))
   ldrd  r2, r3, [r12]
 
   // calculate the top of memory, and record it in mSystemMemoryEnd
@@ -103,14 +79,12 @@  _SetupStackPosition:
   moveq r1, r2
 
   // Calculate Top of the Firmware Device
-  ldr   r12, =PcdGet64 (PcdFdBaseAddress)
-  ldr   r2, [r12]
-  ldr   r3, =FixedPcdGet32 (PcdFdSize)
-  sub   r3, r3, #1
+  LDRL  (r2, PcdGet64 (PcdFdBaseAddress))
+  MOV32 (r3, FixedPcdGet32 (PcdFdSize) - 1)
   add   r3, r3, r2      // r3 = FdTop = PcdFdBaseAddress + PcdFdSize
 
   // UEFI Memory Size (stacks are allocated in this region)
-  LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryUefiRegionSize), r4)
+  MOV32 (r4, FixedPcdGet32(PcdSystemMemoryUefiRegionSize))
 
   //
   // Reserve the memory for the UEFI region (contain stacks on its top)
@@ -141,9 +115,8 @@  _SetupAlignedStack:
 _SetupOverflowStack:
   // Case memory at the top of the address space. Ensure the top of the stack is EFI_PAGE_SIZE
   // aligned (4KB)
-  LoadConstantToReg (EFI_PAGE_MASK, r11)
-  and   r11, r11, r1
-  sub   r1, r1, r11
+  MOV32 (r11, (~EFI_PAGE_MASK) & 0xffffffff)
+  and   r1, r1, r11
 
 _GetBaseUefiMemory:
   // Calculate the Base of the UEFI Memory
@@ -152,22 +125,19 @@  _GetBaseUefiMemory:
 _GetStackBase:
   // r1 = The top of the Mpcore Stacks
   // Stack for the primary core = PrimaryCoreStack
-  LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), r2)
+  MOV32 (r2, FixedPcdGet32(PcdCPUCorePrimaryStackSize))
   sub   r9, r1, r2
 
   // Stack for the secondary core = Number of Cores - 1
-  LoadConstantToReg (FixedPcdGet32(PcdCoreCount), r0)
-  sub   r0, r0, #1
-  LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), r1)
-  mul   r1, r1, r0
+  MOV32 (r1, (FixedPcdGet32(PcdCoreCount) - 1) * FixedPcdGet32(PcdCPUCoreSecondaryStackSize))
   sub   r9, r9, r1
 
   // r9 = The base of the MpCore Stacks (primary stack & secondary stacks)
   mov   r0, r9
   mov   r1, r10
   //ArmPlatformStackSet(StackBase, MpId, PrimaryStackSize, SecondaryStackSize)
-  LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), r2)
-  LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), r3)
+  MOV32 (r2, FixedPcdGet32(PcdCPUCorePrimaryStackSize))
+  MOV32 (r3, FixedPcdGet32(PcdCPUCoreSecondaryStackSize))
   bl    ASM_PFX(ArmPlatformStackSet)
 
   // Is it the Primary Core ?
@@ -189,3 +159,5 @@  _PrepareArguments:
 
 _NeverReturn:
   b _NeverReturn
+
+ASM_PFX(mSystemMemoryEnd):    .quad 0