]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/ArmVirtualizationPkg/PrePi/AArch64/ModuleEntryPoint.S
MdeModulePkg/UfsPciHcDxe: Fix EBC build error
[mirror_edk2.git] / ArmPlatformPkg / ArmVirtualizationPkg / PrePi / AArch64 / ModuleEntryPoint.S
1 //
2 // Copyright (c) 2011-2013, ARM Limited. All rights reserved.
3 // Copyright (c) 2015, Linaro Limited. All rights reserved.
4 //
5 // This program and the accompanying materials
6 // are licensed and made available under the terms and conditions of the BSD License
7 // which accompanies this distribution. The full text of the license may be found at
8 // http://opensource.org/licenses/bsd-license.php
9 //
10 // THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 //
13 //
14
15 #include <AsmMacroIoLibV8.h>
16 #include <Base.h>
17 #include <Library/PcdLib.h>
18 #include <AutoGen.h>
19
20 .text
21 .align 3
22
23 GCC_ASM_IMPORT(ArmPlatformIsPrimaryCore)
24 GCC_ASM_IMPORT(ArmReadMpidr)
25 GCC_ASM_IMPORT(ArmPlatformPeiBootAction)
26 GCC_ASM_IMPORT(ArmPlatformStackSet)
27 GCC_ASM_EXPORT(_ModuleEntryPoint)
28
29 StartupAddr: .8byte ASM_PFX(CEntryPoint)
30
31 ASM_PFX(_ModuleEntryPoint):
32 //
33 // We are built as a ET_DYN PIE executable, so we need to process all
34 // relative relocations regardless of whether or not we are executing from
35 // the same offset we were linked at. This is only possible if we are
36 // running from RAM.
37 //
38 adr x8, __reloc_base
39 adr x9, __reloc_start
40 adr x10, __reloc_end
41
42 .Lreloc_loop:
43 cmp x9, x10
44 bhs .Lreloc_done
45
46 //
47 // AArch64 uses the ELF64 RELA format, which means each entry in the
48 // relocation table consists of
49 //
50 // UINT64 offset : the relative offset of the value that needs to
51 // be relocated
52 // UINT64 info : relocation type and symbol index (the latter is
53 // not used for R_AARCH64_RELATIVE relocations)
54 // UINT64 addend : value to be added to the value being relocated
55 //
56 ldp x11, x12, [x9], #24 // read offset into x11 and info into x12
57 cmp x12, #0x403 // check info == R_AARCH64_RELATIVE?
58 bne .Lreloc_loop // not a relative relocation? then skip
59
60 ldr x12, [x9, #-8] // read addend into x12
61 add x12, x12, x8 // add reloc base to addend to get relocated value
62 str x12, [x11, x8] // write relocated value at offset
63 b .Lreloc_loop
64 .Lreloc_done:
65
66 // Do early platform specific actions
67 bl ASM_PFX(ArmPlatformPeiBootAction)
68
69 // Get ID of this CPU in Multicore system
70 bl ASM_PFX(ArmReadMpidr)
71 // Keep a copy of the MpId register value
72 mov x10, x0
73
74 // Check if we can install the stack at the top of the System Memory or if we need
75 // to install the stacks at the bottom of the Firmware Device (case the FD is located
76 // at the top of the DRAM)
77 _SetupStackPosition:
78 // Compute Top of System Memory
79 ldr x1, PcdGet64 (PcdSystemMemoryBase)
80 ldr x2, PcdGet64 (PcdSystemMemorySize)
81 sub x2, x2, #1
82 add x1, x1, x2 // x1 = SystemMemoryTop = PcdSystemMemoryBase + PcdSystemMemorySize
83
84 // Calculate Top of the Firmware Device
85 ldr x2, PcdGet64 (PcdFdBaseAddress)
86 ldr w3, PcdGet32 (PcdFdSize)
87 sub x3, x3, #1
88 add x3, x3, x2 // x3 = FdTop = PcdFdBaseAddress + PcdFdSize
89
90 // UEFI Memory Size (stacks are allocated in this region)
91 LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryUefiRegionSize), x4)
92
93 //
94 // Reserve the memory for the UEFI region (contain stacks on its top)
95 //
96
97 // Calculate how much space there is between the top of the Firmware and the Top of the System Memory
98 subs x0, x1, x3 // x0 = SystemMemoryTop - FdTop
99 b.mi _SetupStack // Jump if negative (FdTop > SystemMemoryTop). Case when the PrePi is in XIP memory outside of the DRAM
100 cmp x0, x4
101 b.ge _SetupStack
102
103 // Case the top of stacks is the FdBaseAddress
104 mov x1, x2
105
106 _SetupStack:
107 // x1 contains the top of the stack (and the UEFI Memory)
108
109 // Because the 'push' instruction is equivalent to 'stmdb' (decrement before), we need to increment
110 // one to the top of the stack. We check if incrementing one does not overflow (case of DRAM at the
111 // top of the memory space)
112 adds x11, x1, #1
113 b.cs _SetupOverflowStack
114
115 _SetupAlignedStack:
116 mov x1, x11
117 b _GetBaseUefiMemory
118
119 _SetupOverflowStack:
120 // Case memory at the top of the address space. Ensure the top of the stack is EFI_PAGE_SIZE
121 // aligned (4KB)
122 LoadConstantToReg (EFI_PAGE_MASK, x11)
123 and x11, x11, x1
124 sub x1, x1, x11
125
126 _GetBaseUefiMemory:
127 // Calculate the Base of the UEFI Memory
128 sub x11, x1, x4
129
130 _GetStackBase:
131 // r1 = The top of the Mpcore Stacks
132 // Stack for the primary core = PrimaryCoreStack
133 LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), x2)
134 sub x12, x1, x2
135
136 // Stack for the secondary core = Number of Cores - 1
137 LoadConstantToReg (FixedPcdGet32(PcdCoreCount), x0)
138 sub x0, x0, #1
139 LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), x1)
140 mul x1, x1, x0
141 sub x12, x12, x1
142
143 // x12 = The base of the MpCore Stacks (primary stack & secondary stacks)
144 mov x0, x12
145 mov x1, x10
146 //ArmPlatformStackSet(StackBase, MpId, PrimaryStackSize, SecondaryStackSize)
147 LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), x2)
148 LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), x3)
149 bl ASM_PFX(ArmPlatformStackSet)
150
151 // Is it the Primary Core ?
152 mov x0, x10
153 bl ASM_PFX(ArmPlatformIsPrimaryCore)
154 cmp x0, #1
155 bne _PrepareArguments
156
157 _ReserveGlobalVariable:
158 LoadConstantToReg (FixedPcdGet32(PcdPeiGlobalVariableSize), x0)
159 // InitializePrimaryStack($GlobalVariableSize, $Tmp1, $Tmp2)
160 InitializePrimaryStack(x0, x1, x2)
161
162 _PrepareArguments:
163 mov x0, x10
164 mov x1, x11
165 mov x2, x12
166 mov x3, 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 x4, StartupAddr
171
172 // Jump to PrePiCore C code
173 // x0 = MpId
174 // x1 = UefiMemoryBase
175 // x2 = StacksBase
176 // x3 = GlobalVariableBase
177 blr x4
178
179 _NeverReturn:
180 b _NeverReturn