]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/PrePi/Arm/ModuleEntryPoint.asm
993fccfa47d2e0519305c5e6e57ed59ce66496c9
[mirror_edk2.git] / ArmPlatformPkg / PrePi / Arm / ModuleEntryPoint.asm
1 //
2 // Copyright (c) 2011-2013, ARM Limited. All rights reserved.
3 //
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
8 //
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.
11 //
12 //
13
14 #include <AsmMacroIoLib.h>
15 #include <Base.h>
16 #include <Library/PcdLib.h>
17 #include <AutoGen.h>
18
19 #include <Chipset/ArmV7.h>
20
21 INCLUDE AsmMacroIoLib.inc
22
23 IMPORT CEntryPoint
24 IMPORT ArmPlatformIsPrimaryCore
25 IMPORT ArmReadMpidr
26 IMPORT ArmPlatformPeiBootAction
27 IMPORT ArmPlatformStackSet
28
29 EXPORT _ModuleEntryPoint
30
31 PRESERVE8
32 AREA PrePiCoreEntryPoint, CODE, READONLY
33
34 StartupAddr DCD CEntryPoint
35
36 _ModuleEntryPoint
37 // Do early platform specific actions
38 bl ArmPlatformPeiBootAction
39
40 // Get ID of this CPU in Multicore system
41 bl ArmReadMpidr
42 // Keep a copy of the MpId register value
43 mov r6, r0
44
45 _SetSVCMode
46 // Enter SVC mode, Disable FIQ and IRQ
47 mov r1, #(CPSR_MODE_SVC :OR: CPSR_IRQ :OR: CPSR_FIQ)
48 msr CPSR_c, r1
49
50 // Check if we can install the stack at the top of the System Memory or if we need
51 // to install the stacks at the bottom of the Firmware Device (case the FD is located
52 // at the top of the DRAM)
53 _SetupStackPosition
54 // Compute Top of System Memory
55 LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryBase), r1)
56 LoadConstantToReg (FixedPcdGet32(PcdSystemMemorySize), r2)
57 sub r2, r2, #1
58 add r1, r1, r2 // r1 = SystemMemoryTop = PcdSystemMemoryBase + PcdSystemMemorySize
59
60 // Calculate Top of the Firmware Device
61 LoadConstantToReg (FixedPcdGet32(PcdFdBaseAddress), r2)
62 LoadConstantToReg (FixedPcdGet32(PcdFdSize), r3)
63 sub r3, r3, #1
64 add r3, r3, r2 // r3 = FdTop = PcdFdBaseAddress + PcdFdSize
65
66 // UEFI Memory Size (stacks are allocated in this region)
67 LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryUefiRegionSize), r4)
68
69 //
70 // Reserve the memory for the UEFI region (contain stacks on its top)
71 //
72
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
76 cmp r0, r4
77 bge _SetupStack
78
79 // Case the top of stacks is the FdBaseAddress
80 mov r1, r2
81
82 _SetupStack
83 // r1 contains the top of the stack (and the UEFI Memory)
84
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)
88 adds r7, r1, #1
89 bcs _SetupOverflowStack
90
91 _SetupAlignedStack
92 mov r1, r7
93 b _GetBaseUefiMemory
94
95 _SetupOverflowStack
96 // Case memory at the top of the address space. Ensure the top of the stack is EFI_PAGE_SIZE
97 // aligned (4KB)
98 LoadConstantToReg (EFI_PAGE_MASK, r7)
99 and r7, r7, r1
100 sub r1, r1, r7
101
102 _GetBaseUefiMemory
103 // Calculate the Base of the UEFI Memory
104 sub r7, r1, r4
105
106 _GetStackBase
107 // r1 = The top of the Mpcore Stacks
108 // Stack for the primary core = PrimaryCoreStack
109 LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), r2)
110 sub r8, r1, r2
111
112 // Stack for the secondary core = Number of Cores - 1
113 LoadConstantToReg (FixedPcdGet32(PcdCoreCount), r0)
114 sub r0, r0, #1
115 LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), r1)
116 mul r1, r1, r0
117 sub r8, r8, r1
118
119 // r8 = The base of the MpCore Stacks (primary stack & secondary stacks)
120 mov r0, r8
121 mov r1, r6
122 //ArmPlatformStackSet(StackBase, MpId, PrimaryStackSize, SecondaryStackSize)
123 LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), r2)
124 LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), r3)
125 bl ArmPlatformStackSet
126
127 // Is it the Primary Core ?
128 mov r0, r6
129 bl ArmPlatformIsPrimaryCore
130 cmp r0, #1
131 bne _PrepareArguments
132
133 _ReserveGlobalVariable
134 LoadConstantToReg (FixedPcdGet32(PcdPeiGlobalVariableSize), r0)
135 // InitializePrimaryStack($GlobalVariableSize, $Tmp1)
136 InitializePrimaryStack r0, r1
137
138 _PrepareArguments
139 mov r0, r6
140 mov r1, r7
141 mov r2, r8
142 mov r3, sp
143
144 // Move sec startup address into a data register
145 // Ensure we're jumping to FV version of the code (not boot remapped alias)
146 ldr r4, StartupAddr
147
148 // Jump to PrePiCore C code
149 // r0 = MpId
150 // r1 = UefiMemoryBase
151 // r2 = StacksBase
152 // r3 = GlobalVariableBase
153 blx r4
154
155 _NeverReturn
156 b _NeverReturn
157
158 END