1// 2// Copyright (c) 2012-2013, ARM Limited. All rights reserved. 3// 4// This program and the accompanying materials 5// are licensed and made available under the terms and conditions of the BSD License 6// which accompanies this distribution. The full text of the license may be found at 7// http://opensource.org/licenses/bsd-license.php 8// 9// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11// 12// 13 14#include <AsmMacroIoLib.h> 15 16//VOID 17//ArmPlatformStackSet ( 18// IN UINTN StackBase, 19// IN UINTN MpId, 20// IN UINTN PrimaryStackSize, 21// IN UINTN SecondaryStackSize 22// ); 23ASM_FUNC(ArmPlatformStackSet) 24 // Save parameters 25 mov r6, r3 26 mov r5, r2 27 mov r4, r1 28 mov r3, r0 29 30 // Save the Link register 31 mov r7, lr 32 33 // Identify Stack 34 mov r0, r1 35 bl ASM_PFX(ArmPlatformIsPrimaryCore) 36 cmp r0, #1 37 38 // Restore parameters 39 mov r0, r3 40 mov r1, r4 41 mov r2, r5 42 mov r3, r6 43 44 // Restore the Link register 45 mov lr, r7 46 47 beq ASM_PFX(ArmPlatformStackSetPrimary) 48 bne ASM_PFX(ArmPlatformStackSetSecondary) 49 50//VOID 51//ArmPlatformStackSetPrimary ( 52// IN UINTN StackBase, 53// IN UINTN MpId, 54// IN UINTN PrimaryStackSize, 55// IN UINTN SecondaryStackSize 56// ); 57ASM_FUNC(ArmPlatformStackSetPrimary) 58 mov r4, lr 59 60 // Add stack of primary stack to StackBase 61 add r0, r0, r2 62 63 // Compute SecondaryCoresCount * SecondaryCoreStackSize 64 MOV32 (r1, FixedPcdGet32(PcdCoreCount) - 1) 65 mul r3, r3, r1 66 67 // Set Primary Stack ((StackBase + PrimaryStackSize) + (SecondaryCoresCount * SecondaryCoreStackSize)) 68 add sp, r0, r3 69 70 bx r4 71 72//VOID 73//ArmPlatformStackSetSecondary ( 74// IN UINTN StackBase, 75// IN UINTN MpId, 76// IN UINTN PrimaryStackSize, 77// IN UINTN SecondaryStackSize 78// ); 79ASM_FUNC(ArmPlatformStackSetSecondary) 80 mov r4, lr 81 mov sp, r0 82 83 // Get Core Position 84 mov r0, r1 85 bl ASM_PFX(ArmPlatformGetCorePosition) 86 mov r5, r0 87 88 // Get Primary Core Position 89 bl ASM_PFX(ArmPlatformGetPrimaryCoreMpId) 90 bl ASM_PFX(ArmPlatformGetCorePosition) 91 92 // Get Secondary Core Position. We should get consecutive secondary stack number from 1...(CoreCount-1) 93 cmp r5, r0 94 subhi r5, r5, #1 95 add r5, r5, #1 96 97 // Compute top of the secondary stack 98 mul r3, r3, r5 99 100 // Set stack 101 add sp, sp, r3 102 103 bx r4 104 105