ArmPlatformPkg/ArmPlatformStackLib: use callee preserved registers

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>
This commit is contained in:
Ard Biesheuvel 2017-02-22 09:38:18 +00:00
parent 88dab294d2
commit 91231b55d5
1 changed files with 19 additions and 24 deletions

View File

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