2 Common header file for CPU Exception Handler Library.
4 Copyright (c) 2012 - 2013, 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
;
43 extern CONST UINT32 mErrorCodeFlag
;
44 extern CONST UINTN mImageAlignSize
;
45 extern CONST UINTN mDoFarReturnFlag
;
46 extern RESERVED_VECTORS_DATA
*mReservedVectors
;
49 Return address map of exception handler template so that C code can generate
52 @param AddressMap Pointer to a buffer where the address map is returned.
56 AsmGetTemplateAddressMap (
57 OUT EXCEPTION_HANDLER_TEMPLATE_MAP
*AddressMap
61 Return address map of exception handler template so that C code can generate
64 @param IdtEntry Pointer to IDT entry to be updated.
65 @param InterruptHandler IDT handler value.
70 IN IA32_IDT_GATE_DESCRIPTOR
*IdtEntry
,
71 IN UINTN InterruptHandler
75 Read IDT handler value from IDT entry.
77 @param IdtEntry Pointer to IDT entry to be read.
82 IN IA32_IDT_GATE_DESCRIPTOR
*IdtEntry
86 Prints a message to the serial port.
88 @param Format Format string for the message to print.
89 @param ... Variable argument list whose contents are accessed
90 based on the format string specified by Format.
95 InternalPrintMessage (
96 IN CONST CHAR8
*Format
,
101 Find and display image base address and return image base and its entry point.
103 @param CurrentEip Current instruction pointer.
104 @param EntryPoint Return module entry point if module header is found.
106 @return !0 Image base address.
107 @return 0 Image header cannot be found.
110 FindModuleImageBase (
112 OUT UINTN
*EntryPoint
116 Display CPU information.
118 @param ExceptionType Exception type.
119 @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.
123 IN EFI_EXCEPTION_TYPE ExceptionType
,
124 IN EFI_SYSTEM_CONTEXT SystemContext
128 Internal worker function to initialize exception handler.
130 @param[in] VectorInfo Pointer to reserved vector list.
132 @retval EFI_SUCCESS CPU Exception Entries have been successfully initialized
133 with default exception handlers.
134 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.
135 @retval EFI_UNSUPPORTED This function is not supported.
139 InitializeCpuExceptionHandlersWorker (
140 IN EFI_VECTOR_HANDOFF_INFO
*VectorInfo OPTIONAL
144 Registers a function to be called from the processor interrupt handler.
146 @param[in] InterruptType Defines which interrupt or exception to hook.
147 @param[in] InterruptHandler A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called
148 when a processor interrupt occurs. If this parameter is NULL, then the handler
151 @retval EFI_SUCCESS The handler for the processor interrupt was successfully installed or uninstalled.
152 @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler for InterruptType was
153 previously installed.
154 @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for InterruptType was not
155 previously installed.
156 @retval EFI_UNSUPPORTED The interrupt specified by InterruptType is not supported,
157 or this function is not supported.
160 RegisterCpuInterruptHandlerWorker (
161 IN EFI_EXCEPTION_TYPE InterruptType
,
162 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
166 Internal worker function to update IDT entries accordling to vector attributes.
168 @param[in] IdtTable Pointer to IDT table.
169 @param[in] TemplateMap Pointer to a buffer where the address map is returned.
170 @param[in] IdtEntryCount IDT entries number to be updated.
175 IN IA32_IDT_GATE_DESCRIPTOR
*IdtTable
,
176 IN EXCEPTION_HANDLER_TEMPLATE_MAP
*TemplateMap
,
177 IN UINTN IdtEntryCount
181 Save CPU exception context when handling EFI_VECTOR_HANDOFF_HOOK_AFTER case.
183 @param[in] ExceptionType Exception type.
184 @param[in] SystemContext Pointer to EFI_SYSTEM_CONTEXT.
188 ArchSaveExceptionContext (
189 IN UINTN ExceptionType
,
190 IN EFI_SYSTEM_CONTEXT SystemContext
194 Restore CPU exception context when handling EFI_VECTOR_HANDOFF_HOOK_AFTER case.
196 @param[in] ExceptionType Exception type.
197 @param[in] SystemContext Pointer to EFI_SYSTEM_CONTEXT.
201 ArchRestoreExceptionContext (
202 IN UINTN ExceptionType
,
203 IN EFI_SYSTEM_CONTEXT SystemContext
207 Fix up the vector number and function address in the vector code.
209 @param[in] NewVectorAddr New vector handler address.
210 @param[in] VectorNum Index of vector.
211 @param[in] OldVectorAddr Old vector handler address.
217 IN VOID
*NewVectorAddr
,
219 IN VOID
*OldVectorAddr
223 Read and save reserved vector information
225 @param[in] VectorInfo Pointer to reserved vector list.
226 @param[out] ReservedVector Pointer to reserved vector data buffer.
227 @param[in] VectorCount Vector number to be updated.
229 @return EFI_SUCCESS Read and save vector info successfully.
230 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.
234 ReadAndVerifyVectorInfo (
235 IN EFI_VECTOR_HANDOFF_INFO
*VectorInfo
,
236 OUT RESERVED_VECTORS_DATA
*ReservedVector
,