]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/PrePi/ModuleEntryPoint.asm
5efdb532af5beb1d423915d8ee443e1894c9c120
[mirror_edk2.git] / ArmPlatformPkg / PrePi / 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 ArmReadMpidr
25 IMPORT ArmPlatformStackSet
26
27 EXPORT _ModuleEntryPoint
28
29 PRESERVE8
30 AREA PrePiCoreEntryPoint, CODE, READONLY
31
32 StartupAddr DCD CEntryPoint
33
34 _ModuleEntryPoint
35 // Get ID of this CPU in Multicore system
36 bl ArmReadMpidr
37 LoadConstantToReg (FixedPcdGet32(PcdArmPrimaryCoreMask), r1)
38 and r6, r0, r1
39
40 _SetSVCMode
41 // Enter SVC mode, Disable FIQ and IRQ
42 mov r1, #(CPSR_MODE_SVC :OR: CPSR_IRQ :OR: CPSR_FIQ)
43 msr CPSR_c, r1
44
45 // Check if we can install the stack at the top of the System Memory or if we need
46 // to install the stacks at the bottom of the Firmware Device (case the FD is located
47 // at the top of the DRAM)
48 _SetupStackPosition
49 // Compute Top of System Memory
50 LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryBase), r1)
51 LoadConstantToReg (FixedPcdGet32(PcdSystemMemorySize), r2)
52 sub r2, r2, #1
53 add r1, r1, r2 // r1 = SystemMemoryTop = PcdSystemMemoryBase + PcdSystemMemorySize
54
55 // Calculate Top of the Firmware Device
56 LoadConstantToReg (FixedPcdGet32(PcdFdBaseAddress), r2)
57 LoadConstantToReg (FixedPcdGet32(PcdFdSize), r3)
58 sub r3, r3, #1
59 add r3, r3, r2 // r3 = FdTop = PcdFdBaseAddress + PcdFdSize
60
61 // UEFI Memory Size (stacks are allocated in this region)
62 LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryUefiRegionSize), r4)
63
64 //
65 // Reserve the memory for the UEFI region (contain stacks on its top)
66 //
67
68 // Calculate how much space there is between the top of the Firmware and the Top of the System Memory
69 subs r0, r1, r3 // r0 = SystemMemoryTop - FdTop
70 bmi _SetupStack // Jump if negative (FdTop > SystemMemoryTop). Case when the PrePi is in XIP memory outside of the DRAM
71 cmp r0, r4
72 bge _SetupStack
73
74 // Case the top of stacks is the FdBaseAddress
75 mov r1, r2
76
77 _SetupStack
78 // r1 contains the top of the stack (and the UEFI Memory)
79
80 // Because the 'push' instruction is equivalent to 'stmdb' (decrement before), we need to increment
81 // one to the top of the stack. We check if incrementing one does not overflow (case of DRAM at the
82 // top of the memory space)
83 adds r7, r1, #1
84 bcs _SetupOverflowStack
85
86 _SetupAlignedStack
87 mov r1, r7
88 b _GetBaseUefiMemory
89
90 _SetupOverflowStack
91 // Case memory at the top of the address space. Ensure the top of the stack is EFI_PAGE_SIZE
92 // aligned (4KB)
93 LoadConstantToReg (EFI_PAGE_MASK, r7)
94 and r7, r7, r1
95 sub r1, r1, r7
96
97 _GetBaseUefiMemory
98 // Calculate the Base of the UEFI Memory
99 sub r7, r1, r4
100
101 _GetStackBase
102 // r1 = The top of the Mpcore Stacks
103 // Stack for the primary core = PrimaryCoreStack
104 LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), r2)
105 sub r8, r1, r2
106
107 // Stack for the secondary core = Number of Cores - 1
108 LoadConstantToReg (FixedPcdGet32(PcdCoreCount), r0)
109 sub r0, r0, #1
110 LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), r1)
111 mul r1, r1, r0
112 sub r8, r8, r1
113
114 // r8 = The base of the MpCore Stacks (primary stack & secondary stacks)
115 mov r0, r8
116 mov r1, r6
117 //ArmPlatformStackSet(StackBase, MpId, PrimaryStackSize, SecondaryStackSize)
118 LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), r2)
119 LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), r3)
120 bl ArmPlatformStackSet
121
122 // Is it the Primary Core ?
123 LoadConstantToReg (FixedPcdGet32(PcdArmPrimaryCore), r4)
124 cmp r6, r4
125 bne _PrepareArguments
126
127 _ReserveGlobalVariable
128 LoadConstantToReg (FixedPcdGet32(PcdPeiGlobalVariableSize), r0)
129 // InitializePrimaryStack($GlobalVariableSize, $Tmp1)
130 InitializePrimaryStack r0, r1
131
132 _PrepareArguments
133 mov r0, r6
134 mov r1, r7
135 mov r2, r8
136 mov r3, sp
137
138 // Move sec startup address into a data register
139 // Ensure we're jumping to FV version of the code (not boot remapped alias)
140 ldr r4, StartupAddr
141
142 // Jump to PrePiCore C code
143 // r0 = MpId
144 // r1 = UefiMemoryBase
145 // r2 = StacksBase
146 // r3 = GlobalVariableBase
147 blx r4
148
149 _NeverReturn
150 b _NeverReturn
151
152 END