2 Common header file for CPU Exception Handler Library.
4 Copyright (c) 2012 - 2016, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #ifndef _CPU_EXCEPTION_COMMON_H_
16 #define _CPU_EXCEPTION_COMMON_H_
18 #include <Ppi/VectorHandoffInfo.h>
19 #include <Protocol/Cpu.h>
20 #include <Library/BaseLib.h>
21 #include <Library/SerialPortLib.h>
22 #include <Library/PrintLib.h>
23 #include <Library/LocalApicLib.h>
24 #include <Library/PeCoffGetEntryPointLib.h>
25 #include <Library/BaseMemoryLib.h>
26 #include <Library/SynchronizationLib.h>
28 #define CPU_EXCEPTION_NUM 32
29 #define CPU_INTERRUPT_NUM 256
30 #define HOOKAFTER_STUB_SIZE 16
32 #include "ArchInterruptDefs.h"
34 #define CPU_EXCEPTION_HANDLER_LIB_HOB_GUID \
36 0xb21d9148, 0x9211, 0x4d8f, { 0xad, 0xd3, 0x66, 0xb1, 0x89, 0xc9, 0x2c, 0x83 } \
40 // Record exception handler information
44 UINTN ExceptionStubHeaderSize
;
45 UINTN HookAfterStubHeaderStart
;
46 } EXCEPTION_HANDLER_TEMPLATE_MAP
;
50 SPIN_LOCK DisplayMessageSpinLock
;
51 RESERVED_VECTORS_DATA
*ReservedVectors
;
52 EFI_CPU_INTERRUPT_HANDLER
*ExternalInterruptHandler
;
53 } EXCEPTION_HANDLER_DATA
;
55 extern CONST UINT32 mErrorCodeFlag
;
56 extern CONST UINTN mImageAlignSize
;
57 extern CONST UINTN mDoFarReturnFlag
;
60 Return address map of exception handler template so that C code can generate
63 @param AddressMap Pointer to a buffer where the address map is returned.
67 AsmGetTemplateAddressMap (
68 OUT EXCEPTION_HANDLER_TEMPLATE_MAP
*AddressMap
72 Return address map of exception handler template so that C code can generate
75 @param IdtEntry Pointer to IDT entry to be updated.
76 @param InterruptHandler IDT handler value.
81 IN IA32_IDT_GATE_DESCRIPTOR
*IdtEntry
,
82 IN UINTN InterruptHandler
86 Read IDT handler value from IDT entry.
88 @param IdtEntry Pointer to IDT entry to be read.
93 IN IA32_IDT_GATE_DESCRIPTOR
*IdtEntry
97 Prints a message to the serial port.
99 @param Format Format string for the message to print.
100 @param ... Variable argument list whose contents are accessed
101 based on the format string specified by Format.
106 InternalPrintMessage (
107 IN CONST CHAR8
*Format
,
112 Find and display image base address and return image base and its entry point.
114 @param CurrentEip Current instruction pointer.
115 @param EntryPoint Return module entry point if module header is found.
117 @return !0 Image base address.
118 @return 0 Image header cannot be found.
121 FindModuleImageBase (
123 OUT UINTN
*EntryPoint
127 Display CPU information.
129 @param ExceptionType Exception type.
130 @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.
134 IN EFI_EXCEPTION_TYPE ExceptionType
,
135 IN EFI_SYSTEM_CONTEXT SystemContext
139 Internal worker function to initialize exception handler.
141 @param[in] VectorInfo Pointer to reserved vector list.
142 @param[in, out] ExceptionHandlerData Pointer to exception handler data.
144 @retval EFI_SUCCESS CPU Exception Entries have been successfully initialized
145 with default exception handlers.
146 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.
147 @retval EFI_UNSUPPORTED This function is not supported.
151 InitializeCpuExceptionHandlersWorker (
152 IN EFI_VECTOR_HANDOFF_INFO
*VectorInfo OPTIONAL
,
153 IN OUT EXCEPTION_HANDLER_DATA
*ExceptionHandlerData
157 Registers a function to be called from the processor interrupt handler.
159 @param[in] InterruptType Defines which interrupt or exception to hook.
160 @param[in] InterruptHandler A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called
161 when a processor interrupt occurs. If this parameter is NULL, then the handler
163 @param[in] ExceptionHandlerData Pointer to exception handler data.
165 @retval EFI_SUCCESS The handler for the processor interrupt was successfully installed or uninstalled.
166 @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler for InterruptType was
167 previously installed.
168 @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for InterruptType was not
169 previously installed.
170 @retval EFI_UNSUPPORTED The interrupt specified by InterruptType is not supported,
171 or this function is not supported.
174 RegisterCpuInterruptHandlerWorker (
175 IN EFI_EXCEPTION_TYPE InterruptType
,
176 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
,
177 IN EXCEPTION_HANDLER_DATA
*ExceptionHandlerData
181 Internal worker function to update IDT entries accordling to vector attributes.
183 @param[in] IdtTable Pointer to IDT table.
184 @param[in] TemplateMap Pointer to a buffer where the address map is
186 @param[in] ExceptionHandlerData Pointer to exception handler data.
191 IN IA32_IDT_GATE_DESCRIPTOR
*IdtTable
,
192 IN EXCEPTION_HANDLER_TEMPLATE_MAP
*TemplateMap
,
193 IN EXCEPTION_HANDLER_DATA
*ExceptionHandlerData
197 Save CPU exception context when handling EFI_VECTOR_HANDOFF_HOOK_AFTER case.
199 @param[in] ExceptionType Exception type.
200 @param[in] SystemContext Pointer to EFI_SYSTEM_CONTEXT.
201 @param[in] ExceptionHandlerData Pointer to exception handler data.
204 ArchSaveExceptionContext (
205 IN UINTN ExceptionType
,
206 IN EFI_SYSTEM_CONTEXT SystemContext
,
207 IN EXCEPTION_HANDLER_DATA
*ExceptionHandlerData
211 Restore CPU exception context when handling EFI_VECTOR_HANDOFF_HOOK_AFTER case.
213 @param[in] ExceptionType Exception type.
214 @param[in] SystemContext Pointer to EFI_SYSTEM_CONTEXT.
215 @param[in] ExceptionHandlerData Pointer to exception handler data.
218 ArchRestoreExceptionContext (
219 IN UINTN ExceptionType
,
220 IN EFI_SYSTEM_CONTEXT SystemContext
,
221 IN EXCEPTION_HANDLER_DATA
*ExceptionHandlerData
225 Fix up the vector number and function address in the vector code.
227 @param[in] NewVectorAddr New vector handler address.
228 @param[in] VectorNum Index of vector.
229 @param[in] OldVectorAddr Old vector handler address.
235 IN VOID
*NewVectorAddr
,
237 IN VOID
*OldVectorAddr
241 Read and save reserved vector information
243 @param[in] VectorInfo Pointer to reserved vector list.
244 @param[out] ReservedVector Pointer to reserved vector data buffer.
245 @param[in] VectorCount Vector number to be updated.
247 @return EFI_SUCCESS Read and save vector info successfully.
248 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.
252 ReadAndVerifyVectorInfo (
253 IN EFI_VECTOR_HANDOFF_INFO
*VectorInfo
,
254 OUT RESERVED_VECTORS_DATA
*ReservedVector
,
259 Get ASCII format string exception name by exception type.
261 @param ExceptionType Exception type.
263 @return ASCII format string exception name.
266 GetExceptionNameStr (
267 IN EFI_EXCEPTION_TYPE ExceptionType
271 Internal worker function for common exception handler.
273 @param ExceptionType Exception type.
274 @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.
275 @param ExceptionHandlerData Pointer to exception handler data.
278 CommonExceptionHandlerWorker (
279 IN EFI_EXCEPTION_TYPE ExceptionType
,
280 IN EFI_SYSTEM_CONTEXT SystemContext
,
281 IN EXCEPTION_HANDLER_DATA
*ExceptionHandlerData