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 <AutoGen.h> 15 16 INCLUDE AsmMacroIoLib.inc 17 18 EXPORT ArmPlatformStackSet 19 EXPORT ArmPlatformStackSetPrimary 20 EXPORT ArmPlatformStackSetSecondary 21 22 IMPORT ArmPlatformIsPrimaryCore 23 IMPORT ArmPlatformGetCorePosition 24 IMPORT ArmPlatformGetPrimaryCoreMpId 25 26 IMPORT _gPcd_FixedAtBuild_PcdCoreCount 27 28 PRESERVE8 29 AREA ArmPlatformStackLib, CODE, READONLY 30 31//VOID 32//ArmPlatformStackSet ( 33// IN UINTN StackBase, 34// IN UINTN MpId, 35// IN UINTN PrimaryStackSize, 36// IN UINTN SecondaryStackSize 37// ); 38ArmPlatformStackSet FUNCTION 39 // Save parameters 40 mov r6, r3 41 mov r5, r2 42 mov r4, r1 43 mov r3, r0 44 45 // Save the Link register 46 mov r7, lr 47 48 // Identify Stack 49 mov r0, r1 50 bl ArmPlatformIsPrimaryCore 51 cmp r0, #1 52 53 // Restore parameters 54 mov r0, r3 55 mov r1, r4 56 mov r2, r5 57 mov r3, r6 58 59 // Restore the Link register 60 mov lr, r7 61 62 beq ArmPlatformStackSetPrimary 63 bne ArmPlatformStackSetSecondary 64 ENDFUNC 65 66//VOID 67//ArmPlatformStackSetPrimary ( 68// IN UINTN StackBase, 69// IN UINTN MpId, 70// IN UINTN PrimaryStackSize, 71// IN UINTN SecondaryStackSize 72// ); 73ArmPlatformStackSetPrimary FUNCTION 74 mov r4, lr 75 76 // Add stack of primary stack to StackBase 77 add r0, r0, r2 78 79 // Compute SecondaryCoresCount * SecondaryCoreStackSize 80 mov32 r1, FixedPcdGet32 (PcdCoreCount) 81 sub r1, #1 82 mul r3, r3, r1 83 84 // Set Primary Stack ((StackBase + PrimaryStackSize) + (SecondaryCoresCount * SecondaryCoreStackSize)) 85 add sp, r0, r3 86 87 bx r4 88 ENDFUNC 89 90//VOID 91//ArmPlatformStackSetSecondary ( 92// IN UINTN StackBase, 93// IN UINTN MpId, 94// IN UINTN PrimaryStackSize, 95// IN UINTN SecondaryStackSize 96// ); 97ArmPlatformStackSetSecondary FUNCTION 98 mov r4, lr 99 mov sp, r0 100 101 // Get Core Position 102 mov r0, r1 103 bl ArmPlatformGetCorePosition 104 mov r5, r0 105 106 // Get Primary Core Position 107 bl ArmPlatformGetPrimaryCoreMpId 108 bl ArmPlatformGetCorePosition 109 110 // Get Secondary Core Position. We should get consecutive secondary stack number from 1...(CoreCount-1) 111 cmp r5, r0 112 subhi r5, r5, #1 113 add r5, r5, #1 114 115 // Compute top of the secondary stack 116 mul r3, r3, r5 117 118 // Set stack 119 add sp, sp, r3 120 121 bx r4 122 ENDFUNC 123 124 END 125