ArmPkg,ArmPkg/ArmExceptionLib: drop vector relocation variant/support

There were several bugs in the vector table relocation code which means
it can't really have been used by anyone on AArch64 in the last decade or
so. So delete the support code from the library, as well as the
ArmRelocateExceptionLib.inf file.

This gets rid of PcdDebuggerExceptionSupport (including a duff reference
in CpuDxe), PcdCpuVectorBaseAddress and PcdRelocateVectorTable.

Signed-off-by: Leif Lindholm <leif.lindholm@oss.qualcomm.com>
This commit is contained in:
Leif Lindholm 2025-01-30 12:02:08 +00:00 committed by mergify[bot]
parent 43233ff9f8
commit 74376f0b72
9 changed files with 21 additions and 252 deletions

View File

@ -134,15 +134,6 @@
[PcdsFeatureFlag.common]
gArmTokenSpaceGuid.PcdCpuDxeProduceDebugSupport|FALSE|BOOLEAN|0x00000001
# On ARM Architecture with the Security Extension, the address for the
# Vector Table can be mapped anywhere in the memory map. It means we can
# point the Exception Vector Table to its location in CpuDxe.
# By default we copy the Vector Table at PcdGet64(PcdCpuVectorBaseAddress)
gArmTokenSpaceGuid.PcdRelocateVectorTable|TRUE|BOOLEAN|0x00000022
# Set this PCD to TRUE if the Exception Vector is changed to add debugger support before
# it has been configured by the CPU DXE
gArmTokenSpaceGuid.PcdDebuggerExceptionSupport|FALSE|BOOLEAN|0x00000032
# Whether to remap all unused memory NX before installing the CPU arch
# protocol driver. This is needed on platforms that map all DRAM with RWX
# attributes initially, and can be disabled otherwise.
@ -161,7 +152,6 @@
# Using a FeaturePcd make a '(BOOLEAN) casting for its value which is not understood by the preprocessor.
gArmTokenSpaceGuid.PcdVFPEnabled|0|UINT32|0x00000024
gArmTokenSpaceGuid.PcdCpuVectorBaseAddress|0xffff0000|UINT64|0x00000004
gArmTokenSpaceGuid.PcdCpuResetAddress|0x00000000|UINT32|0x00000005
#

View File

@ -120,7 +120,6 @@
ArmPkg/Library/SemiHostingSerialPortLib/SemiHostingSerialPortLib.inf
ArmPkg/Library/SemihostLib/SemihostLib.inf
ArmPkg/Library/ArmExceptionLib/ArmExceptionLib.inf
ArmPkg/Library/ArmExceptionLib/ArmRelocateExceptionLib.inf
ArmPkg/Drivers/CpuDxe/CpuDxe.inf
ArmPkg/Drivers/CpuPei/CpuPei.inf

View File

@ -69,7 +69,6 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdDxeNxMemoryProtectionPolicy
[FeaturePcd.common]
gArmTokenSpaceGuid.PcdDebuggerExceptionSupport
gArmTokenSpaceGuid.PcdRemapUnusedMemoryNx
[Depex]

View File

@ -14,11 +14,9 @@
#include <Library/MemoryAllocationLib.h>
#include <Protocol/DebugSupport.h> // for MAX_AARCH64_EXCEPTION
UINTN gMaxExceptionNumber = MAX_AARCH64_EXCEPTION;
EFI_EXCEPTION_CALLBACK gExceptionHandlers[MAX_AARCH64_EXCEPTION + 1] = { 0 };
EFI_EXCEPTION_CALLBACK gDebuggerExceptionHandlers[MAX_AARCH64_EXCEPTION + 1] = { 0 };
PHYSICAL_ADDRESS gExceptionVectorAlignmentMask = ARM_VECTOR_TABLE_ALIGNMENT;
UINTN gDebuggerNoHandlerValue = 0; // todo: define for AArch64
UINTN gMaxExceptionNumber = MAX_AARCH64_EXCEPTION;
EFI_EXCEPTION_CALLBACK gExceptionHandlers[MAX_AARCH64_EXCEPTION + 1] = { 0 };
PHYSICAL_ADDRESS gExceptionVectorAlignmentMask = ARM_VECTOR_TABLE_ALIGNMENT;
#define EL0_STACK_SIZE EFI_PAGES_TO_SIZE(2)
STATIC UINTN mNewStackBase[EL0_STACK_SIZE / sizeof (UINTN)];

View File

@ -109,12 +109,7 @@ GCC_ASM_EXPORT(CommonCExceptionHandler)
// exception vector initialization method is used.
//
#if defined(ARM_RELOCATE_VECTORS)
GCC_ASM_EXPORT(ExceptionHandlersStart)
ASM_PFX(ExceptionHandlersStart):
#else
VECTOR_BASE(ExceptionHandlersStart)
#endif
.macro ExceptionEntry, val, sp=SPx
//
@ -168,13 +163,7 @@ VECTOR_BASE(ExceptionHandlersStart)
mov x0, #\val
// Jump to our general handler to deal with all the common parts and process the exception.
#if defined(ARM_RELOCATE_VECTORS)
ldr x1, =ASM_PFX(CommonExceptionEntry)
br x1
.ltorg
#else
b ASM_PFX(CommonExceptionEntry)
#endif
.endm
//

View File

@ -17,14 +17,9 @@
#include <Protocol/DebugSupport.h> // for MAX_ARM_EXCEPTION
UINTN gMaxExceptionNumber = MAX_ARM_EXCEPTION;
EFI_EXCEPTION_CALLBACK gExceptionHandlers[MAX_ARM_EXCEPTION + 1] = { 0 };
EFI_EXCEPTION_CALLBACK gDebuggerExceptionHandlers[MAX_ARM_EXCEPTION + 1] = { 0 };
PHYSICAL_ADDRESS gExceptionVectorAlignmentMask = ARM_VECTOR_TABLE_ALIGNMENT;
// Exception handler contains branch to vector location (jmp $) so no handler
// NOTE: This code assumes vectors are ARM and not Thumb code
UINTN gDebuggerNoHandlerValue = 0xEAFFFFFE;
UINTN gMaxExceptionNumber = MAX_ARM_EXCEPTION;
EFI_EXCEPTION_CALLBACK gExceptionHandlers[MAX_ARM_EXCEPTION + 1] = { 0 };
PHYSICAL_ADDRESS gExceptionVectorAlignmentMask = ARM_VECTOR_TABLE_ALIGNMENT;
RETURN_STATUS
ArchVectorConfig (

View File

@ -21,19 +21,6 @@
#include <Library/DebugLib.h>
#include <Library/DefaultExceptionHandlerLib.h>
STATIC
RETURN_STATUS
CopyExceptionHandlers (
IN PHYSICAL_ADDRESS BaseAddress
);
EFI_STATUS
EFIAPI
RegisterExceptionHandler (
IN EFI_EXCEPTION_TYPE ExceptionType,
IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
);
VOID
ExceptionHandlersStart (
VOID
@ -52,21 +39,7 @@ ArchVectorConfig (
// these globals are provided by the architecture specific source (Arm or AArch64)
extern UINTN gMaxExceptionNumber;
extern EFI_EXCEPTION_CALLBACK gExceptionHandlers[];
extern EFI_EXCEPTION_CALLBACK gDebuggerExceptionHandlers[];
extern PHYSICAL_ADDRESS gExceptionVectorAlignmentMask;
extern UINTN gDebuggerNoHandlerValue;
// A compiler flag adjusts the compilation of this library to a variant where
// the vectors are relocated (copied) to another location versus using the
// vectors in-place. Since this effects an assembly .align directive we must
// address this at library build time. Since this affects the build of the
// library we cannot represent this in a PCD since PCDs are evaluated on
// a per-module basis.
#if defined (ARM_RELOCATE_VECTORS)
STATIC CONST BOOLEAN gArmRelocateVectorTable = TRUE;
#else
STATIC CONST BOOLEAN gArmRelocateVectorTable = FALSE;
#endif
/**
Initializes all CPU exceptions entries and provides the default exception handlers.
@ -90,107 +63,26 @@ InitializeCpuExceptionHandlers (
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
)
{
RETURN_STATUS Status;
UINT64 VectorBase;
UINT64 VectorBase;
Status = EFI_SUCCESS;
// use VBAR to point to where our exception handlers are
// if we are requested to copy exception handlers to another location
if (gArmRelocateVectorTable) {
VectorBase = PcdGet64 (PcdCpuVectorBaseAddress);
Status = CopyExceptionHandlers (VectorBase);
} else {
// use VBAR to point to where our exception handlers are
// The vector table must be aligned for the architecture. If this
// assertion fails ensure the appropriate FFS alignment is in effect,
// which can be accomplished by ensuring the proper Align=X statement
// in the platform packaging rules. For ARM Align=32 is required and
// for AArch64 Align=4K is required. Align=Auto can be used but this
// is known to cause an issue with populating the reset vector area
// for encapsulated FVs.
ASSERT (((UINTN)ExceptionHandlersStart & gExceptionVectorAlignmentMask) == 0);
// The vector table must be aligned for the architecture. If this
// assertion fails ensure the appropriate FFS alignment is in effect,
// which can be accomplished by ensuring the proper Align=X statement
// in the platform packaging rules. For ARM Align=32 is required and
// for AArch64 Align=4K is required. Align=Auto can be used but this
// is known to cause an issue with populating the reset vector area
// for encapsulated FVs.
ASSERT (((UINTN)ExceptionHandlersStart & gExceptionVectorAlignmentMask) == 0);
VectorBase = (UINT64)(UINTN)ExceptionHandlersStart;
// We do not copy the Exception Table at PcdGet64(PcdCpuVectorBaseAddress). We just set Vector
// Base Address to point into CpuDxe code.
VectorBase = (UINT64)(UINTN)ExceptionHandlersStart;
// call the architecture-specific routine to prepare for the new vector
// configuration to take effect
ArchVectorConfig ((UINTN)VectorBase);
Status = RETURN_SUCCESS;
}
if (!RETURN_ERROR (Status)) {
// call the architecture-specific routine to prepare for the new vector
// configuration to take effect
ArchVectorConfig ((UINTN)VectorBase);
ArmWriteVBar ((UINTN)VectorBase);
}
return RETURN_SUCCESS;
}
/**
Copies exception handlers to the specified address.
Caller should try to get an array of interrupt and/or exception vectors that are in use and need to
persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.
If caller cannot get reserved vector list or it does not exists, set VectorInfo to NULL.
If VectorInfo is not NULL, the exception vectors will be initialized per vector attribute accordingly.
@param[in] VectorInfo Pointer to reserved vector list.
@retval EFI_SUCCESS CPU Exception Entries have been successfully initialized
with default exception handlers.
@retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.
@retval EFI_UNSUPPORTED This function is not supported.
**/
STATIC
RETURN_STATUS
CopyExceptionHandlers (
IN PHYSICAL_ADDRESS BaseAddress
)
{
RETURN_STATUS Status;
UINTN Length;
UINTN Index;
UINT32 *VectorBase;
// ensure that the destination value specifies an address meeting the vector alignment requirements
ASSERT ((BaseAddress & gExceptionVectorAlignmentMask) == 0);
//
// Copy an implementation of the exception vectors to PcdCpuVectorBaseAddress.
//
Length = (UINTN)ExceptionHandlersEnd - (UINTN)ExceptionHandlersStart;
VectorBase = (UINT32 *)(UINTN)BaseAddress;
if (FeaturePcdGet (PcdDebuggerExceptionSupport) == TRUE) {
// Save existing vector table, in case debugger is already hooked in
CopyMem ((VOID *)gDebuggerExceptionHandlers, (VOID *)VectorBase, sizeof (EFI_EXCEPTION_CALLBACK)* (gMaxExceptionNumber+1));
}
// Copy our assembly code into the page that contains the exception vectors.
CopyMem ((VOID *)VectorBase, (VOID *)(UINTN)ExceptionHandlersStart, Length);
//
// Initialize the C entry points for interrupts
//
for (Index = 0; Index <= gMaxExceptionNumber; Index++) {
if (!FeaturePcdGet (PcdDebuggerExceptionSupport) ||
(gDebuggerExceptionHandlers[Index] == 0) || (gDebuggerExceptionHandlers[Index] == (VOID *)gDebuggerNoHandlerValue))
{
Status = RegisterExceptionHandler (Index, NULL);
ASSERT_EFI_ERROR (Status);
} else {
// If the debugger has already hooked put its vector back
VectorBase[Index] = (UINT32)(UINTN)gDebuggerExceptionHandlers[Index];
}
}
// Flush Caches since we updated executable stuff
InvalidateInstructionCacheRange ((VOID *)(UINTN)BaseAddress, Length);
ArmWriteVBar ((UINTN)VectorBase);
return RETURN_SUCCESS;
}
@ -239,33 +131,6 @@ RegisterCpuInterruptHandler (
return RETURN_SUCCESS;
}
/**
Register exception handler.
@param This A pointer to the SMM_CPU_SERVICE_PROTOCOL instance.
@param ExceptionType Defines which interrupt or exception to hook. Type EFI_EXCEPTION_TYPE and
the valid values for this parameter are defined in EFI_DEBUG_SUPPORT_PROTOCOL
of the UEFI 2.0 specification.
@param InterruptHandler A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER
that is called when a processor interrupt occurs.
If this parameter is NULL, then the handler will be uninstalled.
@retval EFI_SUCCESS The handler for the processor interrupt was successfully installed or uninstalled.
@retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler for InterruptType was previously installed.
@retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for InterruptType was not previously installed.
@retval EFI_UNSUPPORTED The interrupt specified by InterruptType is not supported.
**/
EFI_STATUS
EFIAPI
RegisterExceptionHandler (
IN EFI_EXCEPTION_TYPE ExceptionType,
IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
)
{
return RegisterCpuInterruptHandler (ExceptionType, InterruptHandler);
}
VOID
EFIAPI
CommonCExceptionHandler (

View File

@ -7,12 +7,6 @@
# alignment must be propagated into the parent FFS/FV through FDF build rules
# for the relevant module types (i.e. Align=Auto).
#
# Note that using this library instance can cause growth to the size of the FV
# due to the padding added by the build tools to meet the vector alignment
# requirements and may not be desirable for space-sensitive FVs (uncompressed /
# XIP components). The alternative library instance, ArmRelocateExceptionLib
# should be considered for these applications.
#
# Copyright (c) 2011-2012, ARM Limited. All rights reserved.
# Copyright (c) 2016 HP Development Company, L.P.
#
@ -53,5 +47,3 @@
MemoryAllocationLib
[Pcd]
gArmTokenSpaceGuid.PcdDebuggerExceptionSupport
gArmTokenSpaceGuid.PcdCpuVectorBaseAddress

View File

@ -1,58 +0,0 @@
## @file
# Instance of CpuExceptionHandlerLib Library for ARM/AArch64 architectures
#
# This library instance is used when exception vectors must be relocated to
# a specific address. The address is specified by PcdCpuVectorBaseAddress.
# Since the alignment requirement for in-place exception handlers causes
# image size to increase, this instance is useful for modules that need to
# minimize space used in their FV (like XIP modules). See ArmExceptionLib.inf
# for the in-place exception handler alternative.
#
# Copyright (c) 2011-2012, ARM Limited. All rights reserved.
# Copyright (c) 2016 HP Development Company, L.P.
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
#
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = ArmRelocateExceptionLib
FILE_GUID = 62AA447A-1FBA-429E-9E0D-CE0D2D8DCF58
MODULE_TYPE = BASE
VERSION_STRING = 1.0
LIBRARY_CLASS = CpuExceptionHandlerLib
[Sources.common]
ArmExceptionLib.c
[Sources.Arm]
Arm/ArmException.c
Arm/ExceptionSupport.S | GCC
[Sources.AARCH64]
AArch64/AArch64Exception.c
AArch64/ExceptionSupport.S
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
ArmPkg/ArmPkg.dec
[LibraryClasses]
ArmLib
DebugLib
DefaultExceptionHandlerLib
BaseMemoryLib
CacheMaintenanceLib
[Pcd]
gArmTokenSpaceGuid.PcdDebuggerExceptionSupport
gArmTokenSpaceGuid.PcdCpuVectorBaseAddress
[BuildOptions]
# We must pass a define to specify that we are relocating vectors so the
# vector alignment is relaxed (space savings); note that this must be done
# as a define and not a PCD since it affects assembly directives.
*_*_*_PP_FLAGS = -DARM_RELOCATE_VECTORS
*_*_*_CC_FLAGS = -DARM_RELOCATE_VECTORS