]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Use RLE (Run Length Encoding) to improve debugging performance.
authorRuiyu Ni <ruiyu.ni@intel.com>
Tue, 20 Jan 2015 08:46:31 +0000 (08:46 +0000)
committerniruiyu <niruiyu@Edk2>
Tue, 20 Jan 2015 08:46:31 +0000 (08:46 +0000)
DEBUG_AGENT_REVISION is DEBUG_AGENT_REVISION_03 to disable this feature and will be changed to DEBUG_AGENT_REVISION_04 when new version of HOST is released.
Reduce the stack usage by re-using the same buffer to send/receive packet.
Zero out the buffer before fxsave so that the reserved field in the buffer remains 0 for better RLE compression ratio.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Jeff Fan <jeff.fan@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16628 6f19259b-4bc3-4df7-8a09-765794883524

SourceLevelDebugPkg/Include/TransferProtocol.h
SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.c
SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.h
SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/Ia32/AsmFuncs.asm
SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/X64/AsmFuncs.asm

index 42add9164a831e2447c73e3c9e82e9c921c6ea56..45d82c2995991e7fab61c57691bbc436abb38950 100644 (file)
@@ -2,7 +2,7 @@
   Transfer protocol defintions used by debug agent and host. It is only\r
   intended to be used by Debug related module implementation.\r
 \r
-  Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2015, 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
 \r
 //\r
 // Current revision of transfer protocol\r
+// 0.4: Packet compression and decompression.\r
 //\r
-#define DEBUG_AGENT_REVISION            ((0 << 16) | 03)\r
+#define DEBUG_AGENT_REVISION_03         ((0 << 16) | 03)\r
+#define DEBUG_AGENT_REVISION_04         ((0 << 16) | 04)\r
+#define DEBUG_AGENT_REVISION            DEBUG_AGENT_REVISION_03\r
 #define DEBUG_AGENT_CAPABILITIES        0\r
 \r
 //\r
-// Definitions for attach command\r
+// Definitions for the (A)ttach command\r
 //\r
 #define DEBUG_STARTING_SYMBOL_ATTACH    (0xFA)\r
 \r
 //\r
 #define DEBUG_STARTING_SYMBOL_NORMAL    (0xFE)\r
 \r
+//\r
+// Definition for starting symbol of a (C)ompressed debug packet. Choose a non-ASCII to avoid conflict with other serial output.\r
+//\r
+#define DEBUG_STARTING_SYMBOL_COMPRESS  (0xFC)\r
+\r
 #pragma pack(1)\r
 \r
 //\r
-// Definition for debug packet header for normal debug packets (not including break/attach command)\r
+// Definition for debug packet header for debug packets (not including attach command)\r
 //\r
 typedef struct {\r
   UINT8                      StartSymbol;\r
index 99878903b1d871076e4f9a85e671b8eb6c55a153..e6be20aa1edc7141a6e570ab5b871ebe6148d038 100644 (file)
@@ -4,7 +4,7 @@
   read/write debug packet to communication with HOST based on transfer\r
   protocol.\r
 \r
-  Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2015, 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
@@ -956,6 +956,51 @@ SendAckPacket (
   UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_LAST_ACK, AckCommand);\r
 }\r
 \r
+/**\r
+  Decompress the Data in place.\r
+\r
+  @param[in, out] Data   The compressed data buffer.\r
+                         The buffer is assumed large enough to hold the uncompressed data.\r
+  @param[in]      Length The length of the compressed data buffer.\r
+\r
+  @return   The length of the uncompressed data buffer.\r
+**/\r
+UINT8\r
+DecompressDataInPlace (\r
+  IN OUT UINT8   *Data,\r
+  IN UINTN       Length\r
+  )\r
+{\r
+  UINTN  Index;\r
+  UINT16 LastChar;\r
+  UINTN  LastCharCount;\r
+  UINT8  CurrentChar;\r
+\r
+  LastChar = (UINT16) -1;\r
+  LastCharCount = 0;\r
+  for (Index = 0; Index < Length; Index++) {\r
+    CurrentChar = Data[Index];\r
+    if (LastCharCount == 2) {\r
+      LastCharCount = 0;\r
+      CopyMem (&Data[Index + CurrentChar], &Data[Index + 1], Length - Index - 1);\r
+      SetMem (&Data[Index], CurrentChar, (UINT8) LastChar);\r
+      LastChar = (UINT16) -1;\r
+      Index += CurrentChar - 1;\r
+      Length += CurrentChar - 1;\r
+    } else {\r
+      if (LastChar != CurrentChar) {\r
+        LastCharCount = 0;\r
+      }\r
+      LastCharCount++;\r
+      LastChar = CurrentChar;\r
+    }\r
+  }\r
+\r
+  ASSERT (Length <= DEBUG_DATA_MAXIMUM_REAL_DATA);\r
+\r
+  return (UINT8) Length;\r
+}\r
+\r
 /**\r
   Receive valid packet from HOST.\r
 \r
@@ -1007,7 +1052,7 @@ ReceivePacket (
       return RETURN_TIMEOUT;\r
     }\r
 \r
-    if (DebugHeader->StartSymbol != DEBUG_STARTING_SYMBOL_NORMAL) {\r
+    if ((DebugHeader->StartSymbol != DEBUG_STARTING_SYMBOL_NORMAL) && (DebugHeader->StartSymbol != DEBUG_STARTING_SYMBOL_COMPRESS)) {\r
       DebugAgentMsgPrint (DEBUG_AGENT_WARNING, "Invalid start symbol received [%02x]\n", DebugHeader->StartSymbol);\r
       continue;\r
     }\r
@@ -1017,7 +1062,7 @@ ReceivePacket (
     //\r
     Received = DebugPortReadBuffer (\r
                  Handle,\r
-                 (UINT8 *)DebugHeader + OFFSET_OF (DEBUG_PACKET_HEADER, Command),\r
+                 (UINT8 *) DebugHeader + OFFSET_OF (DEBUG_PACKET_HEADER, Command),\r
                  OFFSET_OF (DEBUG_PACKET_HEADER, Length) + sizeof (DebugHeader->Length) - sizeof (DebugHeader->StartSymbol),\r
                  Timeout\r
                  );\r
@@ -1061,6 +1106,12 @@ ReceivePacket (
 \r
   DebugAgentDataMsgPrint (DEBUG_AGENT_VERBOSE, FALSE, (UINT8 *) DebugHeader, DebugHeader->Length);\r
 \r
+  if (DebugHeader->StartSymbol == DEBUG_STARTING_SYMBOL_COMPRESS) {\r
+    DebugHeader->StartSymbol = DEBUG_STARTING_SYMBOL_NORMAL;\r
+    DebugHeader->Length      = DecompressDataInPlace (\r
+                                 (UINT8 *) (DebugHeader + 1), DebugHeader->Length - sizeof (DEBUG_PACKET_HEADER)\r
+                                 ) + sizeof (DEBUG_PACKET_HEADER);\r
+  }\r
   return RETURN_SUCCESS;\r
 }\r
 \r
@@ -1290,44 +1341,115 @@ CopyMemByWidth (
   }\r
 }\r
 \r
+/**\r
+  Compress the data buffer but do not modify the original buffer.\r
+\r
+  The compressed data is directly send to the debug channel.\r
+  Compressing in place doesn't work because the data may become larger\r
+  during compressing phase. ("3 3 ..." --> "3 3 0 ...")\r
+  The routine is expected to be called three times:\r
+  1. Compute the length of the compressed data buffer;\r
+  2. Compute the CRC of the compressed data buffer;\r
+  3. Compress the data and send to the debug channel.\r
+\r
+  @param[in]  Data             The data buffer.\r
+  @param[in]  Length           The length of the data buffer.\r
+  @param[out] CompressedLength Return the length of the compressed data buffer.\r
+                               It may be larger than the Length in some cases.\r
+  @param[out] CompressedCrc    Return the CRC of the compressed data buffer.\r
+  @param[in]  Handle           The debug channel handle to send the compressed data buffer.\r
+**/\r
+VOID\r
+CompressDataThenSend (\r
+  IN  UINT8             *Data,\r
+  IN  UINT8             Length,\r
+  OUT UINTN             *CompressedLength,  OPTIONAL\r
+  OUT UINT16            *CompressedCrc,     OPTIONAL\r
+  IN  DEBUG_PORT_HANDLE Handle              OPTIONAL\r
+  )\r
+{\r
+  UINTN  Index;\r
+  UINT8  LastChar;\r
+  UINT8  LastCharCount;\r
+  UINT8  CurrentChar;\r
+  UINTN  CompressedIndex;\r
+\r
+  ASSERT (Length > 0);\r
+\r
+  LastChar = Data[0] + 1; // Just ensure it's different from the first byte.\r
+  LastCharCount = 0;\r
+\r
+  for (Index = 0, CompressedIndex = 0; Index <= Length; Index++) {\r
+    if (Index < Length) {\r
+      CurrentChar = Data[Index];\r
+    } else {\r
+      CurrentChar = (UINT8) LastChar + 1; // just ensure it's different from LastChar\r
+    }\r
+    if (LastChar != CurrentChar) {\r
+      if (LastCharCount == 1) {\r
+        CompressedIndex++;\r
+        if (CompressedCrc != NULL) {\r
+          *CompressedCrc = CalculateCrc16 (&LastChar, 1, *CompressedCrc);\r
+        }\r
+        if (Handle != NULL) {\r
+          DebugPortWriteBuffer (Handle, &LastChar, 1);\r
+        }\r
+        \r
+      } else if (LastCharCount >= 2) {\r
+        CompressedIndex += 3;\r
+        LastCharCount -= 2;\r
+        if (CompressedCrc != NULL) {\r
+          *CompressedCrc = CalculateCrc16 (&LastChar, 1, *CompressedCrc);\r
+          *CompressedCrc = CalculateCrc16 (&LastChar, 1, *CompressedCrc);\r
+          *CompressedCrc = CalculateCrc16 (&LastCharCount, 1, *CompressedCrc);\r
+        }\r
+        if (Handle != NULL) {\r
+          DebugPortWriteBuffer (Handle, &LastChar, 1);\r
+          DebugPortWriteBuffer (Handle, &LastChar, 1);\r
+          DebugPortWriteBuffer (Handle, &LastCharCount, 1);\r
+        }\r
+      }\r
+      LastCharCount = 0;\r
+    }\r
+    LastCharCount++;\r
+    LastChar = CurrentChar;\r
+  }\r
+\r
+  if (CompressedLength != NULL) {\r
+    *CompressedLength = CompressedIndex;\r
+  }\r
+}\r
+\r
 /**\r
   Read memory with speicifed width and send packet with response data to HOST.\r
 \r
   @param[in] Data        Pointer to response data buffer.\r
   @param[in] Count       The number of data with specified Width.\r
   @param[in] Width       Data width in byte.\r
+  @param[in] DebugHeader Pointer to a buffer for creating response packet and receiving ACK packet,\r
+                         to minimize the stack usage.\r
 \r
   @retval RETURN_SUCCESS      Response data was sent successfully.\r
 \r
 **/\r
 RETURN_STATUS\r
 ReadMemoryAndSendResponsePacket (\r
-  IN UINT8                *Data,\r
-  IN UINT16               Count,\r
-  IN UINT8                Width\r
+  IN UINT8                   *Data,\r
+  IN UINT16                  Count,\r
+  IN UINT8                   Width,\r
+  IN DEBUG_PACKET_HEADER     *DebugHeader\r
   )\r
 {\r
   RETURN_STATUS        Status;\r
-  DEBUG_PACKET_HEADER  *DebugHeader;\r
   BOOLEAN              LastPacket;\r
-  DEBUG_PACKET_HEADER  *AckDebugHeader;\r
-  UINT8                DebugPacket[DEBUG_DATA_UPPER_LIMIT + sizeof (UINT64) - 1];\r
-  UINT8                InputPacketBuffer[DEBUG_DATA_UPPER_LIMIT];\r
   DEBUG_PORT_HANDLE    Handle;\r
   UINT8                SequenceNo;\r
   UINTN                RemainingDataSize;\r
-  UINTN                CurrentDataSize;\r
+  UINT8                CurrentDataSize;\r
+  UINTN                CompressedDataSize;\r
 \r
   Handle = GetDebugPortHandle();\r
 \r
-  //\r
-  // Data is appended end of Debug Packet header,  make sure data address\r
-  // in Debug Packet 8-byte alignment always\r
-  //\r
-  DebugHeader = (DEBUG_PACKET_HEADER *) (ALIGN_VALUE ((UINTN)&DebugPacket + sizeof (DEBUG_PACKET_HEADER), sizeof (UINT64))\r
-                                         - sizeof (DEBUG_PACKET_HEADER));\r
-  DebugHeader->StartSymbol = DEBUG_STARTING_SYMBOL_NORMAL;\r
-\r
   RemainingDataSize = Count * Width;\r
   while (TRUE) {\r
     SequenceNo = GetMailboxPointer()->HostSequenceNo;\r
@@ -1335,7 +1457,7 @@ ReadMemoryAndSendResponsePacket (
       //\r
       // If the remaining data is less one real packet size, this is the last data packet\r
       //\r
-      CurrentDataSize = RemainingDataSize;\r
+      CurrentDataSize = (UINT8) RemainingDataSize;\r
       LastPacket = TRUE;\r
       DebugHeader->Command = DEBUG_COMMAND_OK;\r
     } else {\r
@@ -1350,45 +1472,92 @@ ReadMemoryAndSendResponsePacket (
     //\r
     // Construct the rest Debug header\r
     //\r
-    DebugHeader->Length     = (UINT8)(CurrentDataSize + sizeof (DEBUG_PACKET_HEADER));\r
-    DebugHeader->SequenceNo = SequenceNo;\r
-    DebugHeader->Crc        = 0;\r
-    CopyMemByWidth ((UINT8 *)(DebugHeader + 1), Data, (UINT16) CurrentDataSize / Width, Width);\r
+    DebugHeader->StartSymbol = DEBUG_STARTING_SYMBOL_NORMAL;\r
+    DebugHeader->Length      = CurrentDataSize + sizeof (DEBUG_PACKET_HEADER);\r
+    DebugHeader->SequenceNo  = SequenceNo;\r
+    DebugHeader->Crc         = 0;\r
+    CopyMemByWidth ((UINT8 *) (DebugHeader + 1), Data, CurrentDataSize / Width, Width);\r
+\r
     //\r
-    // Calculate and fill the checksum, DebugHeader->Crc should be 0 before invoking CalculateCrc16 ()\r
+    // Compression/decompression support was added since revision 0.4.\r
+    // Revision 0.3 shouldn't compress the packet.\r
     //\r
-    DebugHeader->Crc = CalculateCrc16 ((UINT8 *) DebugHeader, DebugHeader->Length, 0);\r
+    if (DEBUG_AGENT_REVISION >= DEBUG_AGENT_REVISION_04) {\r
+      //\r
+      // Get the compressed data size without modifying the packet.\r
+      //\r
+      CompressDataThenSend (\r
+        (UINT8 *) (DebugHeader + 1),\r
+        CurrentDataSize,\r
+        &CompressedDataSize,\r
+        NULL,\r
+        NULL\r
+        );\r
+    } else {\r
+      CompressedDataSize = CurrentDataSize;\r
+    }\r
+    if (CompressedDataSize < CurrentDataSize) {\r
+      DebugHeader->Length = (UINT8) CompressedDataSize + sizeof (DEBUG_PACKET_HEADER);\r
+      DebugHeader->StartSymbol = DEBUG_STARTING_SYMBOL_COMPRESS;\r
+      //\r
+      // Compute the CRC of the packet head without modifying the packet.\r
+      //\r
+      DebugHeader->Crc = CalculateCrc16 ((UINT8 *) DebugHeader, sizeof (DEBUG_PACKET_HEADER), 0);\r
+      CompressDataThenSend (\r
+        (UINT8 *) (DebugHeader + 1),\r
+        CurrentDataSize,\r
+        NULL,\r
+        &DebugHeader->Crc,\r
+        NULL\r
+        );\r
+      //\r
+      // Send out the packet head.\r
+      //\r
+      DebugPortWriteBuffer (Handle, (UINT8 *) DebugHeader, sizeof (DEBUG_PACKET_HEADER));\r
+      //\r
+      // Compress and send out the packet data.\r
+      //\r
+      CompressDataThenSend (\r
+        (UINT8 *) (DebugHeader + 1),\r
+        CurrentDataSize,\r
+        NULL,\r
+        NULL,\r
+        Handle\r
+        );\r
+    } else {\r
 \r
-    DebugAgentDataMsgPrint (DEBUG_AGENT_VERBOSE, TRUE, (UINT8 *) DebugHeader, DebugHeader->Length);\r
+      //\r
+      // Calculate and fill the checksum, DebugHeader->Crc should be 0 before invoking CalculateCrc16 ()\r
+      //\r
+      DebugHeader->Crc = CalculateCrc16 ((UINT8 *) DebugHeader, DebugHeader->Length, 0);\r
 \r
-    DebugPortWriteBuffer (Handle, (UINT8 *) DebugHeader, DebugHeader->Length);\r
+      DebugAgentDataMsgPrint (DEBUG_AGENT_VERBOSE, TRUE, (UINT8 *) DebugHeader, DebugHeader->Length);\r
+\r
+      DebugPortWriteBuffer (Handle, (UINT8 *) DebugHeader, DebugHeader->Length);\r
+    }\r
 \r
     while (TRUE) {\r
-      Status = ReceivePacket (InputPacketBuffer, NULL, NULL, READ_PACKET_TIMEOUT, FALSE);\r
+      Status = ReceivePacket ((UINT8 *) DebugHeader, NULL, NULL, READ_PACKET_TIMEOUT, FALSE);\r
       if (Status == RETURN_TIMEOUT) {\r
         DebugAgentMsgPrint (DEBUG_AGENT_WARNING, "TARGET: Timeout in SendDataResponsePacket()\n");\r
         break;\r
       }\r
-      AckDebugHeader = (DEBUG_PACKET_HEADER *) InputPacketBuffer;\r
-      SequenceNo = AckDebugHeader->SequenceNo;\r
-      if (AckDebugHeader->Command == DEBUG_COMMAND_OK &&\r
-          SequenceNo == DebugHeader->SequenceNo &&\r
-          LastPacket) {\r
+      if ((DebugHeader->Command == DEBUG_COMMAND_OK) && (DebugHeader->SequenceNo == SequenceNo) && LastPacket) {\r
         //\r
         // If this is the last packet, return RETURN_SUCCESS.\r
         //\r
         return RETURN_SUCCESS;\r
       }\r
-      if ((SequenceNo == (UINT8) (DebugHeader->SequenceNo + 1)) && (AckDebugHeader->Command == DEBUG_COMMAND_CONTINUE)) {\r
+      if ((DebugHeader->Command == DEBUG_COMMAND_CONTINUE) && (DebugHeader->SequenceNo == (UINT8) (SequenceNo + 1))) {\r
         //\r
         // Calculate the rest data size\r
         //\r
         Data              += CurrentDataSize;\r
         RemainingDataSize -= CurrentDataSize;\r
-        UpdateMailboxContent (GetMailboxPointer(), DEBUG_MAILBOX_HOST_SEQUENCE_NO_INDEX, (UINT8) SequenceNo);\r
+        UpdateMailboxContent (GetMailboxPointer(), DEBUG_MAILBOX_HOST_SEQUENCE_NO_INDEX, DebugHeader->SequenceNo);\r
         break;\r
       }\r
-      if (SequenceNo >= DebugHeader->SequenceNo) {\r
+      if (DebugHeader->SequenceNo >= SequenceNo) {\r
         DebugAgentMsgPrint (DEBUG_AGENT_WARNING, "TARGET: Received one old or new command(SequenceNo is %x, last SequenceNo is %x)\n", SequenceNo, DebugHeader->SequenceNo);\r
         break;\r
       }\r
@@ -1399,43 +1568,22 @@ ReadMemoryAndSendResponsePacket (
 /**\r
   Send packet with response data to HOST.\r
 \r
-  @param[in] Data        Pointer to response data buffer.\r
-  @param[in] DataSize    Size of response data in byte.\r
+  @param[in]      Data        Pointer to response data buffer.\r
+  @param[in]      DataSize    Size of response data in byte.\r
+  @param[in, out] DebugHeader Pointer to a buffer for creating response packet and receiving ACK packet,\r
+                              to minimize the stack usage.\r
 \r
   @retval RETURN_SUCCESS      Response data was sent successfully.\r
 \r
 **/\r
 RETURN_STATUS\r
 SendDataResponsePacket (\r
-  IN UINT8                *Data,\r
-  IN UINT16               DataSize\r
+  IN UINT8                   *Data,\r
+  IN UINT16                  DataSize,\r
+  IN OUT DEBUG_PACKET_HEADER *DebugHeader\r
   )\r
 {\r
-  return ReadMemoryAndSendResponsePacket (Data, DataSize, 1);\r
-}\r
-\r
-/**\r
-  Send break cause packet to HOST.\r
-\r
-  @param[in] Vector      Vector value of exception or interrutp.\r
-  @param[in] CpuContext  Pointer to save CPU context.\r
-\r
-  @retval RETURN_SUCCESS      Response data was sent successfully.\r
-  @retval RETURN_DEVICE_ERROR Cannot receive DEBUG_COMMAND_OK from HOST.\r
-\r
-**/\r
-RETURN_STATUS\r
-SendBreakCausePacket (\r
-  IN UINTN                    Vector,\r
-  IN DEBUG_CPU_CONTEXT        *CpuContext\r
-  )\r
-{\r
-  DEBUG_DATA_RESPONSE_BREAK_CAUSE    DebugDataBreakCause;\r
-\r
-  DebugDataBreakCause.StopAddress = CpuContext->Eip;\r
-  DebugDataBreakCause.Cause       = GetBreakCause (Vector, CpuContext);\r
-\r
-  return SendDataResponsePacket ((UINT8 *) &DebugDataBreakCause, (UINT16) sizeof (DEBUG_DATA_RESPONSE_BREAK_CAUSE));\r
+  return ReadMemoryAndSendResponsePacket (Data, DataSize, 1, DebugHeader);\r
 }\r
 \r
 /**\r
@@ -1580,6 +1728,7 @@ CommandCommunication (
   DEBUG_DATA_READ_MSR               *MsrRegisterRead;\r
   DEBUG_DATA_WRITE_MSR              *MsrRegisterWrite;\r
   DEBUG_DATA_CPUID                  *Cpuid;\r
+  DEBUG_DATA_RESPONSE_BREAK_CAUSE   BreakCause;\r
   DEBUG_DATA_RESPONSE_CPUID         CpuidResponse;\r
   DEBUG_DATA_SEARCH_SIGNATURE       *SearchSignature;\r
   DEBUG_DATA_RESPONSE_GET_EXCEPTION Exception;\r
@@ -1646,7 +1795,7 @@ CommandCommunication (
     DebugHeader =(DEBUG_PACKET_HEADER *) InputPacketBuffer;\r
 \r
     DebugAgentMsgPrint (DEBUG_AGENT_INFO, "TARGET: Try to get command from HOST...\n");\r
-    Status = ReceivePacket ((UINT8 *)DebugHeader, &BreakReceived, NULL, READ_PACKET_TIMEOUT, TRUE);\r
+    Status = ReceivePacket ((UINT8 *) DebugHeader, &BreakReceived, NULL, READ_PACKET_TIMEOUT, TRUE);\r
     if (Status != RETURN_SUCCESS || !IS_REQUEST (DebugHeader)) {\r
       DebugAgentMsgPrint (DEBUG_AGENT_WARNING, "TARGET: Get command[%x] sequenceno[%x] returned status is [%x] \n", DebugHeader->Command, DebugHeader->SequenceNo, Status);\r
       DebugAgentMsgPrint (DEBUG_AGENT_WARNING, "TARGET: Get command failed or it's response packet not expected! \n");\r
@@ -1808,14 +1957,13 @@ CommandCommunication (
       break;\r
 \r
     case DEBUG_COMMAND_BREAK_CAUSE:\r
-\r
+      BreakCause.StopAddress = CpuContext->Eip;\r
       if (MultiProcessorDebugSupport() && ProcessorIndex != mDebugMpContext.BreakAtCpuIndex) {\r
-        Status = SendBreakCausePacket (DEBUG_TIMER_VECTOR, CpuContext);\r
-\r
+        BreakCause.Cause       = GetBreakCause (DEBUG_TIMER_VECTOR, CpuContext);\r
       } else {\r
-        Status = SendBreakCausePacket (Vector, CpuContext);\r
+        BreakCause.Cause       = GetBreakCause (Vector, CpuContext);\r
       }\r
-\r
+      SendDataResponsePacket ((UINT8 *) &BreakCause, (UINT16) sizeof (DEBUG_DATA_RESPONSE_BREAK_CAUSE), DebugHeader);\r
       break;\r
 \r
     case DEBUG_COMMAND_SET_HW_BREAKPOINT:\r
@@ -1855,12 +2003,12 @@ CommandCommunication (
       Data64 = (UINTN) (((DEBUG_DATA_SET_SW_BREAKPOINT *) (DebugHeader + 1))->Address);\r
       Data8 = *(UINT8 *) (UINTN) Data64;\r
       *(UINT8 *) (UINTN) Data64 = DEBUG_SW_BREAKPOINT_SYMBOL;\r
-      Status = SendDataResponsePacket ((UINT8 *) &Data8, (UINT16) sizeof (UINT8));\r
+      Status = SendDataResponsePacket ((UINT8 *) &Data8, (UINT16) sizeof (UINT8), DebugHeader);\r
       break;\r
 \r
     case DEBUG_COMMAND_READ_MEMORY:\r
       MemoryRead = (DEBUG_DATA_READ_MEMORY *) (DebugHeader + 1);\r
-      Status = ReadMemoryAndSendResponsePacket ((UINT8 *) (UINTN) MemoryRead->Address, MemoryRead->Count, MemoryRead->Width);\r
+      Status = ReadMemoryAndSendResponsePacket ((UINT8 *) (UINTN) MemoryRead->Address, MemoryRead->Count, MemoryRead->Width, DebugHeader);\r
       break;\r
 \r
     case DEBUG_COMMAND_WRITE_MEMORY:\r
@@ -1894,7 +2042,7 @@ CommandCommunication (
       default:\r
         Data64  = (UINT64) -1;\r
       }\r
-      Status = SendDataResponsePacket ((UINT8 *) &Data64, IoRead->Width);\r
+      Status = SendDataResponsePacket ((UINT8 *) &Data64, IoRead->Width, DebugHeader);\r
       break;\r
 \r
     case DEBUG_COMMAND_WRITE_IO:\r
@@ -1919,7 +2067,7 @@ CommandCommunication (
       break;\r
 \r
     case DEBUG_COMMAND_READ_ALL_REGISTERS:\r
-      Status = SendDataResponsePacket ((UINT8 *) CpuContext, sizeof (*CpuContext));\r
+      Status = SendDataResponsePacket ((UINT8 *) CpuContext, sizeof (*CpuContext), DebugHeader);\r
       break;\r
 \r
     case DEBUG_COMMAND_READ_REGISTER:\r
@@ -1927,7 +2075,7 @@ CommandCommunication (
 \r
       if (RegisterRead->Index <= SOFT_DEBUGGER_REGISTER_MAX) {\r
         RegisterBuffer = ArchReadRegisterBuffer (CpuContext, RegisterRead->Index, &Width);\r
-        Status = SendDataResponsePacket (RegisterBuffer, Width);\r
+        Status = SendDataResponsePacket (RegisterBuffer, Width, DebugHeader);\r
       } else {\r
         Status = RETURN_UNSUPPORTED;\r
       }\r
@@ -1947,13 +2095,13 @@ CommandCommunication (
 \r
     case DEBUG_COMMAND_ARCH_MODE:\r
       Data8 = DEBUG_ARCH_SYMBOL;\r
-      Status = SendDataResponsePacket ((UINT8 *) &Data8, (UINT16) sizeof (UINT8));\r
+      Status = SendDataResponsePacket ((UINT8 *) &Data8, (UINT16) sizeof (UINT8), DebugHeader);\r
       break;\r
 \r
     case DEBUG_COMMAND_READ_MSR:\r
       MsrRegisterRead = (DEBUG_DATA_READ_MSR *) (DebugHeader + 1);\r
       Data64 = AsmReadMsr64 (MsrRegisterRead->Index);\r
-      Status = SendDataResponsePacket ((UINT8 *) &Data64, (UINT16) sizeof (UINT64));\r
+      Status = SendDataResponsePacket ((UINT8 *) &Data64, (UINT16) sizeof (UINT64), DebugHeader);\r
       break;\r
 \r
     case DEBUG_COMMAND_WRITE_MSR:\r
@@ -1972,13 +2120,13 @@ CommandCommunication (
     case DEBUG_COMMAND_GET_REVISION:\r
       DebugAgentRevision.Revision = DEBUG_AGENT_REVISION;\r
       DebugAgentRevision.Capabilities = DEBUG_AGENT_CAPABILITIES;\r
-      Status = SendDataResponsePacket ((UINT8 *) &DebugAgentRevision, (UINT16) sizeof (DEBUG_DATA_RESPONSE_GET_REVISION));\r
+      Status = SendDataResponsePacket ((UINT8 *) &DebugAgentRevision, (UINT16) sizeof (DEBUG_DATA_RESPONSE_GET_REVISION), DebugHeader);\r
       break;\r
 \r
     case DEBUG_COMMAND_GET_EXCEPTION:\r
       Exception.ExceptionNum  = (UINT8) Vector;\r
       Exception.ExceptionData = (UINT32) CpuContext->ExceptionData;\r
-      Status = SendDataResponsePacket ((UINT8 *) &Exception, (UINT16) sizeof (DEBUG_DATA_RESPONSE_GET_EXCEPTION));\r
+      Status = SendDataResponsePacket ((UINT8 *) &Exception, (UINT16) sizeof (DEBUG_DATA_RESPONSE_GET_EXCEPTION), DebugHeader);\r
       break;\r
 \r
     case DEBUG_COMMAND_SET_VIEWPOINT:\r
@@ -2004,12 +2152,12 @@ CommandCommunication (
 \r
     case DEBUG_COMMAND_GET_VIEWPOINT:\r
       Data32 = mDebugMpContext.ViewPointIndex;\r
-      SendDataResponsePacket((UINT8 *) &Data32, (UINT16) sizeof (UINT32));\r
+      SendDataResponsePacket((UINT8 *) &Data32, (UINT16) sizeof (UINT32), DebugHeader);\r
       break;\r
 \r
     case DEBUG_COMMAND_MEMORY_READY:\r
       Data8 = (UINT8) GetDebugFlag (DEBUG_AGENT_FLAG_MEMORY_READY);\r
-      SendDataResponsePacket (&Data8, (UINT16) sizeof (UINT8));\r
+      SendDataResponsePacket (&Data8, (UINT16) sizeof (UINT8), DebugHeader);\r
       break;\r
 \r
     case DEBUG_COMMAND_DETACH:\r
@@ -2024,7 +2172,7 @@ CommandCommunication (
         &CpuidResponse.Eax, &CpuidResponse.Ebx,\r
         &CpuidResponse.Ecx, &CpuidResponse.Edx\r
         );\r
-      SendDataResponsePacket ((UINT8 *) &CpuidResponse, (UINT16) sizeof (CpuidResponse));\r
+      SendDataResponsePacket ((UINT8 *) &CpuidResponse, (UINT16) sizeof (CpuidResponse), DebugHeader);\r
       break;\r
 \r
    case DEBUG_COMMAND_SEARCH_SIGNATURE:\r
@@ -2059,7 +2207,7 @@ CommandCommunication (
             Data64 = (UINT64) -1;\r
           }\r
         }\r
-        SendDataResponsePacket ((UINT8 *) &Data64, (UINT16) sizeof (Data64));\r
+        SendDataResponsePacket ((UINT8 *) &Data64, (UINT16) sizeof (Data64), DebugHeader);\r
       } else {\r
         Status = RETURN_UNSUPPORTED;\r
       }\r
index 53d96609be542496c3e89288c364bd366f3d631c..65e05fb4c65e8ccca19115aba5ceb88cbd97158b 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Command header of for Debug Agent library instance.\r
 \r
-  Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2015, 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
@@ -205,8 +205,10 @@ ArchReadRegisterBuffer (
 /**\r
   Send packet with response data to HOST.\r
 \r
-  @param[in] Data        Pointer to response data buffer.\r
-  @param[in] DataSize    Size of response data in byte.\r
+  @param[in]      Data        Pointer to response data buffer.\r
+  @param[in]      DataSize    Size of response data in byte.\r
+  @param[in, out] DebugHeader Pointer to a buffer for creating response packet and receiving ACK packet,\r
+                              to minimize the stack usage.\r
 \r
   @retval RETURN_SUCCESS      Response data was sent successfully.\r
   @retval RETURN_DEVICE_ERROR Cannot receive DEBUG_COMMAND_OK from HOST.\r
@@ -214,8 +216,9 @@ ArchReadRegisterBuffer (
 **/\r
 RETURN_STATUS\r
 SendDataResponsePacket (\r
-  IN UINT8                *Data,\r
-  IN UINT16               DataSize\r
+  IN UINT8                   *Data,\r
+  IN UINT16                  DataSize,\r
+  IN OUT DEBUG_PACKET_HEADER *DebugHeader\r
   );\r
 \r
 /**\r
index 2aaf5b7b4cc5c886e84adf12395314bc9a528c70..377ade7c3b3ed1aae423e5c092e7a9388d4dcae9 100644 (file)
@@ -1,6 +1,6 @@
 ;------------------------------------------------------------------------------\r
 ;\r
-; Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>\r
+; Copyright (c) 2010 - 2015, 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
@@ -302,17 +302,22 @@ NoExtrPush:
     mov     eax, dr0\r
     push    eax\r
 \r
+    ;; Clear Direction Flag\r
+    cld\r
+\r
     ;; FX_SAVE_STATE_IA32 FxSaveState;\r
-    sub esp, 512\r
-    mov edi, esp\r
+    sub     esp, 512\r
+    mov     edi, esp\r
+    ;; Clear the buffer\r
+    xor     eax, eax\r
+    mov     ecx, 128 ;= 512 / 4\r
+    rep     stosd\r
+    mov     edi, esp\r
     db 0fh, 0aeh, 00000111y ;fxsave [edi]\r
 \r
-    ;; save the exception data    \r
+    ;; save the exception data\r
     push    dword ptr [ebp + 8]\r
 \r
-    ;; Clear Direction Flag\r
-    cld\r
-       \r
     ; call the C interrupt process function\r
     push    esp     ; Structure\r
     push    ebx     ; vector\r
@@ -323,7 +328,7 @@ NoExtrPush:
     add     esp, 4\r
 \r
     ;; FX_SAVE_STATE_IA32 FxSaveState;\r
-    mov esi, esp\r
+    mov     esi, esp\r
     db 0fh, 0aeh, 00001110y ; fxrstor [esi]\r
     add esp, 512\r
 \r
index 0f076a76dae41280158b6c7d62bffc7d29695b74..6d01f64d0fdb1b7cb422a571f7a2788aa4b02f69 100644 (file)
@@ -1,6 +1,6 @@
 ;------------------------------------------------------------------------------\r
 ;\r
-; Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>\r
+; Copyright (c) 2010 - 2015, 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
@@ -286,16 +286,23 @@ NoExtrPush:
     mov     rax, dr0\r
     push    rax\r
 \r
+    ;; Clear Direction Flag\r
+    cld\r
+\r
     sub     rsp, 512\r
     mov     rdi, rsp\r
+    ;; Clear the buffer\r
+    xor     rax, rax\r
+    push    rcx\r
+    mov     rcx, 64 ;= 512 / 8\r
+    rep     stosq\r
+    pop     rcx\r
+    mov     rdi, rsp\r
     db 0fh, 0aeh, 00000111y ;fxsave [rdi]\r
 \r
     ;; save the exception data\r
     push    qword ptr [rbp + 16]\r
 \r
-    ;; Clear Direction Flag\r
-    cld\r
-       \r
     ; call the C interrupt process function\r
     mov     rdx, rsp      ; Structure\r
     mov     r15, rcx      ; save vector in r15\r