From 6952d1fa901a9053abe46c317ee820fc28a2835d Mon Sep 17 00:00:00 2001 From: Leif Lindholm Date: Tue, 8 Apr 2025 18:18:08 +0100 Subject: [PATCH] ArmPlatformPkg/Sec: clean up FP enabling code UEFI defines that FP support is required on AArch64, whereas many platforms enable it anyway on Arm. But when it's enabled, C code can generate instructions targeting FP registers, so: - move ArmEnableVFP call to asm - make it unconditional on AArch64 Signed-off-by: Leif Lindholm --- ArmPlatformPkg/PeilessSec/AArch64/ArchPeilessSec.c | 5 ----- ArmPlatformPkg/PeilessSec/AArch64/ModuleEntryPoint.S | 4 ++++ ArmPlatformPkg/PeilessSec/Arm/ArchPeilessSec.c | 4 ---- ArmPlatformPkg/PeilessSec/Arm/ModuleEntryPoint.S | 6 ++++++ ArmPlatformPkg/PeilessSec/PeilessSec.inf | 4 +++- ArmPlatformPkg/Sec/Arm/ModuleEntryPoint.S | 6 ++++++ ArmPlatformPkg/Sec/Sec.c | 5 ----- ArmPlatformPkg/Sec/Sec.inf | 4 +++- 8 files changed, 22 insertions(+), 16 deletions(-) diff --git a/ArmPlatformPkg/PeilessSec/AArch64/ArchPeilessSec.c b/ArmPlatformPkg/PeilessSec/AArch64/ArchPeilessSec.c index ccc9cde6d1..22148f0e20 100644 --- a/ArmPlatformPkg/PeilessSec/AArch64/ArchPeilessSec.c +++ b/ArmPlatformPkg/PeilessSec/AArch64/ArchPeilessSec.c @@ -18,11 +18,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/ArmPlatformPkg/PeilessSec/AArch64/ModuleEntryPoint.S b/ArmPlatformPkg/PeilessSec/AArch64/ModuleEntryPoint.S index c6b7093adb..5f285f3f13 100644 --- a/ArmPlatformPkg/PeilessSec/AArch64/ModuleEntryPoint.S +++ b/ArmPlatformPkg/PeilessSec/AArch64/ModuleEntryPoint.S @@ -11,6 +11,10 @@ ASM_FUNC(_ModuleEntryPoint) // Do early platform specific actions bl ASM_PFX(ArmPlatformPeiBootAction) + // Enable Floating Point. This needs to be done before entering C code, which + // may use FP/SIMD registers. + bl ArmEnableVFP + // Check if we can install the stack at the top of the System Memory or if we need // to install the stacks at the bottom of the Firmware Device (case the FD is located // at the top of the DRAM) diff --git a/ArmPlatformPkg/PeilessSec/Arm/ArchPeilessSec.c b/ArmPlatformPkg/PeilessSec/Arm/ArchPeilessSec.c index 3c3cef6925..e2f6f67904 100644 --- a/ArmPlatformPkg/PeilessSec/Arm/ArchPeilessSec.c +++ b/ArmPlatformPkg/PeilessSec/Arm/ArchPeilessSec.c @@ -18,8 +18,4 @@ ArchInitialize ( { // Enable program flow prediction, if supported. ArmEnableBranchPrediction (); - - if (FixedPcdGet32 (PcdVFPEnabled)) { - ArmEnableVFP (); - } } diff --git a/ArmPlatformPkg/PeilessSec/Arm/ModuleEntryPoint.S b/ArmPlatformPkg/PeilessSec/Arm/ModuleEntryPoint.S index 6b38b86e01..9043d8679a 100644 --- a/ArmPlatformPkg/PeilessSec/Arm/ModuleEntryPoint.S +++ b/ArmPlatformPkg/PeilessSec/Arm/ModuleEntryPoint.S @@ -13,6 +13,12 @@ ASM_FUNC(_ModuleEntryPoint) // Do early platform specific actions bl ASM_PFX(ArmPlatformPeiBootAction) +#if (FixedPcdGet32 (PcdVFPEnabled)) + // Enable Floating Point. This needs to be done before entering C code, which + // may use FP/SIMD registers. + bl ArmEnableVFP +#endif + // Check if we can install the stack at the top of the System Memory or if we need // to install the stacks at the bottom of the Firmware Device (case the FD is located // at the top of the DRAM) diff --git a/ArmPlatformPkg/PeilessSec/PeilessSec.inf b/ArmPlatformPkg/PeilessSec/PeilessSec.inf index 7f67adfa71..e210d016da 100644 --- a/ArmPlatformPkg/PeilessSec/PeilessSec.inf +++ b/ArmPlatformPkg/PeilessSec/PeilessSec.inf @@ -70,9 +70,11 @@ gArmTokenSpaceGuid.PcdFdSize gArmTokenSpaceGuid.PcdFvBaseAddress gArmTokenSpaceGuid.PcdFvSize - gArmTokenSpaceGuid.PcdVFPEnabled gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize +[FixedPcd.ARM] + gArmTokenSpaceGuid.PcdVFPEnabled + [Pcd] gArmTokenSpaceGuid.PcdSystemMemoryBase gArmTokenSpaceGuid.PcdSystemMemorySize diff --git a/ArmPlatformPkg/Sec/Arm/ModuleEntryPoint.S b/ArmPlatformPkg/Sec/Arm/ModuleEntryPoint.S index 1207497dc7..7cb3de7d35 100644 --- a/ArmPlatformPkg/Sec/Arm/ModuleEntryPoint.S +++ b/ArmPlatformPkg/Sec/Arm/ModuleEntryPoint.S @@ -11,6 +11,12 @@ ASM_FUNC(_ModuleEntryPoint) // Do early platform specific actions bl ASM_PFX(ArmPlatformPeiBootAction) +#if (FixedPcdGet32 (PcdVFPEnabled)) + // Enable Floating Point. This needs to be done before entering C code, which + // may use FP/SIMD registers. + bl ArmEnableVFP +#endif + // Get the top of the primary stacks (and the base of the secondary stacks) MOV32 (r1, FixedPcdGet64(PcdCPUCoresStackBase) + FixedPcdGet32(PcdCPUCorePrimaryStackSize)) diff --git a/ArmPlatformPkg/Sec/Sec.c b/ArmPlatformPkg/Sec/Sec.c index 9a700e5ef2..4535ae7e78 100644 --- a/ArmPlatformPkg/Sec/Sec.c +++ b/ArmPlatformPkg/Sec/Sec.c @@ -223,11 +223,6 @@ CEntryPoint ( ASSERT (((UINTN)PeiVectorTable & ARM_VECTOR_TABLE_ALIGNMENT) == 0); ArmWriteVBar ((UINTN)PeiVectorTable); - // Enable Floating Point - if (FixedPcdGet32 (PcdVFPEnabled)) { - ArmEnableVFP (); - } - // Invoke "ProcessLibraryConstructorList" to have all library constructors // called. ProcessLibraryConstructorList (); diff --git a/ArmPlatformPkg/Sec/Sec.inf b/ArmPlatformPkg/Sec/Sec.inf index b5af19e7a4..a75ce8d5ec 100644 --- a/ArmPlatformPkg/Sec/Sec.inf +++ b/ArmPlatformPkg/Sec/Sec.inf @@ -58,9 +58,11 @@ [FixedPcd] gArmTokenSpaceGuid.PcdFvBaseAddress gArmTokenSpaceGuid.PcdFvSize - gArmTokenSpaceGuid.PcdVFPEnabled gArmPlatformTokenSpaceGuid.PcdCPUCoresStackBase gArmPlatformTokenSpaceGuid.PcdCPUCorePrimaryStackSize gEfiMdeModulePkgTokenSpaceGuid.PcdInitValueInTempStack + +[FixedPcd.ARM] + gArmTokenSpaceGuid.PcdVFPEnabled