1// 2// Copyright (c) 2012-2014, 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 <AsmMacroIoLibV8.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 x6, x3 26 mov x5, x2 27 mov x4, x1 28 mov x3, x0 29 30 // Save the Link register 31 mov x7, x30 32 33 // Identify Stack 34 mov x0, x1 35 bl ASM_PFX(ArmPlatformIsPrimaryCore) 36 cmp x0, #1 37 38 // Restore parameters 39 mov x0, x3 40 mov x1, x4 41 mov x2, x5 42 mov x3, x6 43 44 // Restore the Link register 45 mov x30, x7 46 47 b.ne 0f 48 49 b ASM_PFX(ArmPlatformStackSetPrimary) 500:b ASM_PFX(ArmPlatformStackSetSecondary) 51 52//VOID 53//ArmPlatformStackSetPrimary ( 54// IN UINTN StackBase, 55// IN UINTN MpId, 56// IN UINTN PrimaryStackSize, 57// IN UINTN SecondaryStackSize 58// ); 59ASM_FUNC(ArmPlatformStackSetPrimary) 60 // Save the Link register 61 mov x4, x30 62 63 // Add stack of primary stack to StackBase 64 add x0, x0, x2 65 66 // Compute SecondaryCoresCount * SecondaryCoreStackSize 67 MOV32 (w1, FixedPcdGet32(PcdCoreCount) - 1) 68 mul x3, x3, x1 69 70 // Set Primary Stack ((StackBase + PrimaryStackSize) + (SecondaryCoresCount * SecondaryCoreStackSize)) 71 add sp, x0, x3 72 73 br x4 74 75//VOID 76//ArmPlatformStackSetSecondary ( 77// IN UINTN StackBase, 78// IN UINTN MpId, 79// IN UINTN PrimaryStackSize, 80// IN UINTN SecondaryStackSize 81// ); 82ASM_FUNC(ArmPlatformStackSetSecondary) 83 // Save the Link register 84 mov x4, x30 85 mov sp, x0 86 87 // Get Core Position 88 mov x0, x1 89 bl ASM_PFX(ArmPlatformGetCorePosition) 90 mov x5, x0 91 92 // Get Primary Core Position 93 bl ASM_PFX(ArmPlatformGetPrimaryCoreMpId) 94 bl ASM_PFX(ArmPlatformGetCorePosition) 95 96 // Get Secondary Core Position. We should get consecutive secondary stack number from 1...(CoreCount-1) 97 cmp x5, x0 98 b.ls 1f 99 // Decrement the position if after the primary core 100 sub x5, x5, #1 1011: 102 add x5, x5, #1 103 104 // Compute top of the secondary stack 105 mul x3, x3, x5 106 107 // Set stack 108 add sp, sp, x3 109 110 br x4 111