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
;
58 extern RESERVED_VECTORS_DATA
*mReservedVectors
;
61 Return address map of exception handler template so that C code can generate
64 @param AddressMap Pointer to a buffer where the address map is returned.
68 AsmGetTemplateAddressMap (
69 OUT EXCEPTION_HANDLER_TEMPLATE_MAP
*AddressMap
73 Return address map of exception handler template so that C code can generate
76 @param IdtEntry Pointer to IDT entry to be updated.
77 @param InterruptHandler IDT handler value.
82 IN IA32_IDT_GATE_DESCRIPTOR
*IdtEntry
,
83 IN UINTN InterruptHandler
87 Read IDT handler value from IDT entry.
89 @param IdtEntry Pointer to IDT entry to be read.
94 IN IA32_IDT_GATE_DESCRIPTOR
*IdtEntry
98 Prints a message to the serial port.
100 @param Format Format string for the message to print.
101 @param ... Variable argument list whose contents are accessed
102 based on the format string specified by Format.
107 InternalPrintMessage (
108 IN CONST CHAR8
*Format
,
113 Find and display image base address and return image base and its entry point.
115 @param CurrentEip Current instruction pointer.
116 @param EntryPoint Return module entry point if module header is found.
118 @return !0 Image base address.
119 @return 0 Image header cannot be found.
122 FindModuleImageBase (
124 OUT UINTN
*EntryPoint
128 Display CPU information.
130 @param ExceptionType Exception type.
131 @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.
135 IN EFI_EXCEPTION_TYPE ExceptionType
,
136 IN EFI_SYSTEM_CONTEXT SystemContext
140 Internal worker function to initialize exception handler.
142 @param[in] VectorInfo Pointer to reserved vector list.
143 @param[in, out] ExceptionHandlerData Pointer to exception handler data.
145 @retval EFI_SUCCESS CPU Exception Entries have been successfully initialized
146 with default exception handlers.
147 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.
148 @retval EFI_UNSUPPORTED This function is not supported.
152 InitializeCpuExceptionHandlersWorker (
153 IN EFI_VECTOR_HANDOFF_INFO
*VectorInfo OPTIONAL
,
154 IN OUT EXCEPTION_HANDLER_DATA
*ExceptionHandlerData
158 Registers a function to be called from the processor interrupt handler.
160 @param[in] InterruptType Defines which interrupt or exception to hook.
161 @param[in] InterruptHandler A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called
162 when a processor interrupt occurs. If this parameter is NULL, then the handler
164 @param[in] ExceptionHandlerData Pointer to exception handler data.
166 @retval EFI_SUCCESS The handler for the processor interrupt was successfully installed or uninstalled.
167 @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler for InterruptType was
168 previously installed.
169 @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for InterruptType was not
170 previously installed.
171 @retval EFI_UNSUPPORTED The interrupt specified by InterruptType is not supported,
172 or this function is not supported.
175 RegisterCpuInterruptHandlerWorker (
176 IN EFI_EXCEPTION_TYPE InterruptType
,
177 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
,
178 IN EXCEPTION_HANDLER_DATA
*ExceptionHandlerData
182 Internal worker function to update IDT entries accordling to vector attributes.
184 @param[in] IdtTable Pointer to IDT table.
185 @param[in] TemplateMap Pointer to a buffer where the address map is
187 @param[in] ExceptionHandlerData Pointer to exception handler data.
192 IN IA32_IDT_GATE_DESCRIPTOR
*IdtTable
,
193 IN EXCEPTION_HANDLER_TEMPLATE_MAP
*TemplateMap
,
194 IN EXCEPTION_HANDLER_DATA
*ExceptionHandlerData
198 Save CPU exception context when handling EFI_VECTOR_HANDOFF_HOOK_AFTER case.
200 @param[in] ExceptionType Exception type.
201 @param[in] SystemContext Pointer to EFI_SYSTEM_CONTEXT.
205 ArchSaveExceptionContext (
206 IN UINTN ExceptionType
,
207 IN EFI_SYSTEM_CONTEXT SystemContext
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.
218 ArchRestoreExceptionContext (
219 IN UINTN ExceptionType
,
220 IN EFI_SYSTEM_CONTEXT SystemContext
224 Fix up the vector number and function address in the vector code.
226 @param[in] NewVectorAddr New vector handler address.
227 @param[in] VectorNum Index of vector.
228 @param[in] OldVectorAddr Old vector handler address.
234 IN VOID
*NewVectorAddr
,
236 IN VOID
*OldVectorAddr
240 Read and save reserved vector information
242 @param[in] VectorInfo Pointer to reserved vector list.
243 @param[out] ReservedVector Pointer to reserved vector data buffer.
244 @param[in] VectorCount Vector number to be updated.
246 @return EFI_SUCCESS Read and save vector info successfully.
247 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.
251 ReadAndVerifyVectorInfo (
252 IN EFI_VECTOR_HANDOFF_INFO
*VectorInfo
,
253 OUT RESERVED_VECTORS_DATA
*ReservedVector
,
258 Get ASCII format string exception name by exception type.
260 @param ExceptionType Exception type.
262 @return ASCII format string exception name.
265 GetExceptionNameStr (
266 IN EFI_EXCEPTION_TYPE ExceptionType
270 Internal worker function for common exception handler.
272 @param ExceptionType Exception type.
273 @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.
274 @param ExceptionHandlerData Pointer to exception handler data.
277 CommonExceptionHandlerWorker (
278 IN EFI_EXCEPTION_TYPE ExceptionType
,
279 IN EFI_SYSTEM_CONTEXT SystemContext
,
280 IN EXCEPTION_HANDLER_DATA
*ExceptionHandlerData