2 // Copyright (c) 2011, 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 <AsmMacroIoLib.h>
16 #include <Library/PcdLib.h>
19 INCLUDE AsmMacroIoLib.inc
23 EXPORT _ModuleEntryPoint
26 AREA PrePiCoreEntryPoint, CODE, READONLY
28 StartupAddr DCD CEntryPoint
31 // Get ID of this CPU in Multicore system
33 LoadConstantToReg (FixedPcdGet32(PcdArmPrimaryCoreMask), r1)
38 mov r1, #0x13|0x80|0x40
41 // Check if we can install the size at the top of the System Memory or if we need
42 // to install the stacks at the bottom of the Firmware Device (case the FD is located
43 // at the top of the DRAM)
45 // Compute Top of System Memory
46 LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryBase), r1)
47 LoadConstantToReg (FixedPcdGet32(PcdSystemMemorySize), r2)
48 add r1, r1, r2 // r1 = SystemMemoryTop = PcdSystemMemoryBase + PcdSystemMemorySize
50 // Calculate Top of the Firmware Device
51 LoadConstantToReg (FixedPcdGet32(PcdNormalFdBaseAddress), r2)
52 LoadConstantToReg (FixedPcdGet32(PcdNormalFdSize), r3)
53 add r3, r3, r2 // r4 = FdTop = PcdNormalFdBaseAddress + PcdNormalFdSize
55 // UEFI Memory Size (stacks are allocated in this region)
56 LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryUefiRegionSize), r4)
59 // Reserve the memory for the UEFI region (contain stacks on its top)
62 // Calculate how much space there is between the top of the Firmware and the Top of the System Memory
63 subs r5, r1, r3 // r5 = SystemMemoryTop - FdTop
64 bmi _SetupStack // Jump if negative (FdTop > SystemMemoryTop)
68 // Case the top of stacks is the FdBaseAddress
72 // Compute Base of Normal stacks for CPU Cores
73 LoadConstantToReg (FixedPcdGet32(PcdCPUCoresNonSecStackSize), r5)
74 mul r3, r0, r5 // r3 = core_id * stack_size = offset from the stack base
75 sub sp, r1, r3 // r3 = (SystemMemoryTop|FdBaseAddress) - StackOffset = TopOfStack
77 // Calculate the Base of the UEFI Memory
80 // Only allocate memory for global variables at top of the primary core stack
84 _AllocateGlobalPrePiVariables
85 // Reserve top of the stack for Global PEI Variables (eg: PeiServicesTablePointer)
86 LoadConstantToReg (FixedPcdGet32(PcdPeiGlobalVariableSize), r4)
87 // The reserved place must be 8-bytes aligned for pushing 64-bit variable on the stack
94 // Move sec startup address into a data register
95 // Ensure we're jumping to FV version of the code (not boot remapped alias)
98 // Jump to PrePiCore C code
100 // r1 = UefiMemoryBase