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