TianoCore EDK2 master
Loading...
Searching...
No Matches
DxeExceptionLib.c
Go to the documentation of this file.
1
10#include <Library/BaseLib.h>
12#include <Library/CpuLib.h>
14#include <Library/DebugLib.h>
18
19#include "ExceptionCommon.h"
20
21EFI_EXCEPTION_CALLBACK ExternalInterruptHandler[MAX_LOONGARCH_INTERRUPT + 1] = { 0 };
22EFI_EXCEPTION_CALLBACK ExceptionHandler[MAX_LOONGARCH_EXCEPTION + 1] = { 0 };
23
48 IN EFI_EXCEPTION_TYPE InterruptType,
49 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
50 )
51{
52 EFI_EXCEPTION_TYPE ExceptionType;
53
54 ExceptionType = InterruptType & CSR_ESTAT_EXC;
55
56 if (ExceptionType != 0) {
57 //
58 // Exception >>= CSR_ESTAT_EXC_SHIFT, convert to ECODE
59 //
60 ExceptionType >>= CSR_ESTAT_EXC_SHIFT;
61
62 if (ExceptionType > EXCEPT_LOONGARCH_FPE) {
63 return EFI_UNSUPPORTED;
64 }
65
66 if ((InterruptHandler == NULL) && (ExceptionHandler[InterruptType] == NULL)) {
67 return EFI_INVALID_PARAMETER;
68 }
69
70 if ((InterruptHandler != NULL) && (ExceptionHandler[ExceptionType] != NULL)) {
71 return EFI_ALREADY_STARTED;
72 }
73
74 ExceptionHandler[ExceptionType] = InterruptHandler;
75 } else {
76 //
77 // Interrupt
78 //
79 if (InterruptType > MAX_LOONGARCH_INTERRUPT) {
80 return EFI_UNSUPPORTED;
81 }
82
83 if ((InterruptHandler == NULL) && (ExternalInterruptHandler[InterruptType] == NULL)) {
84 return EFI_INVALID_PARAMETER;
85 }
86
87 if ((InterruptHandler != NULL) && (ExternalInterruptHandler[InterruptType] != NULL)) {
88 return EFI_ALREADY_STARTED;
89 }
90
91 ExternalInterruptHandler[InterruptType] = InterruptHandler;
92 }
93
94 return EFI_SUCCESS;
95}
96
104VOID
105EFIAPI
107 IN EFI_EXCEPTION_TYPE ExceptionType,
108 IN OUT EFI_SYSTEM_CONTEXT SystemContext
109 )
110{
111 EFI_EXCEPTION_TYPE InterruptType;
112
113 if (ExceptionType == EXCEPT_LOONGARCH_INT) {
114 //
115 // Interrupt
116 //
117 InterruptType = GetInterruptType (SystemContext);
118 if (InterruptType == 0xFF) {
119 ExceptionType = InterruptType;
120 } else {
121 if ((ExternalInterruptHandler != NULL) && (ExternalInterruptHandler[InterruptType] != NULL)) {
122 ExternalInterruptHandler[InterruptType](InterruptType, SystemContext);
123 return;
124 }
125 }
126 } else if (ExceptionType == EXCEPT_LOONGARCH_FPD) {
127 EnableFloatingPointUnits ();
129 return;
130 } else {
131 //
132 // Exception
133 //
134 ExceptionType >>= CSR_ESTAT_EXC_SHIFT;
135 if ((ExceptionHandler != NULL) && (ExceptionHandler[ExceptionType] != NULL)) {
136 ExceptionHandler[ExceptionType](ExceptionType, SystemContext);
137 return;
138 }
139 }
140
141 //
142 // Only the TLB refill exception use the same entry point as normal exceptions.
143 //
144 if (CsrRead (LOONGARCH_CSR_TLBRERA) & 0x1) {
145 ExceptionType = mExceptionKnownNameNum - 1; // Use only to dump the exception context.
146 }
147
148 DefaultExceptionHandler (ExceptionType, SystemContext);
149}
150
168EFIAPI
170 IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
171 )
172{
173 return EFI_SUCCESS;
174}
175
191EFIAPI
193 IN VOID *Buffer,
194 IN OUT UINTN *BufferSize
195 )
196{
197 return EFI_SUCCESS;
198}
UINT64 UINTN
VOID(EFIAPI * EFI_CPU_INTERRUPT_HANDLER)(IN CONST EFI_EXCEPTION_TYPE InterruptType, IN CONST EFI_SYSTEM_CONTEXT SystemContext)
Definition: Cpu.h:52
UINTN EFIAPI CsrRead(IN UINT16 Select)
Definition: Csr.c:37
VOID DefaultExceptionHandler(IN EFI_EXCEPTION_TYPE ExceptionType, IN OUT EFI_SYSTEM_CONTEXT SystemContext)
EFI_STATUS EFIAPI InitializeSeparateExceptionStacks(IN VOID *Buffer, IN OUT UINTN *BufferSize)
EFI_STATUS EFIAPI InitializeCpuExceptionHandlers(IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL)
VOID EFIAPI CommonExceptionHandler(IN EFI_EXCEPTION_TYPE ExceptionType, IN OUT EFI_SYSTEM_CONTEXT SystemContext)
EFI_STATUS RegisterCpuInterruptHandler(IN EFI_EXCEPTION_TYPE InterruptType, IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler)
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
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:816
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
VOID EFIAPI InitializeFloatingPointUnits(VOID)