]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c
UefiCpuPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / UefiCpuPkg / Library / CpuExceptionHandlerLib / PeiDxeSmmCpuException.c
index 0facfde5dd236da89253405173514095fbf0b368..72c2aeca4c130f8d4e9341fff231b235229a5fac 100644 (file)
@@ -1,14 +1,8 @@
 /** @file\r
   CPU Exception Library provides PEI/DXE/SMM CPU common exception handler.\r
 \r
-Copyright (c) 2012 - 2017, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials are licensed and made available under\r
-the terms and conditions of the BSD License that accompanies this distribution.\r
-The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php.\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2012 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -40,7 +34,8 @@ CommonExceptionHandlerWorker (
   switch (ReservedVectors[ExceptionType].Attribute) {\r
   case EFI_VECTOR_HANDOFF_HOOK_BEFORE:\r
     //\r
-    // Need to jmp to old IDT handler after this exception handler\r
+    // The new exception handler registered by RegisterCpuInterruptHandler() is executed BEFORE original handler.\r
+    // Save the original handler to stack so the assembly code can jump to it instead of returning from handler.\r
     //\r
     ExceptionHandlerContext->ExceptionDataFlag = (mErrorCodeFlag & (1 << ExceptionType)) ? TRUE : FALSE;\r
     ExceptionHandlerContext->OldIdtHandler     = ReservedVectors[ExceptionType].ExceptonHandler;\r
@@ -48,11 +43,13 @@ CommonExceptionHandlerWorker (
   case EFI_VECTOR_HANDOFF_HOOK_AFTER:\r
     while (TRUE) {\r
       //\r
-      // If if anyone has gotten SPIN_LOCK for owner running hook after\r
+      // If spin-lock can be acquired, it's the first time entering here.\r
       //\r
       if (AcquireSpinLockOrFail (&ReservedVectors[ExceptionType].SpinLock)) {\r
         //\r
-        // Need to execute old IDT handler before running this exception handler\r
+        // The new exception handler registered by RegisterCpuInterruptHandler() is executed AFTER original handler.\r
+        // Save the original handler to stack but skip running the new handler so the original handler is executed\r
+        // firstly.\r
         //\r
         ReservedVectors[ExceptionType].ApicId = GetApicId ();\r
         ArchSaveExceptionContext (ExceptionType, SystemContext, ExceptionHandlerData);\r
@@ -61,7 +58,8 @@ CommonExceptionHandlerWorker (
         return;\r
       }\r
       //\r
-      // If failed to acquire SPIN_LOCK, check if it was locked by processor itself\r
+      // If spin-lock cannot be acquired, it's the second time entering here.\r
+      // 'break' instead of 'return' is used so the new exception handler can be executed.\r
       //\r
       if (ReservedVectors[ExceptionType].ApicId == GetApicId ()) {\r
         //\r
@@ -99,6 +97,10 @@ CommonExceptionHandlerWorker (
       CpuPause ();\r
     }\r
     //\r
+    // Initialize the serial port before dumping.\r
+    //\r
+    SerialPortInitialize ();\r
+    //\r
     // Display ExceptionType, CPU information and Image information\r
     //\r
     DumpImageAndCpuContent (ExceptionType, SystemContext);\r