2 // Copyright (c) 2011-2015, ARM Limited. All rights reserved.
4 // This program and the accompanying materials
5 // are licensed and made available under the terms and conditions of the BSD License
6 // which accompanies this distribution. The full text of the license may be found at
7 // http://opensource.org/licenses/bsd-license.php
9 // THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 #include <AsmMacroIoLibV8.h>
16 ASM_GLOBAL ASM_PFX(mSystemMemoryEnd)
18 ASM_FUNC(_ModuleEntryPoint)
19 // Do early platform specific actions
20 bl ASM_PFX(ArmPlatformPeiBootAction)
22 // Get ID of this CPU in Multicore system
23 bl ASM_PFX(ArmReadMpidr)
24 // Keep a copy of the MpId register value
28 // Check if we can install the stack at the top of the System Memory or if we need
29 // to install the stacks at the bottom of the Firmware Device (case the FD is located
30 // at the top of the DRAM)
32 ldr x1, mSystemMemoryEnd
34 // Is mSystemMemoryEnd initialized?
36 bne _SetupStackPosition
38 MOV64 (x1, FixedPcdGet64(PcdSystemMemoryBase) + FixedPcdGet64(PcdSystemMemorySize) - 1)
40 // Update the global variable
41 adr x2, mSystemMemoryEnd
45 // r1 = SystemMemoryTop
47 // Calculate Top of the Firmware Device
48 MOV64 (x2, FixedPcdGet64(PcdFdBaseAddress))
49 MOV32 (x3, FixedPcdGet32(PcdFdSize) - 1)
51 add x3, x3, x2 // x3 = FdTop = PcdFdBaseAddress + PcdFdSize
53 // UEFI Memory Size (stacks are allocated in this region)
54 MOV32 (x4, FixedPcdGet32(PcdSystemMemoryUefiRegionSize))
57 // Reserve the memory for the UEFI region (contain stacks on its top)
60 // Calculate how much space there is between the top of the Firmware and the Top of the System Memory
61 subs x0, x1, x3 // x0 = SystemMemoryTop - FdTop
62 b.mi _SetupStack // Jump if negative (FdTop > SystemMemoryTop). Case when the PrePi is in XIP memory outside of the DRAM
66 // Case the top of stacks is the FdBaseAddress
70 // x1 contains the top of the stack (and the UEFI Memory)
72 // Because the 'push' instruction is equivalent to 'stmdb' (decrement before), we need to increment
73 // one to the top of the stack. We check if incrementing one does not overflow (case of DRAM at the
74 // top of the memory space)
76 b.cs _SetupOverflowStack
83 // Case memory at the top of the address space. Ensure the top of the stack is EFI_PAGE_SIZE
85 and x1, x1, ~EFI_PAGE_MASK
88 // Calculate the Base of the UEFI Memory
92 // r1 = The top of the Mpcore Stacks
93 // Stack for the primary core = PrimaryCoreStack
94 MOV32 (x2, FixedPcdGet32(PcdCPUCorePrimaryStackSize))
97 // Stack for the secondary core = Number of Cores - 1
98 MOV32 (x1, (FixedPcdGet32(PcdCoreCount) - 1) * FixedPcdGet32(PcdCPUCoreSecondaryStackSize))
101 // x12 = The base of the MpCore Stacks (primary stack & secondary stacks)
104 //ArmPlatformStackSet(StackBase, MpId, PrimaryStackSize, SecondaryStackSize)
105 MOV32 (x2, FixedPcdGet32(PcdCPUCorePrimaryStackSize))
106 MOV32 (x3, FixedPcdGet32(PcdCPUCoreSecondaryStackSize))
107 bl ASM_PFX(ArmPlatformStackSet)
109 // Is it the Primary Core ?
111 bl ASM_PFX(ArmPlatformIsPrimaryCore)
113 bne _PrepareArguments
120 // Move sec startup address into a data register
121 // Ensure we're jumping to FV version of the code (not boot remapped alias)
122 ldr x4, =ASM_PFX(CEntryPoint)
124 // Jump to PrePiCore C code
126 // x1 = UefiMemoryBase
133 ASM_PFX(mSystemMemoryEnd): .8byte 0