2 // Copyright (c) 2011 - 2020, Arm Limited. All rights reserved.<BR>
4 // SPDX-License-Identifier: BSD-2-Clause-Patent
8 #include <AsmMacroIoLibV8.h>
10 ASM_FUNC(_ModuleEntryPoint)
11 // Do early platform specific actions
12 bl ASM_PFX(ArmPlatformPeiBootAction)
14 // Get ID of this CPU in multi-core system
15 bl ASM_PFX(ArmReadMpidr)
16 // Keep a copy of the MpId register value
20 // Check if we can install the stack at the top of the System Memory or if we need
21 // to install the stacks at the bottom of the Firmware Device (case the FD is located
22 // at the top of the DRAM)
24 ldr x1, mSystemMemoryEnd
27 // r1 = SystemMemoryTop
29 // Calculate Top of the Firmware Device
30 MOV64 (x2, FixedPcdGet64(PcdFdBaseAddress))
31 MOV32 (x3, FixedPcdGet32(PcdFdSize) - 1)
33 add x3, x3, x2 // x3 = FdTop = PcdFdBaseAddress + PcdFdSize
35 // UEFI Memory Size (stacks are allocated in this region)
36 MOV32 (x4, FixedPcdGet32(PcdSystemMemoryUefiRegionSize))
39 // Reserve the memory for the UEFI region (contain stacks on its top)
42 // Calculate how much space there is between the top of the Firmware and the Top of the System Memory
43 subs x0, x1, x3 // x0 = SystemMemoryTop - FdTop
44 b.mi _SetupStack // Jump if negative (FdTop > SystemMemoryTop). Case when the PrePi is in XIP memory outside of the DRAM
48 // Case the top of stacks is the FdBaseAddress
52 // x1 contains the top of the stack (and the UEFI Memory)
54 // Because the 'push' instruction is equivalent to 'stmdb' (decrement before), we need to increment
55 // one to the top of the stack. We check if incrementing one does not overflow (case of DRAM at the
56 // top of the memory space)
58 b.cs _SetupOverflowStack
65 // Case memory at the top of the address space. Ensure the top of the stack is EFI_PAGE_SIZE
67 and x1, x1, ~EFI_PAGE_MASK
70 // Calculate the Base of the UEFI Memory
74 // r1 = The top of the Mpcore Stacks
75 // Stack for the primary core = PrimaryCoreStack
76 MOV32 (x2, FixedPcdGet32(PcdCPUCorePrimaryStackSize))
79 // Stack for the secondary core = Number of Cores - 1
80 MOV32 (x1, (FixedPcdGet32(PcdCoreCount) - 1) * FixedPcdGet32(PcdCPUCoreSecondaryStackSize))
83 // x12 = The base of the MpCore Stacks (primary stack & secondary stacks)
86 //ArmPlatformStackSet(StackBase, MpId, PrimaryStackSize, SecondaryStackSize)
87 MOV32 (x2, FixedPcdGet32(PcdCPUCorePrimaryStackSize))
88 MOV32 (x3, FixedPcdGet32(PcdCPUCoreSecondaryStackSize))
89 bl ASM_PFX(ArmPlatformStackSet)
91 // Is it the Primary Core ?
93 bl ASM_PFX(ArmPlatformIsPrimaryCore)
102 // Move sec startup address into a data register
103 // Ensure we're jumping to FV version of the code (not boot remapped alias)
104 ldr x4, =ASM_PFX(CEntryPoint)
106 // Set the frame pointer to NULL so any backtraces terminate here
109 // Jump to PrePiCore C code
111 // x1 = UefiMemoryBase