]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EmbeddedPkg/Library/GdbDebugAgent/Arm/Processor.c
Fix more InitializeDebugAgent API change bugs. GDB stub was not turned on in example...
[mirror_edk2.git] / EmbeddedPkg / Library / GdbDebugAgent / Arm / Processor.c
index e09e18d6c1c8eafa72a2c81f7e5797d4a8c30444..d3c050499a302fb2f9155649bc8f669ab4429122 100755 (executable)
@@ -1,9 +1,9 @@
 /** @file\r
   Processor specific parts of the GDB stub\r
 \r
-  Copyright (c) 2008-2010, Apple Inc. All rights reserved.\r
+  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
   \r
-  All rights reserved. This program and the accompanying materials\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
   http://opensource.org/licenses/bsd-license.php\r
@@ -15,7 +15,6 @@
 \r
 \r
 #include <GdbDebugAgent.h>\r
-#include <Library/CacheMaintenanceLib.h>\r
 #include <Library/PrintLib.h>\r
 #include <Library/ArmLib.h>\r
 \r
@@ -466,6 +465,33 @@ ProcessorSendTSignal (
   *TSignalPtr = '\0';
 }
 \r
+/**\r
+ FIQ state is only changed by FIQ exception. We don't want to take FIQ\r
+ ticks in the GDB stub. The stub disables FIQ on entry, but this is the \r
+ third instruction that executes in the execption handler. Thus we have\r
+ a crack we need to test for.\r
+\r
+ @param PC     PC of execption\r
+\r
+ @return  TRUE  We are in the GDB stub exception preamble \r
+ @return  FALSE We are not in GDB stub code\r
+ **/
+BOOLEAN
+InFiqCrack (
+  IN UINT32 PC
+  )
+{
+  UINT32 VectorBase = PcdGet32 (PcdCpuVectorBaseAddress);
+  UINT32 Length     = (UINTN)ExceptionHandlersEnd - (UINTN)ExceptionHandlersStart;
+
+  if ((PC >= VectorBase) && (PC <= (VectorBase + Length))) {
+    return TRUE;
+  }
+
+  return FALSE;
+}
+\r
+\r
 /**\r
  Check to see if this exception is related to ctrl-c handling.\r
 \r
@@ -486,6 +512,7 @@ ProcessorControlC (
   IN OUT EFI_SYSTEM_CONTEXT     SystemContext \r
   )\r
 {\r
+  CHAR8     Char;\r
   BOOLEAN   Return = TRUE;\r
 \r
   if (ExceptionType != EXCEPT_ARM_FIQ) {\r
@@ -493,6 +520,12 @@ ProcessorControlC (
     return FALSE;\r
   }\r
 \r
+  if (InFiqCrack (SystemContext.SystemContextArm->PC)) {\r
+    // We are in our own interrupt preable, so skip this tick.\r
+    // We never want to let gdb see the debug stub running if we can help it\r
+    return FALSE;\r
+  }\r
+\r
   while (TRUE) {
     if (!GdbIsCharAvailable ()) {
       //
@@ -502,7 +535,8 @@ ProcessorControlC (
       break;
     }
     
-    if (GdbGetChar () == 0x03) {
+    Char = GdbGetChar ();
+    if (Char == 0x03) {
       //
       // We have a ctrl-c so exit and process exception for ctrl-c
       //
@@ -527,7 +561,8 @@ ProcessorControlC (
 \r
   @param[in] EnableStatus    Enable/Disable.\r
 \r
-  @return FALSE always.\r
+  @retval TRUE  Debug timer interrupt were enabled on entry to this call.\r
+  @retval FALSE Debug timer interrupt were disabled on entry to this call.\r
 \r
 **/\r
 BOOLEAN\r
@@ -541,7 +576,7 @@ SaveAndSetDebugTimerInterrupt (
   FiqEnabled = ArmGetFiqState ();\r
 \r
   if (EnableStatus) {\r
-    DebugAgentTimerSetPeriod (100);\r
+    DebugAgentTimerSetPeriod (PcdGet32 (PcdGdbTimerPeriodMilliseconds));\r
     ArmEnableFiq ();\r
   } else {\r
     DebugAgentTimerSetPeriod (0);\r
@@ -551,6 +586,8 @@ SaveAndSetDebugTimerInterrupt (
   return FiqEnabled;\r
 }\r
 \r
+\r
+\r
 VOID\r
 GdbFPutString (\r
   IN CHAR8  *String\r
@@ -559,37 +596,44 @@ GdbFPutString (
 /**\r
   Initialize debug agent.\r
 \r
-  This function is used to set up debug enviroment. It may enable interrupts.\r
+  This function is used to set up debug environment to support source level debugging.\r
+  If certain Debug Agent Library instance has to save some private data in the stack,\r
+  this function must work on the mode that doesn't return to the caller, then\r
+  the caller needs to wrap up all rest of logic after InitializeDebugAgent() into one\r
+  function and pass it into InitializeDebugAgent(). InitializeDebugAgent() is\r
+  responsible to invoke the passing-in function at the end of InitializeDebugAgent().\r
+\r
+  If the parameter Function is not NULL, Debug Agent Libary instance will invoke it by\r
+  passing in the Context to be its parameter.\r
 \r
-  @param[in] InitFlag   Init flag is used to decide initialize process.\r
-  @param[in] Context    Context needed according to InitFlag, it was optional.\r
+  If Function() is NULL, Debug Agent Library instance will return after setup debug\r
+  environment.\r
+\r
+  @param[in] InitFlag     Init flag is used to decide the initialize process.\r
+  @param[in] Context      Context needed according to InitFlag; it was optional.\r
+  @param[in] Function     Continue function called by debug agent library; it was\r
+                          optional.\r
 \r
 **/\r
 VOID\r
 EFIAPI\r
 InitializeDebugAgent (\r
   IN UINT32                InitFlag,\r
-  IN VOID                  *Context  OPTIONAL\r
+  IN VOID                  *Context, OPTIONAL\r
+  IN DEBUG_AGENT_CONTINUE  Function  OPTIONAL\r
   )\r
 {  
   UINTN                Offset;\r
   UINTN                Length;\r
   BOOLEAN              IrqEnabled;\r
-  BOOLEAN              FiqEnabled;\r
   UINT32               *VectorBase;\r
 \r
-    
+
   //\r
   // Disable interrupts\r
   //\r
   IrqEnabled = ArmGetInterruptState ();\r
   ArmDisableInterrupts ();\r
-\r
-  //\r
-  // EFI does not use the FIQ, but a debugger might so we must disable \r
-  // as we take over the exception vectors. \r
-  //\r
-  FiqEnabled = ArmGetFiqState ();\r
   ArmDisableFiq ();\r
 \r
   //\r
@@ -615,16 +659,17 @@ InitializeDebugAgent (
   // Flush Caches since we updated executable stuff\r
   InvalidateInstructionCacheRange ((VOID *)PcdGet32(PcdCpuVectorBaseAddress), Length);\r
 \r
+  // setup a timer so gdb can break in via ctrl-c\r
   DebugAgentTimerIntialize ();\r
 \r
-  if (FiqEnabled) {\r
-    ArmEnableFiq ();\r
-  }\r
-\r
   if (IrqEnabled) {\r
     ArmEnableInterrupts ();\r
   }\r
 \r
+  if (Function != NULL) {\r
+    Function (Context);\r
+  }\r
+\r
   return;\r
 }\r
 \r