]>
Commit | Line | Data |
---|---|---|
809a639e 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 |
809a639e 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 <AsmMacroIoLib.h>\r | |
809a639e | 16 | \r |
dfc28388 | 17 | ASM_FUNC(_ModuleEntryPoint)\r |
809a639e AB |
18 | //\r |
19 | // We are built as a ET_DYN PIE executable, so we need to process all\r | |
20 | // relative relocations if we are executing from a different offset than we\r | |
21 | // were linked at. This is only possible if we are running from RAM.\r | |
22 | //\r | |
dfc28388 AB |
23 | ADRL (r4, __reloc_base)\r |
24 | ADRL (r5, __reloc_start)\r | |
25 | ADRL (r6, __reloc_end)\r | |
809a639e AB |
26 | \r |
27 | .Lreloc_loop:\r | |
28 | cmp r5, r6\r | |
29 | bhs .Lreloc_done\r | |
30 | \r | |
31 | //\r | |
32 | // AArch32 uses the ELF32 REL format, which means each entry in the\r | |
33 | // relocation table consists of\r | |
34 | //\r | |
35 | // UINT32 offset : the relative offset of the value that needs to\r | |
36 | // be relocated\r | |
37 | // UINT32 info : relocation type and symbol index (the latter is\r | |
38 | // not used for R_ARM_RELATIVE relocations)\r | |
39 | //\r | |
40 | ldrd r8, r9, [r5], #8 // read offset into r8 and info into r9\r | |
41 | cmp r9, #23 // check info == R_ARM_RELATIVE?\r | |
42 | bne .Lreloc_loop // not a relative relocation? then skip\r | |
43 | \r | |
44 | ldr r9, [r8, r4] // read addend into r9\r | |
45 | add r9, r9, r1 // add image base to addend to get relocated value\r | |
46 | str r9, [r8, r4] // write relocated value at offset\r | |
47 | b .Lreloc_loop\r | |
48 | .Lreloc_done:\r | |
49 | \r | |
50 | // Do early platform specific actions\r | |
51 | bl ASM_PFX(ArmPlatformPeiBootAction)\r | |
52 | \r | |
53 | // Get ID of this CPU in Multicore system\r | |
54 | bl ASM_PFX(ArmReadMpidr)\r | |
55 | // Keep a copy of the MpId register value\r | |
56 | mov r10, r0\r | |
57 | \r | |
58 | // Check if we can install the stack at the top of the System Memory or if we need\r | |
59 | // to install the stacks at the bottom of the Firmware Device (case the FD is located\r | |
60 | // at the top of the DRAM)\r | |
61 | _SetupStackPosition:\r | |
62 | // Compute Top of System Memory\r | |
dfc28388 AB |
63 | LDRL (r1, PcdGet64 (PcdSystemMemoryBase))\r |
64 | ADRL (r12, PcdGet64 (PcdSystemMemorySize))\r | |
809a639e AB |
65 | ldrd r2, r3, [r12]\r |
66 | \r | |
5b005a6b | 67 | // calculate the top of memory\r |
809a639e AB |
68 | adds r2, r2, r1\r |
69 | sub r2, r2, #1\r | |
70 | addcs r3, r3, #1\r | |
809a639e AB |
71 | \r |
72 | // truncate the memory used by UEFI to 4 GB range\r | |
73 | teq r3, #0\r | |
74 | movne r1, #-1\r | |
75 | moveq r1, r2\r | |
76 | \r | |
77 | // Calculate Top of the Firmware Device\r | |
dfc28388 AB |
78 | LDRL (r2, PcdGet64 (PcdFdBaseAddress))\r |
79 | MOV32 (r3, FixedPcdGet32 (PcdFdSize) - 1)\r | |
809a639e AB |
80 | add r3, r3, r2 // r3 = FdTop = PcdFdBaseAddress + PcdFdSize\r |
81 | \r | |
82 | // UEFI Memory Size (stacks are allocated in this region)\r | |
dfc28388 | 83 | MOV32 (r4, FixedPcdGet32(PcdSystemMemoryUefiRegionSize))\r |
809a639e AB |
84 | \r |
85 | //\r | |
86 | // Reserve the memory for the UEFI region (contain stacks on its top)\r | |
87 | //\r | |
88 | \r | |
89 | // Calculate how much space there is between the top of the Firmware and the Top of the System Memory\r | |
90 | subs r0, r1, r3 // r0 = SystemMemoryTop - FdTop\r | |
91 | bmi _SetupStack // Jump if negative (FdTop > SystemMemoryTop). Case when the PrePi is in XIP memory outside of the DRAM\r | |
92 | cmp r0, r4\r | |
93 | bge _SetupStack\r | |
94 | \r | |
95 | // Case the top of stacks is the FdBaseAddress\r | |
96 | mov r1, r2\r | |
97 | \r | |
98 | _SetupStack:\r | |
99 | // r1 contains the top of the stack (and the UEFI Memory)\r | |
100 | \r | |
101 | // Because the 'push' instruction is equivalent to 'stmdb' (decrement before), we need to increment\r | |
102 | // one to the top of the stack. We check if incrementing one does not overflow (case of DRAM at the\r | |
103 | // top of the memory space)\r | |
104 | adds r11, r1, #1\r | |
105 | bcs _SetupOverflowStack\r | |
106 | \r | |
107 | _SetupAlignedStack:\r | |
108 | mov r1, r11\r | |
109 | b _GetBaseUefiMemory\r | |
110 | \r | |
111 | _SetupOverflowStack:\r | |
112 | // Case memory at the top of the address space. Ensure the top of the stack is EFI_PAGE_SIZE\r | |
113 | // aligned (4KB)\r | |
dfc28388 AB |
114 | MOV32 (r11, (~EFI_PAGE_MASK) & 0xffffffff)\r |
115 | and r1, r1, r11\r | |
809a639e AB |
116 | \r |
117 | _GetBaseUefiMemory:\r | |
118 | // Calculate the Base of the UEFI Memory\r | |
119 | sub r11, r1, r4\r | |
120 | \r | |
121 | _GetStackBase:\r | |
122 | // r1 = The top of the Mpcore Stacks\r | |
523509ae AB |
123 | mov sp, r1\r |
124 | \r | |
809a639e | 125 | // Stack for the primary core = PrimaryCoreStack\r |
dfc28388 | 126 | MOV32 (r2, FixedPcdGet32(PcdCPUCorePrimaryStackSize))\r |
298f8361 | 127 | sub r9, r1, r2\r |
809a639e | 128 | \r |
809a639e AB |
129 | mov r0, r10\r |
130 | mov r1, r11\r | |
298f8361 | 131 | mov r2, r9\r |
809a639e | 132 | \r |
809a639e AB |
133 | // Jump to PrePiCore C code\r |
134 | // r0 = MpId\r | |
135 | // r1 = UefiMemoryBase\r | |
136 | // r2 = StacksBase\r | |
16a9fe2c | 137 | bl ASM_PFX(CEntryPoint)\r |
809a639e AB |
138 | \r |
139 | _NeverReturn:\r | |
140 | b _NeverReturn\r | |
83270956 AB |
141 | \r |
142 | ASM_PFX(ArmPlatformPeiBootAction):\r | |
143 | //\r | |
144 | // If we are booting from RAM using the Linux kernel boot protocol, r0 will\r | |
145 | // point to the DTB image in memory. Otherwise, use the default value defined\r | |
146 | // by the platform.\r | |
147 | //\r | |
148 | teq r0, #0\r | |
149 | bne 0f\r | |
150 | LDRL (r0, PcdGet64 (PcdDeviceTreeInitialBaseAddress))\r | |
151 | \r | |
152 | 0:mov r11, r14 // preserve LR\r | |
153 | mov r10, r0 // preserve DTB pointer\r | |
154 | mov r9, r1 // preserve base of image pointer\r | |
155 | \r | |
156 | //\r | |
157 | // The base of the runtime image has been preserved in r1. Check whether\r | |
158 | // the expected magic number can be found in the header.\r | |
159 | //\r | |
160 | ldr r8, .LArm32LinuxMagic\r | |
161 | ldr r7, [r1, #0x24]\r | |
162 | cmp r7, r8\r | |
163 | bne .Lout\r | |
164 | \r | |
165 | //\r | |
166 | //\r | |
167 | // OK, so far so good. We have confirmed that we likely have a DTB and are\r | |
168 | // booting via the ARM Linux boot protocol. Update the base-of-image PCD\r | |
169 | // to the actual relocated value, and add the shift of PcdFdBaseAddress to\r | |
170 | // PcdFvBaseAddress as well\r | |
171 | //\r | |
172 | ADRL (r8, PcdGet64 (PcdFdBaseAddress))\r | |
173 | ADRL (r7, PcdGet64 (PcdFvBaseAddress))\r | |
174 | ldr r6, [r8]\r | |
175 | ldr r5, [r7]\r | |
176 | sub r5, r5, r6\r | |
177 | add r5, r5, r1\r | |
178 | str r1, [r8]\r | |
179 | str r5, [r7]\r | |
180 | \r | |
181 | //\r | |
182 | // Discover the memory size and offset from the DTB, and record in the\r | |
183 | // respective PCDs. This will also return false if a corrupt DTB is\r | |
184 | // encountered. Since we are calling a C function, use the window at the\r | |
185 | // beginning of the FD image as a temp stack.\r | |
186 | //\r | |
187 | ADRL (r1, PcdGet64 (PcdSystemMemoryBase))\r | |
188 | ADRL (r2, PcdGet64 (PcdSystemMemorySize))\r | |
189 | mov sp, r5\r | |
190 | bl FindMemnode\r | |
191 | teq r0, #0\r | |
192 | beq .Lout\r | |
193 | \r | |
194 | //\r | |
195 | // Copy the DTB to the slack space right after the 64 byte arm64/Linux style\r | |
196 | // image header at the base of this image (defined in the FDF), and record the\r | |
197 | // pointer in PcdDeviceTreeInitialBaseAddress.\r | |
198 | //\r | |
199 | ADRL (r8, PcdGet64 (PcdDeviceTreeInitialBaseAddress))\r | |
200 | add r9, r9, #0x40\r | |
201 | str r9, [r8]\r | |
202 | \r | |
203 | mov r0, r9\r | |
204 | mov r1, r10\r | |
205 | bl CopyFdt\r | |
206 | \r | |
207 | .Lout:\r | |
208 | bx r11\r | |
209 | \r | |
210 | .LArm32LinuxMagic:\r | |
211 | .byte 0x18, 0x28, 0x6f, 0x01\r |