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