2 // Copyright (c) 2011-2015, 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.
15 #include <Chipset/ArmV7.h>
17 INCLUDE AsmMacroIoLib.inc
20 IMPORT ArmPlatformIsPrimaryCore
22 IMPORT ArmPlatformPeiBootAction
23 IMPORT ArmPlatformStackSet
24 IMPORT mSystemMemoryEnd
26 EXPORT _ModuleEntryPoint
29 AREA PrePiCoreEntryPoint, CODE, READONLY
31 StartupAddr DCD CEntryPoint
34 // Do early platform specific actions
35 bl ArmPlatformPeiBootAction
37 // Get ID of this CPU in Multicore system
39 // Keep a copy of the MpId register value
43 // Enter SVC mode, Disable FIQ and IRQ
44 mov r1, #(CPSR_MODE_SVC :OR: CPSR_IRQ :OR: CPSR_FIQ)
47 // Check if we can install the stack at the top of the System Memory or if we need
48 // to install the stacks at the bottom of the Firmware Device (case the FD is located
49 // at the top of the DRAM)
51 adrll r1, mSystemMemoryEnd
58 // r1 = SystemMemoryTop
60 // Calculate Top of the Firmware Device
61 mov32 r2, FixedPcdGet32(PcdFdBaseAddress)
62 mov32 r3, FixedPcdGet32(PcdFdSize)
64 add r3, r3, r2 // r3 = FdTop = PcdFdBaseAddress + PcdFdSize
66 // UEFI Memory Size (stacks are allocated in this region)
67 mov32 r4, FixedPcdGet32(PcdSystemMemoryUefiRegionSize)
70 // Reserve the memory for the UEFI region (contain stacks on its top)
73 // Calculate how much space there is between the top of the Firmware and the Top of the System Memory
74 subs r0, r1, r3 // r0 = SystemMemoryTop - FdTop
75 bmi _SetupStack // Jump if negative (FdTop > SystemMemoryTop). Case when the PrePi is in XIP memory outside of the DRAM
79 // Case the top of stacks is the FdBaseAddress
83 // r1 contains the top of the stack (and the UEFI Memory)
85 // Because the 'push' instruction is equivalent to 'stmdb' (decrement before), we need to increment
86 // one to the top of the stack. We check if incrementing one does not overflow (case of DRAM at the
87 // top of the memory space)
89 bcs _SetupOverflowStack
96 // Case memory at the top of the address space. Ensure the top of the stack is EFI_PAGE_SIZE
98 mov32 r9, EFI_PAGE_MASK
103 // Calculate the Base of the UEFI Memory
107 // r1 = The top of the Mpcore Stacks
108 // Stack for the primary core = PrimaryCoreStack
109 mov32 r2, FixedPcdGet32(PcdCPUCorePrimaryStackSize)
112 // Stack for the secondary core = Number of Cores - 1
113 mov32 r1, (FixedPcdGet32(PcdCoreCount) - 1) * FixedPcdGet32(PcdCPUCoreSecondaryStackSize)
116 // r10 = The base of the MpCore Stacks (primary stack & secondary stacks)
119 //ArmPlatformStackSet(StackBase, MpId, PrimaryStackSize, SecondaryStackSize)
120 mov32 r2, FixedPcdGet32(PcdCPUCorePrimaryStackSize)
121 mov32 r3, FixedPcdGet32(PcdCPUCoreSecondaryStackSize)
122 bl ArmPlatformStackSet
124 // Is it the Primary Core ?
126 bl ArmPlatformIsPrimaryCore
128 bne _PrepareArguments
135 // Move sec startup address into a data register
136 // Ensure we're jumping to FV version of the code (not boot remapped alias)
139 // Jump to PrePiCore C code
141 // r1 = UefiMemoryBase