]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/Library/ArmPlatformStackLib/AArch64/ArmPlatformStackLib.S
ArmPlatformPkg/ArmPlatformStackLib: use callee preserved registers
[mirror_edk2.git] / ArmPlatformPkg / Library / ArmPlatformStackLib / AArch64 / ArmPlatformStackLib.S
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 // );
23 ASM_FUNC(ArmPlatformStackSet)
24 // Save parameters
25 mov x26, x3
26 mov x25, x2
27 mov x24, x1
28 mov x23, x0
29
30 // Save the Link register
31 mov x27, 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, x23
40 mov x1, x24
41 mov x2, x25
42 mov x3, x26
43
44 // Restore the Link register
45 mov x30, x27
46
47 b.ne 0f
48
49 b ASM_PFX(ArmPlatformStackSetPrimary)
50 0: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 // );
59 ASM_FUNC(ArmPlatformStackSetPrimary)
60 // Add size of primary stack to StackBase
61 add x0, x0, x2
62
63 // Compute SecondaryCoresCount * SecondaryCoreStackSize
64 MOV32 (w1, FixedPcdGet32(PcdCoreCount) - 1)
65 mul x3, x3, x1
66
67 // Set Primary Stack ((StackBase + PrimaryStackSize) + (SecondaryCoresCount * SecondaryCoreStackSize))
68 add sp, x0, x3
69
70 ret
71
72 //VOID
73 //ArmPlatformStackSetSecondary (
74 // IN UINTN StackBase,
75 // IN UINTN MpId,
76 // IN UINTN PrimaryStackSize,
77 // IN UINTN SecondaryStackSize
78 // );
79 ASM_FUNC(ArmPlatformStackSetSecondary)
80 // Save the Link register
81 mov x24, x30
82 mov sp, x0
83
84 // Get Core Position
85 mov x0, x1
86 bl ASM_PFX(ArmPlatformGetCorePosition)
87 mov x25, x0
88
89 // Get Primary Core Position
90 bl ASM_PFX(ArmPlatformGetPrimaryCoreMpId)
91 bl ASM_PFX(ArmPlatformGetCorePosition)
92
93 // Get Secondary Core Position. We should get consecutive secondary stack number from 1...(CoreCount-1)
94 cmp x25, x0
95
96 // Decrement the position if after the primary core
97 cinc x25, x25, ls
98
99 // Compute top of the secondary stack
100 mul x3, x3, x25
101
102 // Set stack
103 add sp, sp, x3
104
105 ret x24