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