]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPlatformPkg/ArmPlatformStackLib: use callee preserved registers
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Wed, 22 Feb 2017 09:38:18 +0000 (09:38 +0000)
committerArd Biesheuvel <ard.biesheuvel@linaro.org>
Wed, 22 Feb 2017 13:22:41 +0000 (13:22 +0000)
The entry code in ArmPlatformStackSet () is a 1:1 transliteration of the
ARM version, which uses the callee preserved registers r3 - r7 (*) to
preserve the function arguments and the link register across a call to
ArmPlatformIsPrimaryCore ().

However, x3 - x7 are not callee preserved on AARCH64, and so we should use
registers >= x19 instead. While we're at it, drop an unnecessary preserve
of the link register, and simplify/deobfuscate the calculation of the
secondary stack position.

(*) Note that r3 is not actually a callee saved register even on ARM.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
ArmPlatformPkg/Library/ArmPlatformStackLib/AArch64/ArmPlatformStackLib.S

index 65d7d6c6d686b88f63e7d752531dbdbbdd6d5d15..e219d53cb71dc67061b4a4be1cd95df4806474d7 100644 (file)
 //  );\r
 ASM_FUNC(ArmPlatformStackSet)\r
   // Save parameters\r
-  mov   x6, x3\r
-  mov   x5, x2\r
-  mov   x4, x1\r
-  mov   x3, x0\r
+  mov   x26, x3\r
+  mov   x25, x2\r
+  mov   x24, x1\r
+  mov   x23, x0\r
 \r
   // Save the Link register\r
-  mov   x7, x30\r
+  mov   x27, x30\r
 \r
   // Identify Stack\r
   mov   x0, x1\r
@@ -36,13 +36,13 @@ ASM_FUNC(ArmPlatformStackSet)
   cmp   x0, #1\r
 \r
   // Restore parameters\r
-  mov   x0, x3\r
-  mov   x1, x4\r
-  mov   x2, x5\r
-  mov   x3, x6\r
+  mov   x0, x23\r
+  mov   x1, x24\r
+  mov   x2, x25\r
+  mov   x3, x26\r
 \r
   // Restore the Link register\r
-  mov   x30, x7\r
+  mov   x30, x27\r
 \r
   b.ne  0f\r
 \r
@@ -57,10 +57,7 @@ ASM_FUNC(ArmPlatformStackSet)
 //  IN UINTN SecondaryStackSize\r
 //  );\r
 ASM_FUNC(ArmPlatformStackSetPrimary)\r
-  // Save the Link register\r
-  mov   x4, x30\r
-\r
-  // Add stack of primary stack to StackBase\r
+  // Add size of primary stack to StackBase\r
   add   x0, x0, x2\r
 \r
   // Compute SecondaryCoresCount * SecondaryCoreStackSize\r
@@ -70,7 +67,7 @@ ASM_FUNC(ArmPlatformStackSetPrimary)
   // Set Primary Stack ((StackBase + PrimaryStackSize) + (SecondaryCoresCount * SecondaryCoreStackSize))\r
   add   sp, x0, x3\r
 \r
-  br    x4\r
+  ret\r
 \r
 //VOID\r
 //ArmPlatformStackSetSecondary (\r
@@ -81,30 +78,28 @@ ASM_FUNC(ArmPlatformStackSetPrimary)
 //  );\r
 ASM_FUNC(ArmPlatformStackSetSecondary)\r
   // Save the Link register\r
-  mov   x4, x30\r
+  mov   x24, x30\r
   mov   sp, x0\r
 \r
   // Get Core Position\r
   mov   x0, x1\r
   bl    ASM_PFX(ArmPlatformGetCorePosition)\r
-  mov   x5, x0\r
+  mov   x25, x0\r
 \r
   // Get Primary Core Position\r
   bl    ASM_PFX(ArmPlatformGetPrimaryCoreMpId)\r
   bl    ASM_PFX(ArmPlatformGetCorePosition)\r
 \r
   // Get Secondary Core Position. We should get consecutive secondary stack number from 1...(CoreCount-1)\r
-  cmp   x5, x0\r
-  b.ls  1f\r
+  cmp   x25, x0\r
+\r
   // Decrement the position if after the primary core\r
-  sub   x5, x5, #1\r
-1:\r
-  add   x5, x5, #1\r
+  cinc  x25, x25, ls\r
 \r
   // Compute top of the secondary stack\r
-  mul   x3, x3, x5\r
+  mul   x3, x3, x25\r
 \r
   // Set stack\r
   add   sp, sp, x3\r
 \r
-  br    x4\r
+  ret   x24\r