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