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/ReportStatusCodeLib.h>
26 #include <Library/BaseMemoryLib.h>
27 #include <Library/SynchronizationLib.h>
29 #define CPU_EXCEPTION_NUM 32
30 #define CPU_INTERRUPT_NUM 256
31 #define HOOKAFTER_STUB_SIZE 16
33 #include "ArchInterruptDefs.h"
36 // Record exception handler information
40 UINTN ExceptionStubHeaderSize
;
41 UINTN HookAfterStubHeaderStart
;
42 } EXCEPTION_HANDLER_TEMPLATE_MAP
;
44 extern CONST UINT32 mErrorCodeFlag
;
45 extern CONST UINTN mImageAlignSize
;
46 extern CONST UINTN mDoFarReturnFlag
;
47 extern RESERVED_VECTORS_DATA
*mReservedVectors
;
50 Return address map of exception handler template so that C code can generate
53 @param AddressMap Pointer to a buffer where the address map is returned.
57 AsmGetTemplateAddressMap (
58 OUT EXCEPTION_HANDLER_TEMPLATE_MAP
*AddressMap
62 Return address map of exception handler template so that C code can generate
65 @param IdtEntry Pointer to IDT entry to be updated.
66 @param InterruptHandler IDT handler value.
71 IN IA32_IDT_GATE_DESCRIPTOR
*IdtEntry
,
72 IN UINTN InterruptHandler
76 Read IDT handler value from IDT entry.
78 @param IdtEntry Pointer to IDT entry to be read.
83 IN IA32_IDT_GATE_DESCRIPTOR
*IdtEntry
87 Prints a message to the serial port.
89 @param Format Format string for the message to print.
90 @param ... Variable argument list whose contents are accessed
91 based on the format string specified by Format.
96 InternalPrintMessage (
97 IN CONST CHAR8
*Format
,
102 Find and display image base address and return image base and its entry point.
104 @param CurrentEip Current instruction pointer.
105 @param EntryPoint Return module entry point if module header is found.
107 @return !0 Image base address.
108 @return 0 Image header cannot be found.
111 FindModuleImageBase (
113 OUT UINTN
*EntryPoint
117 Display CPU information.
119 @param InterruptType Exception type.
120 @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.
124 IN EFI_EXCEPTION_TYPE ExceptionType
,
125 IN EFI_SYSTEM_CONTEXT SystemContext
129 Internal worker function to initialize exception handler.
131 @param[in] VectorInfo Pointer to reserved vector list.
133 @retval EFI_SUCCESS CPU Exception Entries have been successfully initialized
134 with default exception handlers.
135 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.
136 @retval EFI_UNSUPPORTED This function is not supported.
140 InitializeCpuExceptionHandlersWorker (
141 IN EFI_VECTOR_HANDOFF_INFO
*VectorInfo OPTIONAL
145 Registers a function to be called from the processor interrupt handler.
147 @param[in] InterruptType Defines which interrupt or exception to hook.
148 @param[in] InterruptHandler A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called
149 when a processor interrupt occurs. If this parameter is NULL, then the handler
152 @retval EFI_SUCCESS The handler for the processor interrupt was successfully installed or uninstalled.
153 @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler for InterruptType was
154 previously installed.
155 @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for InterruptType was not
156 previously installed.
157 @retval EFI_UNSUPPORTED The interrupt specified by InterruptType is not supported,
158 or this function is not supported.
161 RegisterCpuInterruptHandlerWorker (
162 IN EFI_EXCEPTION_TYPE InterruptType
,
163 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
167 Internal worker function to update IDT entries accordling to vector attributes.
169 @param[in] IdtTable Pointer to IDT table.
170 @param[in] TemplateMap Pointer to a buffer where the address map is returned.
171 @param[in] IdtEntryCount IDT entries number to be updated.
176 IN IA32_IDT_GATE_DESCRIPTOR
*IdtTable
,
177 IN EXCEPTION_HANDLER_TEMPLATE_MAP
*TemplateMap
,
178 IN UINTN IdtEntryCount
182 Save CPU exception context when handling EFI_VECTOR_HANDOFF_HOOK_AFTER case.
184 @param[in] ExceptionType Exception type.
185 @param[in] SystemContext Pointer to EFI_SYSTEM_CONTEXT.
189 ArchSaveExceptionContext (
190 IN UINTN ExceptionType
,
191 IN EFI_SYSTEM_CONTEXT SystemContext
195 Restore CPU exception context when handling EFI_VECTOR_HANDOFF_HOOK_AFTER case.
197 @param[in] ExceptionType Exception type.
198 @param[in] SystemContext Pointer to EFI_SYSTEM_CONTEXT.
202 ArchRestoreExceptionContext (
203 IN UINTN ExceptionType
,
204 IN EFI_SYSTEM_CONTEXT SystemContext
208 Fix up the vector number in the vector code.
210 @param[in] VectorBase Base address of the vector handler.
211 @param[in] VectorNum Index of vector.
222 Read and save reserved vector information
224 @param[in] VectorInfo Pointer to reserved vector list.
225 @param[out] ReservedVector Pointer to reserved vector data buffer.
226 @param[in] VectorCount Vector number to be updated.
228 @return EFI_SUCCESS Read and save vector info successfully.
229 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.
233 ReadAndVerifyVectorInfo (
234 IN EFI_VECTOR_HANDOFF_INFO
*VectorInfo
,
235 OUT RESERVED_VECTORS_DATA
*ReservedVector
,