]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c
UefiCpuPkg: Replace BSD License with BSD+Patent License
[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
0d25074c 17CONST UINT32 mErrorCodeFlag = 0x00227d00;\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
JY
46 "#VE - Virtualization",\r
47 "#CP - Control Protection"\r
a51ee144
JF
48};\r
49\r
50#define EXCEPTION_KNOWN_NAME_NUM (sizeof (mExceptionNameStr) / sizeof (CHAR8 *))\r
51\r
52/**\r
53 Get ASCII format string exception name by exception type.\r
54\r
55 @param ExceptionType Exception type.\r
56\r
57 @return ASCII format string exception name.\r
58**/\r
59CONST CHAR8 *\r
60GetExceptionNameStr (\r
61 IN EFI_EXCEPTION_TYPE ExceptionType\r
62 )\r
63{\r
64 if ((UINTN) ExceptionType < EXCEPTION_KNOWN_NAME_NUM) {\r
65 return mExceptionNameStr[ExceptionType];\r
66 } else {\r
67 return mExceptionReservedStr;\r
68 }\r
69}\r
70\r
8f07f895 71/**\r
72 Prints a message to the serial port.\r
73\r
74 @param Format Format string for the message to print.\r
a51ee144 75 @param ... Variable argument list whose contents are accessed\r
8f07f895 76 based on the format string specified by Format.\r
77\r
78**/\r
79VOID\r
80EFIAPI\r
81InternalPrintMessage (\r
82 IN CONST CHAR8 *Format,\r
83 ...\r
84 )\r
85{\r
86 CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH];\r
87 VA_LIST Marker;\r
88\r
89 //\r
90 // Convert the message to an ASCII String\r
91 //\r
92 VA_START (Marker, Format);\r
93 AsciiVSPrint (Buffer, sizeof (Buffer), Format, Marker);\r
94 VA_END (Marker);\r
95\r
96 //\r
a51ee144 97 // Send the print string to a Serial Port\r
8f07f895 98 //\r
99 SerialPortWrite ((UINT8 *)Buffer, AsciiStrLen (Buffer));\r
100}\r
101\r
102/**\r
103 Find and display image base address and return image base and its entry point.\r
dd563742 104\r
a9c7ab95 105 @param CurrentEip Current instruction pointer.\r
dd563742 106\r
8f07f895 107**/\r
dd563742 108VOID\r
1b2f7b3e
JF
109DumpModuleImageInfo (\r
110 IN UINTN CurrentEip\r
8f07f895 111 )\r
112{\r
1b2f7b3e 113 EFI_STATUS Status;\r
8f07f895 114 UINTN Pe32Data;\r
8f07f895 115 VOID *PdbPointer;\r
1b2f7b3e 116 VOID *EntryPoint;\r
8f07f895 117\r
9e981317 118 Pe32Data = PeCoffSearchImageBase (CurrentEip);\r
1b2f7b3e
JF
119 if (Pe32Data == 0) {\r
120 InternalPrintMessage ("!!!! Can't find image information. !!!!\n");\r
121 } else {\r
8f07f895 122 //\r
1b2f7b3e 123 // Find Image Base entry point\r
a51ee144 124 //\r
1b2f7b3e
JF
125 Status = PeCoffLoaderGetEntryPoint ((VOID *) Pe32Data, &EntryPoint);\r
126 if (EFI_ERROR (Status)) {\r
127 EntryPoint = NULL;\r
128 }\r
bb207f6c 129 InternalPrintMessage ("!!!! Find image based on IP(0x%x) ", CurrentEip);\r
8f07f895 130 PdbPointer = PeCoffLoaderGetPdbPointer ((VOID *) Pe32Data);\r
131 if (PdbPointer != NULL) {\r
132 InternalPrintMessage ("%a", PdbPointer);\r
133 } else {\r
134 InternalPrintMessage ("(No PDB) " );\r
135 }\r
1b2f7b3e
JF
136 InternalPrintMessage (\r
137 " (ImageBase=%016lp, EntryPoint=%016p) !!!!\n",\r
138 (VOID *) Pe32Data,\r
139 EntryPoint\r
140 );\r
8f07f895 141 }\r
8f07f895 142}\r
143\r
e41aad15
JF
144/**\r
145 Read and save reserved vector information\r
a51ee144 146\r
e41aad15
JF
147 @param[in] VectorInfo Pointer to reserved vector list.\r
148 @param[out] ReservedVector Pointer to reserved vector data buffer.\r
149 @param[in] VectorCount Vector number to be updated.\r
a51ee144 150\r
e41aad15
JF
151 @return EFI_SUCCESS Read and save vector info successfully.\r
152 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.\r
153\r
154**/\r
155EFI_STATUS\r
156ReadAndVerifyVectorInfo (\r
157 IN EFI_VECTOR_HANDOFF_INFO *VectorInfo,\r
158 OUT RESERVED_VECTORS_DATA *ReservedVector,\r
159 IN UINTN VectorCount\r
160 )\r
161{\r
162 while (VectorInfo->Attribute != EFI_VECTOR_HANDOFF_LAST_ENTRY) {\r
163 if (VectorInfo->Attribute > EFI_VECTOR_HANDOFF_HOOK_AFTER) {\r
164 //\r
165 // If vector attrubute is invalid\r
166 //\r
167 return EFI_INVALID_PARAMETER;\r
168 }\r
169 if (VectorInfo->VectorNumber < VectorCount) {\r
170 ReservedVector[VectorInfo->VectorNumber].Attribute = VectorInfo->Attribute;\r
171 }\r
172 VectorInfo ++;\r
173 }\r
174 return EFI_SUCCESS;\r
7367cc6c 175}\r