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