]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/PrePi/ModuleEntryPoint.asm
ArmPlatformPkg: Introduction of gArmPlatformTokenSpaceGuid.PcdCoreCount
[mirror_edk2.git] / ArmPlatformPkg / PrePi / ModuleEntryPoint.asm
1 //
2 // Copyright (c) 2011-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 <Library/PcdLib.h>
17 #include <AutoGen.h>
18
19 INCLUDE AsmMacroIoLib.inc
20
21 IMPORT CEntryPoint
22 IMPORT ArmReadMpidr
23 IMPORT ArmPlatformStackSet
24
25 EXPORT _ModuleEntryPoint
26
27 PRESERVE8
28 AREA PrePiCoreEntryPoint, CODE, READONLY
29
30 StartupAddr DCD CEntryPoint
31
32 _ModuleEntryPoint
33 // Get ID of this CPU in Multicore system
34 bl ArmReadMpidr
35 LoadConstantToReg (FixedPcdGet32(PcdArmPrimaryCoreMask), r1)
36 and r5, r0, r1
37
38 _SetSVCMode
39 // Enter SVC mode, Disable FIQ and IRQ
40 mov r1, #0x13 :OR: 0x80 :OR: 0x40
41 msr CPSR_c, r1
42
43 // Check if we can install the stack at the top of the System Memory or if we need
44 // to install the stacks at the bottom of the Firmware Device (case the FD is located
45 // at the top of the DRAM)
46 _SetupStackPosition
47 // Compute Top of System Memory
48 LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryBase), r1)
49 LoadConstantToReg (FixedPcdGet32(PcdSystemMemorySize), r2)
50 sub r2, r2, #1
51 add r1, r1, r2 // r1 = SystemMemoryTop = PcdSystemMemoryBase + PcdSystemMemorySize
52
53 // Calculate Top of the Firmware Device
54 LoadConstantToReg (FixedPcdGet32(PcdFdBaseAddress), r2)
55 LoadConstantToReg (FixedPcdGet32(PcdFdSize), r3)
56 sub r3, r3, #1
57 add r3, r3, r2 // r3 = FdTop = PcdFdBaseAddress + PcdFdSize
58
59 // UEFI Memory Size (stacks are allocated in this region)
60 LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryUefiRegionSize), r4)
61
62 //
63 // Reserve the memory for the UEFI region (contain stacks on its top)
64 //
65
66 // Calculate how much space there is between the top of the Firmware and the Top of the System Memory
67 subs r0, r1, r3 // r0 = SystemMemoryTop - FdTop
68 bmi _SetupStack // Jump if negative (FdTop > SystemMemoryTop). Case when the PrePi is in XIP memory outside of the DRAM
69 cmp r0, r4
70 bge _SetupStack
71
72 // Case the top of stacks is the FdBaseAddress
73 mov r1, r2
74
75 _SetupStack
76 // r1 contains the top of the stack (and the UEFI Memory)
77
78 // Because the 'push' instruction is equivalent to 'stmdb' (decrement before), we need to increment
79 // one to the top of the stack. We check if incrementing one does not overflow (case of DRAM at the
80 // top of the memory space)
81 adds r6, r1, #1
82 bcs _SetupOverflowStack
83
84 _SetupAlignedStack
85 mov r1, r6
86 b _GetBaseUefiMemory
87
88 _SetupOverflowStack
89 // Case memory at the top of the address space. Ensure the top of the stack is EFI_PAGE_SIZE
90 // aligned (4KB)
91 LoadConstantToReg (EFI_PAGE_MASK, r6)
92 and r6, r6, r1
93 sub r1, r1, r6
94
95 _GetBaseUefiMemory
96 // Calculate the Base of the UEFI Memory
97 sub r6, r1, r4
98
99 _GetStackBase
100 // Compute Base of Normal stacks for CPU Cores
101 // Is it MpCore system
102 bl ArmIsMpCore
103 cmp r0, #0
104 // Case it is not an MP Core system. Just setup the primary core
105 beq _SetupUnicoreStack
106
107 _GetStackBaseMpCore
108 // r1 = The top of the Mpcore Stacks
109 // Stack for the primary core = PrimaryCoreStack
110 LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), r2)
111 sub r8, r1, r2
112
113 // Stack for the secondary core = Number of Cores - 1
114 LoadConstantToReg (FixedPcdGet32(PcdCoreCount), r0)
115 sub r0, r0, #1
116 LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), r1)
117 mul r1, r1, r0
118 sub r8, r8, r1
119
120 // r8 = The base of the MpCore Stacks (primary stack & secondary stacks)
121 mov r0, r8
122 mov r1, r6
123 //ArmPlatformStackSet(StackBase, MpId, PrimaryStackSize, SecondaryStackSize)
124 LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), r2)
125 LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), r3)
126 mul r2, r2, r3
127 sub r7, r7, r2
128
129 // The base of the secondary Stacks = Top of Primary stack
130 LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), r2)
131 add r1, r7, r2
132
133 // r7 = The base of the MpCore Stacks (primary stack + cluster_count * 4 * secondary stacks)
134 // r1 = The base of the secondary Stacks = Top of the Primary stack
135
136 // Is it the Primary Core ?
137 LoadConstantToReg (FixedPcdGet32(PcdArmPrimaryCore), r4)
138 cmp r5, r4
139 beq _SetupPrimaryCoreStack
140
141 _SetupSecondaryCoreStack
142 // r1 = The base of the secondary Stacks
143
144 // Get the position of the cores (ClusterId * 4) + CoreId
145 GetCorePositionFromMpId(r0, r5, r4)
146 // The stack starts at the top of the stack region. Add '1' to the Core Position to get the top of the stack
147 add r0, r0, #1
148 // Get the offset for the Secondary Stack
149 mul r0, r0, r3
150 add sp, r1, r0
151
152 bne _PrepareArguments
153
154 _SetupPrimaryCoreStack
155 // r1 = Top of the primary stack
156 LoadConstantToReg (FixedPcdGet32(PcdPeiGlobalVariableSize), r2)
157 b _PreparePrimaryStack
158
159 _SetupUnicoreStack
160 // The top of the Unicore Stack is in r1
161 LoadConstantToReg (FixedPcdGet32(PcdPeiGlobalVariableSize), r2)
162 LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), r3)
163
164 // Calculate the bottom of the primary stack (StackBase)
165 sub r7, r1, r3
166
167 _PreparePrimaryStack
168 // The reserved space for global variable must be 8-bytes aligned for pushing
169 // 64-bit variable on the stack
170 SetPrimaryStack (r1, r2, r3)
171
172 _PrepareArguments
173 mov r0, r5
174 mov r1, r6
175 mov r2, r7
176 mov r3, sp
177
178 // Move sec startup address into a data register
179 // Ensure we're jumping to FV version of the code (not boot remapped alias)
180 ldr r4, StartupAddr
181
182 // Jump to PrePiCore C code
183 // r0 = MpId
184 // r1 = UefiMemoryBase
185 // r2 = StacksBase
186 // r3 = GlobalVariableBase
187 blx r4
188
189 _NeverReturn
190 b _NeverReturn
191
192 END