2 // Copyright (c) 2011-2012, 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
23 IMPORT ArmPlatformStackSet
25 EXPORT _ModuleEntryPoint
28 AREA PrePiCoreEntryPoint, CODE, READONLY
30 StartupAddr DCD CEntryPoint
33 // Get ID of this CPU in Multicore system
35 LoadConstantToReg (FixedPcdGet32(PcdArmPrimaryCoreMask), r1)
39 // Enter SVC mode, Disable FIQ and IRQ
40 //TODO: remove hardcoded values
41 mov r1, #0x13 :OR: 0x80 :OR: 0x40
44 // Check if we can install the stack at the top of the System Memory or if we need
45 // to install the stacks at the bottom of the Firmware Device (case the FD is located
46 // at the top of the DRAM)
48 // Compute Top of System Memory
49 LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryBase), r1)
50 LoadConstantToReg (FixedPcdGet32(PcdSystemMemorySize), r2)
52 add r1, r1, r2 // r1 = SystemMemoryTop = PcdSystemMemoryBase + PcdSystemMemorySize
54 // Calculate Top of the Firmware Device
55 LoadConstantToReg (FixedPcdGet32(PcdFdBaseAddress), r2)
56 LoadConstantToReg (FixedPcdGet32(PcdFdSize), r3)
58 add r3, r3, r2 // r3 = FdTop = PcdFdBaseAddress + PcdFdSize
60 // UEFI Memory Size (stacks are allocated in this region)
61 LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryUefiRegionSize), r4)
64 // Reserve the memory for the UEFI region (contain stacks on its top)
67 // Calculate how much space there is between the top of the Firmware and the Top of the System Memory
68 subs r0, r1, r3 // r0 = SystemMemoryTop - FdTop
69 bmi _SetupStack // Jump if negative (FdTop > SystemMemoryTop). Case when the PrePi is in XIP memory outside of the DRAM
73 // Case the top of stacks is the FdBaseAddress
77 // r1 contains the top of the stack (and the UEFI Memory)
79 // Because the 'push' instruction is equivalent to 'stmdb' (decrement before), we need to increment
80 // one to the top of the stack. We check if incrementing one does not overflow (case of DRAM at the
81 // top of the memory space)
83 bcs _SetupOverflowStack
90 // Case memory at the top of the address space. Ensure the top of the stack is EFI_PAGE_SIZE
92 LoadConstantToReg (EFI_PAGE_MASK, r7)
97 // Calculate the Base of the UEFI Memory
101 // r1 = The top of the Mpcore Stacks
102 // Stack for the primary core = PrimaryCoreStack
103 LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), r2)
106 // Stack for the secondary core = Number of Cores - 1
107 LoadConstantToReg (FixedPcdGet32(PcdCoreCount), r0)
109 LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), r1)
113 // r8 = The base of the MpCore Stacks (primary stack & secondary stacks)
116 //ArmPlatformStackSet(StackBase, MpId, PrimaryStackSize, SecondaryStackSize)
117 LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), r2)
118 LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), r3)
119 bl ArmPlatformStackSet
121 // Is it the Primary Core ?
122 LoadConstantToReg (FixedPcdGet32(PcdArmPrimaryCore), r4)
124 bne _PrepareArguments
126 _ReserveGlobalVariable
127 LoadConstantToReg (FixedPcdGet32(PcdPeiGlobalVariableSize), r0)
128 // InitializePrimaryStack($GlobalVariableSize, $Tmp1)
129 InitializePrimaryStack r0, r1
137 // Move sec startup address into a data register
138 // Ensure we're jumping to FV version of the code (not boot remapped alias)
141 // Jump to PrePiCore C code
143 // r1 = UefiMemoryBase
145 // r3 = GlobalVariableBase