]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/Library/ArmPlatformStackLib/ArmPlatformStackLib.S
ArmPkg: Fixed unsigned type to be architecture independent
[mirror_edk2.git] / ArmPlatformPkg / Library / ArmPlatformStackLib / ArmPlatformStackLib.S
1 //
2 // Copyright (c) 2012, 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
21 GCC_ASM_EXPORT(ArmPlatformStackSet)
22 GCC_ASM_EXPORT(ArmPlatformStackSetPrimary)
23 GCC_ASM_EXPORT(ArmPlatformStackSetSecondary)
24
25 GCC_ASM_IMPORT(ArmPlatformGetCorePosition)
26
27 GCC_ASM_IMPORT(gPcd_FixedAtBuild_PcdCoreCount)
28 GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdArmPrimaryCore)
29
30 //VOID
31 //ArmPlatformStackSet (
32 // IN UINTN StackBase,
33 // IN UINTN MpId,
34 // IN UINTN PrimaryStackSize,
35 // IN UINTN SecondaryStackSize
36 // );
37 ASM_PFX(ArmPlatformStackSet):
38 // Identify Stack
39 // Mask for ClusterId|CoreId
40 LoadConstantToReg (0xFFFF, r4)
41 and r1, r1, r4
42 // Is it the Primary Core ?
43 LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCore, r4)
44 ldr r4, [r4]
45 cmp r1, r4
46 beq ASM_PFX(ArmPlatformStackSetPrimary)
47 bne ASM_PFX(ArmPlatformStackSetSecondary)
48
49 //VOID
50 //ArmPlatformStackSetPrimary (
51 // IN UINTN StackBase,
52 // IN UINTN MpId,
53 // IN UINTN PrimaryStackSize,
54 // IN UINTN SecondaryStackSize
55 // );
56 ASM_PFX(ArmPlatformStackSetPrimary):
57 mov r4, lr
58
59 // Add stack of primary stack to StackBase
60 add r0, r0, r2
61
62 // Compute SecondaryCoresCount * SecondaryCoreStackSize
63 LoadConstantToReg (_gPcd_FixedAtBuild_PcdCoreCount, r1)
64 ldr r1, [r1]
65 sub r1, #1
66 mul r3, r3, r1
67
68 // Set Primary Stack ((StackBase + PrimaryStackSize) + (SecondaryCoresCount * SecondaryCoreStackSize))
69 add sp, r0, r3
70
71 bx r4
72
73 //VOID
74 //ArmPlatformStackSetSecondary (
75 // IN UINTN StackBase,
76 // IN UINTN MpId,
77 // IN UINTN PrimaryStackSize,
78 // IN UINTN SecondaryStackSize
79 // );
80 ASM_PFX(ArmPlatformStackSetSecondary):
81 mov r4, lr
82 mov sp, r0
83
84 // Get Core Position
85 mov r0, r1
86 bl ASM_PFX(ArmPlatformGetCorePosition)
87 mov r5, r0
88
89 // Get Primary Core Position
90 LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCore, r0)
91 ldr r0, [r0]
92 bl ASM_PFX(ArmPlatformGetCorePosition)
93
94 // Get Secondary Core Position. We should get consecutive secondary stack number from 1...(CoreCount-1)
95 cmp r5, r0
96 subhi r5, r5, #1
97 add r5, r5, #1
98
99 // Compute top of the secondary stack
100 mul r3, r3, r5
101
102 // Set stack
103 add sp, sp, r3
104
105 bx r4
106