]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/Library/ArmPlatformStackLib/AArch64/ArmPlatformStackLib.S
ArmPlatformPkg/ArmPlatformStackLib: use callee preserved registers
[mirror_edk2.git] / ArmPlatformPkg / Library / ArmPlatformStackLib / AArch64 / ArmPlatformStackLib.S
CommitLineData
1bc83266 1//\r
51ad04cb 2// Copyright (c) 2012-2014, ARM Limited. All rights reserved.\r
1bc83266
HL
3//\r
4// This program and the accompanying materials\r
5// are licensed and made available under the terms and conditions of the BSD License\r
6// which accompanies this distribution. The full text of the license may be found at\r
7// http://opensource.org/licenses/bsd-license.php\r
8//\r
9// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11//\r
12//\r
13\r
51ad04cb 14#include <AsmMacroIoLibV8.h>\r
1bc83266
HL
15\r
16//VOID\r
17//ArmPlatformStackSet (\r
18// IN UINTN StackBase,\r
19// IN UINTN MpId,\r
20// IN UINTN PrimaryStackSize,\r
21// IN UINTN SecondaryStackSize\r
22// );\r
92605930 23ASM_FUNC(ArmPlatformStackSet)\r
1bc83266 24 // Save parameters\r
91231b55
AB
25 mov x26, x3\r
26 mov x25, x2\r
27 mov x24, x1\r
28 mov x23, x0\r
1bc83266
HL
29\r
30 // Save the Link register\r
91231b55 31 mov x27, x30\r
1bc83266
HL
32\r
33 // Identify Stack\r
34 mov x0, x1\r
35 bl ASM_PFX(ArmPlatformIsPrimaryCore)\r
36 cmp x0, #1\r
37\r
38 // Restore parameters\r
91231b55
AB
39 mov x0, x23\r
40 mov x1, x24\r
41 mov x2, x25\r
42 mov x3, x26\r
1bc83266
HL
43\r
44 // Restore the Link register\r
91231b55 45 mov x30, x27\r
1bc83266 46\r
92605930
AB
47 b.ne 0f\r
48\r
49 b ASM_PFX(ArmPlatformStackSetPrimary)\r
500:b ASM_PFX(ArmPlatformStackSetSecondary)\r
1bc83266
HL
51\r
52//VOID\r
53//ArmPlatformStackSetPrimary (\r
54// IN UINTN StackBase,\r
55// IN UINTN MpId,\r
56// IN UINTN PrimaryStackSize,\r
57// IN UINTN SecondaryStackSize\r
58// );\r
92605930 59ASM_FUNC(ArmPlatformStackSetPrimary)\r
91231b55 60 // Add size of primary stack to StackBase\r
1bc83266
HL
61 add x0, x0, x2\r
62\r
63 // Compute SecondaryCoresCount * SecondaryCoreStackSize\r
92605930 64 MOV32 (w1, FixedPcdGet32(PcdCoreCount) - 1)\r
1bc83266
HL
65 mul x3, x3, x1\r
66\r
67 // Set Primary Stack ((StackBase + PrimaryStackSize) + (SecondaryCoresCount * SecondaryCoreStackSize))\r
68 add sp, x0, x3\r
69\r
91231b55 70 ret\r
1bc83266
HL
71\r
72//VOID\r
73//ArmPlatformStackSetSecondary (\r
74// IN UINTN StackBase,\r
75// IN UINTN MpId,\r
76// IN UINTN PrimaryStackSize,\r
77// IN UINTN SecondaryStackSize\r
78// );\r
92605930 79ASM_FUNC(ArmPlatformStackSetSecondary)\r
1bc83266 80 // Save the Link register\r
91231b55 81 mov x24, x30\r
1bc83266
HL
82 mov sp, x0\r
83\r
84 // Get Core Position\r
85 mov x0, x1\r
86 bl ASM_PFX(ArmPlatformGetCorePosition)\r
91231b55 87 mov x25, x0\r
1bc83266
HL
88\r
89 // Get Primary Core Position\r
90 bl ASM_PFX(ArmPlatformGetPrimaryCoreMpId)\r
91 bl ASM_PFX(ArmPlatformGetCorePosition)\r
92\r
93 // Get Secondary Core Position. We should get consecutive secondary stack number from 1...(CoreCount-1)\r
91231b55
AB
94 cmp x25, x0\r
95\r
1bc83266 96 // Decrement the position if after the primary core\r
91231b55 97 cinc x25, x25, ls\r
1bc83266
HL
98\r
99 // Compute top of the secondary stack\r
91231b55 100 mul x3, x3, x25\r
1bc83266
HL
101\r
102 // Set stack\r
103 add sp, sp, x3\r
104\r
91231b55 105 ret x24\r