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