]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/PrePi/ModuleEntryPoint.asm
ArmPlatformPkg: Introduce ArmPlatformGlobalVariableLib
[mirror_edk2.git] / ArmPlatformPkg / PrePi / ModuleEntryPoint.asm
CommitLineData
cd872e40 1//\r
2// Copyright (c) 2011, ARM Limited. All rights reserved.\r
3//\r
4// This program and the accompanying materials\r
5// are licensed and made available under the terms and conditions of the BSD License\r
6// which accompanies this distribution. The full text of the license may be found at\r
7// http://opensource.org/licenses/bsd-license.php\r
8//\r
9// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11//\r
12//\r
13\r
14#include <AsmMacroIoLib.h>\r
15#include <Base.h>\r
16#include <Library/PcdLib.h>\r
17#include <AutoGen.h>\r
18\r
19 INCLUDE AsmMacroIoLib.inc\r
20 \r
21 IMPORT CEntryPoint\r
0787bc61 22 IMPORT ArmReadMpidr\r
2dbcb8f0 23 IMPORT ArmIsMPCore\r
cd872e40 24 EXPORT _ModuleEntryPoint\r
25\r
26 PRESERVE8\r
27 AREA PrePiCoreEntryPoint, CODE, READONLY\r
28 \r
29StartupAddr DCD CEntryPoint\r
30\r
31_ModuleEntryPoint\r
0787bc61 32 // Get ID of this CPU in Multicore system\r
33 bl ArmReadMpidr\r
34 LoadConstantToReg (FixedPcdGet32(PcdArmPrimaryCoreMask), r1)\r
35 and r5, r0, r1\r
cd872e40 36\r
d269095b 37_SetSVCMode\r
38 // Enter SVC mode\r
39 mov r1, #0x13|0x80|0x40\r
40 msr CPSR_c, r1\r
41\r
2dbcb8f0 42// Check if we can install the stack at the top of the System Memory or if we need\r
d269095b 43// to install the stacks at the bottom of the Firmware Device (case the FD is located\r
44// at the top of the DRAM)\r
45_SetupStackPosition\r
cd872e40 46 // Compute Top of System Memory\r
47 LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryBase), r1)\r
48 LoadConstantToReg (FixedPcdGet32(PcdSystemMemorySize), r2)\r
49 add r1, r1, r2 // r1 = SystemMemoryTop = PcdSystemMemoryBase + PcdSystemMemorySize\r
cd872e40 50\r
d269095b 51 // Calculate Top of the Firmware Device\r
f92b93c9 52 LoadConstantToReg (FixedPcdGet32(PcdFdBaseAddress), r2)\r
53 LoadConstantToReg (FixedPcdGet32(PcdFdSize), r3)\r
54 add r3, r3, r2 // r4 = FdTop = PcdFdBaseAddress + PcdFdSize\r
d269095b 55\r
56 // UEFI Memory Size (stacks are allocated in this region)\r
57 LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryUefiRegionSize), r4)\r
58\r
59 //\r
60 // Reserve the memory for the UEFI region (contain stacks on its top)\r
61 //\r
62\r
63 // Calculate how much space there is between the top of the Firmware and the Top of the System Memory\r
2dbcb8f0 64 subs r0, r1, r3 // r0 = SystemMemoryTop - FdTop\r
65 bmi _SetupStack // Jump if negative (FdTop > SystemMemoryTop). Case when the PrePi is in XIP memory outside of the DRAM\r
66 cmp r0, r4\r
d269095b 67 bge _SetupStack\r
68\r
69 // Case the top of stacks is the FdBaseAddress\r
70 mov r1, r2\r
cd872e40 71\r
72_SetupStack\r
2dbcb8f0 73 // r1 contains the top of the stack (and the UEFI Memory)\r
d269095b 74\r
75 // Calculate the Base of the UEFI Memory\r
2dbcb8f0 76 sub r6, r1, r4\r
cd872e40 77\r
2dbcb8f0 78_GetStackBase\r
79 // Compute Base of Normal stacks for CPU Cores\r
80 // Is it MpCore system\r
81 bl ArmIsMPCore\r
cd872e40 82 cmp r0, #0\r
2dbcb8f0 83 // Case it is not an MP Core system. Just setup the primary core\r
84 beq _SetupUnicoreStack\r
85\r
86_GetStackBaseMpCore\r
87 // Stack for the primary core = PrimaryCoreStack\r
88 LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), r2)\r
89 sub r7, r1, r2\r
90 // Stack for the secondary core = Number of Cluster * (4 Core per cluster) * SecondaryStackSize\r
91 LoadConstantToReg (FixedPcdGet32(PcdClusterCount), r2)\r
92 lsl r2, r2, #2\r
93 LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), r3)\r
94 mul r2, r2, r3\r
95 sub r7, r7, r2\r
96\r
97 // The top of the Mpcore Stacks is in r1\r
98 // The base of the MpCore Stacks is in r7\r
99\r
100 // Is it the Primary Core ?\r
101 LoadConstantToReg (FixedPcdGet32(PcdArmPrimaryCore), r4)\r
102 cmp r0, r4\r
103 beq _SetupPrimaryCoreStack\r
104\r
105_SetupSecondaryCoreStack\r
106 // Base of the stack for the secondary cores is in r7\r
107\r
108 // Get the position of the cores (ClusterId * 4) + CoreId\r
109 GetCorePositionInStack(r0, r5, r4)\r
110 // The stack starts at the top of the stack region. Add '1' to the Core Position to get the top of the stack\r
111 add r0, r0, #1\r
112 // Get the offset for the Secondary Stack\r
113 mul r0, r0, r3\r
114 add sp, r7, r0\r
115\r
cd872e40 116 bne _PrepareArguments\r
117\r
2dbcb8f0 118_SetupPrimaryCoreStack\r
119 // The top of the Mpcore Stacks is in r1\r
120 LoadConstantToReg (FixedPcdGet32(PcdPeiGlobalVariableSize), r2)\r
121\r
122 // The reserved space for global variable must be 8-bytes aligned for pushing\r
123 // 64-bit variable on the stack\r
124 SetPrimaryStack (r1, r2, r3)\r
125\r
126_SetGlobals\r
127 // Set all the PrePi global variables to 0\r
128 mov r3, sp\r
129 mov r2, #0x0\r
130_InitGlobals\r
131 str r2, [r3], #4\r
132 cmp r3, r1\r
133 blt _InitGlobals\r
134\r
cd872e40 135\r
136_PrepareArguments\r
c524ffbb 137 mov r0, r5\r
138 mov r1, r6\r
139 mov r2, r7\r
140 mov r3, sp\r
141\r
cd872e40 142 // Move sec startup address into a data register\r
143 // Ensure we're jumping to FV version of the code (not boot remapped alias)\r
c524ffbb 144 ldr r4, StartupAddr\r
cd872e40 145\r
d269095b 146 // Jump to PrePiCore C code\r
0787bc61 147 // r0 = MpId\r
cd872e40 148 // r1 = UefiMemoryBase\r
c524ffbb 149 // r2 = StacksBase\r
150 // r3 = GlobalVariableBase\r
151 blx r4\r
cd872e40 152\r
2dbcb8f0 153_NeverReturn\r
154 b _NeverReturn\r
155\r
156_SetupUnicoreStack\r
157 // The top of the Unicore Stack is in r1\r
158 LoadConstantToReg (FixedPcdGet32(PcdPeiGlobalVariableSize), r2)\r
159 LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), r3)\r
160\r
161 // Calculate the bottom of the primary stack (StackBase)\r
162 sub r7, r1, r3\r
163\r
164 // The reserved space for global variable must be 8-bytes aligned for pushing\r
165 // 64-bit variable on the stack\r
166 SetPrimaryStack (r1, r2, r3)\r
167\r
168 b _SetGlobals\r
169\r
cd872e40 170 END\r