• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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#include <Base.h>
16#include <AutoGen.h>
17
18.text
19.align 3
20
21GCC_ASM_EXPORT(ArmPlatformStackSet)
22GCC_ASM_EXPORT(ArmPlatformStackSetPrimary)
23GCC_ASM_EXPORT(ArmPlatformStackSetSecondary)
24
25GCC_ASM_IMPORT(ArmPlatformIsPrimaryCore)
26GCC_ASM_IMPORT(ArmPlatformGetCorePosition)
27GCC_ASM_IMPORT(ArmPlatformGetPrimaryCoreMpId)
28
29GCC_ASM_IMPORT(gPcd_FixedAtBuild_PcdCoreCount)
30
31//VOID
32//ArmPlatformStackSet (
33//  IN UINTN StackBase,
34//  IN UINTN MpId,
35//  IN UINTN PrimaryStackSize,
36//  IN UINTN SecondaryStackSize
37//  );
38ASM_PFX(ArmPlatformStackSet):
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    ASM_PFX(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   ASM_PFX(ArmPlatformStackSetPrimary)
63  bne   ASM_PFX(ArmPlatformStackSetSecondary)
64
65//VOID
66//ArmPlatformStackSetPrimary (
67//  IN UINTN StackBase,
68//  IN UINTN MpId,
69//  IN UINTN PrimaryStackSize,
70//  IN UINTN SecondaryStackSize
71//  );
72ASM_PFX(ArmPlatformStackSetPrimary):
73  mov   r4, lr
74
75  // Add stack of primary stack to StackBase
76  add   r0, r0, r2
77
78  // Compute SecondaryCoresCount * SecondaryCoreStackSize
79  LoadConstantToReg (_gPcd_FixedAtBuild_PcdCoreCount, r1)
80  ldr   r1, [r1]
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
89//VOID
90//ArmPlatformStackSetSecondary (
91//  IN UINTN StackBase,
92//  IN UINTN MpId,
93//  IN UINTN PrimaryStackSize,
94//  IN UINTN SecondaryStackSize
95//  );
96ASM_PFX(ArmPlatformStackSetSecondary):
97  mov   r4, lr
98  mov   sp, r0
99
100  // Get Core Position
101  mov   r0, r1
102  bl    ASM_PFX(ArmPlatformGetCorePosition)
103  mov   r5, r0
104
105  // Get Primary Core Position
106  bl    ASM_PFX(ArmPlatformGetPrimaryCoreMpId)
107  bl    ASM_PFX(ArmPlatformGetCorePosition)
108
109  // Get Secondary Core Position. We should get consecutive secondary stack number from 1...(CoreCount-1)
110  cmp   r5, r0
111  subhi r5, r5, #1
112  add   r5, r5, #1
113
114  // Compute top of the secondary stack
115  mul   r3, r3, r5
116
117  // Set stack
118  add   sp, sp, r3
119
120  bx r4
121
122