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