TianoCore EDK2 master
Loading...
Searching...
No Matches
CpuExceptionHandlerLib.c File Reference

Go to the source code of this file.

Macros

#define MAX_DEBUG_MESSAGE_LENGTH   0x100
 
#define REGS()
 
#define REG(x)
 

Functions

STATIC VOID EFIAPI InternalPrintMessage (IN CONST CHAR8 *Format,...)
 
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 InitializeCpuExceptionHandlers (IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL)
 
EFI_STATUS EFIAPI RegisterCpuInterruptHandler (IN EFI_EXCEPTION_TYPE ExceptionType, IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler)
 
EFI_STATUS EFIAPI InitializeSeparateExceptionStacks (IN VOID *Buffer, IN OUT UINTN *BufferSize)
 
VOID RiscVSupervisorModeTrapHandler (SMODE_TRAP_REGISTERS *SmodeTrapReg)
 

Variables

STATIC EFI_CPU_INTERRUPT_HANDLER mExceptionHandlers [EXCEPT_RISCV_MAX_EXCEPTIONS+1]
 
STATIC EFI_CPU_INTERRUPT_HANDLER mIrqHandlers [EXCEPT_RISCV_MAX_IRQS+1]
 
STATIC CONST CHAR8 mExceptionOrIrqUnknown [] = "Unknown"
 
STATIC CONST CHAR8 * mExceptionNameStr [EXCEPT_RISCV_MAX_EXCEPTIONS+1]
 
STATIC CONST CHAR8 * mIrqNameStr [EXCEPT_RISCV_MAX_IRQS+1]
 

Detailed Description

RISC-V Exception Handler library implementation.

Copyright (c) 2016 - 2022, Hewlett Packard Enterprise Development LP. All rights reserved.

SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file CpuExceptionHandlerLib.c.

Macro Definition Documentation

◆ MAX_DEBUG_MESSAGE_LENGTH

#define MAX_DEBUG_MESSAGE_LENGTH   0x100

Definition at line 22 of file CpuExceptionHandlerLib.c.

◆ REG

#define REG (   x)
Value:
do { \
InternalPrintMessage ("%7a = 0x%017lx%c", #x, Regs->x, \
(++Printed % 2) ? L'\t' : L'\n'); \
} while (0);

◆ REGS

#define REGS ( )
Value:
REG (t0); REG (t1); REG (t2); REG (t3); REG (t4); REG (t5); REG (t6); \
REG (s0); REG (s1); REG (s2); REG (s3); REG (s4); REG (s5); REG (s6); \
REG (s7); REG (s8); REG (s9); REG (s10); REG (s11); \
REG (a0); REG (a1); REG (a2); REG (a3); REG (a4); REG (a5); REG (a6); \
REG (a7); \
REG (zero); REG (ra); REG (sp); REG (gp); REG (tp); \
REG (sepc); REG (sstatus); REG (stval);

Function Documentation

◆ DumpCpuContext()

VOID EFIAPI DumpCpuContext ( IN EFI_EXCEPTION_TYPE  ExceptionType,
IN EFI_SYSTEM_CONTEXT  SystemContext 
)

Display CPU information. This can be called by 3rd-party handlers set by RegisterCpuInterruptHandler.

Parameters
ExceptionTypeException type.
SystemContextPointer to EFI_SYSTEM_CONTEXT.

Definition at line 133 of file CpuExceptionHandlerLib.c.

◆ GetExceptionNameStr()

STATIC CONST CHAR8 * GetExceptionNameStr ( IN EFI_EXCEPTION_TYPE  ExceptionType)

Get ASCII format string exception name by exception type.

Parameters
ExceptionTypeException type.
Returns
ASCII format string exception name.

Definition at line 105 of file CpuExceptionHandlerLib.c.

◆ InitializeCpuExceptionHandlers()

EFI_STATUS EFIAPI InitializeCpuExceptionHandlers ( IN EFI_VECTOR_HANDOFF_INFO *VectorInfo  OPTIONAL)

Initializes all CPU exceptions entries and provides the default exception handlers.

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.

Parameters
[in]VectorInfoPointer to reserved vector list.
Return values
EFI_SUCCESSCPU Exception Entries have been successfully initialized with default exception handlers.
EFI_INVALID_PARAMETERVectorInfo includes the invalid content if VectorInfo is not NULL.
EFI_UNSUPPORTEDThis function is not supported.

Definition at line 195 of file CpuExceptionHandlerLib.c.

◆ InitializeSeparateExceptionStacks()

EFI_STATUS EFIAPI InitializeSeparateExceptionStacks ( IN VOID *  Buffer,
IN OUT UINTN BufferSize 
)

Setup separate stacks for certain exception handlers. If the input Buffer and BufferSize are both NULL, use global variable if possible.

Parameters
[in]BufferPoint to buffer used to separate exception stack.
[in,out]BufferSizeOn input, it indicates the byte size of Buffer. If the size is not enough, the return status will be EFI_BUFFER_TOO_SMALL, and output BufferSize will be the size it needs.
Return values
EFI_SUCCESSThe stacks are assigned successfully.
EFI_UNSUPPORTEDThis function is not supported.
EFI_BUFFER_TOO_SMALLThis BufferSize is too small.

Definition at line 279 of file CpuExceptionHandlerLib.c.

◆ InternalPrintMessage()

STATIC VOID EFIAPI InternalPrintMessage ( IN CONST CHAR8 *  Format,
  ... 
)

Prints a message to the serial port.

Parameters
FormatFormat string for the message to print.
...Variable argument list whose contents are accessed based on the format string specified by Format.

Definition at line 75 of file CpuExceptionHandlerLib.c.

◆ RegisterCpuInterruptHandler()

EFI_STATUS EFIAPI RegisterCpuInterruptHandler ( IN EFI_EXCEPTION_TYPE  ExceptionType,
IN EFI_CPU_INTERRUPT_HANDLER  InterruptHandler 
)

Registers a function to be called from the processor interrupt handler.

This function registers and enables the handler specified by InterruptHandler for a processor interrupt or exception type specified by ExceptionType. If InterruptHandler is NULL, then the handler for the processor interrupt or exception type specified by ExceptionType is uninstalled. The installed handler is called once for each processor interrupt or exception. NOTE: This function should be invoked after InitializeCpuExceptionHandlers() or InitializeCpuInterruptHandlers() invoked, otherwise EFI_UNSUPPORTED returned.

Parameters
[in]ExceptionTypeDefines which interrupt or exception to hook.
[in]InterruptHandlerA 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.
Return values
EFI_SUCCESSThe handler for the processor interrupt was successfully installed or uninstalled.
EFI_ALREADY_STARTEDInterruptHandler is not NULL, and a handler for ExceptionType was previously installed.
EFI_INVALID_PARAMETERInterruptHandler is NULL, and a handler for ExceptionType was not previously installed.
EFI_UNSUPPORTEDThe interrupt specified by ExceptionType is not supported, or this function is not supported.

Definition at line 228 of file CpuExceptionHandlerLib.c.

◆ RiscVSupervisorModeTrapHandler()

VOID RiscVSupervisorModeTrapHandler ( SMODE_TRAP_REGISTERS SmodeTrapReg)

Supervisor mode trap handler.

Parameters
[in]SmodeTrapRegRegisters before trap occurred.

Definition at line 294 of file CpuExceptionHandlerLib.c.

Variable Documentation

◆ mExceptionHandlers

STATIC EFI_CPU_INTERRUPT_HANDLER mExceptionHandlers[EXCEPT_RISCV_MAX_EXCEPTIONS+1]

Definition at line 24 of file CpuExceptionHandlerLib.c.

◆ mExceptionNameStr

STATIC CONST CHAR8* mExceptionNameStr[EXCEPT_RISCV_MAX_EXCEPTIONS+1]
Initial value:
= {
"EXCEPT_RISCV_INST_MISALIGNED",
"EXCEPT_RISCV_INST_ACCESS_FAULT",
"EXCEPT_RISCV_ILLEGAL_INST",
"EXCEPT_RISCV_BREAKPOINT",
"EXCEPT_RISCV_LOAD_ADDRESS_MISALIGNED",
"EXCEPT_RISCV_LOAD_ACCESS_FAULT",
"EXCEPT_RISCV_STORE_AMO_ADDRESS_MISALIGNED",
"EXCEPT_RISCV_STORE_AMO_ACCESS_FAULT",
"EXCEPT_RISCV_ENV_CALL_FROM_UMODE",
"EXCEPT_RISCV_ENV_CALL_FROM_SMODE",
"EXCEPT_RISCV_ENV_CALL_FROM_VS_MODE",
"EXCEPT_RISCV_ENV_CALL_FROM_MMODE",
"EXCEPT_RISCV_INST_ACCESS_PAGE_FAULT",
"EXCEPT_RISCV_LOAD_ACCESS_PAGE_FAULT",
"EXCEPT_RISCV_14",
"EXCEPT_RISCV_STORE_ACCESS_PAGE_FAULT",
"EXCEPT_RISCV_16",
"EXCEPT_RISCV_17",
"EXCEPT_RISCV_18",
"EXCEPT_RISCV_19",
"EXCEPT_RISCV_INST_GUEST_PAGE_FAULT",
"EXCEPT_RISCV_LOAD_GUEST_PAGE_FAULT",
"EXCEPT_RISCV_VIRTUAL_INSTRUCTION",
"EXCEPT_RISCV_STORE_GUEST_PAGE_FAULT"
}

Definition at line 28 of file CpuExceptionHandlerLib.c.

◆ mExceptionOrIrqUnknown

STATIC CONST CHAR8 mExceptionOrIrqUnknown[] = "Unknown"

Definition at line 27 of file CpuExceptionHandlerLib.c.

◆ mIrqHandlers

STATIC EFI_CPU_INTERRUPT_HANDLER mIrqHandlers[EXCEPT_RISCV_MAX_IRQS+1]

Definition at line 25 of file CpuExceptionHandlerLib.c.

◆ mIrqNameStr

STATIC CONST CHAR8* mIrqNameStr[EXCEPT_RISCV_MAX_IRQS+1]
Initial value:
= {
"EXCEPT_RISCV_IRQ_0",
"EXCEPT_RISCV_IRQ_SOFT_FROM_SMODE",
"EXCEPT_RISCV_IRQ_SOFT_FROM_VSMODE",
"EXCEPT_RISCV_IRQ_SOFT_FROM_MMODE",
"EXCEPT_RISCV_IRQ_4",
"EXCEPT_RISCV_IRQ_TIMER_FROM_SMODE",
}

Definition at line 55 of file CpuExceptionHandlerLib.c.