]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/CapsulePei/X64/X64Entry.c
1. Introduced CPU Exception Handler Library to provide the CPU exception handlers...
[mirror_edk2.git] / MdeModulePkg / Universal / CapsulePei / X64 / X64Entry.c
index a4e44a4f5ef1964bf39963214ee322c663335821..fa29e3dbfb561a5187d3a197b1032abe7b69f9c1 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   The X64 entrypoint is used to process capsule in long mode.\r
 \r
-Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2011 - 2012, 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
@@ -13,8 +13,12 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 **/\r
 \r
 #include <Library/DebugLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/CpuExceptionHandlerLib.h>\r
 #include "CommonHeader.h"\r
 \r
+#define EXCEPTION_VECTOR_NUMBER     0x20\r
+\r
 /**\r
   The X64 entrypoint is used to process capsule in long mode then\r
   return to 32-bit protected mode.\r
@@ -32,7 +36,28 @@ _ModuleEntryPoint (
   SWITCH_64_TO_32_CONTEXT       *ReturnContext\r
 )\r
 {\r
-  EFI_STATUS    Status;\r
+  EFI_STATUS                    Status;\r
+  IA32_DESCRIPTOR               Ia32Idtr;\r
+  IA32_DESCRIPTOR               X64Idtr;\r
+  IA32_IDT_GATE_DESCRIPTOR      IdtEntryTable[EXCEPTION_VECTOR_NUMBER];\r
+\r
+  //\r
+  // Save the IA32 IDT Descriptor\r
+  //\r
+  AsmReadIdtr ((IA32_DESCRIPTOR *) &Ia32Idtr); \r
+\r
+  //\r
+  // Setup X64 IDT table\r
+  //\r
+  ZeroMem (IdtEntryTable, sizeof (IA32_IDT_GATE_DESCRIPTOR) * EXCEPTION_VECTOR_NUMBER);\r
+  X64Idtr.Base = (UINTN) IdtEntryTable;\r
+  X64Idtr.Limit = (UINT16) (sizeof (IA32_IDT_GATE_DESCRIPTOR) * EXCEPTION_VECTOR_NUMBER - 1);\r
+  AsmWriteIdtr ((IA32_DESCRIPTOR *) &X64Idtr);  \r
+\r
+  //\r
+  // Setup the default CPU exception handlers\r
+  //\r
+  SetupCpuExceptionHandlers ();                \r
 \r
   //\r
   // Call CapsuleDataCoalesce to process capsule.\r
@@ -46,6 +71,11 @@ _ModuleEntryPoint (
   \r
   ReturnContext->ReturnStatus = Status;\r
 \r
+  //\r
+  // Restore IA32 IDT table\r
+  //\r
+  AsmWriteIdtr ((IA32_DESCRIPTOR *) &Ia32Idtr);  \r
+  \r
   //\r
   // Finish to coalesce capsule, and return to 32-bit mode.\r
   //\r