]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c
StandaloneMmPkg: Apply uncrustify changes
[mirror_edk2.git] / UefiCpuPkg / Library / CpuExceptionHandlerLib / CpuExceptionCommon.c
CommitLineData
3ff40610 1/** @file\r
e3644786 2 CPU Exception Handler Library common functions.\r
8f07f895 3\r
0d25074c 4 Copyright (c) 2012 - 2019, Intel Corporation. All rights reserved.<BR>\r
0acd8697 5 SPDX-License-Identifier: BSD-2-Clause-Patent\r
8f07f895 6\r
7**/\r
8\r
9#include "CpuExceptionCommon.h"\r
10\r
11//\r
e41aad15 12// Error code flag indicating whether or not an error code will be\r
8f07f895 13// pushed on the stack if an exception occurs.\r
14//\r
15// 1 means an error code will be pushed, otherwise 0\r
16//\r
5277540e 17CONST UINT32 mErrorCodeFlag = 0x20227d00;\r
8f07f895 18\r
19//\r
a51ee144 20// Define the maximum message length\r
8f07f895 21//\r
22#define MAX_DEBUG_MESSAGE_LENGTH 0x100\r
23\r
a51ee144
JF
24CONST CHAR8 mExceptionReservedStr[] = "Reserved";\r
25CONST CHAR8 *mExceptionNameStr[] = {\r
26 "#DE - Divide Error",\r
27 "#DB - Debug",\r
28 "NMI Interrupt",\r
29 "#BP - Breakpoint",\r
30 "#OF - Overflow",\r
31 "#BR - BOUND Range Exceeded",\r
32 "#UD - Invalid Opcode",\r
33 "#NM - Device Not Available",\r
34 "#DF - Double Fault",\r
35 "Coprocessor Segment Overrun",\r
36 "#TS - Invalid TSS",\r
37 "#NP - Segment Not Present",\r
38 "#SS - Stack Fault Fault",\r
39 "#GP - General Protection",\r
40 "#PF - Page-Fault",\r
41 "Reserved",\r
42 "#MF - x87 FPU Floating-Point Error",\r
43 "#AC - Alignment Check",\r
44 "#MC - Machine-Check",\r
45 "#XM - SIMD floating-point",\r
0d25074c 46 "#VE - Virtualization",\r
32928415 47 "#CP - Control Protection",\r
5277540e
TL
48 "Reserved",\r
49 "Reserved",\r
50 "Reserved",\r
51 "Reserved",\r
52 "Reserved",\r
53 "Reserved",\r
54 "Reserved",\r
55 "#VC - VMM Communication",\r
a51ee144
JF
56};\r
57\r
58#define EXCEPTION_KNOWN_NAME_NUM (sizeof (mExceptionNameStr) / sizeof (CHAR8 *))\r
59\r
60/**\r
61 Get ASCII format string exception name by exception type.\r
62\r
63 @param ExceptionType Exception type.\r
64\r
65 @return ASCII format string exception name.\r
66**/\r
67CONST CHAR8 *\r
68GetExceptionNameStr (\r
69 IN EFI_EXCEPTION_TYPE ExceptionType\r
70 )\r
71{\r
72 if ((UINTN) ExceptionType < EXCEPTION_KNOWN_NAME_NUM) {\r
73 return mExceptionNameStr[ExceptionType];\r
74 } else {\r
75 return mExceptionReservedStr;\r
76 }\r
77}\r
78\r
8f07f895 79/**\r
80 Prints a message to the serial port.\r
81\r
82 @param Format Format string for the message to print.\r
a51ee144 83 @param ... Variable argument list whose contents are accessed\r
8f07f895 84 based on the format string specified by Format.\r
85\r
86**/\r
87VOID\r
88EFIAPI\r
89InternalPrintMessage (\r
90 IN CONST CHAR8 *Format,\r
91 ...\r
92 )\r
93{\r
94 CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH];\r
95 VA_LIST Marker;\r
96\r
97 //\r
98 // Convert the message to an ASCII String\r
99 //\r
100 VA_START (Marker, Format);\r
101 AsciiVSPrint (Buffer, sizeof (Buffer), Format, Marker);\r
102 VA_END (Marker);\r
103\r
104 //\r
a51ee144 105 // Send the print string to a Serial Port\r
8f07f895 106 //\r
107 SerialPortWrite ((UINT8 *)Buffer, AsciiStrLen (Buffer));\r
108}\r
109\r
110/**\r
111 Find and display image base address and return image base and its entry point.\r
dd563742 112\r
a9c7ab95 113 @param CurrentEip Current instruction pointer.\r
dd563742 114\r
8f07f895 115**/\r
dd563742 116VOID\r
1b2f7b3e
JF
117DumpModuleImageInfo (\r
118 IN UINTN CurrentEip\r
8f07f895 119 )\r
120{\r
1b2f7b3e 121 EFI_STATUS Status;\r
8f07f895 122 UINTN Pe32Data;\r
8f07f895 123 VOID *PdbPointer;\r
1b2f7b3e 124 VOID *EntryPoint;\r
8f07f895 125\r
9e981317 126 Pe32Data = PeCoffSearchImageBase (CurrentEip);\r
1b2f7b3e
JF
127 if (Pe32Data == 0) {\r
128 InternalPrintMessage ("!!!! Can't find image information. !!!!\n");\r
129 } else {\r
8f07f895 130 //\r
1b2f7b3e 131 // Find Image Base entry point\r
a51ee144 132 //\r
1b2f7b3e
JF
133 Status = PeCoffLoaderGetEntryPoint ((VOID *) Pe32Data, &EntryPoint);\r
134 if (EFI_ERROR (Status)) {\r
135 EntryPoint = NULL;\r
136 }\r
bb207f6c 137 InternalPrintMessage ("!!!! Find image based on IP(0x%x) ", CurrentEip);\r
8f07f895 138 PdbPointer = PeCoffLoaderGetPdbPointer ((VOID *) Pe32Data);\r
139 if (PdbPointer != NULL) {\r
140 InternalPrintMessage ("%a", PdbPointer);\r
141 } else {\r
142 InternalPrintMessage ("(No PDB) " );\r
143 }\r
1b2f7b3e
JF
144 InternalPrintMessage (\r
145 " (ImageBase=%016lp, EntryPoint=%016p) !!!!\n",\r
146 (VOID *) Pe32Data,\r
147 EntryPoint\r
148 );\r
8f07f895 149 }\r
8f07f895 150}\r
151\r
e41aad15
JF
152/**\r
153 Read and save reserved vector information\r
a51ee144 154\r
e41aad15
JF
155 @param[in] VectorInfo Pointer to reserved vector list.\r
156 @param[out] ReservedVector Pointer to reserved vector data buffer.\r
157 @param[in] VectorCount Vector number to be updated.\r
a51ee144 158\r
e41aad15
JF
159 @return EFI_SUCCESS Read and save vector info successfully.\r
160 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.\r
161\r
162**/\r
163EFI_STATUS\r
164ReadAndVerifyVectorInfo (\r
165 IN EFI_VECTOR_HANDOFF_INFO *VectorInfo,\r
166 OUT RESERVED_VECTORS_DATA *ReservedVector,\r
167 IN UINTN VectorCount\r
168 )\r
169{\r
170 while (VectorInfo->Attribute != EFI_VECTOR_HANDOFF_LAST_ENTRY) {\r
171 if (VectorInfo->Attribute > EFI_VECTOR_HANDOFF_HOOK_AFTER) {\r
172 //\r
173 // If vector attrubute is invalid\r
174 //\r
175 return EFI_INVALID_PARAMETER;\r
176 }\r
177 if (VectorInfo->VectorNumber < VectorCount) {\r
178 ReservedVector[VectorInfo->VectorNumber].Attribute = VectorInfo->Attribute;\r
179 }\r
180 VectorInfo ++;\r
181 }\r
182 return EFI_SUCCESS;\r
7367cc6c 183}\r