* Main file supporting the SEC Phase for Versatile Express\r
*\r
* Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
-* Copyright (c) 2011-2014, ARM Limited. All rights reserved.\r
+* Copyright (c) 2011-2021, Arm Limited. All rights reserved.<BR>\r
* Copyright (c) 2016 HP Development Company, L.P.\r
+* Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>\r
*\r
* SPDX-License-Identifier: BSD-2-Clause-Patent\r
*\r
\r
STATIC\r
RETURN_STATUS\r
-CopyExceptionHandlers(\r
- IN PHYSICAL_ADDRESS BaseAddress\r
+CopyExceptionHandlers (\r
+ IN PHYSICAL_ADDRESS BaseAddress\r
);\r
\r
EFI_STATUS\r
EFIAPI\r
-RegisterExceptionHandler(\r
- IN EFI_EXCEPTION_TYPE ExceptionType,\r
- IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler\r
+RegisterExceptionHandler (\r
+ IN EFI_EXCEPTION_TYPE ExceptionType,\r
+ IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler\r
);\r
\r
VOID\r
-ExceptionHandlersStart(\r
+ExceptionHandlersStart (\r
VOID\r
);\r
\r
VOID\r
-ExceptionHandlersEnd(\r
+ExceptionHandlersEnd (\r
VOID\r
);\r
\r
-RETURN_STATUS ArchVectorConfig(\r
- IN UINTN VectorBaseAddress\r
+RETURN_STATUS\r
+ArchVectorConfig (\r
+ IN UINTN VectorBaseAddress\r
);\r
\r
// these globals are provided by the architecture specific source (Arm or AArch64)\r
-extern UINTN gMaxExceptionNumber;\r
-extern EFI_EXCEPTION_CALLBACK gExceptionHandlers[];\r
-extern EFI_EXCEPTION_CALLBACK gDebuggerExceptionHandlers[];\r
-extern PHYSICAL_ADDRESS gExceptionVectorAlignmentMask;\r
-extern UINTN gDebuggerNoHandlerValue;\r
+extern UINTN gMaxExceptionNumber;\r
+extern EFI_EXCEPTION_CALLBACK gExceptionHandlers[];\r
+extern EFI_EXCEPTION_CALLBACK gDebuggerExceptionHandlers[];\r
+extern PHYSICAL_ADDRESS gExceptionVectorAlignmentMask;\r
+extern UINTN gDebuggerNoHandlerValue;\r
\r
// A compiler flag adjusts the compilation of this library to a variant where\r
// the vectors are relocated (copied) to another location versus using the\r
// address this at library build time. Since this affects the build of the\r
// library we cannot represent this in a PCD since PCDs are evaluated on\r
// a per-module basis.\r
-#if defined(ARM_RELOCATE_VECTORS)\r
-STATIC CONST BOOLEAN gArmRelocateVectorTable = TRUE;\r
+#if defined (ARM_RELOCATE_VECTORS)\r
+STATIC CONST BOOLEAN gArmRelocateVectorTable = TRUE;\r
#else\r
-STATIC CONST BOOLEAN gArmRelocateVectorTable = FALSE;\r
+STATIC CONST BOOLEAN gArmRelocateVectorTable = FALSE;\r
#endif\r
\r
-\r
/**\r
Initializes all CPU exceptions entries and provides the default exception handlers.\r
\r
**/\r
EFI_STATUS\r
EFIAPI\r
-InitializeCpuExceptionHandlers(\r
- IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL\r
+InitializeCpuExceptionHandlers (\r
+ IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL\r
)\r
{\r
- RETURN_STATUS Status;\r
- UINTN VectorBase;\r
+ RETURN_STATUS Status;\r
+ UINTN VectorBase;\r
\r
Status = EFI_SUCCESS;\r
\r
- // if we are requested to copy exceptin handlers to another location\r
+ // if we are requested to copy exception handlers to another location\r
if (gArmRelocateVectorTable) {\r
-\r
- VectorBase = PcdGet64(PcdCpuVectorBaseAddress);\r
- Status = CopyExceptionHandlers(VectorBase);\r
-\r
- }\r
- else { // use VBAR to point to where our exception handlers are\r
+ VectorBase = PcdGet64 (PcdCpuVectorBaseAddress);\r
+ Status = CopyExceptionHandlers (VectorBase);\r
+ } else {\r
+ // use VBAR to point to where our exception handlers are\r
\r
// The vector table must be aligned for the architecture. If this\r
// assertion fails ensure the appropriate FFS alignment is in effect,\r
// for AArch64 Align=4K is required. Align=Auto can be used but this\r
// is known to cause an issue with populating the reset vector area\r
// for encapsulated FVs.\r
- ASSERT(((UINTN)ExceptionHandlersStart & gExceptionVectorAlignmentMask) == 0);\r
+ ASSERT (((UINTN)ExceptionHandlersStart & gExceptionVectorAlignmentMask) == 0);\r
\r
// We do not copy the Exception Table at PcdGet64(PcdCpuVectorBaseAddress). We just set Vector\r
// Base Address to point into CpuDxe code.\r
Status = RETURN_SUCCESS;\r
}\r
\r
- if (!RETURN_ERROR(Status)) {\r
+ if (!RETURN_ERROR (Status)) {\r
// call the architecture-specific routine to prepare for the new vector\r
// configuration to take effect\r
- ArchVectorConfig(VectorBase);\r
+ ArchVectorConfig (VectorBase);\r
\r
- ArmWriteVBar(VectorBase);\r
+ ArmWriteVBar (VectorBase);\r
}\r
\r
return RETURN_SUCCESS;\r
}\r
\r
/**\r
-Copies exception handlers to the speciifed address.\r
+Copies exception handlers to the specified address.\r
\r
Caller should try to get an array of interrupt and/or exception vectors that are in use and need to\r
persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.\r
**/\r
STATIC\r
RETURN_STATUS\r
-CopyExceptionHandlers(\r
- IN PHYSICAL_ADDRESS BaseAddress\r
+CopyExceptionHandlers (\r
+ IN PHYSICAL_ADDRESS BaseAddress\r
)\r
{\r
- RETURN_STATUS Status;\r
- UINTN Length;\r
- UINTN Index;\r
- UINT32 *VectorBase;\r
+ RETURN_STATUS Status;\r
+ UINTN Length;\r
+ UINTN Index;\r
+ UINT32 *VectorBase;\r
\r
// ensure that the destination value specifies an address meeting the vector alignment requirements\r
ASSERT ((BaseAddress & gExceptionVectorAlignmentMask) == 0);\r
\r
VectorBase = (UINT32 *)(UINTN)BaseAddress;\r
\r
- if (FeaturePcdGet(PcdDebuggerExceptionSupport) == TRUE) {\r
+ if (FeaturePcdGet (PcdDebuggerExceptionSupport) == TRUE) {\r
// Save existing vector table, in case debugger is already hooked in\r
- CopyMem((VOID *)gDebuggerExceptionHandlers, (VOID *)VectorBase, sizeof (EFI_EXCEPTION_CALLBACK)* (gMaxExceptionNumber+1));\r
+ CopyMem ((VOID *)gDebuggerExceptionHandlers, (VOID *)VectorBase, sizeof (EFI_EXCEPTION_CALLBACK)* (gMaxExceptionNumber+1));\r
}\r
\r
// Copy our assembly code into the page that contains the exception vectors.\r
- CopyMem((VOID *)VectorBase, (VOID *)ExceptionHandlersStart, Length);\r
+ CopyMem ((VOID *)VectorBase, (VOID *)ExceptionHandlersStart, Length);\r
\r
//\r
// Initialize the C entry points for interrupts\r
//\r
for (Index = 0; Index <= gMaxExceptionNumber; Index++) {\r
- if (!FeaturePcdGet(PcdDebuggerExceptionSupport) ||\r
- (gDebuggerExceptionHandlers[Index] == 0) || (gDebuggerExceptionHandlers[Index] == (VOID *)gDebuggerNoHandlerValue)) {\r
-\r
- Status = RegisterExceptionHandler(Index, NULL);\r
- ASSERT_EFI_ERROR(Status);\r
- }\r
- else {\r
+ if (!FeaturePcdGet (PcdDebuggerExceptionSupport) ||\r
+ (gDebuggerExceptionHandlers[Index] == 0) || (gDebuggerExceptionHandlers[Index] == (VOID *)gDebuggerNoHandlerValue))\r
+ {\r
+ Status = RegisterExceptionHandler (Index, NULL);\r
+ ASSERT_EFI_ERROR (Status);\r
+ } else {\r
// If the debugger has already hooked put its vector back\r
VectorBase[Index] = (UINT32)(UINTN)gDebuggerExceptionHandlers[Index];\r
}\r
}\r
\r
// Flush Caches since we updated executable stuff\r
- InvalidateInstructionCacheRange((VOID *)(UINTN)BaseAddress, Length);\r
+ InvalidateInstructionCacheRange ((VOID *)(UINTN)BaseAddress, Length);\r
\r
return RETURN_SUCCESS;\r
}\r
\r
-\r
-/**\r
-Initializes all CPU interrupt/exceptions entries and provides the default interrupt/exception handlers.\r
-\r
-Caller should try to get an array of interrupt and/or exception vectors that are in use and need to\r
-persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.\r
-If caller cannot get reserved vector list or it does not exists, set VectorInfo to NULL.\r
-If VectorInfo is not NULL, the exception vectors will be initialized per vector attribute accordingly.\r
-\r
-@param[in] VectorInfo Pointer to reserved vector list.\r
-\r
-@retval EFI_SUCCESS All CPU interrupt/exception entries have been successfully initialized\r
-with default interrupt/exception handlers.\r
-@retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.\r
-@retval EFI_UNSUPPORTED This function is not supported.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-InitializeCpuInterruptHandlers(\r
-IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL\r
-)\r
-{\r
- // not needed, this is what the CPU driver is for\r
- return EFI_UNSUPPORTED;\r
-}\r
-\r
/**\r
Registers a function to be called from the processor exception handler. (On ARM/AArch64 this only\r
provides exception handlers, not interrupt handling which is provided through the Hardware Interrupt\r
interrupt or exception type specified by ExceptionType. If ExceptionHandler is NULL, then the\r
handler for the processor interrupt or exception type specified by ExceptionType is uninstalled.\r
The installed handler is called once for each processor interrupt or exception.\r
-NOTE: This function should be invoked after InitializeCpuExceptionHandlers() or\r
-InitializeCpuInterruptHandlers() invoked, otherwise EFI_UNSUPPORTED returned.\r
+NOTE: This function should be invoked after InitializeCpuExceptionHandlers() is invoked,\r
+otherwise EFI_UNSUPPORTED returned.\r
\r
@param[in] ExceptionType Defines which interrupt or exception to hook.\r
@param[in] ExceptionHandler A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called\r
or this function is not supported.\r
**/\r
RETURN_STATUS\r
-RegisterCpuInterruptHandler(\r
- IN EFI_EXCEPTION_TYPE ExceptionType,\r
- IN EFI_CPU_INTERRUPT_HANDLER ExceptionHandler\r
- ) {\r
+RegisterCpuInterruptHandler (\r
+ IN EFI_EXCEPTION_TYPE ExceptionType,\r
+ IN EFI_CPU_INTERRUPT_HANDLER ExceptionHandler\r
+ )\r
+{\r
if (ExceptionType > gMaxExceptionNumber) {\r
return RETURN_UNSUPPORTED;\r
}\r
**/\r
EFI_STATUS\r
EFIAPI\r
-RegisterExceptionHandler(\r
- IN EFI_EXCEPTION_TYPE ExceptionType,\r
- IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler\r
+RegisterExceptionHandler (\r
+ IN EFI_EXCEPTION_TYPE ExceptionType,\r
+ IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler\r
)\r
{\r
- return RegisterCpuInterruptHandler(ExceptionType, InterruptHandler);\r
+ return RegisterCpuInterruptHandler (ExceptionType, InterruptHandler);\r
}\r
\r
VOID\r
EFIAPI\r
-CommonCExceptionHandler(\r
- IN EFI_EXCEPTION_TYPE ExceptionType,\r
- IN OUT EFI_SYSTEM_CONTEXT SystemContext\r
+CommonCExceptionHandler (\r
+ IN EFI_EXCEPTION_TYPE ExceptionType,\r
+ IN OUT EFI_SYSTEM_CONTEXT SystemContext\r
)\r
{\r
if (ExceptionType <= gMaxExceptionNumber) {\r
gExceptionHandlers[ExceptionType](ExceptionType, SystemContext);\r
return;\r
}\r
- }\r
- else {\r
- DEBUG((EFI_D_ERROR, "Unknown exception type %d\n", ExceptionType));\r
- ASSERT(FALSE);\r
+ } else {\r
+ DEBUG ((DEBUG_ERROR, "Unknown exception type %d\n", ExceptionType));\r
+ ASSERT (FALSE);\r
}\r
\r
- DefaultExceptionHandler(ExceptionType, SystemContext);\r
+ DefaultExceptionHandler (ExceptionType, SystemContext);\r
}\r
\r
/**\r
- Initializes all CPU exceptions entries with optional extra initializations.\r
-\r
- By default, this method should include all functionalities implemented by\r
- InitializeCpuExceptionHandlers(), plus extra initialization works, if any.\r
- This could be done by calling InitializeCpuExceptionHandlers() directly\r
- in this method besides the extra works.\r
-\r
- InitData is optional and its use and content are processor arch dependent.\r
- The typical usage of it is to convey resources which have to be reserved\r
- elsewhere and are necessary for the extra initializations of exception.\r
-\r
- @param[in] VectorInfo Pointer to reserved vector list.\r
- @param[in] InitData Pointer to data optional for extra initializations\r
- of exception.\r
-\r
- @retval EFI_SUCCESS The exceptions have been successfully\r
- initialized.\r
- @retval EFI_INVALID_PARAMETER VectorInfo or InitData contains invalid\r
- content.\r
-\r
+ Setup separate stacks for certain exception handlers.\r
+ If the input Buffer and BufferSize are both NULL, use global variable if possible.\r
+\r
+ @param[in] Buffer Point to buffer used to separate exception stack.\r
+ @param[in, out] BufferSize On input, it indicates the byte size of Buffer.\r
+ If the size is not enough, the return status will\r
+ be EFI_BUFFER_TOO_SMALL, and output BufferSize\r
+ will be the size it needs.\r
+\r
+ @retval EFI_SUCCESS The stacks are assigned successfully.\r
+ @retval EFI_UNSUPPORTED This function is not supported.\r
+ @retval EFI_BUFFER_TOO_SMALL This BufferSize is too small.\r
**/\r
EFI_STATUS\r
EFIAPI\r
-InitializeCpuExceptionHandlersEx (\r
- IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,\r
- IN CPU_EXCEPTION_INIT_DATA *InitData OPTIONAL\r
+InitializeSeparateExceptionStacks (\r
+ IN VOID *Buffer,\r
+ IN OUT UINTN *BufferSize\r
)\r
{\r
- return InitializeCpuExceptionHandlers (VectorInfo);\r
+ return EFI_SUCCESS;\r
}\r
-\r