]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/PrePi/AArch64/ModuleEntryPoint.S
ArmPlatformPkg: clear frame pointer in startup code
[mirror_edk2.git] / ArmPlatformPkg / PrePi / AArch64 / ModuleEntryPoint.S
CommitLineData
1bc83266 1//\r
5dbacdb2 2// Copyright (c) 2011-2015, ARM Limited. All rights reserved.\r
1bc83266
HL
3//\r
4// This program and the accompanying materials\r
5// are licensed and made available under the terms and conditions of the BSD License\r
6// which accompanies this distribution. The full text of the license may be found at\r
7// http://opensource.org/licenses/bsd-license.php\r
8//\r
9// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11//\r
12//\r
13\r
14#include <AsmMacroIoLibV8.h>\r
1bc83266 15\r
d2fa09a1 16ASM_FUNC(_ModuleEntryPoint)\r
1bc83266
HL
17 // Do early platform specific actions\r
18 bl ASM_PFX(ArmPlatformPeiBootAction)\r
19\r
20 // Get ID of this CPU in Multicore system\r
21 bl ASM_PFX(ArmReadMpidr)\r
22 // Keep a copy of the MpId register value\r
23 mov x10, x0\r
24\r
25_SetSVCMode:\r
26// Check if we can install the stack at the top of the System Memory or if we need\r
27// to install the stacks at the bottom of the Firmware Device (case the FD is located\r
28// at the top of the DRAM)\r
5dbacdb2
OM
29_SystemMemoryEndInit:\r
30 ldr x1, mSystemMemoryEnd\r
31\r
5dbacdb2
OM
32_SetupStackPosition:\r
33 // r1 = SystemMemoryTop\r
1bc83266
HL
34\r
35 // Calculate Top of the Firmware Device\r
d2fa09a1
AB
36 MOV64 (x2, FixedPcdGet64(PcdFdBaseAddress))\r
37 MOV32 (x3, FixedPcdGet32(PcdFdSize) - 1)\r
1bc83266
HL
38 sub x3, x3, #1\r
39 add x3, x3, x2 // x3 = FdTop = PcdFdBaseAddress + PcdFdSize\r
40\r
41 // UEFI Memory Size (stacks are allocated in this region)\r
d2fa09a1 42 MOV32 (x4, FixedPcdGet32(PcdSystemMemoryUefiRegionSize))\r
1bc83266
HL
43\r
44 //\r
45 // Reserve the memory for the UEFI region (contain stacks on its top)\r
46 //\r
47\r
48 // Calculate how much space there is between the top of the Firmware and the Top of the System Memory\r
49 subs x0, x1, x3 // x0 = SystemMemoryTop - FdTop\r
50 b.mi _SetupStack // Jump if negative (FdTop > SystemMemoryTop). Case when the PrePi is in XIP memory outside of the DRAM\r
51 cmp x0, x4\r
52 b.ge _SetupStack\r
53\r
54 // Case the top of stacks is the FdBaseAddress\r
55 mov x1, x2\r
56\r
57_SetupStack:\r
58 // x1 contains the top of the stack (and the UEFI Memory)\r
59\r
60 // Because the 'push' instruction is equivalent to 'stmdb' (decrement before), we need to increment\r
61 // one to the top of the stack. We check if incrementing one does not overflow (case of DRAM at the\r
62 // top of the memory space)\r
63 adds x11, x1, #1\r
64 b.cs _SetupOverflowStack\r
65\r
66_SetupAlignedStack:\r
67 mov x1, x11\r
68 b _GetBaseUefiMemory\r
69\r
70_SetupOverflowStack:\r
71 // Case memory at the top of the address space. Ensure the top of the stack is EFI_PAGE_SIZE\r
72 // aligned (4KB)\r
d2fa09a1 73 and x1, x1, ~EFI_PAGE_MASK\r
1bc83266
HL
74\r
75_GetBaseUefiMemory:\r
76 // Calculate the Base of the UEFI Memory\r
77 sub x11, x1, x4\r
78\r
79_GetStackBase:\r
80 // r1 = The top of the Mpcore Stacks\r
81 // Stack for the primary core = PrimaryCoreStack\r
d2fa09a1 82 MOV32 (x2, FixedPcdGet32(PcdCPUCorePrimaryStackSize))\r
1bc83266
HL
83 sub x12, x1, x2\r
84\r
85 // Stack for the secondary core = Number of Cores - 1\r
d2fa09a1 86 MOV32 (x1, (FixedPcdGet32(PcdCoreCount) - 1) * FixedPcdGet32(PcdCPUCoreSecondaryStackSize))\r
1bc83266
HL
87 sub x12, x12, x1\r
88\r
89 // x12 = The base of the MpCore Stacks (primary stack & secondary stacks)\r
90 mov x0, x12\r
91 mov x1, x10\r
92 //ArmPlatformStackSet(StackBase, MpId, PrimaryStackSize, SecondaryStackSize)\r
d2fa09a1
AB
93 MOV32 (x2, FixedPcdGet32(PcdCPUCorePrimaryStackSize))\r
94 MOV32 (x3, FixedPcdGet32(PcdCPUCoreSecondaryStackSize))\r
1bc83266
HL
95 bl ASM_PFX(ArmPlatformStackSet)\r
96\r
97 // Is it the Primary Core ?\r
98 mov x0, x10\r
99 bl ASM_PFX(ArmPlatformIsPrimaryCore)\r
100 cmp x0, #1\r
101 bne _PrepareArguments\r
102\r
1bc83266
HL
103_PrepareArguments:\r
104 mov x0, x10\r
105 mov x1, x11\r
106 mov x2, x12\r
1bc83266
HL
107\r
108 // Move sec startup address into a data register\r
109 // Ensure we're jumping to FV version of the code (not boot remapped alias)\r
d2fa09a1 110 ldr x4, =ASM_PFX(CEntryPoint)\r
1bc83266 111\r
0bcf71c1
AB
112 // Set the frame pointer to NULL so any backtraces terminate here\r
113 mov x29, xzr\r
114\r
1bc83266
HL
115 // Jump to PrePiCore C code\r
116 // x0 = MpId\r
117 // x1 = UefiMemoryBase\r
118 // x2 = StacksBase\r
1bc83266
HL
119 blr x4\r
120\r
121_NeverReturn:\r
122 b _NeverReturn\r