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"
35 // Record exception handler information
39 UINTN ExceptionStubHeaderSize
;
40 UINTN HookAfterStubHeaderStart
;
41 } EXCEPTION_HANDLER_TEMPLATE_MAP
;
45 SPIN_LOCK DisplayMessageSpinLock
;
46 RESERVED_VECTORS_DATA
*ReservedVectors
;
47 EFI_CPU_INTERRUPT_HANDLER
*ExternalInterruptHandler
;
48 } EXCEPTION_HANDLER_DATA
;
50 extern CONST UINT32 mErrorCodeFlag
;
51 extern CONST UINTN mImageAlignSize
;
52 extern CONST UINTN mDoFarReturnFlag
;
53 extern RESERVED_VECTORS_DATA
*mReservedVectors
;
56 Return address map of exception handler template so that C code can generate
59 @param AddressMap Pointer to a buffer where the address map is returned.
63 AsmGetTemplateAddressMap (
64 OUT EXCEPTION_HANDLER_TEMPLATE_MAP
*AddressMap
68 Return address map of exception handler template so that C code can generate
71 @param IdtEntry Pointer to IDT entry to be updated.
72 @param InterruptHandler IDT handler value.
77 IN IA32_IDT_GATE_DESCRIPTOR
*IdtEntry
,
78 IN UINTN InterruptHandler
82 Read IDT handler value from IDT entry.
84 @param IdtEntry Pointer to IDT entry to be read.
89 IN IA32_IDT_GATE_DESCRIPTOR
*IdtEntry
93 Prints a message to the serial port.
95 @param Format Format string for the message to print.
96 @param ... Variable argument list whose contents are accessed
97 based on the format string specified by Format.
102 InternalPrintMessage (
103 IN CONST CHAR8
*Format
,
108 Find and display image base address and return image base and its entry point.
110 @param CurrentEip Current instruction pointer.
111 @param EntryPoint Return module entry point if module header is found.
113 @return !0 Image base address.
114 @return 0 Image header cannot be found.
117 FindModuleImageBase (
119 OUT UINTN
*EntryPoint
123 Display CPU information.
125 @param ExceptionType Exception type.
126 @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.
130 IN EFI_EXCEPTION_TYPE ExceptionType
,
131 IN EFI_SYSTEM_CONTEXT SystemContext
135 Internal worker function to initialize exception handler.
137 @param[in] VectorInfo Pointer to reserved vector list.
138 @param[in, out] ExceptionHandlerData Pointer to exception handler data.
140 @retval EFI_SUCCESS CPU Exception Entries have been successfully initialized
141 with default exception handlers.
142 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.
143 @retval EFI_UNSUPPORTED This function is not supported.
147 InitializeCpuExceptionHandlersWorker (
148 IN EFI_VECTOR_HANDOFF_INFO
*VectorInfo OPTIONAL
,
149 IN OUT EXCEPTION_HANDLER_DATA
*ExceptionHandlerData
153 Registers a function to be called from the processor interrupt handler.
155 @param[in] InterruptType Defines which interrupt or exception to hook.
156 @param[in] InterruptHandler A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called
157 when a processor interrupt occurs. If this parameter is NULL, then the handler
159 @param[in] ExceptionHandlerData Pointer to exception handler data.
161 @retval EFI_SUCCESS The handler for the processor interrupt was successfully installed or uninstalled.
162 @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler for InterruptType was
163 previously installed.
164 @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for InterruptType was not
165 previously installed.
166 @retval EFI_UNSUPPORTED The interrupt specified by InterruptType is not supported,
167 or this function is not supported.
170 RegisterCpuInterruptHandlerWorker (
171 IN EFI_EXCEPTION_TYPE InterruptType
,
172 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
,
173 IN EXCEPTION_HANDLER_DATA
*ExceptionHandlerData
177 Internal worker function to update IDT entries accordling to vector attributes.
179 @param[in] IdtTable Pointer to IDT table.
180 @param[in] TemplateMap Pointer to a buffer where the address map is
182 @param[in] ExceptionHandlerData Pointer to exception handler data.
187 IN IA32_IDT_GATE_DESCRIPTOR
*IdtTable
,
188 IN EXCEPTION_HANDLER_TEMPLATE_MAP
*TemplateMap
,
189 IN EXCEPTION_HANDLER_DATA
*ExceptionHandlerData
193 Save CPU exception context when handling EFI_VECTOR_HANDOFF_HOOK_AFTER case.
195 @param[in] ExceptionType Exception type.
196 @param[in] SystemContext Pointer to EFI_SYSTEM_CONTEXT.
200 ArchSaveExceptionContext (
201 IN UINTN ExceptionType
,
202 IN EFI_SYSTEM_CONTEXT SystemContext
206 Restore CPU exception context when handling EFI_VECTOR_HANDOFF_HOOK_AFTER case.
208 @param[in] ExceptionType Exception type.
209 @param[in] SystemContext Pointer to EFI_SYSTEM_CONTEXT.
213 ArchRestoreExceptionContext (
214 IN UINTN ExceptionType
,
215 IN EFI_SYSTEM_CONTEXT SystemContext
219 Fix up the vector number and function address in the vector code.
221 @param[in] NewVectorAddr New vector handler address.
222 @param[in] VectorNum Index of vector.
223 @param[in] OldVectorAddr Old vector handler address.
229 IN VOID
*NewVectorAddr
,
231 IN VOID
*OldVectorAddr
235 Read and save reserved vector information
237 @param[in] VectorInfo Pointer to reserved vector list.
238 @param[out] ReservedVector Pointer to reserved vector data buffer.
239 @param[in] VectorCount Vector number to be updated.
241 @return EFI_SUCCESS Read and save vector info successfully.
242 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.
246 ReadAndVerifyVectorInfo (
247 IN EFI_VECTOR_HANDOFF_INFO
*VectorInfo
,
248 OUT RESERVED_VECTORS_DATA
*ReservedVector
,
253 Get ASCII format string exception name by exception type.
255 @param ExceptionType Exception type.
257 @return ASCII format string exception name.
260 GetExceptionNameStr (
261 IN EFI_EXCEPTION_TYPE ExceptionType