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
25 EXPORT _ModuleEntryPoint
26 EXPORT mSystemMemoryEnd
29 AREA PrePiCoreEntryPoint, CODE, READONLY
31 StartupAddr DCD CEntryPoint
32 mSystemMemoryEnd DCQ 0
35 // Do early platform specific actions
36 bl ArmPlatformPeiBootAction
38 // Get ID of this CPU in Multicore system
40 // Keep a copy of the MpId register value
44 // Enter SVC mode, Disable FIQ and IRQ
45 mov r1, #(CPSR_MODE_SVC :OR: CPSR_IRQ :OR: CPSR_FIQ)
48 // Check if we can install the stack at the top of the System Memory or if we need
49 // to install the stacks at the bottom of the Firmware Device (case the FD is located
50 // at the top of the DRAM)
52 ldr r1, mSystemMemoryEnd
54 // Is mSystemMemoryEnd initialized?
56 bne _SetupStackPosition
58 mov32 r1, FixedPcdGet32(PcdSystemMemoryBase)
59 mov32 r2, FixedPcdGet32(PcdSystemMemorySize)
62 // Update the global variable
63 adr r2, mSystemMemoryEnd
67 // r1 = SystemMemoryTop
69 // Calculate Top of the Firmware Device
70 mov32 r2, FixedPcdGet32(PcdFdBaseAddress)
71 mov32 r3, FixedPcdGet32(PcdFdSize)
73 add r3, r3, r2 // r3 = FdTop = PcdFdBaseAddress + PcdFdSize
75 // UEFI Memory Size (stacks are allocated in this region)
76 mov32 r4, FixedPcdGet32(PcdSystemMemoryUefiRegionSize)
79 // Reserve the memory for the UEFI region (contain stacks on its top)
82 // Calculate how much space there is between the top of the Firmware and the Top of the System Memory
83 subs r0, r1, r3 // r0 = SystemMemoryTop - FdTop
84 bmi _SetupStack // Jump if negative (FdTop > SystemMemoryTop). Case when the PrePi is in XIP memory outside of the DRAM
88 // Case the top of stacks is the FdBaseAddress
92 // r1 contains the top of the stack (and the UEFI Memory)
94 // Because the 'push' instruction is equivalent to 'stmdb' (decrement before), we need to increment
95 // one to the top of the stack. We check if incrementing one does not overflow (case of DRAM at the
96 // top of the memory space)
98 bcs _SetupOverflowStack
105 // Case memory at the top of the address space. Ensure the top of the stack is EFI_PAGE_SIZE
107 mov32 r9, EFI_PAGE_MASK
112 // Calculate the Base of the UEFI Memory
116 // r1 = The top of the Mpcore Stacks
117 // Stack for the primary core = PrimaryCoreStack
118 mov32 r2, FixedPcdGet32(PcdCPUCorePrimaryStackSize)
121 // Stack for the secondary core = Number of Cores - 1
122 mov32 r1, (FixedPcdGet32(PcdCoreCount) - 1) * FixedPcdGet32(PcdCPUCoreSecondaryStackSize)
125 // r10 = The base of the MpCore Stacks (primary stack & secondary stacks)
128 //ArmPlatformStackSet(StackBase, MpId, PrimaryStackSize, SecondaryStackSize)
129 mov32 r2, FixedPcdGet32(PcdCPUCorePrimaryStackSize)
130 mov32 r3, FixedPcdGet32(PcdCPUCoreSecondaryStackSize)
131 bl ArmPlatformStackSet
133 // Is it the Primary Core ?
135 bl ArmPlatformIsPrimaryCore
137 bne _PrepareArguments
144 // Move sec startup address into a data register
145 // Ensure we're jumping to FV version of the code (not boot remapped alias)
148 // Jump to PrePiCore C code
150 // r1 = UefiMemoryBase