]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / ArmVirtPkg / PrePi / AArch64 / ModuleEntryPoint.S
... / ...
CommitLineData
1//\r
2// Copyright (c) 2011-2013, ARM Limited. All rights reserved.\r
3// Copyright (c) 2015-2016, Linaro Limited. All rights reserved.\r
4//\r
5// SPDX-License-Identifier: BSD-2-Clause-Patent\r
6//\r
7//\r
8\r
9#include <AsmMacroIoLibV8.h>\r
10\r
11ASM_FUNC(_ModuleEntryPoint)\r
12 bl ASM_PFX(DiscoverDramFromDt)\r
13\r
14 // Get ID of this CPU in Multicore system\r
15 bl ASM_PFX(ArmReadMpidr)\r
16 // Keep a copy of the MpId register value\r
17 mov x20, x0\r
18\r
19// Check if we can install the stack at the top of the System Memory or if we need\r
20// to install the stacks at the bottom of the Firmware Device (case the FD is located\r
21// at the top of the DRAM)\r
22_SetupStackPosition:\r
23 // Compute Top of System Memory\r
24 ldr x1, PcdGet64 (PcdSystemMemoryBase)\r
25 ldr x2, PcdGet64 (PcdSystemMemorySize)\r
26 sub x2, x2, #1\r
27 add x1, x1, x2 // x1 = SystemMemoryTop = PcdSystemMemoryBase + PcdSystemMemorySize\r
28\r
29 // Calculate Top of the Firmware Device\r
30 ldr x2, PcdGet64 (PcdFdBaseAddress)\r
31 MOV32 (w3, FixedPcdGet32 (PcdFdSize) - 1)\r
32 add x3, x3, x2 // x3 = FdTop = PcdFdBaseAddress + PcdFdSize\r
33\r
34 // UEFI Memory Size (stacks are allocated in this region)\r
35 MOV32 (x4, FixedPcdGet32(PcdSystemMemoryUefiRegionSize))\r
36\r
37 //\r
38 // Reserve the memory for the UEFI region (contain stacks on its top)\r
39 //\r
40\r
41 // Calculate how much space there is between the top of the Firmware and the Top of the System Memory\r
42 subs x0, x1, x3 // x0 = SystemMemoryTop - FdTop\r
43 b.mi _SetupStack // Jump if negative (FdTop > SystemMemoryTop). Case when the PrePi is in XIP memory outside of the DRAM\r
44 cmp x0, x4\r
45 b.ge _SetupStack\r
46\r
47 // Case the top of stacks is the FdBaseAddress\r
48 mov x1, x2\r
49\r
50_SetupStack:\r
51 // x1 contains the top of the stack (and the UEFI Memory)\r
52\r
53 // Because the 'push' instruction is equivalent to 'stmdb' (decrement before), we need to increment\r
54 // one to the top of the stack. We check if incrementing one does not overflow (case of DRAM at the\r
55 // top of the memory space)\r
56 adds x21, x1, #1\r
57 b.cs _SetupOverflowStack\r
58\r
59_SetupAlignedStack:\r
60 mov x1, x21\r
61 b _GetBaseUefiMemory\r
62\r
63_SetupOverflowStack:\r
64 // Case memory at the top of the address space. Ensure the top of the stack is EFI_PAGE_SIZE\r
65 // aligned (4KB)\r
66 and x1, x1, ~EFI_PAGE_MASK\r
67\r
68_GetBaseUefiMemory:\r
69 // Calculate the Base of the UEFI Memory\r
70 sub x21, x1, x4\r
71\r
72_GetStackBase:\r
73 // r1 = The top of the Mpcore Stacks\r
74 mov sp, x1\r
75\r
76 // Stack for the primary core = PrimaryCoreStack\r
77 MOV32 (x2, FixedPcdGet32(PcdCPUCorePrimaryStackSize))\r
78 sub x22, x1, x2\r
79\r
80 mov x0, x20\r
81 mov x1, x21\r
82 mov x2, x22\r
83\r
84 // Set the frame pointer to NULL so any backtraces terminate here\r
85 mov x29, xzr\r
86\r
87 // Jump to PrePiCore C code\r
88 // x0 = MpId\r
89 // x1 = UefiMemoryBase\r
90 // x2 = StacksBase\r
91 bl ASM_PFX(CEntryPoint)\r
92\r
93_NeverReturn:\r
94 b _NeverReturn\r
95\r
96// VOID\r
97// DiscoverDramFromDt (\r
98// VOID *DeviceTreeBaseAddress, // passed by loader in x0\r
99// VOID *ImageBase // passed by FDF trampoline in x1\r
100// );\r
101ASM_PFX(DiscoverDramFromDt):\r
102 //\r
103 // If we are booting from RAM using the Linux kernel boot protocol, x0 will\r
104 // point to the DTB image in memory. Otherwise, use the default value defined\r
105 // by the platform.\r
106 //\r
107 cbnz x0, 0f\r
108 ldr x0, PcdGet64 (PcdDeviceTreeInitialBaseAddress)\r
109\r
1100:mov x29, x30 // preserve LR\r
111 mov x28, x0 // preserve DTB pointer\r
112 mov x27, x1 // preserve base of image pointer\r
113\r
114 //\r
115 // The base of the runtime image has been preserved in x1. Check whether\r
116 // the expected magic number can be found in the header.\r
117 //\r
118 ldr w8, .LArm64LinuxMagic\r
119 ldr w9, [x1, #0x38]\r
120 cmp w8, w9\r
121 bne .Lout\r
122\r
123 //\r
124 //\r
125 // OK, so far so good. We have confirmed that we likely have a DTB and are\r
126 // booting via the arm64 Linux boot protocol. Update the base-of-image PCD\r
127 // to the actual relocated value, and add the shift of PcdFdBaseAddress to\r
128 // PcdFvBaseAddress as well\r
129 //\r
130 adr x8, PcdGet64 (PcdFdBaseAddress)\r
131 adr x9, PcdGet64 (PcdFvBaseAddress)\r
132 ldr x6, [x8]\r
133 ldr x7, [x9]\r
134 sub x7, x7, x6\r
135 add x7, x7, x1\r
136 str x1, [x8]\r
137 str x7, [x9]\r
138\r
139 //\r
140 // The runtime address may be different from the link time address so fix\r
141 // up the PE/COFF relocations. Since we are calling a C function, use the\r
142 // window at the beginning of the FD image as a temp stack.\r
143 //\r
144 mov x0, x7\r
145 adr x1, PeCoffLoaderImageReadFromMemory\r
146 mov sp, x7\r
147 bl RelocatePeCoffImage\r
148\r
149 //\r
150 // Discover the memory size and offset from the DTB, and record in the\r
151 // respective PCDs. This will also return false if a corrupt DTB is\r
152 // encountered.\r
153 //\r
154 mov x0, x28\r
155 adr x1, PcdGet64 (PcdSystemMemoryBase)\r
156 adr x2, PcdGet64 (PcdSystemMemorySize)\r
157 bl FindMemnode\r
158 cbz x0, .Lout\r
159\r
160 //\r
161 // Copy the DTB to the slack space right after the 64 byte arm64/Linux style\r
162 // image header at the base of this image (defined in the FDF), and record the\r
163 // pointer in PcdDeviceTreeInitialBaseAddress.\r
164 //\r
165 adr x8, PcdGet64 (PcdDeviceTreeInitialBaseAddress)\r
166 add x27, x27, #0x40\r
167 str x27, [x8]\r
168\r
169 mov x0, x27\r
170 mov x1, x28\r
171 bl CopyFdt\r
172\r
173.Lout:\r
174 ret x29\r
175\r
176.LArm64LinuxMagic:\r
177 .byte 0x41, 0x52, 0x4d, 0x64\r