]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/PrePi/AArch64/ModuleEntryPoint.S
ARM Packages: Removed 'Chipset/ArmV7.h' inclusion from the non-ARMv7 specific files
[mirror_edk2.git] / ArmPlatformPkg / PrePi / AArch64 / ModuleEntryPoint.S
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 <AsmMacroIoLibV8.h>
15 #include <Base.h>
16 #include <Library/PcdLib.h>
17 #include <AutoGen.h>
18
19 .text
20 .align 3
21
22 GCC_ASM_IMPORT(ArmPlatformIsPrimaryCore)
23 GCC_ASM_IMPORT(ArmReadMpidr)
24 GCC_ASM_IMPORT(ArmPlatformPeiBootAction)
25 GCC_ASM_IMPORT(ArmPlatformStackSet)
26 GCC_ASM_EXPORT(_ModuleEntryPoint)
27
28 StartupAddr: .dword ASM_PFX(CEntryPoint)
29
30 ASM_PFX(_ModuleEntryPoint):
31 // Do early platform specific actions
32 bl ASM_PFX(ArmPlatformPeiBootAction)
33
34 // Get ID of this CPU in Multicore system
35 bl ASM_PFX(ArmReadMpidr)
36 // Keep a copy of the MpId register value
37 mov x10, x0
38
39 _SetSVCMode:
40 // Check if we can install the stack at the top of the System Memory or if we need
41 // to install the stacks at the bottom of the Firmware Device (case the FD is located
42 // at the top of the DRAM)
43 _SetupStackPosition:
44 // Compute Top of System Memory
45 LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryBase), x1)
46 LoadConstantToReg (FixedPcdGet32(PcdSystemMemorySize), x2)
47 sub x2, x2, #1
48 add x1, x1, x2 // x1 = SystemMemoryTop = PcdSystemMemoryBase + PcdSystemMemorySize
49
50 // Calculate Top of the Firmware Device
51 LoadConstantToReg (FixedPcdGet32(PcdFdBaseAddress), x2)
52 LoadConstantToReg (FixedPcdGet32(PcdFdSize), x3)
53 sub x3, x3, #1
54 add x3, x3, x2 // x3 = FdTop = PcdFdBaseAddress + PcdFdSize
55
56 // UEFI Memory Size (stacks are allocated in this region)
57 LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryUefiRegionSize), x4)
58
59 //
60 // Reserve the memory for the UEFI region (contain stacks on its top)
61 //
62
63 // Calculate how much space there is between the top of the Firmware and the Top of the System Memory
64 subs x0, x1, x3 // x0 = SystemMemoryTop - FdTop
65 b.mi _SetupStack // Jump if negative (FdTop > SystemMemoryTop). Case when the PrePi is in XIP memory outside of the DRAM
66 cmp x0, x4
67 b.ge _SetupStack
68
69 // Case the top of stacks is the FdBaseAddress
70 mov x1, x2
71
72 _SetupStack:
73 // x1 contains the top of the stack (and the UEFI Memory)
74
75 // Because the 'push' instruction is equivalent to 'stmdb' (decrement before), we need to increment
76 // one to the top of the stack. We check if incrementing one does not overflow (case of DRAM at the
77 // top of the memory space)
78 adds x11, x1, #1
79 b.cs _SetupOverflowStack
80
81 _SetupAlignedStack:
82 mov x1, x11
83 b _GetBaseUefiMemory
84
85 _SetupOverflowStack:
86 // Case memory at the top of the address space. Ensure the top of the stack is EFI_PAGE_SIZE
87 // aligned (4KB)
88 LoadConstantToReg (EFI_PAGE_MASK, x11)
89 and x11, x11, x1
90 sub x1, x1, x11
91
92 _GetBaseUefiMemory:
93 // Calculate the Base of the UEFI Memory
94 sub x11, x1, x4
95
96 _GetStackBase:
97 // r1 = The top of the Mpcore Stacks
98 // Stack for the primary core = PrimaryCoreStack
99 LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), x2)
100 sub x12, x1, x2
101
102 // Stack for the secondary core = Number of Cores - 1
103 LoadConstantToReg (FixedPcdGet32(PcdCoreCount), x0)
104 sub x0, x0, #1
105 LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), x1)
106 mul x1, x1, x0
107 sub x12, x12, x1
108
109 // x12 = The base of the MpCore Stacks (primary stack & secondary stacks)
110 mov x0, x12
111 mov x1, x10
112 //ArmPlatformStackSet(StackBase, MpId, PrimaryStackSize, SecondaryStackSize)
113 LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), x2)
114 LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), x3)
115 bl ASM_PFX(ArmPlatformStackSet)
116
117 // Is it the Primary Core ?
118 mov x0, x10
119 bl ASM_PFX(ArmPlatformIsPrimaryCore)
120 cmp x0, #1
121 bne _PrepareArguments
122
123 _ReserveGlobalVariable:
124 LoadConstantToReg (FixedPcdGet32(PcdPeiGlobalVariableSize), x0)
125 // InitializePrimaryStack($GlobalVariableSize, $Tmp1, $Tmp2)
126 InitializePrimaryStack(x0, x1, x2)
127
128 _PrepareArguments:
129 mov x0, x10
130 mov x1, x11
131 mov x2, x12
132 mov x3, sp
133
134 // Move sec startup address into a data register
135 // Ensure we're jumping to FV version of the code (not boot remapped alias)
136 ldr x4, StartupAddr
137
138 // Jump to PrePiCore C code
139 // x0 = MpId
140 // x1 = UefiMemoryBase
141 // x2 = StacksBase
142 // x3 = GlobalVariableBase
143 blr x4
144
145 _NeverReturn:
146 b _NeverReturn