]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.h
This revision can only work with Intel(c) UDK Debugger Tool version 1.3 or greater...
[mirror_edk2.git] / SourceLevelDebugPkg / Library / DebugAgent / DebugAgentCommon / DebugAgent.h
index 61448448d46e83c6872e7853cb8cc15b1b12aaca..5eb50d038c0433e5ff049f973d252f42d00c1411 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Command header of for Debug Agent library instance.\r
 \r
-  Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2013, 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
@@ -32,6 +32,8 @@
 #include <Library/DebugLib.h>\r
 #include <Library/TimerLib.h>\r
 #include <Library/PrintLib.h>\r
+#include <Library/PeCoffGetEntryPointLib.h>\r
+#include <Library/PeCoffExtraActionLib.h>\r
 \r
 #include <TransferProtocol.h>\r
 #include <ImageDebugSupport.h>\r
 #include "DebugTimer.h"\r
 #include "ArchDebugSupport.h"\r
 \r
+//\r
+// These macros may be already defined in DebugAgentLib.h\r
+//\r
+#define DEBUG_AGENT_INIT_PEI                     9\r
+#define DEBUG_AGENT_INIT_DXE_LOAD               10\r
+#define DEBUG_AGENT_INIT_DXE_UNLOAD             11\r
+#define DEBUG_AGENT_INIT_THUNK_PEI_IA32TOX64    12\r
+\r
 #define DEBUG_INT1_VECTOR               1\r
 #define DEBUG_INT3_VECTOR               3\r
 #define DEBUG_TIMER_VECTOR              32\r
 #define DEBUG_MAILBOX_VECTOR            33\r
 \r
+//\r
+//  Timeout value for reading packet (unit is microsecond)\r
+//\r
+#define READ_PACKET_TIMEOUT     (500 * 1000)\r
+\r
 #define SOFT_INTERRUPT_SIGNATURE    SIGNATURE_32('S','O','F','T')\r
 #define SYSTEM_RESET_SIGNATURE      SIGNATURE_32('S','Y','S','R')\r
 #define MEMORY_READY_SIGNATURE      SIGNATURE_32('M','E','M','R')\r
@@ -53,6 +68,8 @@ extern UINTN  Exception0Handle;
 extern UINTN  TimerInterruptHandle;\r
 extern UINT16 ExceptionStubHeaderSize;\r
 \r
+extern BOOLEAN mSkipBreakpoint;\r
+\r
 //\r
 // CPU exception information issued by debug agent\r
 //\r
@@ -67,23 +84,44 @@ typedef struct {
   DEBUG_DATA_RESPONSE_GET_EXCEPTION   ExceptionContent;\r
 } DEBUG_AGENT_EXCEPTION_BUFFER;\r
 \r
-#pragma pack(1)\r
-typedef struct {\r
-  //\r
-  // Lower 32 bits to store the status of DebugAgent\r
-  //\r
-  UINT32  HostAttached    : 1;   // 1: HOST is attached\r
-  UINT32  AgentInProgress : 1;   // 1: Debug Agent is communicating with HOST\r
-  UINT32  MemoryReady     : 1;   // 1: Memory is ready\r
-  UINT32  SteppingFlag    : 1;   // 1: Agent is running stepping command\r
-  UINT32  Reserved1       : 28;\r
+#define DEBUG_AGENT_FLAG_HOST_ATTACHED         BIT0\r
+#define DEBUG_AGENT_FLAG_AGENT_IN_PROGRESS     BIT1\r
+#define DEBUG_AGENT_FLAG_MEMORY_READY          BIT2\r
+#define DEBUG_AGENT_FLAG_STEPPING              BIT3\r
+#define DEBUG_AGENT_FLAG_CHECK_MAILBOX_IN_HOB  BIT4\r
+#define DEBUG_AGENT_FLAG_BREAK_ON_NEXT_SMI     BIT32\r
+#define DEBUG_AGENT_FLAG_PRINT_ERROR_LEVEL     (BIT33|BIT34|BIT35|BIT36)\r
+#define DEBUG_AGENT_FLAG_BREAK_BOOT_SCRIPT     BIT37\r
+\r
+#define DEBUG_MAILBOX_DEBUG_FLAG_INDEX                1\r
+#define DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX         2\r
+#define DEBUG_MAILBOX_EXCEPTION_BUFFER_POINTER_INDEX  3\r
+#define DEBUG_MAILBOX_LAST_ACK                        4\r
+#define DEBUG_MAILBOX_SEQUENCE_NO_INDEX               5\r
+#define DEBUG_MAILBOX_HOST_SEQUENCE_NO_INDEX          6\r
 \r
-  //\r
-  // Higher 32bits to control the behavior of DebugAgent\r
-  //\r
-  UINT32  BreakOnNextSmi  : 1;   // 1: Break on next SMI\r
-  UINT32  PrintErrorLevel : 8;   // Bitmask of print error level for debug message\r
-  UINT32  Reserved2       : 23;\r
+#pragma pack(1)\r
+typedef union {\r
+  struct {\r
+    //\r
+    // Lower 32 bits to store the status of DebugAgent\r
+    //\r
+    UINT32  HostAttached      : 1;   // 1: HOST is attached\r
+    UINT32  AgentInProgress   : 1;   // 1: Debug Agent is communicating with HOST\r
+    UINT32  MemoryReady       : 1;   // 1: Memory is ready\r
+    UINT32  SteppingFlag      : 1;   // 1: Agent is running stepping command\r
+    UINT32  CheckMailboxInHob : 1;   // 1: Need to check mailbox saved in HOB\r
+    UINT32  SendingPacket     : 1;   // 1: TARGET is sending debug packet to HOST\r
+    UINT32  Reserved1         : 26;\r
+    //\r
+    // Higher 32bits to control the behavior of DebugAgent\r
+    //\r
+    UINT32  BreakOnNextSmi    : 1;   // 1: Break on next SMI\r
+    UINT32  PrintErrorLevel   : 4;   // Bitmask of print error level for debug message\r
+    UINT32  BreakOnBootScript : 1;   // 1: Break before executing boot script \r
+    UINT32  Reserved2         : 26;\r
+  } Bits;\r
+  UINT64  Uint64;\r
 } DEBUG_AGENT_FLAG;\r
 \r
 typedef struct {\r
@@ -93,9 +131,29 @@ typedef struct {
   // Pointer to DEBUG_AGENT_EXCEPTION_BUFFER\r
   //\r
   UINT64                     ExceptionBufferPointer;\r
+  UINT8                      LastAck;      // The last ack packet type\r
+  UINT8                      SequenceNo;\r
+  UINT8                      HostSequenceNo;\r
+  UINT8                      CheckSum;     // Mailbox checksum\r
+  UINT8                      ToBeCheckSum; // To be Mailbox checksum at the next\r
 } DEBUG_AGENT_MAILBOX;\r
 #pragma pack()\r
 \r
+///\r
+/// Byte packed structure for an IA-32 Interrupt Gate Descriptor.\r
+///\r
+typedef union {\r
+  struct {\r
+    UINT32  OffsetLow:16;   ///< Offset bits 15..0.\r
+    UINT32  Selector:16;    ///< Selector.\r
+    UINT32  Reserved_0:8;   ///< Reserved.\r
+    UINT32  GateType:8;     ///< Gate Type.  See #defines above.\r
+    UINT32  OffsetHigh:16;  ///< Offset bits 31..16.\r
+  } Bits;\r
+  UINT64  Uint64;\r
+} IA32_IDT_ENTRY;\r
+\r
+\r
 typedef union {\r
   struct {\r
     UINT32  LimitLow    : 16;\r
@@ -115,22 +173,6 @@ typedef union {
   UINT64  Uint64;\r
 } IA32_GDT;\r
 \r
-/**\r
-  Caller provided function to be invoked at the end of DebugPortInitialize().\r
-\r
-  Refer to the descrption for DebugPortInitialize() for more details.\r
-\r
-  @param[in] Context           The first input argument of DebugPortInitialize().\r
-  @param[in] DebugPortHandle   Debug port handle created by Debug Communication Libary.\r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-InitializeDebugAgentPhase2 (\r
-  IN VOID                  *Context,\r
-  IN DEBUG_PORT_HANDLE     DebugPortHandle\r
-  );\r
-\r
 /**\r
   Initialize IDT entries to support source level debug.\r
 \r
@@ -242,5 +284,184 @@ DebugAgentMsgPrint (
   IN CHAR8         *Format,\r
   ...\r
   );\r
+\r
+/**\r
+  Trigger one software interrupt to debug agent to handle it.\r
+\r
+  @param[in] Signature       Software interrupt signature.\r
+\r
+**/\r
+VOID\r
+TriggerSoftInterrupt (\r
+  IN UINT32                 Signature\r
+  );\r
+\r
+/**\r
+  Check if debug agent support multi-processor.\r
+\r
+  @retval TRUE    Multi-processor is supported.\r
+  @retval FALSE   Multi-processor is not supported.\r
+\r
+**/\r
+BOOLEAN\r
+MultiProcessorDebugSupport (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Find and report module image info to HOST.\r
+  \r
+  @param[in] AlignSize      Image aligned size.\r
+  \r
+**/\r
+VOID \r
+FindAndReportModuleImageInfo (\r
+  IN UINTN          AlignSize                   \r
+  );\r
+\r
+/**\r
+  Read IDT entry to check if IDT entries are setup by Debug Agent.\r
+\r
+  @retval  TRUE     IDT entries were setup by Debug Agent.\r
+  @retval  FALSE    IDT entries were not setup by Debug Agent.\r
+\r
+**/\r
+BOOLEAN \r
+IsDebugAgentInitialzed (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Caculate Mailbox checksum and update the checksum field.\r
+\r
+  @param[in]  Mailbox  Debug Agent Mailbox pointer.\r
+\r
+**/\r
+VOID\r
+UpdateMailboxChecksum (\r
+  IN DEBUG_AGENT_MAILBOX    *Mailbox\r
+  );\r
+\r
+/**\r
+  Verify Mailbox checksum.\r
+\r
+  If checksum error, print debug message and run init dead loop.\r
+\r
+  @param[in]  Mailbox  Debug Agent Mailbox pointer.\r
+\r
+**/\r
+VOID \r
+VerifyMailboxChecksum (\r
+  IN DEBUG_AGENT_MAILBOX    *Mailbox\r
+  );\r
+\r
+/**\r
+  Set debug flag in mailbox.\r
+\r
+  @param[in]  FlagMask      Debug flag mask value.\r
+  @param[in]  FlagValue     Debug flag value.\r
+\r
+**/\r
+VOID \r
+SetDebugFlag (\r
+  IN UINT64                 FlagMask,\r
+  IN UINT32                 FlagValue                          \r
+  );\r
+\r
+/**\r
+  Get debug flag in mailbox.\r
+\r
+  @param[in]  FlagMask      Debug flag mask value.\r
+  \r
+  @return Debug flag value.\r
+\r
+**/\r
+UINT32\r
+GetDebugFlag (\r
+  IN UINT64                 FlagMask\r
+  );\r
+\r
+/**\r
+  Update Mailbox content by index.\r
+\r
+  @param[in]  Mailbox  Debug Agent Mailbox pointer.\r
+  @param[in]  Index    Mailbox content index.\r
+  @param[in]  Value    Value to be set into mail box.\r
+  \r
+**/\r
+VOID\r
+UpdateMailboxContent ( \r
+  IN DEBUG_AGENT_MAILBOX    *Mailbox,\r
+  IN UINTN                  Index,\r
+  IN UINT64                 Value\r
+  );\r
+\r
+/**\r
+  Retrieve exception handler from IDT table by ExceptionNum.\r
+\r
+  @param[in]  ExceptionNum    Exception number\r
\r
+  @return Exception handler\r
+\r
+**/\r
+VOID *\r
+GetExceptionHandlerInIdtEntry (\r
+  IN UINTN             ExceptionNum\r
+  );\r
+\r
+/**\r
+  Set exception handler in IDT table by ExceptionNum.\r
+\r
+  @param[in]  ExceptionNum      Exception number\r
+  @param[in]  ExceptionHandler  Exception Handler to be set \r
+\r
+**/\r
+VOID\r
+SetExceptionHandlerInIdtEntry (\r
+  IN UINTN             ExceptionNum,\r
+  IN VOID              *ExceptionHandler\r
+  );\r
+\r
+/**\r
+  Prints a debug message to the debug output device if the specified error level is enabled.\r
+\r
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function \r
+  GetDebugPrintErrorLevel (), then print the message specified by Format and the \r
+  associated variable argument list to the debug output device.\r
+\r
+  If Format is NULL, then ASSERT().\r
+\r
+  @param[in] ErrorLevel  The error level of the debug message.\r
+  @param[in] IsSend      Flag of debug message to declare that the data is being sent or being received.\r
+  @param[in] Data        Variable argument list whose contents are accessed \r
+  @param[in] Length      based on the format string specified by Format.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+DebugAgentDataMsgPrint (\r
+  IN UINT8             ErrorLevel,\r
+  IN BOOLEAN           IsSend,\r
+  IN UINT8             *Data,\r
+  IN UINT8             Length  \r
+  );\r
+\r
+/**\r
+  Read remaing debug packet except for the start symbol\r
+\r
+  @param[in]      Handle        Pointer to Debug Port handle.\r
+  @param[in, out] DebugHeader   Debug header buffer including start symbol.\r
+\r
+  @retval EFI_SUCCESS        Read the symbol in BreakSymbol.\r
+  @retval EFI_CRC_ERROR      CRC check fail.\r
+  @retval EFI_TIMEOUT        Timeout occurs when reading debug packet.\r
+\r
+**/\r
+EFI_STATUS\r
+ReadRemainingBreakPacket (\r
+  IN     DEBUG_PORT_HANDLE      Handle,\r
+  IN OUT DEBUG_PACKET_HEADER    *DebugHeader\r
+  );\r
+\r
 #endif\r
 \r