22#define MAX_DEBUG_MESSAGE_LENGTH 0x100
27STATIC CONST CHAR8 mExceptionOrIrqUnknown[] =
"Unknown";
28STATIC CONST CHAR8 *mExceptionNameStr[EXCEPT_RISCV_MAX_EXCEPTIONS + 1] = {
29 "EXCEPT_RISCV_INST_MISALIGNED",
30 "EXCEPT_RISCV_INST_ACCESS_FAULT",
31 "EXCEPT_RISCV_ILLEGAL_INST",
32 "EXCEPT_RISCV_BREAKPOINT",
33 "EXCEPT_RISCV_LOAD_ADDRESS_MISALIGNED",
34 "EXCEPT_RISCV_LOAD_ACCESS_FAULT",
35 "EXCEPT_RISCV_STORE_AMO_ADDRESS_MISALIGNED",
36 "EXCEPT_RISCV_STORE_AMO_ACCESS_FAULT",
37 "EXCEPT_RISCV_ENV_CALL_FROM_UMODE",
38 "EXCEPT_RISCV_ENV_CALL_FROM_SMODE",
39 "EXCEPT_RISCV_ENV_CALL_FROM_VS_MODE",
40 "EXCEPT_RISCV_ENV_CALL_FROM_MMODE",
41 "EXCEPT_RISCV_INST_ACCESS_PAGE_FAULT",
42 "EXCEPT_RISCV_LOAD_ACCESS_PAGE_FAULT",
44 "EXCEPT_RISCV_STORE_ACCESS_PAGE_FAULT",
49 "EXCEPT_RISCV_INST_GUEST_PAGE_FAULT",
50 "EXCEPT_RISCV_LOAD_GUEST_PAGE_FAULT",
51 "EXCEPT_RISCV_VIRTUAL_INSTRUCTION",
52 "EXCEPT_RISCV_STORE_GUEST_PAGE_FAULT"
55STATIC CONST CHAR8 *mIrqNameStr[EXCEPT_RISCV_MAX_IRQS + 1] = {
57 "EXCEPT_RISCV_IRQ_SOFT_FROM_SMODE",
58 "EXCEPT_RISCV_IRQ_SOFT_FROM_VSMODE",
59 "EXCEPT_RISCV_IRQ_SOFT_FROM_MMODE",
61 "EXCEPT_RISCV_IRQ_TIMER_FROM_SMODE",
80 CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH];
110 if (EXCEPT_RISCV_IRQ_INDEX (ExceptionType) > EXCEPT_RISCV_MAX_IRQS) {
111 return mExceptionOrIrqUnknown;
114 return mIrqNameStr[EXCEPT_RISCV_IRQ_INDEX (ExceptionType)];
117 if (ExceptionType > EXCEPT_RISCV_MAX_EXCEPTIONS) {
118 return mExceptionOrIrqUnknown;
121 return mExceptionNameStr[ExceptionType];
145 "!!!! RISCV64 Exception Type - %016x(%a) !!!!\n",
153 REG (t0); REG (t1); REG (t2); REG (t3); REG (t4); REG (t5); REG (t6); \
154 REG (s0); REG (s1); REG (s2); REG (s3); REG (s4); REG (s5); REG (s6); \
155 REG (s7); REG (s8); REG (s9); REG (s10); REG (s11); \
156 REG (a0); REG (a1); REG (a2); REG (a3); REG (a4); REG (a5); REG (a6); \
158 REG (zero); REG (ra); REG (sp); REG (gp); REG (tp); \
159 REG (sepc); REG (sstatus); REG (stval);
161 #define REG(x) do { \
162 InternalPrintMessage ("%7a = 0x%017lx%c", #x, Regs->x, \
163 (++Printed % 2) ? L'\t' : L'\n'); \
167 if (Printed % 2 != 0) {
233 DEBUG ((DEBUG_INFO,
"%a: Type:%x Handler: %x\n", __func__, ExceptionType, InterruptHandler));
235 if (EXCEPT_RISCV_IRQ_INDEX (ExceptionType) > EXCEPT_RISCV_MAX_IRQS) {
236 return EFI_UNSUPPORTED;
239 if (mIrqHandlers[EXCEPT_RISCV_IRQ_INDEX (ExceptionType)] !=
NULL) {
240 return EFI_ALREADY_STARTED;
241 }
else if (InterruptHandler ==
NULL) {
242 return EFI_INVALID_PARAMETER;
245 mIrqHandlers[EXCEPT_RISCV_IRQ_INDEX (ExceptionType)] = InterruptHandler;
247 if (ExceptionType > EXCEPT_RISCV_MAX_EXCEPTIONS) {
248 return EFI_UNSUPPORTED;
251 if (mExceptionHandlers[ExceptionType] !=
NULL) {
252 return EFI_ALREADY_STARTED;
253 }
else if (InterruptHandler ==
NULL) {
254 return EFI_INVALID_PARAMETER;
257 mExceptionHandlers[ExceptionType] = InterruptHandler;
303 ExceptionType = (
UINTN)RiscVGetSupervisorTrapCause ();
306 IrqIndex = EXCEPT_RISCV_IRQ_INDEX (ExceptionType);
308 if ((IrqIndex <= EXCEPT_RISCV_MAX_IRQS) &&
309 (mIrqHandlers[IrqIndex] !=
NULL))
311 mIrqHandlers[IrqIndex](ExceptionType, RiscVSystemContext);
315 if ((ExceptionType <= EXCEPT_RISCV_MAX_EXCEPTIONS) &&
316 (mExceptionHandlers[ExceptionType] != 0))
318 mExceptionHandlers[ExceptionType](ExceptionType, RiscVSystemContext);
UINTN EFIAPI SerialPortWrite(IN UINT8 *Buffer, IN UINTN NumberOfBytes)
UINTN EFIAPI AsciiStrLen(IN CONST CHAR8 *String)
VOID EFIAPI CpuDeadLoop(VOID)
VOID(EFIAPI * EFI_CPU_INTERRUPT_HANDLER)(IN CONST EFI_EXCEPTION_TYPE InterruptType, IN CONST 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)
STATIC CONST CHAR8 * GetExceptionNameStr(IN EFI_EXCEPTION_TYPE ExceptionType)
VOID EFIAPI DumpCpuContext(IN EFI_EXCEPTION_TYPE ExceptionType, IN EFI_SYSTEM_CONTEXT SystemContext)
EFI_STATUS EFIAPI RegisterCpuInterruptHandler(IN EFI_EXCEPTION_TYPE ExceptionType, IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler)
STATIC VOID EFIAPI InternalPrintMessage(IN CONST CHAR8 *Format,...)
VOID RiscVSupervisorModeTrapHandler(SMODE_TRAP_REGISTERS *SmodeTrapReg)
UINTN EFIAPI AsciiVSPrint(OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString, IN VA_LIST Marker)
#define VA_START(Marker, Parameter)
#define DEBUG_CODE_BEGIN()
#define DEBUG(Expression)
#define EXCEPT_RISCV_IS_IRQ(x)
VOID SupervisorModeTrap(VOID)