]> git.proxmox.com Git - mirror_edk2.git/commitdiff
SourceLevelDebugPkg/SecPeiDebugAgentLib: Restore CPU interrupt state
authorJeff Fan <jeff.fan@intel.com>
Fri, 10 Jul 2015 05:48:19 +0000 (05:48 +0000)
committervanjeff <vanjeff@Edk2>
Fri, 10 Jul 2015 05:48:19 +0000 (05:48 +0000)
In DEBUG_AGENT_INIT_POSTMEM_SEC case, caller may disable/restore CPU interrupt
to protect the stack/heap migration. SecPeiDebugAgentLib cannot always enable
CPU interrupt. Otherwise system may crash during stack/heap migration.
SecPeiDebugAgentLib should restore original CPU interrupt state in
DEBUG_AGENT_INIT_POSTMEM_SEC case.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan <jeff.fan@intel.com>
Reviewed-by: Brian J. Johnson <bjohnson@sgi.com>
Tested-by: Brian J. Johnson <bjohnson@sgi.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17916 6f19259b-4bc3-4df7-8a09-765794883524

SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c

index 09216c20fe8239fee72bf7bbe50ddc95468794f9..faec574fa4171d585ea6b9587c5455a73a821ada 100644 (file)
@@ -376,8 +376,12 @@ InitializeDebugAgent (
   UINT64                           *MailboxLocationPointer;\r
   EFI_PHYSICAL_ADDRESS             Address;\r
   UINT32                           DebugTimerFrequency;\r
+  BOOLEAN                          CpuInterruptState;\r
 \r
-  DisableInterrupts ();\r
+  //\r
+  // Disable interrupts and save current interrupt state\r
+  //\r
+  CpuInterruptState = SaveAndDisableInterrupts();\r
 \r
   switch (InitFlag) {\r
 \r
@@ -611,17 +615,22 @@ InitializeDebugAgent (
     break;\r
   }\r
 \r
-  //\r
-  // Enable Debug Timer interrupt. In post-memory SEC, the caller enables it.\r
-  //\r
-  if (InitFlag != DEBUG_AGENT_INIT_POSTMEM_SEC) {\r
+  if (InitFlag == DEBUG_AGENT_INIT_POSTMEM_SEC) {\r
+    //\r
+    // Restore CPU Interrupt state and keep debug timer interrupt state as is\r
+    // in DEBUG_AGENT_INIT_POSTMEM_SEC case\r
+    //\r
+    SetInterruptState (CpuInterruptState);\r
+  } else {\r
+    //\r
+    // Enable Debug Timer interrupt\r
+    //\r
     SaveAndSetDebugTimerInterrupt (TRUE);\r
+    //\r
+    // Enable CPU interrupts so debug timer interrupts can be delivered\r
+    //\r
+    EnableInterrupts ();\r
   }\r
-  //\r
-  // Enable CPU interrupts so debug timer interrupts can be delivered\r
-  //\r
-  EnableInterrupts ();\r
-\r
   //\r
   // If Function is not NULL, invoke it always whatever debug agent was initialized sucesssfully or not.\r
   //\r