]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.c
UefiCpuPkg/CpuExceptionHandlerLib: Fix spelling issue
[mirror_edk2.git] / UefiCpuPkg / Library / CpuExceptionHandlerLib / Ia32 / ArchExceptionHandler.c
index 6ac8549839cebb2f7f0a8e4cfd36ceb92d932bfd..531258610aa9b651b86ce9b0ecc7a2ef529f2526 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   IA32 CPU Exception Handler functons.\r
 \r
-  Copyright (c) 2012 - 2017, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2012 - 2018, 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
@@ -66,7 +66,9 @@ ArchSaveExceptionContext (
 \r
   ReservedVectors = ExceptionHandlerData->ReservedVectors;\r
   //\r
-  // Save Exception context in global variable\r
+  // Save Exception context in global variable in first entry of the exception handler.\r
+  // So when original exception handler returns to the new exception handler (second entry),\r
+  // the Eflags/Cs/Eip/ExceptionData can be used.\r
   //\r
   ReservedVectors[ExceptionType].OldFlags      = SystemContext.SystemContextIa32->Eflags;\r
   ReservedVectors[ExceptionType].OldCs         = SystemContext.SystemContextIa32->Cs;\r
@@ -79,7 +81,7 @@ ArchSaveExceptionContext (
   Eflags.Bits.IF = 0;\r
   SystemContext.SystemContextIa32->Eflags = Eflags.UintN;\r
   //\r
-  // Modify the EIP in stack, then old IDT handler will return to the stub code\r
+  // Modify the EIP in stack, then old IDT handler will return to HookAfterStubBegin.\r
   //\r
   SystemContext.SystemContextIa32->Eip    = (UINTN) ReservedVectors[ExceptionType].HookAfterStubHeaderCode;\r
 }\r
@@ -119,7 +121,7 @@ ArchRestoreExceptionContext (
 \r
 **/\r
 EFI_STATUS\r
-ArchSetupExcpetionStack (\r
+ArchSetupExceptionStack (\r
   IN CPU_EXCEPTION_INIT_DATA      *StackSwitchData\r
   )\r
 {\r
@@ -212,6 +214,7 @@ ArchSetupExcpetionStack (
   //\r
   TssBase = (UINTN)Tss;\r
 \r
+  TssDesc->Uint64          = 0;\r
   TssDesc->Bits.LimitLow   = sizeof(IA32_TASK_STATE_SEGMENT) - 1;\r
   TssDesc->Bits.BaseLow    = (UINT16)TssBase;\r
   TssDesc->Bits.BaseMid    = (UINT8)(TssBase >> 16);\r
@@ -236,6 +239,7 @@ ArchSetupExcpetionStack (
     //\r
     TssBase = (UINTN)Tss;\r
 \r
+    TssDesc->Uint64         = 0;\r
     TssDesc->Bits.LimitLow  = sizeof(IA32_TASK_STATE_SEGMENT) - 1;\r
     TssDesc->Bits.BaseLow   = (UINT16)TssBase;\r
     TssDesc->Bits.BaseMid   = (UINT8)(TssBase >> 16);\r
@@ -253,6 +257,7 @@ ArchSetupExcpetionStack (
       continue;\r
     }\r
 \r
+    ZeroMem (Tss, sizeof (*Tss));\r
     Tss->EIP    = (UINT32)(TemplateMap.ExceptionStart\r
                            + Vector * TemplateMap.ExceptionStubHeaderSize);\r
     Tss->EFLAGS = 0x2;\r
@@ -414,5 +419,14 @@ DumpImageAndCpuContent (
   //\r
   // Dump module image base and module entry point by EIP\r
   //\r
-  DumpModuleImageInfo (SystemContext.SystemContextIa32->Eip);\r
+  if ((ExceptionType == EXCEPT_IA32_PAGE_FAULT) &&\r
+      ((SystemContext.SystemContextIa32->ExceptionData & IA32_PF_EC_ID) != 0)) {\r
+    //\r
+    // The EIP in SystemContext could not be used\r
+    // if it is page fault with I/D set.\r
+    //\r
+    DumpModuleImageInfo ((*(UINTN *)(UINTN)SystemContext.SystemContextIa32->Esp));\r
+  } else {\r
+    DumpModuleImageInfo (SystemContext.SystemContextIa32->Eip);\r
+  }\r
 }\r