]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/PrePi/ModuleEntryPoint.S
ARM Packages: Rename PcdNormal* into Pcd* PCDs
[mirror_edk2.git] / ArmPlatformPkg / PrePi / ModuleEntryPoint.S
1 //
2 // Copyright (c) 2011, 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
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 add r1, r1, r2 // r1 = SystemMemoryTop = PcdSystemMemoryBase + PcdSystemMemorySize
49
50 // Calculate Top of the Firmware Device
51 LoadConstantToReg (FixedPcdGet32(PcdFdBaseAddress), r2)
52 LoadConstantToReg (FixedPcdGet32(PcdFdSize), r3)
53 add r3, r3, r2 // r4 = FdTop = PcdFdBaseAddress + PcdFdSize
54
55 // UEFI Memory Size (stacks are allocated in this region)
56 LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryUefiRegionSize), r4)
57
58 //
59 // Reserve the memory for the UEFI region (contain stacks on its top)
60 //
61
62 // Calculate how much space there is between the top of the Firmware and the Top of the System Memory
63 subs r0, r1, r3 // r0 = SystemMemoryTop - FdTop
64 bmi _SetupStack // Jump if negative (FdTop > SystemMemoryTop). Case when the PrePi is in XIP memory outside of the DRAM
65 cmp r0, r4
66 bge _SetupStack
67
68 // Case the top of stacks is the FdBaseAddress
69 mov r1, r2
70
71 _SetupStack:
72 // r1 contains the top of the stack (and the UEFI Memory)
73
74 // Calculate the Base of the UEFI Memory
75 sub r6, r1, r4
76
77 _GetStackBase:
78 // Compute Base of Normal stacks for CPU Cores
79 // Is it MpCore system
80 bl ArmIsMPCore
81 cmp r0, #0
82 // Case it is not an MP Core system. Just setup the primary core
83 beq _SetupUnicoreStack
84
85 _GetStackBaseMpCore:
86 // Stack for the primary core = PrimaryCoreStack
87 LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), r2)
88 sub r7, r1, r2
89 // Stack for the secondary core = Number of Cluster * (4 Core per cluster) * SecondaryStackSize
90 LoadConstantToReg (FixedPcdGet32(PcdClusterCount), r2)
91 lsl r2, r2, #2
92 LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), r3)
93 mul r2, r2, r3
94 sub r7, r7, r2
95
96 // The top of the Mpcore Stacks is in r1
97 // The base of the MpCore Stacks is in r7
98
99 // Is it the Primary Core ?
100 LoadConstantToReg (FixedPcdGet32(PcdArmPrimaryCore), r4)
101 cmp r0, r4
102 beq _SetupPrimaryCoreStack
103
104 _SetupSecondaryCoreStack:
105 // Base of the stack for the secondary cores is in r7
106
107 // Get the position of the cores (ClusterId * 4) + CoreId
108 GetCorePositionInStack(r0, r5, r4)
109 // The stack starts at the top of the stack region. Add '1' to the Core Position to get the top of the stack
110 add r0, r0, #1
111 // Get the offset for the Secondary Stack
112 mul r0, r0, r3
113 add sp, r7, r0
114
115 bne _PrepareArguments
116
117 _SetupPrimaryCoreStack:
118 // The top of the Mpcore Stacks is in r1
119 LoadConstantToReg (FixedPcdGet32(PcdPeiGlobalVariableSize), r2)
120
121 // The reserved space for global variable must be 8-bytes aligned for pushing
122 // 64-bit variable on the stack
123 SetPrimaryStack (r1, r2, r3)
124
125 _SetGlobals:
126 // Set all the PrePi global variables to 0
127 mov r3, sp
128 mov r2, #0x0
129 _InitGlobals:
130 str r2, [r3], #4
131 cmp r3, r1
132 blt _InitGlobals
133
134
135 _PrepareArguments:
136 // Move sec startup address into a data register
137 // Ensure we're jumping to FV version of the code (not boot remapped alias)
138 ldr r2, StartupAddr
139
140 // Jump to PrePiCore C code
141 // r0 = MpId
142 // r1 = UefiMemoryBase
143 blx r2
144
145 _NeverReturn:
146 b _NeverReturn
147
148 _SetupUnicoreStack:
149 // The top of the Unicore Stack is in r1
150 LoadConstantToReg (FixedPcdGet32(PcdPeiGlobalVariableSize), r2)
151 LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), r3)
152
153 // Calculate the bottom of the primary stack (StackBase)
154 sub r7, r1, r3
155
156 // The reserved space for global variable must be 8-bytes aligned for pushing
157 // 64-bit variable on the stack
158 SetPrimaryStack (r1, r2, r3)
159
160 b _SetGlobals
161