]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EmbeddedPkg/GdbStub/Ia32/Processor.c
EmbeddedPkg: Fix various typos
[mirror_edk2.git] / EmbeddedPkg / GdbStub / Ia32 / Processor.c
index e327b3e6db4114c419b5baf5de320f43b541f80c..8dc768f180b57404f1c72fa099ae5c8dfafea2ee 100644 (file)
@@ -2,14 +2,8 @@
   Processor specific parts of the GDB stub\r
 \r
   Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
-  \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
 \r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -20,7 +14,7 @@
 // {EFI mapping, GDB mapping}\r
 //\r
 EFI_EXCEPTION_TYPE_ENTRY gExceptionType[] = {\r
-  { EXCEPT_IA32_DIVIDE_ERROR,     GDB_SIGFPE  }, \r
+  { EXCEPT_IA32_DIVIDE_ERROR,     GDB_SIGFPE  },\r
   { EXCEPT_IA32_DEBUG,            GDB_SIGTRAP },\r
   { EXCEPT_IA32_NMI,              GDB_SIGEMT  },\r
   { EXCEPT_IA32_BREAKPOINT,       GDB_SIGTRAP },\r
@@ -62,7 +56,7 @@ UINTN gRegisterOffsets[] = {
 \r
 \r
 //Debug only..\r
-VOID \r
+VOID\r
 PrintReg (\r
   IN EFI_SYSTEM_CONTEXT SystemContext\r
   )\r
@@ -80,7 +74,7 @@ PrintReg (
 }\r
 \r
 //Debug only..\r
-VOID \r
+VOID\r
 PrintDRreg (\r
   IN EFI_SYSTEM_CONTEXT SystemContext\r
   )\r
@@ -96,8 +90,8 @@ PrintDRreg (
 \r
 /**\r
  Return the number of entries in the gExceptionType[]\r
\r
- @retval  UINTN, the number of entries in the gExceptionType[] array.    \r
+\r
+ @retval  UINTN, the number of entries in the gExceptionType[] array.\r
  **/\r
 UINTN\r
 MaxEfiException (\r
@@ -110,8 +104,8 @@ MaxEfiException (
 \r
 /**\r
  Return the number of entries in the gRegisters[]\r
\r
- @retval  UINTN, the number of entries (registers) in the gRegisters[] array.    \r
+\r
+ @retval  UINTN, the number of entries (registers) in the gRegisters[] array.\r
  **/\r
 UINTN\r
 MaxRegisterCount (\r
@@ -123,9 +117,9 @@ MaxRegisterCount (
 \r
 \r
 /**\r
-  Check to see if the ISA is supported. \r
+  Check to see if the ISA is supported.\r
   ISA = Instruction Set Architecture\r
\r
+\r
   @retval TRUE if Isa is supported,\r
       FALSE otherwise.\r
 **/\r
@@ -142,14 +136,14 @@ CheckIsa (
  This takes in the register number and the System Context, and returns a pointer to the RegNumber-th register in gdb ordering\r
  It is, by default, set to find the register pointer of the IA32 member\r
 \r
- @param   SystemContext     Register content at time of the exception \r
+ @param   SystemContext     Register content at time of the exception\r
  @param   RegNumber       The register to which we want to find a pointer\r
  @retval  the pointer to the RegNumber-th pointer\r
  **/\r
 UINTN *\r
 FindPointerToRegister (\r
   IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
-  IN  UINTN               RegNumber  \r
+  IN  UINTN               RegNumber\r
   )\r
 {\r
   UINT8 *TempPtr;\r
@@ -174,7 +168,7 @@ BasicReadRegister (
   )\r
 {\r
   UINTN RegSize;\r
-  \r
+\r
   RegSize = 0;\r
   while (RegSize < REG_SIZE) {\r
     *OutBufPtr++ = mHexToStr[((*FindPointerToRegister (SystemContext, RegNumber) >> (RegSize+4)) & 0xf)];\r
@@ -185,8 +179,8 @@ BasicReadRegister (
 }\r
 \r
 \r
-/** ‘p n’ \r
- Reads the n-th register's value into an output buffer and sends it as a packet \r
+/** ‘p n’\r
+ Reads the n-th register's value into an output buffer and sends it as a packet\r
 \r
  @param   SystemContext   Register content at time of the exception\r
  @param   InBuffer      Pointer to the input buffer received from gdb server\r
@@ -201,7 +195,7 @@ ReadNthRegister (
   UINTN RegNumber;\r
   CHAR8 OutBuffer[9]; // 1 reg=8 hex chars, and the end '\0' (escape seq)\r
   CHAR8 *OutBufPtr;   // pointer to the output buffer\r
-  \r
+\r
   RegNumber = AsciiStrHexToUintn (&InBuffer[1]);\r
 \r
   if ((RegNumber < 0) || (RegNumber >= MaxRegisterCount())) {\r
@@ -217,14 +211,14 @@ ReadNthRegister (
 }\r
 \r
 \r
-/** ‘g’ \r
- Reads the general registers into an output buffer  and sends it as a packet \r
+/** ‘g’\r
+ Reads the general registers into an output buffer  and sends it as a packet\r
 \r
  @param   SystemContext     Register content at time of the exception\r
  **/\r
 VOID\r
 EFIAPI\r
-ReadGeneralRegisters (  \r
+ReadGeneralRegisters (\r
   IN  EFI_SYSTEM_CONTEXT      SystemContext\r
   )\r
 {\r
@@ -233,7 +227,7 @@ ReadGeneralRegisters (
   CHAR8 *OutBufPtr;   // pointer to the output buffer\r
 \r
   OutBufPtr = OutBuffer;\r
-  for (i = 0 ; i < MaxRegisterCount() ; i++) {  // there are only 16 registers to read   \r
+  for (i = 0 ; i < MaxRegisterCount() ; i++) {  // there are only 16 registers to read\r
     OutBufPtr = BasicReadRegister (SystemContext, i, OutBufPtr);\r
   }\r
 \r
@@ -260,26 +254,26 @@ BasicWriteRegister (
   UINTN RegSize;\r
   UINTN TempValue; // the value transferred from a hex char\r
   UINT32 NewValue; // the new value of the RegNumber-th Register\r
-  \r
+\r
   NewValue = 0;\r
   RegSize = 0;\r
   while (RegSize < REG_SIZE) {\r
     TempValue = HexCharToInt(*InBufPtr++);\r
-    \r
+\r
    if (TempValue < 0) {\r
-      SendError (GDB_EBADMEMDATA); \r
+      SendError (GDB_EBADMEMDATA);\r
       return NULL;\r
     }\r
 \r
     NewValue += (TempValue << (RegSize+4));\r
     TempValue = HexCharToInt(*InBufPtr++);\r
-    \r
+\r
     if (TempValue < 0) {\r
-      SendError (GDB_EBADMEMDATA); \r
+      SendError (GDB_EBADMEMDATA);\r
       return NULL;\r
     }\r
-    \r
-    NewValue += (TempValue << RegSize); \r
+\r
+    NewValue += (TempValue << RegSize);\r
     RegSize = RegSize + 8;\r
   }\r
   *(FindPointerToRegister (SystemContext, RegNumber)) = NewValue;\r
@@ -291,7 +285,7 @@ BasicWriteRegister (
  Writes the new value of n-th register received into the input buffer to the n-th register\r
 \r
  @param   SystemContext   Register content at time of the exception\r
- @param   InBuffer      Ponter to the input buffer received from gdb server\r
+ @param   InBuffer      Pointer to the input buffer received from gdb server\r
  **/\r
 VOID\r
 EFIAPI\r
@@ -304,19 +298,19 @@ WriteNthRegister (
   CHAR8 RegNumBuffer[MAX_REG_NUM_BUF_SIZE];  // put the 'n..' part of the message into this array\r
   CHAR8 *RegNumBufPtr;\r
   CHAR8 *InBufPtr; // pointer to the input buffer\r
-  \r
+\r
   // find the register number to write\r
   InBufPtr = &InBuffer[1];\r
   RegNumBufPtr = RegNumBuffer;\r
   while (*InBufPtr != '=') {\r
     *RegNumBufPtr++ = *InBufPtr++;\r
-  } \r
+  }\r
   *RegNumBufPtr = '\0';\r
-  RegNumber = AsciiStrHexToUintn (RegNumBuffer); \r
+  RegNumber = AsciiStrHexToUintn (RegNumBuffer);\r
 \r
   // check if this is a valid Register Number\r
   if ((RegNumber < 0) || (RegNumber >= MaxRegisterCount())) {\r
-       SendError (GDB_EINVALIDREGNUM); \r
+    SendError (GDB_EINVALIDREGNUM);\r
     return;\r
   }\r
   InBufPtr++;  // skips the '=' character\r
@@ -341,16 +335,16 @@ WriteGeneralRegisters (
   UINTN  i;\r
   CHAR8 *InBufPtr; /// pointer to the input buffer\r
 \r
-  // check to see if the buffer is the right size which is \r
-  // 1 (for 'G') + 16 (for 16 registers) * 8 ( for 8 hex chars each) = 129 \r
+  // check to see if the buffer is the right size which is\r
+  // 1 (for 'G') + 16 (for 16 registers) * 8 ( for 8 hex chars each) = 129\r
   if (AsciiStrLen(InBuffer) != 129) { // 16 regs, 8 hex chars each, and the end '\0' (escape seq)\r
-       //Bad message. Message is not the right length \r
-    SendError (GDB_EBADBUFSIZE); \r
+    //Bad message. Message is not the right length\r
+    SendError (GDB_EBADBUFSIZE);\r
     return;\r
   }\r
 \r
   InBufPtr = &InBuffer[1];\r
-  \r
+\r
   // Read the new values for the registers from the input buffer to an array, NewValueArray.\r
   // The values in the array are in the gdb ordering\r
   for (i=0; i < MaxRegisterCount(); i++) {  // there are only 16 registers to write\r
@@ -361,9 +355,9 @@ WriteGeneralRegisters (
 }\r
 \r
 \r
-/** \r
+/**\r
  Insert Single Step in the SystemContext\r
\r
+\r
  @param SystemContext Register content at time of the exception\r
  **/\r
 VOID\r
@@ -374,10 +368,10 @@ AddSingleStep (
   SystemContext.SystemContextIa32->Eflags |= TF_BIT; //Setting the TF bit.\r
 }\r
 \r
-  \r
-/** \r
+\r
+/**\r
  Remove Single Step in the SystemContext\r
\r
+\r
  @param SystemContext Register content at time of the exception\r
  **/\r
 VOID\r
@@ -390,11 +384,11 @@ RemoveSingleStep (
 \r
 \r
 \r
-/** ‘c [addr ]’ \r
- Continue. addr is Address to resume. If addr is omitted, resume at current \r
+/** ‘c [addr ]’\r
+ Continue. addr is Address to resume. If addr is omitted, resume at current\r
  Address.\r
\r
- @param   SystemContext     Register content at time of the exception  \r
+\r
+ @param   SystemContext     Register content at time of the exception\r
  **/\r
 VOID\r
 EFIAPI\r
@@ -405,15 +399,15 @@ ContinueAtAddress (
 {\r
   if (PacketData[1] != '\0') {\r
     SystemContext.SystemContextIa32->Eip = AsciiStrHexToUintn (&PacketData[1]);\r
-  } \r
+  }\r
 }\r
 \r
 \r
 /** ‘s [addr ]’\r
- Single step. addr is the Address at which to resume. If addr is omitted, resume \r
+ Single step. addr is the Address at which to resume. If addr is omitted, resume\r
  at same Address.\r
\r
- @param   SystemContext     Register content at time of the exception  \r
+\r
+ @param   SystemContext     Register content at time of the exception\r
  **/\r
 VOID\r
 EFIAPI\r
@@ -425,7 +419,7 @@ SingleStep (
   if (PacketData[1] != '\0') {\r
     SystemContext.SystemContextIa32->Eip = AsciiStrHexToUintn (&PacketData[1]);\r
   }\r
-  \r
+\r
   AddSingleStep (SystemContext);\r
 }\r
 \r
@@ -469,9 +463,9 @@ GetBreakpointDataAddress (
 \r
   @param  SystemContext  Register content at time of the exception\r
 \r
-  @retval {1-4}          Currently detected breakpoint value   \r
+  @retval {1-4}          Currently detected breakpoint value\r
   @retval 0              No breakpoint detected.\r
\r
+\r
 **/\r
 UINTN\r
 GetBreakpointDetected (\r
@@ -492,7 +486,7 @@ GetBreakpointDetected (
   } else if (Dr6.Bits.B3 == 1) {\r
     BreakpointNumber = 4;\r
   } else {\r
-    BreakpointNumber = 0;  //No breakpoint detected \r
+    BreakpointNumber = 0;  //No breakpoint detected\r
   }\r
 \r
   return BreakpointNumber;\r
@@ -502,13 +496,13 @@ GetBreakpointDetected (
 /**\r
   Returns Breakpoint type (InstructionExecution, DataWrite, DataRead or DataReadWrite)\r
   based on the Breakpoint number\r
-  \r
+\r
   @param  SystemContext        Register content at time of the exception\r
   @param  BreakpointNumber     Breakpoint number\r
-  \r
+\r
   @retval BREAK_TYPE           Breakpoint type value read from register DR7 RWn field\r
                                For unknown value, it returns NotSupported.\r
-  \r
+\r
 **/\r
 BREAK_TYPE\r
 GetBreakpointType (\r
@@ -522,22 +516,22 @@ GetBreakpointType (
   Dr7.UintN = SystemContext.SystemContextIa32->Dr7;\r
 \r
   if (BreakpointNumber == 1) {\r
-    Type = (BREAK_TYPE) Dr7.Bits.RW0;  \r
+    Type = (BREAK_TYPE) Dr7.Bits.RW0;\r
   } else if (BreakpointNumber == 2) {\r
-    Type = (BREAK_TYPE) Dr7.Bits.RW1;  \r
+    Type = (BREAK_TYPE) Dr7.Bits.RW1;\r
   } else if (BreakpointNumber == 3) {\r
-    Type = (BREAK_TYPE) Dr7.Bits.RW2;  \r
+    Type = (BREAK_TYPE) Dr7.Bits.RW2;\r
   } else if (BreakpointNumber == 4) {\r
-    Type = (BREAK_TYPE) Dr7.Bits.RW3;  \r
+    Type = (BREAK_TYPE) Dr7.Bits.RW3;\r
   }\r
 \r
   return Type;\r
 }\r
 \r
 \r
-/** \r
+/**\r
   Parses Length and returns the length which DR7 LENn field accepts.\r
-  For example: If we receive 1-Byte length then we should return 0. \r
+  For example: If we receive 1-Byte length then we should return 0.\r
                Zero gets written to DR7 LENn field.\r
 \r
   @param  Length  Breakpoint length in Bytes (1 byte, 2 byte, 4 byte)\r
@@ -550,7 +544,7 @@ ConvertLengthData (
   IN     UINTN   Length\r
   )\r
 {\r
-  if (Length == 1) {         //1-Byte length \r
+  if (Length == 1) {         //1-Byte length\r
     return 0;\r
   } else if (Length == 2) {  //2-Byte length\r
     return 1;\r
@@ -563,8 +557,8 @@ ConvertLengthData (
 \r
 \r
 /**\r
-  Finds the next free debug register. If all the registers are occupied then \r
-  EFI_OUT_OF_RESOURCES is returned.  \r
+  Finds the next free debug register. If all the registers are occupied then\r
+  EFI_OUT_OF_RESOURCES is returned.\r
 \r
   @param  SystemContext   Register content at time of the exception\r
   @param  Register        Register value (0 - 3 for the first free debug register)\r
@@ -601,11 +595,11 @@ FindNextFreeDebugRegister (
 /**\r
   Enables the debug register. Writes Address value to appropriate DR0-3 register.\r
   Sets LENn, Gn, RWn bits in DR7 register.\r
\r
+\r
   @param  SystemContext   Register content at time of the exception\r
-  @param  Register        Register value (0 - 3) \r
+  @param  Register        Register value (0 - 3)\r
   @param  Address         Breakpoint address value\r
-  @param  Type            Breakpoint type (Instruction, Data write, Data read \r
+  @param  Type            Breakpoint type (Instruction, Data write, Data read\r
                           or write etc.)\r
 \r
   @retval EFI_STATUS      Appropriate status value.\r
@@ -625,15 +619,15 @@ EnableDebugRegister (
   //Convert length data\r
   Length = ConvertLengthData (Length);\r
 \r
-  //For Instruction execution, length should be 0 \r
+  //For Instruction execution, length should be 0\r
   //(Ref. Intel reference manual 18.2.4)\r
   if ((Type == 0) && (Length != 0)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
\r
+\r
   //Hardware doesn't support ReadWatch (z3 packet) type. GDB can handle\r
   //software breakpoint. We should send empty packet in both these cases.\r
-  if ((Type == (BREAK_TYPE)DataRead) || \r
+  if ((Type == (BREAK_TYPE)DataRead) ||\r
       (Type == (BREAK_TYPE)SoftwareBreakpoint)) {\r
     return EFI_UNSUPPORTED;\r
   }\r
@@ -665,7 +659,7 @@ EnableDebugRegister (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  //Update Dr7 with appropriate Gn, RWn and LENn bits \r
+  //Update Dr7 with appropriate Gn, RWn and LENn bits\r
   SystemContext.SystemContextIa32->Dr7 = Dr7.UintN;\r
 \r
   return EFI_SUCCESS;\r
@@ -673,7 +667,7 @@ EnableDebugRegister (
 \r
 \r
 /**\r
-  Returns register number 0 - 3 for the maching debug register.\r
+  Returns register number 0 - 3 for the matching debug register.\r
   This function compares incoming Address, Type, Length and\r
   if there is a match then it returns the appropriate register number.\r
   In case of mismatch, function returns EFI_NOT_FOUND message.\r
@@ -681,7 +675,7 @@ EnableDebugRegister (
   @param  SystemContext  Register content at time of the exception\r
   @param  Address        Breakpoint address value\r
   @param  Length         Breakpoint length value\r
-  @param  Type           Breakpoint type (Instruction, Data write, \r
+  @param  Type           Breakpoint type (Instruction, Data write,\r
                          Data read or write etc.)\r
   @param  Register       Register value to be returned\r
 \r
@@ -701,7 +695,7 @@ FindMatchingDebugRegister (
 \r
   //Hardware doesn't support ReadWatch (z3 packet) type. GDB can handle\r
   //software breakpoint. We should send empty packet in both these cases.\r
-  if ((Type == (BREAK_TYPE)DataRead) || \r
+  if ((Type == (BREAK_TYPE)DataRead) ||\r
       (Type == (BREAK_TYPE)SoftwareBreakpoint)) {\r
     return EFI_UNSUPPORTED;\r
   }\r
@@ -711,24 +705,24 @@ FindMatchingDebugRegister (
 \r
   Dr7.UintN = SystemContext.SystemContextIa32->Dr7;\r
 \r
-  if ((Dr7.Bits.G0 == 1) && \r
+  if ((Dr7.Bits.G0 == 1) &&\r
       (Dr7.Bits.LEN0 == Length) &&\r
-      (Dr7.Bits.RW0 == Type) && \r
+      (Dr7.Bits.RW0 == Type) &&\r
       (Address == SystemContext.SystemContextIa32->Dr0)) {\r
     *Register = 0;\r
-  } else if ((Dr7.Bits.G1 == 1) && \r
+  } else if ((Dr7.Bits.G1 == 1) &&\r
              (Dr7.Bits.LEN1 == Length) &&\r
-             (Dr7.Bits.RW1 == Type) && \r
+             (Dr7.Bits.RW1 == Type) &&\r
              (Address == SystemContext.SystemContextIa32->Dr1)) {\r
     *Register = 1;\r
-  } else if ((Dr7.Bits.G2 == 1) && \r
+  } else if ((Dr7.Bits.G2 == 1) &&\r
              (Dr7.Bits.LEN2 == Length) &&\r
-             (Dr7.Bits.RW2 == Type) && \r
+             (Dr7.Bits.RW2 == Type) &&\r
              (Address == SystemContext.SystemContextIa32->Dr2)) {\r
     *Register = 2;\r
-  } else if ((Dr7.Bits.G3 == 1) && \r
+  } else if ((Dr7.Bits.G3 == 1) &&\r
              (Dr7.Bits.LEN3 == Length) &&\r
-             (Dr7.Bits.RW3 == Type) && \r
+             (Dr7.Bits.RW3 == Type) &&\r
              (Address == SystemContext.SystemContextIa32->Dr3)) {\r
     *Register = 3;\r
   } else {\r
@@ -752,12 +746,12 @@ FindMatchingDebugRegister (
 EFI_STATUS\r
 DisableDebugRegister (\r
  IN  EFI_SYSTEM_CONTEXT  SystemContext,\r
- IN  UINTN               Register  \r
+ IN  UINTN               Register\r
  )\r
 {\r
   IA32_DR7  Dr7;\r
   UINTN Address = 0;\r
\r
+\r
   //Read DR7 register so appropriate Gn, RWn and LENn bits can be turned off.\r
   Dr7.UintN = SystemContext.SystemContextIa32->Dr7;\r
 \r
@@ -914,15 +908,15 @@ RemoveBreakPoint (
   }\r
 \r
   switch (Type) {\r
-  \r
+\r
     case    0:   //Software breakpoint\r
       BreakType = SoftwareBreakpoint;\r
       break;\r
-      \r
+\r
     case    1:   //Hardware breakpoint\r
       BreakType = InstructionExecution;\r
       break;\r
-      \r
+\r
     case    2:   //Write watchpoint\r
       BreakType = DataWrite;\r
       break;\r
@@ -984,8 +978,8 @@ ValidateAddress (
 \r
 BOOLEAN\r
 ValidateException (\r
-  IN  EFI_EXCEPTION_TYPE    ExceptionType, \r
-  IN OUT EFI_SYSTEM_CONTEXT SystemContext \r
+  IN  EFI_EXCEPTION_TYPE    ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT SystemContext\r
   )\r
 {\r
   return TRUE;\r