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>
22 # Global symbols referenced by this module
23 GCC_ASM_IMPORT(CEntryPoint)
24 GCC_ASM_EXPORT(_ModuleEntryPoint)
26 StartupAddr: .word CEntryPoint
29 ASM_PFX(_ModuleEntryPoint):
31 mrc p15, 0, r0, c0, c0, 5
36 mov r1, #0x13|0x80|0x40
39 // Check if we can install the size at the top of the System Memory or if we need
40 // to install the stacks at the bottom of the Firmware Device (case the FD is located
41 // at the top of the DRAM)
43 // Compute Top of System Memory
44 LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryBase), r1)
45 LoadConstantToReg (FixedPcdGet32(PcdSystemMemorySize), r2)
46 add r1, r1, r2 // r1 = SystemMemoryTop = PcdSystemMemoryBase + PcdSystemMemorySize
48 // Calculate Top of the Firmware Device
49 LoadConstantToReg (FixedPcdGet32(PcdNormalFdBaseAddress), r2)
50 LoadConstantToReg (FixedPcdGet32(PcdNormalFdSize), r3)
51 add r3, r3, r2 // r4 = FdTop = PcdNormalFdBaseAddress + PcdNormalFdSize
53 // UEFI Memory Size (stacks are allocated in this region)
54 LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryUefiRegionSize), r4)
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 r5, r1, r3 // r5 = SystemMemoryTop - FdTop
62 bmi _SetupStack // Jump if negative (FdTop > SystemMemoryTop)
66 // Case the top of stacks is the FdBaseAddress
70 // Compute Base of Normal stacks for CPU Cores
71 LoadConstantToReg (FixedPcdGet32(PcdCPUCoresNonSecStackSize), r5)
72 mul r3, r0, r5 // r3 = core_id * stack_size = offset from the stack base
73 sub sp, r1, r3 // r3 = (SystemMemoryTop|FdBaseAddress) - StackOffset = TopOfStack
75 // Calculate the Base of the UEFI Memory
78 // Only allocate memory for global variables at top of the primary core stack
82 _AllocateGlobalPrePiVariables:
83 // Reserve top of the stack for Global PEI Variables (eg: PeiServicesTablePointer)
84 LoadConstantToReg (FixedPcdGet32(PcdPeiGlobalVariableSize), r4)
85 // The reserved place must be 8-bytes aligned for pushing 64-bit variable on the stack
92 // Move sec startup address into a data register
93 // Ensure we're jumping to FV version of the code (not boot remapped alias)
96 // Jump to PrePiCore C code
98 // r1 = UefiMemoryBase