Revision: 14334
          http://edk2.svn.sourceforge.net/edk2/?rev=14334&view=rev
Author:   vanjeff
Date:     2013-05-09 07:47:13 +0000 (Thu, 09 May 2013)
Log Message:
-----------
Sync patches r14306, r14324 and r14328 from main trunk.
1. Add security check. 
2. Read/Write memory space including MMIO range with the width requested from 
HOST.
3. Updated connecting HOST version information from 1.3 to 1.3.1.

Revision Links:
--------------
    http://edk2.svn.sourceforge.net/edk2/?rev=14306&view=rev
    http://edk2.svn.sourceforge.net/edk2/?rev=14324&view=rev
    http://edk2.svn.sourceforge.net/edk2/?rev=14328&view=rev

Modified Paths:
--------------
    
branches/UDK2010.SR1/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.c
    
branches/UDK2010.SR1/SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c

Modified: 
branches/UDK2010.SR1/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.c
===================================================================
--- 
branches/UDK2010.SR1/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.c
   2013-05-09 06:13:30 UTC (rev 14333)
+++ 
branches/UDK2010.SR1/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.c
   2013-05-09 07:47:13 UTC (rev 14334)
@@ -19,7 +19,7 @@
 #include "Ia32/DebugException.h"
 
 CHAR8 mErrorMsgVersionAlert[]       = "\rThe SourceLevelDebugPkg you are using 
requires a newer version of the Intel(R) UDK Debugger Tool.\r\n";
-CHAR8 mErrorMsgSendInitPacket[]     = "\rSend INIT break packet and try to 
connect the HOST (Intel(R) UDK Debugger Tool v1.3) ...\r\n";
+CHAR8 mErrorMsgSendInitPacket[]     = "\rSend INIT break packet and try to 
connect the HOST (Intel(R) UDK Debugger Tool v1.3.1) ...\r\n";
 CHAR8 mErrorMsgConnectOK[]          = "HOST connection is successful!\r\n";
 CHAR8 mErrorMsgConnectFail[]        = "HOST connection is failed!\r\n";
 CHAR8 mWarningMsgIngoreBreakpoint[] = "Ignore break point in SMM for SMI 
issued during DXE debugging!\r\n";
@@ -1110,56 +1110,128 @@
 }
 
 /**
-  Send packet with response data to HOST.
+  Copy memory from source to destination with specified width.
 
+  @param[out] Dest        A pointer to the destination buffer of the memory 
copy.
+  @param[in]  Src         A pointer to the source buffer of the memory copy.
+  @param[in]  Count       The number of data with specified width to copy from 
source to destination.
+  @param[in]  Width       Data width in byte.
+
+**/
+VOID
+CopyMemByWidth (
+  OUT UINT8               *Dest,
+  IN  UINT8               *Src,
+  IN  UINT16              Count,
+  IN  UINT8               Width
+  )
+{
+  UINT8                   *Destination;
+  UINT8                   *Source;
+  INT8                    Step;
+
+  if (Src > Dest) {
+    Destination = Dest;
+    Source      = Src;
+    Step        = Width;
+  } else {
+    //
+    // Copy memory from tail to avoid memory overlap
+    //
+    Destination = Dest + (Count - 1) * Width;
+    Source      = Src  + (Count - 1) * Width;
+    Step        = -Width;
+  }
+
+  while (Count-- != 0) {
+    switch (Width) {
+    case 1:
+      *(UINT8 *) Destination = MmioRead8 ((UINTN) Source);
+      break;
+    case 2:
+      *(UINT16 *) Destination = MmioRead16 ((UINTN) Source);
+      break;
+    case 4:
+      *(UINT32 *) Destination = MmioRead32 ((UINTN) Source);
+      break;
+    case 8:
+      *(UINT64 *) Destination = MmioRead64 ((UINTN) Source);
+      break;
+    default:
+      ASSERT (FALSE);
+    }
+    Source      += Step;
+    Destination += Step;
+  }
+}
+
+/**
+  Read memory with speicifed width and send packet with response data to HOST.
+
   @param[in] Data        Pointer to response data buffer.
-  @param[in] DataSize    Size of response data in byte.
+  @param[in] Count       The number of data with specified Width.
+  @param[in] Width       Data width in byte.
 
   @retval RETURN_SUCCESS      Response data was sent successfully.
 
 **/
 RETURN_STATUS
-SendDataResponsePacket (
+ReadMemoryAndSendResponsePacket (
   IN UINT8                *Data,
-  IN UINT16               DataSize
+  IN UINT16               Count,
+  IN UINT8                Width
   )
 {
   RETURN_STATUS        Status;
   DEBUG_PACKET_HEADER  *DebugHeader;
   BOOLEAN              LastPacket;
   DEBUG_PACKET_HEADER  *AckDebugHeader;
-  UINT8                DebugPacket[DEBUG_DATA_UPPER_LIMIT];
+  UINT8                DebugPacket[DEBUG_DATA_UPPER_LIMIT + sizeof (UINT64) - 
1];
   UINT8                InputPacketBuffer[DEBUG_DATA_UPPER_LIMIT];
   DEBUG_PORT_HANDLE    Handle;
   UINT8                SequenceNo;
+  UINTN                RemainingDataSize;
+  UINTN                CurrentDataSize;
 
   Handle = GetDebugPortHandle();
 
-  DebugHeader = (DEBUG_PACKET_HEADER *) &DebugPacket;
+  //
+  // Data is appended end of Debug Packet header,  make sure data address
+  // in Debug Packet 8-byte alignment always
+  //
+  DebugHeader = (DEBUG_PACKET_HEADER *) (ALIGN_VALUE ((UINTN)&DebugPacket + 
sizeof (DEBUG_PACKET_HEADER), sizeof (UINT64))
+                                         - sizeof (DEBUG_PACKET_HEADER));
   DebugHeader->StartSymbol = DEBUG_STARTING_SYMBOL_NORMAL;
 
+  RemainingDataSize = Count * Width;
   while (TRUE) {
     SequenceNo = GetMailboxPointer()->HostSequenceNo;
-    if (DataSize <= DEBUG_DATA_MAXIMUM_REAL_DATA) {
+    if (RemainingDataSize <= DEBUG_DATA_MAXIMUM_REAL_DATA) {
+      //
+      // If the remaining data is less one real packet size, this is the last 
data packet
+      //
+      CurrentDataSize = RemainingDataSize;
       LastPacket = TRUE;
-      DebugHeader->Command    = DEBUG_COMMAND_OK;
-      DebugHeader->Length     = (UINT8) (DataSize + sizeof 
(DEBUG_PACKET_HEADER));
-      DebugHeader->SequenceNo = SequenceNo;
-      DebugHeader->Crc        = 0;
-      CopyMem (DebugHeader + 1, Data, DataSize);
-
+      DebugHeader->Command = DEBUG_COMMAND_OK;
     } else {
+      //
+      // Data is too larger to be sent in one packet, calculate the actual 
data size could
+      // be sent in one Maximum data packet
+      //
+      CurrentDataSize = (DEBUG_DATA_MAXIMUM_REAL_DATA / Width) * Width;
       LastPacket = FALSE;
-      DebugHeader->Command    = DEBUG_COMMAND_IN_PROGRESS;
-      DebugHeader->Length     = DEBUG_DATA_MAXIMUM_REAL_DATA + sizeof 
(DEBUG_PACKET_HEADER);
-      DebugHeader->SequenceNo = SequenceNo;
-      DebugHeader->Crc        = 0;
-      CopyMem (DebugHeader + 1, Data, DEBUG_DATA_MAXIMUM_REAL_DATA);
+      DebugHeader->Command = DEBUG_COMMAND_IN_PROGRESS;
     }
-
     //
-    // Calculate and fill the checksum
+    // Construct the rest Debug header
     //
+    DebugHeader->Length     = (UINT8)(CurrentDataSize + sizeof 
(DEBUG_PACKET_HEADER));
+    DebugHeader->SequenceNo = SequenceNo;
+    DebugHeader->Crc        = 0;
+    CopyMemByWidth ((UINT8 *)(DebugHeader + 1), Data, (UINT16) CurrentDataSize 
/ Width, Width);
+    //
+    // Calculate and fill the checksum, DebugHeader->Crc should be 0 before 
invoking CalculateCrc16 ()
+    //
     DebugHeader->Crc = CalculateCrc16 ((UINT8 *) DebugHeader, 
DebugHeader->Length, 0);
 
     DebugAgentDataMsgPrint (DEBUG_AGENT_VERBOSE, TRUE, (UINT8 *) DebugHeader, 
DebugHeader->Length);
@@ -1184,10 +1256,10 @@
       }
       if ((SequenceNo == (UINT8) (DebugHeader->SequenceNo + 1)) && 
(AckDebugHeader->Command == DEBUG_COMMAND_CONTINUE)) {
         //
-        // Send the rest packet
+        // Calculate the rest data size
         //
-        Data     += DEBUG_DATA_MAXIMUM_REAL_DATA;
-        DataSize -= DEBUG_DATA_MAXIMUM_REAL_DATA;
+        Data              += CurrentDataSize;
+        RemainingDataSize -= CurrentDataSize;
         UpdateMailboxContent (GetMailboxPointer(), 
DEBUG_MAILBOX_HOST_SEQUENCE_NO_INDEX, (UINT8) SequenceNo);
         break;
       }
@@ -1200,6 +1272,24 @@
 }
 
 /**
+  Send packet with response data to HOST.
+
+  @param[in] Data        Pointer to response data buffer.
+  @param[in] DataSize    Size of response data in byte.
+
+  @retval RETURN_SUCCESS      Response data was sent successfully.
+
+**/
+RETURN_STATUS
+SendDataResponsePacket (
+  IN UINT8                *Data,
+  IN UINT16               DataSize
+  )
+{
+  return ReadMemoryAndSendResponsePacket (Data, DataSize, 1);
+}
+
+/**
   Send break cause packet to HOST.
 
   @param[in] Vector      Vector value of exception or interrutp.
@@ -1349,7 +1439,7 @@
   )
 {
   RETURN_STATUS                     Status;
-  UINT8                             InputPacketBuffer[DEBUG_DATA_UPPER_LIMIT];
+  UINT8                             InputPacketBuffer[DEBUG_DATA_UPPER_LIMIT + 
sizeof (UINT64) - 1];
   DEBUG_PACKET_HEADER               *DebugHeader;
   UINT8                             Width;
   UINT8                             Data8;
@@ -1376,6 +1466,7 @@
   DEBUG_AGENT_EXCEPTION_BUFFER      AgentExceptionBuffer;
   UINT32                            IssuedViewPoint;
   DEBUG_AGENT_MAILBOX               *Mailbox;
+  UINT8                             *AlignedDataPtr;
 
   ProcessorIndex  = 0;
   IssuedViewPoint = 0;
@@ -1644,12 +1735,19 @@
 
     case DEBUG_COMMAND_READ_MEMORY:
       MemoryRead = (DEBUG_DATA_READ_MEMORY *) (DebugHeader + 1);
-      Status = SendDataResponsePacket ((UINT8 *) (UINTN) MemoryRead->Address, 
(UINT16) (MemoryRead->Count * MemoryRead->Width));
+      Status = ReadMemoryAndSendResponsePacket ((UINT8 *) (UINTN) 
MemoryRead->Address, MemoryRead->Count, MemoryRead->Width);
       break;
 
     case DEBUG_COMMAND_WRITE_MEMORY:
       MemoryWrite = (DEBUG_DATA_WRITE_MEMORY *) (DebugHeader + 1);
-      CopyMem ((VOID *) (UINTN) MemoryWrite->Address, &MemoryWrite->Data, 
MemoryWrite->Count * MemoryWrite->Width);
+      //
+      // Copy data into one memory with 8-byte alignment address
+      //
+      AlignedDataPtr = ALIGN_POINTER ((UINT8 *) &MemoryWrite->Data, sizeof 
(UINT64));
+      if (AlignedDataPtr != (UINT8 *) &MemoryWrite->Data) {
+        CopyMem (AlignedDataPtr, (UINT8 *) &MemoryWrite->Data, 
MemoryWrite->Count * MemoryWrite->Width);
+      }
+      CopyMemByWidth ((UINT8 *) (UINTN) MemoryWrite->Address, AlignedDataPtr, 
MemoryWrite->Count, MemoryWrite->Width);
       SendAckPacket (DEBUG_COMMAND_OK);
       break;
 
@@ -1915,7 +2013,7 @@
     // the saved CPU content in CommandCommunication()
     //
     if (GetDebugFlag (DEBUG_AGENT_FLAG_AGENT_IN_PROGRESS) == 1) {
-      DebugAgentMsgPrint (DEBUG_AGENT_ERROR, "Debug agent meet one Exception, 
ExceptionNum is %d.\n", Vector);
+      DebugAgentMsgPrint (DEBUG_AGENT_ERROR, "Debug agent meet one Exception, 
ExceptionNum is %d, EIP = 0x%x.\n", Vector, (UINTN)CpuContext->Eip);
       ExceptionBuffer = (DEBUG_AGENT_EXCEPTION_BUFFER *) (UINTN) 
GetMailboxPointer()->ExceptionBufferPointer;
       ExceptionBuffer->ExceptionContent.ExceptionNum  = (UINT8) Vector;
       ExceptionBuffer->ExceptionContent.ExceptionData = (UINT32) 
CpuContext->ExceptionData;

Modified: 
branches/UDK2010.SR1/SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c
===================================================================
--- 
branches/UDK2010.SR1/SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c
  2013-05-09 06:13:30 UTC (rev 14333)
+++ 
branches/UDK2010.SR1/SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c
  2013-05-09 07:47:13 UTC (rev 14334)
@@ -281,6 +281,7 @@
   // Update Mailbox Location pointer in GUIDed HOB and IDT entry with new one
   //
   MailboxLocationInHob = GetMailboxLocationFromHob ();
+  ASSERT (MailboxLocationInHob != NULL);
   *MailboxLocationInHob = (UINT64)(UINTN)NewMailbox;
   SetLocationSavedMailboxPointerInIdtEntry (MailboxLocationInHob);
   //

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and 
their applications. This 200-page book is written by three acclaimed 
leaders in the field. The early access version is available now. 
Download your free book today! http://p.sf.net/sfu/neotech_d2d_may
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to