]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[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
053e878b 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
053e878b
MK
24CONST CHAR8 mExceptionReservedStr[] = "Reserved";\r
25CONST CHAR8 *mExceptionNameStr[] = {\r
a51ee144
JF
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
053e878b 69 IN EFI_EXCEPTION_TYPE ExceptionType\r
a51ee144
JF
70 )\r
71{\r
053e878b 72 if ((UINTN)ExceptionType < EXCEPTION_KNOWN_NAME_NUM) {\r
a51ee144
JF
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 117DumpModuleImageInfo (\r
053e878b 118 IN UINTN CurrentEip\r
8f07f895 119 )\r
120{\r
053e878b
MK
121 EFI_STATUS Status;\r
122 UINTN Pe32Data;\r
123 VOID *PdbPointer;\r
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
053e878b 133 Status = PeCoffLoaderGetEntryPoint ((VOID *)Pe32Data, &EntryPoint);\r
1b2f7b3e
JF
134 if (EFI_ERROR (Status)) {\r
135 EntryPoint = NULL;\r
136 }\r
053e878b 137\r
bb207f6c 138 InternalPrintMessage ("!!!! Find image based on IP(0x%x) ", CurrentEip);\r
053e878b 139 PdbPointer = PeCoffLoaderGetPdbPointer ((VOID *)Pe32Data);\r
8f07f895 140 if (PdbPointer != NULL) {\r
141 InternalPrintMessage ("%a", PdbPointer);\r
142 } else {\r
053e878b 143 InternalPrintMessage ("(No PDB) ");\r
8f07f895 144 }\r
053e878b 145\r
1b2f7b3e
JF
146 InternalPrintMessage (\r
147 " (ImageBase=%016lp, EntryPoint=%016p) !!!!\n",\r
053e878b 148 (VOID *)Pe32Data,\r
1b2f7b3e
JF
149 EntryPoint\r
150 );\r
8f07f895 151 }\r
8f07f895 152}\r
153\r
e41aad15
JF
154/**\r
155 Read and save reserved vector information\r
a51ee144 156\r
e41aad15
JF
157 @param[in] VectorInfo Pointer to reserved vector list.\r
158 @param[out] ReservedVector Pointer to reserved vector data buffer.\r
159 @param[in] VectorCount Vector number to be updated.\r
a51ee144 160\r
e41aad15
JF
161 @return EFI_SUCCESS Read and save vector info successfully.\r
162 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.\r
163\r
164**/\r
165EFI_STATUS\r
166ReadAndVerifyVectorInfo (\r
053e878b
MK
167 IN EFI_VECTOR_HANDOFF_INFO *VectorInfo,\r
168 OUT RESERVED_VECTORS_DATA *ReservedVector,\r
169 IN UINTN VectorCount\r
e41aad15
JF
170 )\r
171{\r
172 while (VectorInfo->Attribute != EFI_VECTOR_HANDOFF_LAST_ENTRY) {\r
173 if (VectorInfo->Attribute > EFI_VECTOR_HANDOFF_HOOK_AFTER) {\r
174 //\r
175 // If vector attrubute is invalid\r
176 //\r
177 return EFI_INVALID_PARAMETER;\r
178 }\r
053e878b 179\r
e41aad15
JF
180 if (VectorInfo->VectorNumber < VectorCount) {\r
181 ReservedVector[VectorInfo->VectorNumber].Attribute = VectorInfo->Attribute;\r
182 }\r
053e878b
MK
183\r
184 VectorInfo++;\r
e41aad15 185 }\r
053e878b 186\r
e41aad15 187 return EFI_SUCCESS;\r
7367cc6c 188}\r