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