2012-03-15 06:24:07 +01:00
|
|
|
/** @file
|
|
|
|
Common header file for CPU Exception Handler Library.
|
|
|
|
|
2016-05-24 14:21:04 +02:00
|
|
|
Copyright (c) 2012 - 2016, Intel Corporation. All rights reserved.<BR>
|
2012-03-15 06:24:07 +01:00
|
|
|
This program and the accompanying materials
|
|
|
|
are licensed and made available under the terms and conditions of the BSD License
|
|
|
|
which accompanies this distribution. The full text of the license may be found at
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
#ifndef _CPU_EXCEPTION_COMMON_H_
|
|
|
|
#define _CPU_EXCEPTION_COMMON_H_
|
|
|
|
|
2013-11-22 07:24:41 +01:00
|
|
|
#include <Ppi/VectorHandoffInfo.h>
|
|
|
|
#include <Protocol/Cpu.h>
|
2012-03-15 06:24:07 +01:00
|
|
|
#include <Library/BaseLib.h>
|
|
|
|
#include <Library/SerialPortLib.h>
|
|
|
|
#include <Library/PrintLib.h>
|
|
|
|
#include <Library/LocalApicLib.h>
|
|
|
|
#include <Library/PeCoffGetEntryPointLib.h>
|
2013-11-22 07:24:41 +01:00
|
|
|
#include <Library/BaseMemoryLib.h>
|
|
|
|
#include <Library/SynchronizationLib.h>
|
|
|
|
|
|
|
|
#define CPU_EXCEPTION_NUM 32
|
|
|
|
#define CPU_INTERRUPT_NUM 256
|
|
|
|
#define HOOKAFTER_STUB_SIZE 16
|
|
|
|
|
|
|
|
#include "ArchInterruptDefs.h"
|
2012-03-15 06:24:07 +01:00
|
|
|
|
2016-05-24 15:39:35 +02:00
|
|
|
#define CPU_EXCEPTION_HANDLER_LIB_HOB_GUID \
|
|
|
|
{ \
|
|
|
|
0xb21d9148, 0x9211, 0x4d8f, { 0xad, 0xd3, 0x66, 0xb1, 0x89, 0xc9, 0x2c, 0x83 } \
|
|
|
|
}
|
|
|
|
|
2012-03-15 06:24:07 +01:00
|
|
|
//
|
|
|
|
// Record exception handler information
|
|
|
|
//
|
|
|
|
typedef struct {
|
|
|
|
UINTN ExceptionStart;
|
|
|
|
UINTN ExceptionStubHeaderSize;
|
2013-11-22 07:24:41 +01:00
|
|
|
UINTN HookAfterStubHeaderStart;
|
2012-03-15 06:24:07 +01:00
|
|
|
} EXCEPTION_HANDLER_TEMPLATE_MAP;
|
|
|
|
|
2016-05-24 14:21:04 +02:00
|
|
|
typedef struct {
|
|
|
|
UINTN IdtEntryCount;
|
|
|
|
SPIN_LOCK DisplayMessageSpinLock;
|
|
|
|
RESERVED_VECTORS_DATA *ReservedVectors;
|
|
|
|
EFI_CPU_INTERRUPT_HANDLER *ExternalInterruptHandler;
|
|
|
|
} EXCEPTION_HANDLER_DATA;
|
|
|
|
|
2013-11-22 07:24:41 +01:00
|
|
|
extern CONST UINT32 mErrorCodeFlag;
|
|
|
|
extern CONST UINTN mImageAlignSize;
|
|
|
|
extern CONST UINTN mDoFarReturnFlag;
|
|
|
|
extern RESERVED_VECTORS_DATA *mReservedVectors;
|
2012-03-15 06:24:07 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
Return address map of exception handler template so that C code can generate
|
|
|
|
exception tables.
|
|
|
|
|
|
|
|
@param AddressMap Pointer to a buffer where the address map is returned.
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
EFIAPI
|
2013-11-22 07:24:41 +01:00
|
|
|
AsmGetTemplateAddressMap (
|
2012-03-15 06:24:07 +01:00
|
|
|
OUT EXCEPTION_HANDLER_TEMPLATE_MAP *AddressMap
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
2013-11-22 07:24:41 +01:00
|
|
|
Return address map of exception handler template so that C code can generate
|
|
|
|
exception tables.
|
|
|
|
|
|
|
|
@param IdtEntry Pointer to IDT entry to be updated.
|
|
|
|
@param InterruptHandler IDT handler value.
|
2012-03-15 06:24:07 +01:00
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
2013-11-22 07:24:41 +01:00
|
|
|
ArchUpdateIdtEntry (
|
|
|
|
IN IA32_IDT_GATE_DESCRIPTOR *IdtEntry,
|
|
|
|
IN UINTN InterruptHandler
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Read IDT handler value from IDT entry.
|
|
|
|
|
|
|
|
@param IdtEntry Pointer to IDT entry to be read.
|
|
|
|
|
|
|
|
**/
|
|
|
|
UINTN
|
|
|
|
ArchGetIdtHandler (
|
|
|
|
IN IA32_IDT_GATE_DESCRIPTOR *IdtEntry
|
2012-03-15 06:24:07 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Prints a message to the serial port.
|
|
|
|
|
|
|
|
@param Format Format string for the message to print.
|
|
|
|
@param ... Variable argument list whose contents are accessed
|
|
|
|
based on the format string specified by Format.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
EFIAPI
|
|
|
|
InternalPrintMessage (
|
|
|
|
IN CONST CHAR8 *Format,
|
|
|
|
...
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Find and display image base address and return image base and its entry point.
|
|
|
|
|
2012-03-19 09:58:57 +01:00
|
|
|
@param CurrentEip Current instruction pointer.
|
|
|
|
@param EntryPoint Return module entry point if module header is found.
|
|
|
|
|
|
|
|
@return !0 Image base address.
|
|
|
|
@return 0 Image header cannot be found.
|
2012-03-15 06:24:07 +01:00
|
|
|
**/
|
|
|
|
UINTN
|
|
|
|
FindModuleImageBase (
|
|
|
|
IN UINTN CurrentEip,
|
|
|
|
OUT UINTN *EntryPoint
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Display CPU information.
|
|
|
|
|
2013-12-06 02:13:11 +01:00
|
|
|
@param ExceptionType Exception type.
|
2012-03-15 06:24:07 +01:00
|
|
|
@param SystemContext Pointer to EFI_SYSTEM_CONTEXT.
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
DumpCpuContent (
|
2013-11-22 07:24:41 +01:00
|
|
|
IN EFI_EXCEPTION_TYPE ExceptionType,
|
2012-03-15 06:24:07 +01:00
|
|
|
IN EFI_SYSTEM_CONTEXT SystemContext
|
|
|
|
);
|
|
|
|
|
2013-11-22 07:24:41 +01:00
|
|
|
/**
|
|
|
|
Internal worker function to initialize exception handler.
|
|
|
|
|
2016-05-24 15:00:02 +02:00
|
|
|
@param[in] VectorInfo Pointer to reserved vector list.
|
|
|
|
@param[in, out] ExceptionHandlerData Pointer to exception handler data.
|
2013-11-22 07:24:41 +01:00
|
|
|
|
|
|
|
@retval EFI_SUCCESS CPU Exception Entries have been successfully initialized
|
|
|
|
with default exception handlers.
|
|
|
|
@retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.
|
|
|
|
@retval EFI_UNSUPPORTED This function is not supported.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
InitializeCpuExceptionHandlersWorker (
|
2016-05-24 15:00:02 +02:00
|
|
|
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,
|
|
|
|
IN OUT EXCEPTION_HANDLER_DATA *ExceptionHandlerData
|
2013-11-22 07:24:41 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Registers a function to be called from the processor interrupt handler.
|
|
|
|
|
2016-05-24 15:25:17 +02:00
|
|
|
@param[in] InterruptType Defines which interrupt or exception to hook.
|
|
|
|
@param[in] InterruptHandler A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called
|
|
|
|
when a processor interrupt occurs. If this parameter is NULL, then the handler
|
|
|
|
will be uninstalled
|
|
|
|
@param[in] ExceptionHandlerData Pointer to exception handler data.
|
2013-11-22 07:24:41 +01:00
|
|
|
|
|
|
|
@retval EFI_SUCCESS The handler for the processor interrupt was successfully installed or uninstalled.
|
|
|
|
@retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler for InterruptType was
|
|
|
|
previously installed.
|
|
|
|
@retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for InterruptType was not
|
|
|
|
previously installed.
|
|
|
|
@retval EFI_UNSUPPORTED The interrupt specified by InterruptType is not supported,
|
|
|
|
or this function is not supported.
|
2013-12-06 02:13:11 +01:00
|
|
|
**/
|
2013-11-22 07:24:41 +01:00
|
|
|
EFI_STATUS
|
|
|
|
RegisterCpuInterruptHandlerWorker (
|
|
|
|
IN EFI_EXCEPTION_TYPE InterruptType,
|
2016-05-24 15:25:17 +02:00
|
|
|
IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler,
|
|
|
|
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
|
2013-11-22 07:24:41 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Internal worker function to update IDT entries accordling to vector attributes.
|
|
|
|
|
2016-05-24 15:09:22 +02:00
|
|
|
@param[in] IdtTable Pointer to IDT table.
|
|
|
|
@param[in] TemplateMap Pointer to a buffer where the address map is
|
|
|
|
returned.
|
|
|
|
@param[in] ExceptionHandlerData Pointer to exception handler data.
|
2013-11-22 07:24:41 +01:00
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
UpdateIdtTable (
|
|
|
|
IN IA32_IDT_GATE_DESCRIPTOR *IdtTable,
|
|
|
|
IN EXCEPTION_HANDLER_TEMPLATE_MAP *TemplateMap,
|
2016-05-24 15:09:22 +02:00
|
|
|
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
|
2013-11-22 07:24:41 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Save CPU exception context when handling EFI_VECTOR_HANDOFF_HOOK_AFTER case.
|
|
|
|
|
|
|
|
@param[in] ExceptionType Exception type.
|
|
|
|
@param[in] SystemContext Pointer to EFI_SYSTEM_CONTEXT.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
ArchSaveExceptionContext (
|
|
|
|
IN UINTN ExceptionType,
|
|
|
|
IN EFI_SYSTEM_CONTEXT SystemContext
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Restore CPU exception context when handling EFI_VECTOR_HANDOFF_HOOK_AFTER case.
|
|
|
|
|
|
|
|
@param[in] ExceptionType Exception type.
|
|
|
|
@param[in] SystemContext Pointer to EFI_SYSTEM_CONTEXT.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
ArchRestoreExceptionContext (
|
|
|
|
IN UINTN ExceptionType,
|
|
|
|
IN EFI_SYSTEM_CONTEXT SystemContext
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
2014-09-09 08:50:51 +02:00
|
|
|
Fix up the vector number and function address in the vector code.
|
2013-11-22 07:24:41 +01:00
|
|
|
|
2014-09-09 08:50:51 +02:00
|
|
|
@param[in] NewVectorAddr New vector handler address.
|
|
|
|
@param[in] VectorNum Index of vector.
|
|
|
|
@param[in] OldVectorAddr Old vector handler address.
|
2013-11-22 07:24:41 +01:00
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
EFIAPI
|
|
|
|
AsmVectorNumFixup (
|
2014-09-09 08:50:51 +02:00
|
|
|
IN VOID *NewVectorAddr,
|
|
|
|
IN UINT8 VectorNum,
|
|
|
|
IN VOID *OldVectorAddr
|
2013-11-22 07:24:41 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Read and save reserved vector information
|
|
|
|
|
|
|
|
@param[in] VectorInfo Pointer to reserved vector list.
|
|
|
|
@param[out] ReservedVector Pointer to reserved vector data buffer.
|
|
|
|
@param[in] VectorCount Vector number to be updated.
|
|
|
|
|
|
|
|
@return EFI_SUCCESS Read and save vector info successfully.
|
|
|
|
@retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
ReadAndVerifyVectorInfo (
|
|
|
|
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo,
|
|
|
|
OUT RESERVED_VECTORS_DATA *ReservedVector,
|
|
|
|
IN UINTN VectorCount
|
|
|
|
);
|
|
|
|
|
2015-07-08 07:45:10 +02:00
|
|
|
/**
|
|
|
|
Get ASCII format string exception name by exception type.
|
|
|
|
|
|
|
|
@param ExceptionType Exception type.
|
|
|
|
|
|
|
|
@return ASCII format string exception name.
|
|
|
|
**/
|
|
|
|
CONST CHAR8 *
|
|
|
|
GetExceptionNameStr (
|
|
|
|
IN EFI_EXCEPTION_TYPE ExceptionType
|
|
|
|
);
|
|
|
|
|
2016-05-24 15:31:11 +02:00
|
|
|
/**
|
|
|
|
Internal worker function for common exception handler.
|
|
|
|
|
|
|
|
@param ExceptionType Exception type.
|
|
|
|
@param SystemContext Pointer to EFI_SYSTEM_CONTEXT.
|
|
|
|
@param ExceptionHandlerData Pointer to exception handler data.
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
CommonExceptionHandlerWorker (
|
|
|
|
IN EFI_EXCEPTION_TYPE ExceptionType,
|
|
|
|
IN EFI_SYSTEM_CONTEXT SystemContext,
|
|
|
|
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
|
|
|
|
);
|
|
|
|
|
2012-03-15 06:24:07 +01:00
|
|
|
#endif
|
2013-11-22 07:24:41 +01:00
|
|
|
|