2 // Copyright (c) 2011-2013, 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 #include <Library/PcdLib.h>
19 #include <Chipset/ArmV7.h>
24 GCC_ASM_IMPORT(ArmPlatformIsPrimaryCore)
25 GCC_ASM_IMPORT(ArmReadMpidr)
26 GCC_ASM_IMPORT(ArmPlatformPeiBootAction)
27 GCC_ASM_IMPORT(ArmPlatformStackSet)
28 GCC_ASM_EXPORT(_ModuleEntryPoint)
30 StartupAddr: .dword ASM_PFX(CEntryPoint)
32 ASM_PFX(_ModuleEntryPoint):
33 // Do early platform specific actions
34 bl ASM_PFX(ArmPlatformPeiBootAction)
36 // Get ID of this CPU in Multicore system
37 bl ASM_PFX(ArmReadMpidr)
38 // Keep a copy of the MpId register value
42 // Check if we can install the stack at the top of the System Memory or if we need
43 // to install the stacks at the bottom of the Firmware Device (case the FD is located
44 // at the top of the DRAM)
46 // Compute Top of System Memory
47 LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryBase), x1)
48 LoadConstantToReg (FixedPcdGet32(PcdSystemMemorySize), x2)
50 add x1, x1, x2 // x1 = SystemMemoryTop = PcdSystemMemoryBase + PcdSystemMemorySize
52 // Calculate Top of the Firmware Device
53 LoadConstantToReg (FixedPcdGet32(PcdFdBaseAddress), x2)
54 LoadConstantToReg (FixedPcdGet32(PcdFdSize), x3)
56 add x3, x3, x2 // x3 = FdTop = PcdFdBaseAddress + PcdFdSize
58 // UEFI Memory Size (stacks are allocated in this region)
59 LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryUefiRegionSize), x4)
62 // Reserve the memory for the UEFI region (contain stacks on its top)
65 // Calculate how much space there is between the top of the Firmware and the Top of the System Memory
66 subs x0, x1, x3 // x0 = SystemMemoryTop - FdTop
67 b.mi _SetupStack // Jump if negative (FdTop > SystemMemoryTop). Case when the PrePi is in XIP memory outside of the DRAM
71 // Case the top of stacks is the FdBaseAddress
75 // x1 contains the top of the stack (and the UEFI Memory)
77 // Because the 'push' instruction is equivalent to 'stmdb' (decrement before), we need to increment
78 // one to the top of the stack. We check if incrementing one does not overflow (case of DRAM at the
79 // top of the memory space)
81 b.cs _SetupOverflowStack
88 // Case memory at the top of the address space. Ensure the top of the stack is EFI_PAGE_SIZE
90 LoadConstantToReg (EFI_PAGE_MASK, x11)
95 // Calculate the Base of the UEFI Memory
99 // r1 = The top of the Mpcore Stacks
100 // Stack for the primary core = PrimaryCoreStack
101 LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), x2)
104 // Stack for the secondary core = Number of Cores - 1
105 LoadConstantToReg (FixedPcdGet32(PcdCoreCount), x0)
107 LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), x1)
111 // x12 = The base of the MpCore Stacks (primary stack & secondary stacks)
114 //ArmPlatformStackSet(StackBase, MpId, PrimaryStackSize, SecondaryStackSize)
115 LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), x2)
116 LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), x3)
117 bl ASM_PFX(ArmPlatformStackSet)
119 // Is it the Primary Core ?
121 bl ASM_PFX(ArmPlatformIsPrimaryCore)
123 bne _PrepareArguments
125 _ReserveGlobalVariable:
126 LoadConstantToReg (FixedPcdGet32(PcdPeiGlobalVariableSize), x0)
127 // InitializePrimaryStack($GlobalVariableSize, $Tmp1, $Tmp2)
128 InitializePrimaryStack(x0, x1, x2)
136 // Move sec startup address into a data register
137 // Ensure we're jumping to FV version of the code (not boot remapped alias)
140 // Jump to PrePiCore C code
142 // x1 = UefiMemoryBase
144 // x3 = GlobalVariableBase