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