]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h
UefiCpuPkg: Convert all .uni files to utf-8
[mirror_edk2.git] / UefiCpuPkg / Library / CpuExceptionHandlerLib / CpuExceptionCommon.h
index fa245e2ac8a4044a12dff6b4498c221ef296938c..b28e9c574a65ec4a06ed24d9c1729f4b0b795e64 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Common header file for CPU Exception Handler Library.\r
 \r
-  Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2012 - 2015, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
 #ifndef _CPU_EXCEPTION_COMMON_H_\r
 #define _CPU_EXCEPTION_COMMON_H_\r
 \r
+#include <Ppi/VectorHandoffInfo.h>\r
+#include <Protocol/Cpu.h>\r
 #include <Library/BaseLib.h>\r
 #include <Library/SerialPortLib.h>\r
 #include <Library/PrintLib.h>\r
 #include <Library/LocalApicLib.h>\r
 #include <Library/PeCoffGetEntryPointLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/SynchronizationLib.h>\r
+\r
+#define  CPU_EXCEPTION_NUM          32\r
+#define  CPU_INTERRUPT_NUM         256\r
+#define  HOOKAFTER_STUB_SIZE        16\r
+\r
+#include "ArchInterruptDefs.h"\r
 \r
-#define  CPU_EXCEPTION_NUM     32\r
 //\r
 // Record exception handler information\r
 //\r
 typedef struct {\r
   UINTN ExceptionStart;\r
   UINTN ExceptionStubHeaderSize;\r
+  UINTN HookAfterStubHeaderStart;\r
 } EXCEPTION_HANDLER_TEMPLATE_MAP;\r
 \r
-extern UINT32           mErrorCodeFlag;\r
-extern CONST UINTN      mImageAlignSize;\r
+extern CONST UINT32                mErrorCodeFlag;\r
+extern CONST UINTN                 mImageAlignSize;\r
+extern CONST UINTN                 mDoFarReturnFlag;\r
+extern RESERVED_VECTORS_DATA       *mReservedVectors;\r
 \r
 /**\r
   Return address map of exception handler template so that C code can generate\r
@@ -41,17 +53,33 @@ extern CONST UINTN      mImageAlignSize;
 **/\r
 VOID\r
 EFIAPI\r
-GetTemplateAddressMap (\r
+AsmGetTemplateAddressMap (\r
   OUT EXCEPTION_HANDLER_TEMPLATE_MAP *AddressMap\r
   );\r
 \r
 /**\r
-  Internal function to setup CPU exception handlers.\r
+  Return address map of exception handler template so that C code can generate\r
+  exception tables.\r
+\r
+  @param IdtEntry          Pointer to IDT entry to be updated.\r
+  @param InterruptHandler  IDT handler value.\r
 \r
 **/\r
 VOID\r
-InternalSetupCpuExceptionHandlers (\r
-  VOID\r
+ArchUpdateIdtEntry (\r
+  IN IA32_IDT_GATE_DESCRIPTOR        *IdtEntry,\r
+  IN UINTN                           InterruptHandler\r
+  );\r
+\r
+/**\r
+  Read IDT handler value from IDT entry.\r
+\r
+  @param IdtEntry          Pointer to IDT entry to be read.\r
+\r
+**/\r
+UINTN\r
+ArchGetIdtHandler (\r
+  IN IA32_IDT_GATE_DESCRIPTOR        *IdtEntry\r
   );\r
 \r
 /**\r
@@ -72,8 +100,11 @@ InternalPrintMessage (
 /**\r
   Find and display image base address and return image base and its entry point.\r
   \r
-  @return EFI_SUCCESS     Image base address.\r
-  @return 0               Image header cannot be found.\r
+  @param CurrentEip      Current instruction pointer.\r
+  @param EntryPoint      Return module entry point if module header is found.\r
+  \r
+  @return !0     Image base address.\r
+  @return 0      Image header cannot be found.\r
 **/\r
 UINTN \r
 FindModuleImageBase (\r
@@ -84,13 +115,139 @@ FindModuleImageBase (
 /**\r
   Display CPU information.\r
 \r
-  @param InterruptType  Exception type.\r
+  @param ExceptionType  Exception type.\r
   @param SystemContext  Pointer to EFI_SYSTEM_CONTEXT.\r
 **/\r
 VOID\r
 DumpCpuContent (\r
-  IN UINTN                InterruptType,\r
+  IN EFI_EXCEPTION_TYPE   ExceptionType,\r
   IN EFI_SYSTEM_CONTEXT   SystemContext\r
   );\r
 \r
+/**\r
+  Internal worker function to initialize exception handler.\r
+\r
+  @param[in]  VectorInfo    Pointer to reserved vector list.\r
+  \r
+  @retval EFI_SUCCESS           CPU Exception Entries have been successfully initialized \r
+                                with default exception handlers.\r
+  @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.\r
+  @retval EFI_UNSUPPORTED       This function is not supported.\r
+\r
+**/\r
+EFI_STATUS\r
+InitializeCpuExceptionHandlersWorker (\r
+  IN EFI_VECTOR_HANDOFF_INFO       *VectorInfo OPTIONAL\r
+  );\r
+\r
+/**\r
+  Registers a function to be called from the processor interrupt handler.\r
+\r
+  @param[in]  InterruptType     Defines which interrupt or exception to hook.\r
+  @param[in]  InterruptHandler  A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called\r
+                                when a processor interrupt occurs. If this parameter is NULL, then the handler\r
+                                will be uninstalled.\r
+\r
+  @retval EFI_SUCCESS           The handler for the processor interrupt was successfully installed or uninstalled.\r
+  @retval EFI_ALREADY_STARTED   InterruptHandler is not NULL, and a handler for InterruptType was\r
+                                previously installed.\r
+  @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for InterruptType was not\r
+                                previously installed.\r
+  @retval EFI_UNSUPPORTED       The interrupt specified by InterruptType is not supported,\r
+                                or this function is not supported.\r
+**/\r
+EFI_STATUS\r
+RegisterCpuInterruptHandlerWorker (\r
+  IN EFI_EXCEPTION_TYPE            InterruptType,\r
+  IN EFI_CPU_INTERRUPT_HANDLER     InterruptHandler\r
+  );\r
+\r
+/**\r
+  Internal worker function to update IDT entries accordling to vector attributes.\r
+\r
+  @param[in] IdtTable       Pointer to IDT table.\r
+  @param[in] TemplateMap    Pointer to a buffer where the address map is returned.\r
+  @param[in] IdtEntryCount  IDT entries number to be updated.\r
+\r
+**/\r
+VOID\r
+UpdateIdtTable (\r
+  IN IA32_IDT_GATE_DESCRIPTOR        *IdtTable,\r
+  IN EXCEPTION_HANDLER_TEMPLATE_MAP  *TemplateMap,\r
+  IN UINTN                           IdtEntryCount\r
+  );\r
+\r
+/**\r
+  Save CPU exception context when handling EFI_VECTOR_HANDOFF_HOOK_AFTER case.\r
+\r
+  @param[in] ExceptionType  Exception type.\r
+  @param[in] SystemContext  Pointer to EFI_SYSTEM_CONTEXT.\r
+\r
+**/\r
+VOID\r
+ArchSaveExceptionContext (\r
+  IN UINTN                ExceptionType,\r
+  IN EFI_SYSTEM_CONTEXT   SystemContext \r
+  );\r
+\r
+/**\r
+  Restore CPU exception context when handling EFI_VECTOR_HANDOFF_HOOK_AFTER case.\r
+\r
+  @param[in] ExceptionType  Exception type.\r
+  @param[in] SystemContext  Pointer to EFI_SYSTEM_CONTEXT.\r
+\r
+**/\r
+VOID\r
+ArchRestoreExceptionContext (\r
+  IN UINTN                ExceptionType,\r
+  IN EFI_SYSTEM_CONTEXT   SystemContext \r
+  );\r
+\r
+/**\r
+  Fix up the vector number and function address in the vector code.\r
\r
+  @param[in] NewVectorAddr   New vector handler address.\r
+  @param[in] VectorNum       Index of vector.\r
+  @param[in] OldVectorAddr   Old vector handler address.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+AsmVectorNumFixup (\r
+  IN VOID    *NewVectorAddr,\r
+  IN UINT8   VectorNum,\r
+  IN VOID    *OldVectorAddr\r
+  );\r
+\r
+/**\r
+  Read and save reserved vector information\r
+  \r
+  @param[in]  VectorInfo        Pointer to reserved vector list.\r
+  @param[out] ReservedVector    Pointer to reserved vector data buffer.\r
+  @param[in]  VectorCount       Vector number to be updated.\r
+  \r
+  @return EFI_SUCCESS           Read and save vector info successfully.\r
+  @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.\r
+\r
+**/\r
+EFI_STATUS\r
+ReadAndVerifyVectorInfo (\r
+  IN  EFI_VECTOR_HANDOFF_INFO       *VectorInfo,\r
+  OUT RESERVED_VECTORS_DATA         *ReservedVector,\r
+  IN  UINTN                         VectorCount\r
+  );\r
+\r
+/**\r
+  Get ASCII format string exception name by exception type.\r
+\r
+  @param ExceptionType  Exception type.\r
+\r
+  @return  ASCII format string exception name.\r
+**/\r
+CONST CHAR8 *\r
+GetExceptionNameStr (\r
+  IN EFI_EXCEPTION_TYPE          ExceptionType\r
+  );\r
+\r
 #endif\r
+\r