2 // Copyright (c) 2011-2013, ARM Limited. All rights reserved.
3 // Copyright (c) 2015-2016, Linaro Limited. All rights reserved.
5 // This program and the accompanying materials
6 // are licensed and made available under the terms and conditions of the BSD License
7 // which accompanies this distribution. The full text of the license may be found at
8 // http://opensource.org/licenses/bsd-license.php
10 // THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include <AsmMacroIoLibV8.h>
17 ASM_GLOBAL ASM_PFX(mSystemMemoryEnd)
19 ASM_FUNC(_ModuleEntryPoint)
21 // We are built as a ET_DYN PIE executable, so we need to process all
22 // relative relocations regardless of whether or not we are executing from
23 // the same offset we were linked at. This is only possible if we are
35 // AArch64 uses the ELF64 RELA format, which means each entry in the
36 // relocation table consists of
38 // UINT64 offset : the relative offset of the value that needs to
40 // UINT64 info : relocation type and symbol index (the latter is
41 // not used for R_AARCH64_RELATIVE relocations)
42 // UINT64 addend : value to be added to the value being relocated
44 ldp x11, x12, [x9], #24 // read offset into x11 and info into x12
45 cmp x12, #0x403 // check info == R_AARCH64_RELATIVE?
46 bne .Lreloc_loop // not a relative relocation? then skip
48 ldr x12, [x9, #-8] // read addend into x12
49 add x12, x12, x8 // add reloc base to addend to get relocated value
50 str x12, [x11, x8] // write relocated value at offset
54 // Do early platform specific actions
55 bl ASM_PFX(ArmPlatformPeiBootAction)
57 // Get ID of this CPU in Multicore system
58 bl ASM_PFX(ArmReadMpidr)
59 // Keep a copy of the MpId register value
62 // Check if we can install the stack at the top of the System Memory or if we need
63 // to install the stacks at the bottom of the Firmware Device (case the FD is located
64 // at the top of the DRAM)
66 // Compute Top of System Memory
67 ldr x1, PcdGet64 (PcdSystemMemoryBase)
68 ldr x2, PcdGet64 (PcdSystemMemorySize)
70 add x1, x1, x2 // x1 = SystemMemoryTop = PcdSystemMemoryBase + PcdSystemMemorySize
71 adr x2, mSystemMemoryEnd
74 // Calculate Top of the Firmware Device
75 ldr x2, PcdGet64 (PcdFdBaseAddress)
76 MOV32 (w3, FixedPcdGet32 (PcdFdSize) - 1)
77 add x3, x3, x2 // x3 = FdTop = PcdFdBaseAddress + PcdFdSize
79 // UEFI Memory Size (stacks are allocated in this region)
80 MOV32 (x4, FixedPcdGet32(PcdSystemMemoryUefiRegionSize))
83 // Reserve the memory for the UEFI region (contain stacks on its top)
86 // Calculate how much space there is between the top of the Firmware and the Top of the System Memory
87 subs x0, x1, x3 // x0 = SystemMemoryTop - FdTop
88 b.mi _SetupStack // Jump if negative (FdTop > SystemMemoryTop). Case when the PrePi is in XIP memory outside of the DRAM
92 // Case the top of stacks is the FdBaseAddress
96 // x1 contains the top of the stack (and the UEFI Memory)
98 // Because the 'push' instruction is equivalent to 'stmdb' (decrement before), we need to increment
99 // one to the top of the stack. We check if incrementing one does not overflow (case of DRAM at the
100 // top of the memory space)
102 b.cs _SetupOverflowStack
109 // Case memory at the top of the address space. Ensure the top of the stack is EFI_PAGE_SIZE
111 and x1, x1, ~EFI_PAGE_MASK
114 // Calculate the Base of the UEFI Memory
118 // r1 = The top of the Mpcore Stacks
119 // Stack for the primary core = PrimaryCoreStack
120 MOV32 (x2, FixedPcdGet32(PcdCPUCorePrimaryStackSize))
123 // Stack for the secondary core = Number of Cores - 1
124 MOV32 (x1, (FixedPcdGet32(PcdCoreCount) - 1) * FixedPcdGet32(PcdCPUCoreSecondaryStackSize))
127 // x22 = The base of the MpCore Stacks (primary stack & secondary stacks)
130 //ArmPlatformStackSet(StackBase, MpId, PrimaryStackSize, SecondaryStackSize)
131 MOV32 (x2, FixedPcdGet32(PcdCPUCorePrimaryStackSize))
132 MOV32 (x3, FixedPcdGet32(PcdCPUCoreSecondaryStackSize))
133 bl ASM_PFX(ArmPlatformStackSet)
135 // Is it the Primary Core ?
137 bl ASM_PFX(ArmPlatformIsPrimaryCore)
139 bne _PrepareArguments
146 // Jump to PrePiCore C code
148 // x1 = UefiMemoryBase
150 bl ASM_PFX(CEntryPoint)
155 ASM_PFX(mSystemMemoryEnd): .8byte 0