]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c
UefiCpuPkg: Convert all .uni files to utf-8
[mirror_edk2.git] / UefiCpuPkg / Library / CpuExceptionHandlerLib / CpuExceptionCommon.c
index 4a4925afe5669d1b1646c8972c3e724d7b895bc3..5d2816111fb9997dfb68819fa290272f6be9a066 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
-  CPU Exception Hanlder Library common functions.\r
+  CPU Exception Handler Library common functions.\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
 #include "CpuExceptionCommon.h"\r
 \r
 //\r
-// Error code flag indicating whether or not an error code will be \r
+// Error code flag indicating whether or not an error code will be\r
 // pushed on the stack if an exception occurs.\r
 //\r
 // 1 means an error code will be pushed, otherwise 0\r
 //\r
-UINT32 mErrorCodeFlag = 0x00027d00;\r
+CONST UINT32 mErrorCodeFlag             = 0x00027d00;\r
+RESERVED_VECTORS_DATA *mReservedVectors = NULL;\r
 \r
 //\r
-// Define the maximum message length \r
+// Define the maximum message length\r
 //\r
 #define MAX_DEBUG_MESSAGE_LENGTH  0x100\r
 \r
+CONST CHAR8 mExceptionReservedStr[] = "Reserved";\r
+CONST CHAR8 *mExceptionNameStr[] = {\r
+  "#DE - Divide Error",\r
+  "#DB - Debug",\r
+  "NMI Interrupt",\r
+  "#BP - Breakpoint",\r
+  "#OF - Overflow",\r
+  "#BR - BOUND Range Exceeded",\r
+  "#UD - Invalid Opcode",\r
+  "#NM - Device Not Available",\r
+  "#DF - Double Fault",\r
+  "Coprocessor Segment Overrun",\r
+  "#TS - Invalid TSS",\r
+  "#NP - Segment Not Present",\r
+  "#SS - Stack Fault Fault",\r
+  "#GP - General Protection",\r
+  "#PF - Page-Fault",\r
+  "Reserved",\r
+  "#MF - x87 FPU Floating-Point Error",\r
+  "#AC - Alignment Check",\r
+  "#MC - Machine-Check",\r
+  "#XM - SIMD floating-point",\r
+  "#VE - Virtualization"\r
+};\r
+\r
+#define EXCEPTION_KNOWN_NAME_NUM  (sizeof (mExceptionNameStr) / sizeof (CHAR8 *))\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
+  if ((UINTN) ExceptionType < EXCEPTION_KNOWN_NAME_NUM) {\r
+    return mExceptionNameStr[ExceptionType];\r
+  } else {\r
+    return mExceptionReservedStr;\r
+  }\r
+}\r
+\r
 /**\r
   Prints a message to the serial port.\r
 \r
   @param  Format      Format string for the message to print.\r
-  @param  ...         Variable argument list whose contents are accessed \r
+  @param  ...         Variable argument list whose contents are accessed\r
                       based on the format string specified by Format.\r
 \r
 **/\r
@@ -53,18 +100,21 @@ InternalPrintMessage (
   VA_END (Marker);\r
 \r
   //\r
-  // Send the print string to a Serial Port \r
+  // Send the print string to a Serial Port\r
   //\r
   SerialPortWrite ((UINT8 *)Buffer, AsciiStrLen (Buffer));\r
 }\r
 \r
 /**\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
+\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
+UINTN\r
 FindModuleImageBase (\r
   IN  UINTN              CurrentEip,\r
   OUT UINTN              *EntryPoint\r
@@ -86,13 +136,18 @@ FindModuleImageBase (
       // DOS image header is present, so read the PE header after the DOS image header.\r
       //\r
       Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)(Pe32Data + (UINTN) ((DosHdr->e_lfanew) & 0x0ffff));\r
-      if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {\r
-        //\r
-        // It's PE image.\r
-        //\r
-        InternalPrintMessage ("!!!! Find PE image ");\r
-        *EntryPoint = (UINTN)Pe32Data + (UINTN)(Hdr.Pe32->OptionalHeader.AddressOfEntryPoint & 0x0ffffffff);\r
-        break;\r
+      //\r
+      // Make sure PE header address does not overflow and is less than the initial address.\r
+      //\r
+      if (((UINTN)Hdr.Pe32 > Pe32Data) && ((UINTN)Hdr.Pe32 < CurrentEip)) {\r
+        if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {\r
+          //\r
+          // It's PE image.\r
+          //\r
+          InternalPrintMessage ("!!!! Find PE image ");\r
+          *EntryPoint = (UINTN)Pe32Data + (UINTN)(Hdr.Pe32->OptionalHeader.AddressOfEntryPoint & 0x0ffffffff);\r
+          break;\r
+        }\r
       }\r
     } else {\r
       //\r
@@ -112,7 +167,7 @@ FindModuleImageBase (
 \r
     //\r
     // Not found the image base, check the previous aligned address\r
-    // \r
+    //\r
     Pe32Data -= mImageAlignSize;\r
   }\r
 \r
@@ -130,3 +185,35 @@ FindModuleImageBase (
   return Pe32Data;\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
+  while (VectorInfo->Attribute != EFI_VECTOR_HANDOFF_LAST_ENTRY) {\r
+    if (VectorInfo->Attribute > EFI_VECTOR_HANDOFF_HOOK_AFTER) {\r
+      //\r
+      // If vector attrubute is invalid\r
+      //\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+    if (VectorInfo->VectorNumber < VectorCount) {\r
+      ReservedVector[VectorInfo->VectorNumber].Attribute = VectorInfo->Attribute;\r
+    }\r
+    VectorInfo ++;\r
+  }\r
+  return EFI_SUCCESS;\r
+}
\ No newline at end of file