VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S@ 108794

Last change on this file since 108794 was 108794, checked in by vboxsync, 2 weeks ago

Devices/EFI/FirmwareNew: Merge edk2-stable202502 from the vendor branch and make it build for the important platforms, bugref:4643

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette