summaryrefslogtreecommitdiffstats
path: root/ArmVirtPkg/PrePi
diff options
context:
space:
mode:
authorArd Biesheuvel <ardb@kernel.org>2024-06-07 10:02:25 +0200
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2024-06-10 08:44:48 +0000
commit5bea69123349ef3c02e5d8a49ceaae971975ba90 (patch)
treebb6c5a070f568ccd6df91b7cf12f47d37697a90c /ArmVirtPkg/PrePi
parentab069d580111ccc64d6b0c9697b7c5fd6e1507ce (diff)
downloadedk2-5bea69123349ef3c02e5d8a49ceaae971975ba90.tar.gz
edk2-5bea69123349ef3c02e5d8a49ceaae971975ba90.tar.bz2
edk2-5bea69123349ef3c02e5d8a49ceaae971975ba90.zip
ArmVirtPkg/PrePi: Enable VFP before calling into C code
When building ArmVirtQemuKernel with CLANGDWARF (which does not require a GCC workaround where -mgeneral-regs-only is needed to ensure -mstrict-align works as expected), the C code invoked from the PrePi startup code may contain instructions that access the FP/SIMD register file. This means that the FP/SIMD must be enabled before making such calls, and this is currently not the case. So fix that, by moving the call to ArmEnableVFP() early into the asm startup code. Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Diffstat (limited to 'ArmVirtPkg/PrePi')
-rw-r--r--ArmVirtPkg/PrePi/AArch64/ArchPrePi.c5
-rw-r--r--ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S41
2 files changed, 24 insertions, 22 deletions
diff --git a/ArmVirtPkg/PrePi/AArch64/ArchPrePi.c b/ArmVirtPkg/PrePi/AArch64/ArchPrePi.c
index 9cab88ca08..a02c2ad560 100644
--- a/ArmVirtPkg/PrePi/AArch64/ArchPrePi.c
+++ b/ArmVirtPkg/PrePi/AArch64/ArchPrePi.c
@@ -15,11 +15,6 @@ ArchInitialize (
VOID
)
{
- // Enable Floating Point
- if (FixedPcdGet32 (PcdVFPEnabled)) {
- ArmEnableVFP ();
- }
-
if (ArmReadCurrentEL () == AARCH64_EL2) {
// Trap General Exceptions. All exceptions that would be routed to EL1 are routed to EL2
ArmWriteHcr (ARM_HCR_TGE);
diff --git a/ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S b/ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S
index 01623b6b35..fc06c28daa 100644
--- a/ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S
+++ b/ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S
@@ -9,6 +9,23 @@
#include <AsmMacroIoLibV8.h>
ASM_FUNC(_ModuleEntryPoint)
+ //
+ // If we are booting from RAM using the Linux kernel boot protocol, x0 will
+ // point to the DTB image in memory. Otherwise, use the default value defined
+ // by the platform.
+ //
+ cbnz x0, 0f
+ ldr x0, PcdGet64 (PcdDeviceTreeInitialBaseAddress)
+
+0:mov x28, x0 // preserve DTB pointer
+ mov x27, x1 // preserve base of image pointer
+
+#if (FixedPcdGet32 (PcdVFPEnabled))
+ // Enable Floating Point. This needs to be done before entering C code, which
+ // may use FP/SIMD registers.
+ bl ArmEnableVFP
+#endif
+
bl ASM_PFX(DiscoverDramFromDt)
// Get ID of this CPU in Multicore system
@@ -95,28 +112,18 @@ _NeverReturn:
// VOID
// DiscoverDramFromDt (
-// VOID *DeviceTreeBaseAddress, // passed by loader in x0
-// VOID *ImageBase // passed by FDF trampoline in x1
+// VOID *DeviceTreeBaseAddress, // passed by loader in x0, preserved in x28
+// VOID *ImageBase // passed by FDF trampoline in x1, preserved in x27
// );
ASM_PFX(DiscoverDramFromDt):
- //
- // If we are booting from RAM using the Linux kernel boot protocol, x0 will
- // point to the DTB image in memory. Otherwise, use the default value defined
- // by the platform.
- //
- cbnz x0, 0f
- ldr x0, PcdGet64 (PcdDeviceTreeInitialBaseAddress)
-
-0:mov x29, x30 // preserve LR
- mov x28, x0 // preserve DTB pointer
- mov x27, x1 // preserve base of image pointer
+ mov x29, x30 // preserve LR
//
- // The base of the runtime image has been preserved in x1. Check whether
+ // The base of the runtime image has been preserved in x27. Check whether
// the expected magic number can be found in the header.
//
ldr w8, .LArm64LinuxMagic
- ldr w9, [x1, #0x38]
+ ldr w9, [x27, #0x38]
cmp w8, w9
bne .Lout
@@ -132,8 +139,8 @@ ASM_PFX(DiscoverDramFromDt):
ldr x6, [x8]
ldr x7, [x9]
sub x7, x7, x6
- add x7, x7, x1
- str x1, [x8]
+ add x7, x7, x27
+ str x27, [x8]
str x7, [x9]
//