]> git.proxmox.com Git - mirror_edk2.git/blame - ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S
ArmVirtPkg/PrePi: remove mSystemMemoryEnd
[mirror_edk2.git] / ArmVirtPkg / PrePi / AArch64 / ModuleEntryPoint.S
CommitLineData
f9a9d2dc
AB
1//\r
2// Copyright (c) 2011-2013, ARM Limited. All rights reserved.\r
dfc28388 3// Copyright (c) 2015-2016, Linaro Limited. All rights reserved.\r
f9a9d2dc
AB
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
f9a9d2dc 16\r
dfc28388 17ASM_FUNC(_ModuleEntryPoint)\r
f9a9d2dc
AB
18 //\r
19 // We are built as a ET_DYN PIE executable, so we need to process all\r
20 // relative relocations regardless of whether or not we are executing from\r
21 // the same offset we were linked at. This is only possible if we are\r
22 // running from RAM.\r
23 //\r
24 adr x8, __reloc_base\r
25 adr x9, __reloc_start\r
26 adr x10, __reloc_end\r
27\r
28.Lreloc_loop:\r
29 cmp x9, x10\r
30 bhs .Lreloc_done\r
31\r
32 //\r
33 // AArch64 uses the ELF64 RELA format, which means each entry in the\r
34 // relocation table consists of\r
35 //\r
36 // UINT64 offset : the relative offset of the value that needs to\r
37 // be relocated\r
38 // UINT64 info : relocation type and symbol index (the latter is\r
39 // not used for R_AARCH64_RELATIVE relocations)\r
40 // UINT64 addend : value to be added to the value being relocated\r
41 //\r
42 ldp x11, x12, [x9], #24 // read offset into x11 and info into x12\r
43 cmp x12, #0x403 // check info == R_AARCH64_RELATIVE?\r
44 bne .Lreloc_loop // not a relative relocation? then skip\r
45\r
46 ldr x12, [x9, #-8] // read addend into x12\r
47 add x12, x12, x8 // add reloc base to addend to get relocated value\r
48 str x12, [x11, x8] // write relocated value at offset\r
49 b .Lreloc_loop\r
50.Lreloc_done:\r
51\r
52 // Do early platform specific actions\r
53 bl ASM_PFX(ArmPlatformPeiBootAction)\r
54\r
55 // Get ID of this CPU in Multicore system\r
56 bl ASM_PFX(ArmReadMpidr)\r
57 // Keep a copy of the MpId register value\r
298f8361 58 mov x20, x0\r
f9a9d2dc
AB
59\r
60// Check if we can install the stack at the top of the System Memory or if we need\r
61// to install the stacks at the bottom of the Firmware Device (case the FD is located\r
62// at the top of the DRAM)\r
63_SetupStackPosition:\r
64 // Compute Top of System Memory\r
65 ldr x1, PcdGet64 (PcdSystemMemoryBase)\r
66 ldr x2, PcdGet64 (PcdSystemMemorySize)\r
67 sub x2, x2, #1\r
68 add x1, x1, x2 // x1 = SystemMemoryTop = PcdSystemMemoryBase + PcdSystemMemorySize\r
69\r
70 // Calculate Top of the Firmware Device\r
71 ldr x2, PcdGet64 (PcdFdBaseAddress)\r
dfc28388 72 MOV32 (w3, FixedPcdGet32 (PcdFdSize) - 1)\r
f9a9d2dc
AB
73 add x3, x3, x2 // x3 = FdTop = PcdFdBaseAddress + PcdFdSize\r
74\r
75 // UEFI Memory Size (stacks are allocated in this region)\r
dfc28388 76 MOV32 (x4, FixedPcdGet32(PcdSystemMemoryUefiRegionSize))\r
f9a9d2dc
AB
77\r
78 //\r
79 // Reserve the memory for the UEFI region (contain stacks on its top)\r
80 //\r
81\r
82 // Calculate how much space there is between the top of the Firmware and the Top of the System Memory\r
83 subs x0, x1, x3 // x0 = SystemMemoryTop - FdTop\r
84 b.mi _SetupStack // Jump if negative (FdTop > SystemMemoryTop). Case when the PrePi is in XIP memory outside of the DRAM\r
85 cmp x0, x4\r
86 b.ge _SetupStack\r
87\r
88 // Case the top of stacks is the FdBaseAddress\r
89 mov x1, x2\r
90\r
91_SetupStack:\r
92 // x1 contains the top of the stack (and the UEFI Memory)\r
93\r
94 // Because the 'push' instruction is equivalent to 'stmdb' (decrement before), we need to increment\r
95 // one to the top of the stack. We check if incrementing one does not overflow (case of DRAM at the\r
96 // top of the memory space)\r
298f8361 97 adds x21, x1, #1\r
f9a9d2dc
AB
98 b.cs _SetupOverflowStack\r
99\r
100_SetupAlignedStack:\r
298f8361 101 mov x1, x21\r
f9a9d2dc
AB
102 b _GetBaseUefiMemory\r
103\r
104_SetupOverflowStack:\r
105 // Case memory at the top of the address space. Ensure the top of the stack is EFI_PAGE_SIZE\r
106 // aligned (4KB)\r
dfc28388 107 and x1, x1, ~EFI_PAGE_MASK\r
f9a9d2dc
AB
108\r
109_GetBaseUefiMemory:\r
110 // Calculate the Base of the UEFI Memory\r
298f8361 111 sub x21, x1, x4\r
f9a9d2dc
AB
112\r
113_GetStackBase:\r
114 // r1 = The top of the Mpcore Stacks\r
115 // Stack for the primary core = PrimaryCoreStack\r
dfc28388 116 MOV32 (x2, FixedPcdGet32(PcdCPUCorePrimaryStackSize))\r
298f8361 117 sub x22, x1, x2\r
f9a9d2dc
AB
118\r
119 // Stack for the secondary core = Number of Cores - 1\r
dfc28388 120 MOV32 (x1, (FixedPcdGet32(PcdCoreCount) - 1) * FixedPcdGet32(PcdCPUCoreSecondaryStackSize))\r
298f8361 121 sub x22, x22, x1\r
f9a9d2dc 122\r
298f8361
AB
123 // x22 = The base of the MpCore Stacks (primary stack & secondary stacks)\r
124 mov x0, x22\r
125 mov x1, x20\r
f9a9d2dc 126 //ArmPlatformStackSet(StackBase, MpId, PrimaryStackSize, SecondaryStackSize)\r
dfc28388
AB
127 MOV32 (x2, FixedPcdGet32(PcdCPUCorePrimaryStackSize))\r
128 MOV32 (x3, FixedPcdGet32(PcdCPUCoreSecondaryStackSize))\r
f9a9d2dc
AB
129 bl ASM_PFX(ArmPlatformStackSet)\r
130\r
131 // Is it the Primary Core ?\r
132 mov x0, x10\r
133 bl ASM_PFX(ArmPlatformIsPrimaryCore)\r
134 cmp x0, #1\r
135 bne _PrepareArguments\r
136\r
f9a9d2dc 137_PrepareArguments:\r
298f8361
AB
138 mov x0, x20\r
139 mov x1, x21\r
140 mov x2, x22\r
f9a9d2dc 141\r
f9a9d2dc
AB
142 // Jump to PrePiCore C code\r
143 // x0 = MpId\r
144 // x1 = UefiMemoryBase\r
145 // x2 = StacksBase\r
16a9fe2c 146 bl ASM_PFX(CEntryPoint)\r
f9a9d2dc
AB
147\r
148_NeverReturn:\r
149 b _NeverReturn\r