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 #start of the code section
23 #global symbols referenced by this module
24 GCC_ASM_IMPORT(CEntryPoint)
26 StartupAddr: .word CEntryPoint
28 #make _ModuleEntryPoint as global
29 GCC_ASM_EXPORT(_ModuleEntryPoint)
32 ASM_PFX(_ModuleEntryPoint):
34 mrc p15, 0, r0, c0, c0, 5
38 #if FixedPcdGet32(PcdStandalone)
39 // Compute Top of System Memory
40 LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryBase), r1)
41 LoadConstantToReg (FixedPcdGet32(PcdSystemMemorySize), r2)
42 add r1, r1, r2 // r1 = SystemMemoryTop = PcdSystemMemoryBase + PcdSystemMemorySize
44 // If it is not a Standalone, we must compute the top of the UEFI memory with the base of the FD
45 LoadConstantToReg (FixedPcdGet32(PcdNormalFdBaseAddress), r1)
48 // Compute Base of UEFI Memory
49 LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryUefiRegionSize), r2)
50 sub r1, r1, r2 // r1 = SystemMemoryTop - PcdSystemMemoryUefiRegionSize = UefiMemoryBase
53 // Compute Base of Normal stacks for CPU Cores
54 LoadConstantToReg (FixedPcdGet32(PcdCPUCoresNonSecStackSize), r2)
55 mul r3, r0, r2 // r3 = core_id * stack_size = offset from the stack base
56 sub sp, r1, r3 // r3 = UefiMemoryBase - StackOffset = TopOfStack
58 // Only allocate memory in top of the primary core stack
62 _AllocateGlobalPeiVariables:
63 // Reserve top of the stack for Global PEI Variables (eg: PeiServicesTablePointer)
64 LoadConstantToReg (FixedPcdGet32(PcdPeiGlobalVariableSize), r4)
65 // The reserved place must be 8-bytes aligned for pushing 64-bit variable on the stack
72 // Pass the StackBase to the C Entrypoint (UefiMemoryBase - StackSize - StackOffset)
75 // Move sec startup address into a data register
76 // Ensure we're jumping to FV version of the code (not boot remapped alias)
79 // jump to PrePiCore C code
81 // r1 = UefiMemoryBase