2 // Copyright (c) 2011-2015, ARM Limited. All rights reserved.
4 // SPDX-License-Identifier: BSD-2-Clause-Patent
8 #include <AsmMacroIoLib.h>
10 #include <Chipset/ArmV7.h>
12 ASM_FUNC(_ModuleEntryPoint)
13 // Do early platform specific actions
14 bl ASM_PFX(ArmPlatformPeiBootAction)
16 // Get ID of this CPU in Multicore system
17 bl ASM_PFX(ArmReadMpidr)
18 // Keep a copy of the MpId register value
22 // Enter SVC mode, Disable FIQ and IRQ
23 mov r1, #(CPSR_MODE_SVC | CPSR_IRQ | CPSR_FIQ)
26 // Check if we can install the stack at the top of the System Memory or if we need
27 // to install the stacks at the bottom of the Firmware Device (case the FD is located
28 // at the top of the DRAM)
30 ADRL (r1, mSystemMemoryEnd)
37 // r1 = SystemMemoryTop
39 // Calculate Top of the Firmware Device
40 MOV32 (r2, FixedPcdGet32(PcdFdBaseAddress))
41 MOV32 (r3, FixedPcdGet32(PcdFdSize) - 1)
42 add r3, r3, r2 // r3 = FdTop = PcdFdBaseAddress + PcdFdSize
44 // UEFI Memory Size (stacks are allocated in this region)
45 MOV32 (r4, FixedPcdGet32(PcdSystemMemoryUefiRegionSize))
48 // Reserve the memory for the UEFI region (contain stacks on its top)
51 // Calculate how much space there is between the top of the Firmware and the Top of the System Memory
52 subs r0, r1, r3 // r0 = SystemMemoryTop - FdTop
53 bmi _SetupStack // Jump if negative (FdTop > SystemMemoryTop). Case when the PrePi is in XIP memory outside of the DRAM
57 // Case the top of stacks is the FdBaseAddress
61 // r1 contains the top of the stack (and the UEFI Memory)
63 // Because the 'push' instruction is equivalent to 'stmdb' (decrement before), we need to increment
64 // one to the top of the stack. We check if incrementing one does not overflow (case of DRAM at the
65 // top of the memory space)
67 bcs _SetupOverflowStack
74 // Case memory at the top of the address space. Ensure the top of the stack is EFI_PAGE_SIZE
76 MOV32 (r9, ~EFI_PAGE_MASK & 0xFFFFFFFF)
80 // Calculate the Base of the UEFI Memory
84 // r1 = The top of the Mpcore Stacks
85 // Stack for the primary core = PrimaryCoreStack
86 MOV32 (r2, FixedPcdGet32(PcdCPUCorePrimaryStackSize))
89 // Stack for the secondary core = Number of Cores - 1
90 MOV32 (r1, (FixedPcdGet32(PcdCoreCount) - 1) * FixedPcdGet32(PcdCPUCoreSecondaryStackSize))
93 // r10 = The base of the MpCore Stacks (primary stack & secondary stacks)
96 //ArmPlatformStackSet(StackBase, MpId, PrimaryStackSize, SecondaryStackSize)
97 MOV32 (r2, FixedPcdGet32(PcdCPUCorePrimaryStackSize))
98 MOV32 (r3, FixedPcdGet32(PcdCPUCoreSecondaryStackSize))
99 bl ASM_PFX(ArmPlatformStackSet)
101 // Is it the Primary Core ?
103 bl ASM_PFX(ArmPlatformIsPrimaryCore)
105 bne _PrepareArguments
113 // Move sec startup address into a data register
114 // Ensure we're jumping to FV version of the code (not boot remapped alias)
115 ldr r4, =ASM_PFX(CEntryPoint)
117 // Jump to PrePiCore C code
119 // r1 = UefiMemoryBase