TianoCore EDK2 master
Loading...
Searching...
No Matches
ArmExceptionLib.c
1/* @file
2* Main file supporting the SEC Phase for Versatile Express
3*
4* Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
5* Copyright (c) 2011-2021, Arm Limited. All rights reserved.<BR>
6* Copyright (c) 2016 HP Development Company, L.P.
7* Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
8*
9* SPDX-License-Identifier: BSD-2-Clause-Patent
10*
11**/
12
13#include <Uefi.h>
15
16#include <Library/ArmLib.h>
17#include <Library/PcdLib.h>
19#include <Library/BaseLib.h>
21#include <Library/DebugLib.h>
23
24VOID
25ExceptionHandlersStart (
26 VOID
27 );
28
29RETURN_STATUS
30ArchVectorConfig (
31 IN UINTN VectorBaseAddress
32 );
33
34// these globals are provided by the architecture specific source (AArch64)
35extern UINTN gMaxExceptionNumber;
36extern EFI_EXCEPTION_CALLBACK gExceptionHandlers[];
37extern PHYSICAL_ADDRESS gExceptionVectorAlignmentMask;
38
56EFIAPI
57InitializeCpuExceptionHandlers (
58 IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
59 )
60{
61 UINT64 VectorBase;
62
63 // use VBAR to point to where our exception handlers are
64
65 // The vector table must be aligned for the architecture. If this
66 // assertion fails ensure the appropriate FFS alignment is in effect,
67 // which can be accomplished by ensuring the proper Align=X statement
68 // in the platform packaging rules. For AArch64 Align=4K is required.
69 // Align=Auto can be used but this is known to cause an issue with
70 // populating the reset vector area for encapsulated FVs.
71 ASSERT (((UINTN)ExceptionHandlersStart & gExceptionVectorAlignmentMask) == 0);
72
73 VectorBase = (UINT64)(UINTN)ExceptionHandlersStart;
74
75 // call the architecture-specific routine to prepare for the new vector
76 // configuration to take effect
77 ArchVectorConfig ((UINTN)VectorBase);
78
79 ArmWriteVBar ((UINTN)VectorBase);
80
81 return RETURN_SUCCESS;
82}
83
109RETURN_STATUS
110RegisterCpuInterruptHandler (
111 IN EFI_EXCEPTION_TYPE ExceptionType,
112 IN EFI_CPU_INTERRUPT_HANDLER ExceptionHandler
113 )
114{
115 if ((UINTN)ExceptionType > gMaxExceptionNumber) {
116 return RETURN_UNSUPPORTED;
117 }
118
119 if ((ExceptionHandler != NULL) && (gExceptionHandlers[ExceptionType] != NULL)) {
121 }
122
123 gExceptionHandlers[ExceptionType] = ExceptionHandler;
124
125 return RETURN_SUCCESS;
126}
127
128VOID
129EFIAPI
130CommonCExceptionHandler (
131 IN EFI_EXCEPTION_TYPE ExceptionType,
132 IN OUT EFI_SYSTEM_CONTEXT SystemContext
133 )
134{
135 if ((UINTN)ExceptionType <= gMaxExceptionNumber) {
136 if (gExceptionHandlers[ExceptionType]) {
137 gExceptionHandlers[ExceptionType](ExceptionType, SystemContext);
138 return;
139 }
140 } else {
141 DEBUG ((DEBUG_ERROR, "Unknown exception type %d\n", ExceptionType));
142 ASSERT (FALSE);
143 }
144
145 DefaultExceptionHandler (ExceptionType, SystemContext);
146}
147
163EFIAPI
164InitializeSeparateExceptionStacks (
165 IN VOID *Buffer,
166 IN OUT UINTN *BufferSize
167 )
168{
169 return EFI_SUCCESS;
170}
UINT64 UINTN
VOID(EFIAPI * EFI_CPU_INTERRUPT_HANDLER)(IN CONST EFI_EXCEPTION_TYPE InterruptType, IN CONST EFI_SYSTEM_CONTEXT SystemContext)
Definition: Cpu.h:52
VOID DefaultExceptionHandler(IN EFI_EXCEPTION_TYPE ExceptionType, IN OUT EFI_SYSTEM_CONTEXT SystemContext)
#define NULL
Definition: Base.h:319
#define RETURN_UNSUPPORTED
Definition: Base.h:1081
#define VOID
Definition: Base.h:269
#define RETURN_SUCCESS
Definition: Base.h:1066
#define FALSE
Definition: Base.h:307
#define RETURN_ALREADY_STARTED
Definition: Base.h:1172
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:435
INTN EFI_EXCEPTION_TYPE
Definition: DebugSupport.h:35
VOID(EFIAPI * EFI_EXCEPTION_CALLBACK)(IN EFI_EXCEPTION_TYPE ExceptionType, IN OUT EFI_SYSTEM_CONTEXT SystemContext)
Definition: DebugSupport.h:827
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112