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