TianoCore EDK2 master
Loading...
Searching...
No Matches
ExceptionCommon.c
1
10#include <Library/BaseLib.h>
12#include <Library/PrintLib.h>
15#include "ExceptionCommon.h"
16
17CONST CHAR8 mExceptionReservedStr[] = "Reserved";
18CONST CHAR8 *mExceptionNameStr[] = {
19 "#INT - Interrupt(CSR.ECFG.VS=0)",
20 "#PIL - Page invalid exception for Load option",
21 "#PIS - Page invalid exception for Store operation",
22 "#PIF - Page invalid exception for Fetch operation",
23 "#PME - Page modification exception",
24 "#PNR - Page non-readable exception",
25 "#PNX - Page non-executable exception",
26 "#PPI - Page privilege level illegal exception",
27 "#ADE - Address error exception",
28 "#ALE - Address alignment fault exception",
29 "#BCE - Bound check exception",
30 "#SYS - System call exception",
31 "#BRK - Beeakpoint exception",
32 "#INE - Instruction non-defined exception",
33 "#IPE - Instruction privilege error exception",
34 "#FPD - Floating-point instruction disable exception",
35 "#SXD - 128-bit vector (SIMD instructions) expansion instruction disable exception",
36 "#ASXD - 256-bit vector (Advanced SIMD instructions) expansion instruction disable exception",
37 "#FPE - Floating-Point error exception",
38 "#WPE - WatchPoint Exception for Fetch watchpoint or Memory load/store watchpoint",
39 "#BTD - Binary Translation expansion instruction Disable exception",
40 "#BTE - Binary Translation related exceptions",
41 "#GSPR - Guest Sensitive Privileged Resource exception",
42 "#HVC - HyperVisor Call exception",
43 "#GCXC - Guest CSR Software/Hardware Change exception",
44 "#TBR - TLB refill exception" // !!! NOTICE: Because the TLB refill exception is not instructed in ECODE, so the TLB refill exception must be the last one!
45};
46
47INTN mExceptionKnownNameNum = (sizeof (mExceptionNameStr) / sizeof (CHAR8 *));
48
57CONST CHAR8 *
59 IN EFI_EXCEPTION_TYPE ExceptionType
60 )
61{
62 if ((UINTN)ExceptionType < mExceptionKnownNameNum) {
63 return mExceptionNameStr[ExceptionType];
64 } else {
65 return mExceptionReservedStr;
66 }
67}
68
77VOID
78EFIAPI
80 IN CONST CHAR8 *Format,
81 ...
82 )
83{
84 CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH];
85 VA_LIST Marker;
86
87 //
88 // Convert the message to an ASCII String
89 //
90 VA_START (Marker, Format);
91 AsciiVSPrint (Buffer, sizeof (Buffer), Format, Marker);
92 VA_END (Marker);
93
94 //
95 // Send the print string to a Serial Port
96 //
97 SerialPortWrite ((UINT8 *)Buffer, AsciiStrLen (Buffer));
98}
99
106VOID
108 IN UINTN CurrentEra
109 )
110{
111 EFI_STATUS Status;
112 UINTN Pe32Data;
113 VOID *PdbPointer;
114 VOID *EntryPoint;
115
116 Pe32Data = PeCoffSearchImageBase (CurrentEra);
117 if (Pe32Data == 0) {
118 InternalPrintMessage ("!!!! Can't find image information. !!!!\n");
119 } else {
120 //
121 // Find Image Base entry point
122 //
123 Status = PeCoffLoaderGetEntryPoint ((VOID *)Pe32Data, &EntryPoint);
124 if (EFI_ERROR (Status)) {
125 EntryPoint = NULL;
126 }
127
128 InternalPrintMessage ("!!!! Find image based on IP(0x%x) ", CurrentEra);
129 PdbPointer = PeCoffLoaderGetPdbPointer ((VOID *)Pe32Data);
130 if (PdbPointer != NULL) {
131 InternalPrintMessage ("%a", PdbPointer);
132 } else {
133 InternalPrintMessage ("(No PDB) ");
134 }
135
137 " (ImageBase=%016lp, EntryPoint=%016p) !!!!\n",
138 (VOID *)Pe32Data,
139 EntryPoint
140 );
141 }
142}
143
151VOID
152EFIAPI
154 IN EFI_EXCEPTION_TYPE ExceptionType,
155 IN OUT EFI_SYSTEM_CONTEXT SystemContext
156 )
157{
158 //
159 // Initialize the serial port before dumping.
160 //
162 //
163 // Display ExceptionType, CPU information and Image information
164 //
165 DumpImageAndCpuContent (ExceptionType, SystemContext);
166
167 //
168 // Enter a dead loop.
169 //
170 CpuDeadLoop ();
171}
UINT64 UINTN
INT64 INTN
RETURN_STATUS EFIAPI SerialPortInitialize(VOID)
Definition: SerialPortLib.c:25
UINTN EFIAPI SerialPortWrite(IN UINT8 *Buffer, IN UINTN NumberOfBytes)
Definition: SerialPortLib.c:52
UINTN EFIAPI AsciiStrLen(IN CONST CHAR8 *String)
Definition: String.c:641
VOID EFIAPI CpuDeadLoop(VOID)
Definition: CpuDeadLoop.c:25
VOID DumpModuleImageInfo(IN UINTN CurrentEip)
VOID DumpImageAndCpuContent(IN EFI_EXCEPTION_TYPE ExceptionType, IN EFI_SYSTEM_CONTEXT SystemContext)
STATIC CONST CHAR8 * GetExceptionNameStr(IN EFI_EXCEPTION_TYPE ExceptionType)
STATIC VOID EFIAPI InternalPrintMessage(IN CONST CHAR8 *Format,...)
VOID DefaultExceptionHandler(IN EFI_EXCEPTION_TYPE ExceptionType, IN OUT EFI_SYSTEM_CONTEXT SystemContext)
UINTN EFIAPI AsciiVSPrint(OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString, IN VA_LIST Marker)
Definition: PrintLib.c:702
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define VA_START(Marker, Parameter)
Definition: Base.h:661
CHAR8 * VA_LIST
Definition: Base.h:643
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define VA_END(Marker)
Definition: Base.h:691
INTN EFI_EXCEPTION_TYPE
Definition: DebugSupport.h:35
UINTN EFIAPI PeCoffSearchImageBase(IN UINTN Address)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29