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
22 EXPORT _ModuleEntryPoint
25 AREA PrePiCoreEntryPoint, CODE, READONLY
27 StartupAddr DCD CEntryPoint
31 mrc p15, 0, r0, c0, c0, 5
35 #if FixedPcdGet32(PcdStandalone)
36 // Compute Top of System Memory
37 LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryBase), r1)
38 LoadConstantToReg (FixedPcdGet32(PcdSystemMemorySize), r2)
39 add r1, r1, r2 // r1 = SystemMemoryTop = PcdSystemMemoryBase + PcdSystemMemorySize
41 // If it is not a Standalone, we must compute the top of the UEFI memory with the base of the FD
42 LoadConstantToReg (FixedPcdGet32(PcdNormalFdBaseAddress), r1)
45 // Compute Base of UEFI Memory
46 LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryUefiRegionSize), r2)
47 sub r1, r1, r2 // r1 = SystemMemoryTop - PcdSystemMemoryUefiRegionSize = UefiMemoryBase
50 // Compute Base of Normal stacks for CPU Cores
51 LoadConstantToReg (FixedPcdGet32(PcdCPUCoresNonSecStackSize), r2)
52 mul r3, r0, r2 // r3 = core_id * stack_size = offset from the stack base
53 sub sp, r1, r3 // r3 = UefiMemoryBase - StackOffset = TopOfStack
55 // Only allocate memory in top of the primary core stack
59 _AllocateGlobalPrePiVariables
60 // Reserve top of the stack for Global PEI Variables (eg: PeiServicesTablePointer)
61 LoadConstantToReg (FixedPcdGet32(PcdPeiGlobalVariableSize), r4)
62 // The reserved place must be 8-bytes aligned for pushing 64-bit variable on the stack
69 // Pass the StackBase to the C Entrypoint (UefiMemoryBase - StackSize - StackOffset)
72 // Move sec startup address into a data register
73 // Ensure we're jumping to FV version of the code (not boot remapped alias)
76 // jump to PrePiCore C code
78 // r1 = UefiMemoryBase