]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EmbeddedPkg/GdbStub/Arm/Processor.c
EmbeddedPkg: Fix various typos
[mirror_edk2.git] / EmbeddedPkg / GdbStub / Arm / Processor.c
index 77ea933977995f687359846351227d88d77c8304..f15d356c44810ccadd99d1de19f018723c101455 100644 (file)
@@ -1,27 +1,9 @@
 /** @file\r
   Processor specific parts of the GDB stub\r
 \r
-  Copyright (c) 2008-2009, Apple Inc. All rights reserved.\r
-  \r
-  All rights reserved. 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
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\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
-\r
-**/\r
-/** @file\r
-  \r
-  Copyright (c) 2008, Apple, Inc                                                         \r
-  All rights reserved. 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
 //\r
 EFI_EXCEPTION_TYPE_ENTRY gExceptionType[] = {\r
   { EXCEPT_ARM_SOFTWARE_INTERRUPT,  GDB_SIGTRAP }\r
-//  { EXCEPT_ARM_UNDEFINED_INSTRUCTION, GDB_SIGTRAP },  \r
-//  { EXCEPT_ARM_PREFETCH_ABORT,        GDB_SIGTRAP }, \r
-//  { EXCEPT_ARM_DATA_ABORT,            GDB_SIGEMT  },  \r
-//  { EXCEPT_ARM_RESERVED,              GDB_SIGILL  }  \r
+//  { EXCEPT_ARM_UNDEFINED_INSTRUCTION, GDB_SIGTRAP },\r
+//  { EXCEPT_ARM_PREFETCH_ABORT,        GDB_SIGTRAP },\r
+//  { EXCEPT_ARM_DATA_ABORT,            GDB_SIGEMT  },\r
+//  { EXCEPT_ARM_RESERVED,              GDB_SIGILL  }\r
 };\r
 \r
 // Shut up some annoying RVCT warnings\r
@@ -98,37 +80,37 @@ UINTN gRegisterOffsets[] = {
 \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
   VOID\r
   )\r
 {\r
-  return sizeof (gExceptionType)/sizeof (EFI_EXCEPTION_TYPE_ENTRY);\r
+  return sizeof (gExceptionType) / sizeof (EFI_EXCEPTION_TYPE_ENTRY);\r
 }\r
 \r
 \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
   VOID\r
   )\r
 {\r
-  return sizeof (gRegisterOffsets)/sizeof (UINTN);\r
+  return sizeof (gRegisterOffsets) / sizeof (UINTN);\r
 }\r
 \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
- @retval TRUE if Isa is supported    \r
+ @retval TRUE if Isa is supported\r
 \r
 **/\r
 BOOLEAN\r
@@ -147,14 +129,14 @@ CheckIsa (
 /**\r
  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 ARM member\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
+ **/\r
 UINTN *\r
-FindPointerToRegister(\r
+FindPointerToRegister (\r
   IN  EFI_SYSTEM_CONTEXT      SystemContext,\r
-  IN  UINTN           RegNumber  \r
+  IN  UINTN           RegNumber\r
   )\r
 {\r
   UINT8 *TempPtr;\r
@@ -180,35 +162,35 @@ BasicReadRegister (
 {\r
   UINTN RegSize;\r
   CHAR8 Char;\r
-  \r
+\r
   if (gRegisterOffsets[RegNumber] > 0xF00) {\r
-    AsciiSPrint(OutBufPtr, 9, "00000000");\r
+    AsciiSPrint (OutBufPtr, 9, "00000000");\r
     OutBufPtr += 8;\r
     return OutBufPtr;\r
   }\r
 \r
   RegSize = 0;\r
   while (RegSize < 32) {\r
-    Char = mHexToStr[(UINT8)((*FindPointerToRegister(SystemContext, RegNumber) >> (RegSize+4)) & 0xf)];\r
+    Char = mHexToStr[(UINT8)((*FindPointerToRegister (SystemContext, RegNumber) >> (RegSize+4)) & 0xf)];\r
     if ((Char >= 'A') && (Char <= 'F')) {\r
       Char = Char - 'A' + 'a';\r
     }\r
     *OutBufPtr++ = Char;\r
-    \r
-    Char = mHexToStr[(UINT8)((*FindPointerToRegister(SystemContext, RegNumber) >> RegSize) & 0xf)];\r
+\r
+    Char = mHexToStr[(UINT8)((*FindPointerToRegister (SystemContext, RegNumber) >> RegSize) & 0xf)];\r
     if ((Char >= 'A') && (Char <= 'F')) {\r
       Char = Char - 'A' + 'a';\r
     }\r
     *OutBufPtr++ = Char;\r
-    \r
+\r
     RegSize = RegSize + 8;\r
   }\r
   return OutBufPtr;\r
 }\r
 \r
 \r
-/** ‘p n’ \r
- Reads the n-th register's value into an output buffer and sends it as a packet \r
+/**\r
+ Reads the n-th register's value into an output buffer and sends it as a packet\r
  @param   SystemContext   Register content at time of the exception\r
  @param   InBuffer      Pointer to the input buffer received from gdb server\r
  **/\r
@@ -221,47 +203,47 @@ 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 >= MaxRegisterCount()) {\r
-    SendError (GDB_EINVALIDREGNUM); \r
+\r
+  if (RegNumber >= MaxRegisterCount ()) {\r
+    SendError (GDB_EINVALIDREGNUM);\r
     return;\r
   }\r
-  \r
+\r
   OutBufPtr = OutBuffer;\r
   OutBufPtr = BasicReadRegister (SystemContext, RegNumber, OutBufPtr);\r
-  \r
+\r
   *OutBufPtr = '\0';  // the end of the buffer\r
-  SendPacket(OutBuffer);\r
+  SendPacket (OutBuffer);\r
 }\r
 \r
 \r
-/** ‘g’ \r
- Reads the general registers into an output buffer  and sends it as a packet \r
+/**\r
+ Reads the general registers into an output buffer  and sends it as a packet\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
   UINTN   Index;\r
   CHAR8   *OutBuffer;\r
   CHAR8   *OutBufPtr;\r
-  UINTN   RegisterCount = MaxRegisterCount();\r
-  \r
+  UINTN   RegisterCount = MaxRegisterCount ();\r
+\r
   // It is not safe to allocate pool here....\r
-  OutBuffer = AllocatePool((RegisterCount * 8) + 1); // 8 bytes per register in string format plus a null to terminate\r
+  OutBuffer = AllocatePool ((RegisterCount * 8) + 1); // 8 bytes per register in string format plus a null to terminate\r
   OutBufPtr = OutBuffer;\r
   for (Index = 0; Index < RegisterCount; Index++) {\r
     OutBufPtr = BasicReadRegister (SystemContext, Index, OutBufPtr);\r
   }\r
-  \r
+\r
   *OutBufPtr = '\0';\r
-  SendPacket(OutBuffer);\r
-  FreePool(OutBuffer);\r
+  SendPacket (OutBuffer);\r
+  FreePool (OutBuffer);\r
 }\r
 \r
 \r
@@ -282,7 +264,7 @@ CHAR8
   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
   if (gRegisterOffsets[RegNumber] > 0xF00) {\r
     return InBufPtr + 8;\r
   }\r
@@ -290,25 +272,25 @@ CHAR8
   NewValue = 0;\r
   RegSize = 0;\r
   while (RegSize < 32) {\r
-    TempValue = HexCharToInt(*InBufPtr++);\r
-    \r
+    TempValue = HexCharToInt (*InBufPtr++);\r
+\r
     if ((INTN)TempValue < 0) {\r
-      SendError (GDB_EBADMEMDATA); \r
+      SendError (GDB_EBADMEMDATA);\r
       return NULL;\r
     }\r
-    \r
+\r
     NewValue += (TempValue << (RegSize+4));\r
-    TempValue = HexCharToInt(*InBufPtr++);\r
-    \r
+    TempValue = HexCharToInt (*InBufPtr++);\r
+\r
     if ((INTN)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
+  *(FindPointerToRegister (SystemContext, RegNumber)) = NewValue;\r
   return InBufPtr;\r
 }\r
 \r
@@ -316,7 +298,7 @@ CHAR8
 /** ‘P n...=r...’\r
  Writes the new value of n-th register received into the input buffer to the n-th register\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
 WriteNthRegister (\r
@@ -328,19 +310,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
-  \r
+  RegNumber = AsciiStrHexToUintn (RegNumBuffer);\r
+\r
   // check if this is a valid Register Number\r
-  if (RegNumber >= MaxRegisterCount()) {\r
-    SendError (GDB_EINVALIDREGNUM); \r
+  if (RegNumber >= MaxRegisterCount ()) {\r
+    SendError (GDB_EINVALIDREGNUM);\r
     return;\r
   }\r
   InBufPtr++;  // skips the '=' character\r
@@ -365,24 +347,24 @@ WriteGeneralRegisters (
   UINTN  i;\r
   CHAR8  *InBufPtr; /// pointer to the input buffer\r
   UINTN  MinLength;\r
-  UINTN  RegisterCount = MaxRegisterCount();\r
+  UINTN  RegisterCount = MaxRegisterCount ();\r
 \r
   MinLength = (RegisterCount * 8) + 1;  // 'G' plus the registers in ASCII format\r
-  \r
-  if (AsciiStrLen(InBuffer) < MinLength) {\r
-    //Bad message. Message is not the right length \r
-    SendError (GDB_EBADBUFSIZE); \r
+\r
+  if (AsciiStrLen (InBuffer) < MinLength) {\r
+    //Bad message. Message is not the right length\r
+    SendError (GDB_EBADBUFSIZE);\r
     return;\r
   }\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 < RegisterCount; i++) {\r
+  for (i = 0; i < RegisterCount; i++) {\r
     InBufPtr = BasicWriteRegister (SystemContext, i, InBufPtr);\r
   }\r
-  \r
+\r
   SendSuccess ();\r
 }\r
 \r
@@ -407,10 +389,10 @@ typedef struct {
 \r
 LIST_ENTRY  BreakpointList;\r
 \r
-/** \r
+/**\r
  Insert Single Step in the SystemContext\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
 AddSingleStep (\r
@@ -422,26 +404,26 @@ AddSingleStep (
     return;\r
   }\r
   mSingleStepActive = TRUE;\r
-  \r
+\r
   mSingleStepPC = SystemContext.SystemContextArm->PC;\r
 \r
   mSingleStepDataSize = sizeof (UINT32);\r
-  mSingleStepData = (*(UINT32 *)mSingleStepPC); \r
+  mSingleStepData = (*(UINT32 *)mSingleStepPC);\r
   *(UINT32 *)mSingleStepPC = GDB_ARM_BKPT;\r
   if (*(UINT32 *)mSingleStepPC != GDB_ARM_BKPT) {\r
     // For some reason our breakpoint did not take\r
     mSingleStepActive = FALSE;\r
   }\r
 \r
-  InvalidateInstructionCacheRange((VOID *)mSingleStepPC, mSingleStepDataSize);\r
+  InvalidateInstructionCacheRange ((VOID *)mSingleStepPC, mSingleStepDataSize);\r
   //DEBUG((EFI_D_ERROR, "AddSingleStep at 0x%08x (was: 0x%08x is:0x%08x)\n", SystemContext.SystemContextArm->PC, mSingleStepData, *(UINT32 *)mSingleStepPC));\r
 }\r
 \r
-  \r
-/** \r
+\r
+/**\r
  Remove Single Step in the SystemContext\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
 RemoveSingleStep (\r
@@ -451,24 +433,24 @@ RemoveSingleStep (
   if (!mSingleStepActive) {\r
     return;\r
   }\r
-  \r
+\r
   if (mSingleStepDataSize == sizeof (UINT16)) {\r
     *(UINT16 *)mSingleStepPC = (UINT16)mSingleStepData;\r
   } else {\r
     //DEBUG((EFI_D_ERROR, "RemoveSingleStep at 0x%08x (was: 0x%08x is:0x%08x)\n", SystemContext.SystemContextArm->PC, *(UINT32 *)mSingleStepPC, mSingleStepData));\r
     *(UINT32 *)mSingleStepPC = mSingleStepData;\r
   }\r
-  InvalidateInstructionCacheRange((VOID *)mSingleStepPC, mSingleStepDataSize);\r
+  InvalidateInstructionCacheRange ((VOID *)mSingleStepPC, mSingleStepDataSize);\r
   mSingleStepActive = FALSE;\r
 }\r
 \r
 \r
 \r
-/** ‘c [addr ]’ \r
- Continue. addr is Address to resume. If addr is omitted, resume at current \r
+/**\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
@@ -478,16 +460,16 @@ ContinueAtAddress (
   )\r
 {\r
   if (PacketData[1] != '\0') {\r
-    SystemContext.SystemContextArm->PC = AsciiStrHexToUintn(&PacketData[1]);\r
-  } \r
+    SystemContext.SystemContextArm->PC = AsciiStrHexToUintn (&PacketData[1]);\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
@@ -496,7 +478,7 @@ SingleStep (
   IN    CHAR8                       *PacketData\r
   )\r
 {\r
-  SendNotSupported();\r
+  SendNotSupported ();\r
 }\r
 \r
 UINTN\r
@@ -533,15 +515,15 @@ SearchBreakpointList (
   LIST_ENTRY              *Current;\r
   ARM_SOFTWARE_BREAKPOINT *Breakpoint;\r
 \r
-  Current = GetFirstNode(&BreakpointList);\r
-  while (!IsNull(&BreakpointList, Current)) {\r
+  Current = GetFirstNode (&BreakpointList);\r
+  while (!IsNull (&BreakpointList, Current)) {\r
     Breakpoint = ARM_SOFTWARE_BREAKPOINT_FROM_LINK(Current);\r
 \r
     if (Address == Breakpoint->Address) {\r
       return Breakpoint;\r
     }\r
 \r
-    Current = GetNextNode(&BreakpointList, Current);\r
+    Current = GetNextNode (&BreakpointList, Current);\r
   }\r
 \r
   return NULL;\r
@@ -554,25 +536,25 @@ SetBreakpoint (
 {\r
   ARM_SOFTWARE_BREAKPOINT *Breakpoint;\r
 \r
-  Breakpoint = SearchBreakpointList(Address);\r
+  Breakpoint = SearchBreakpointList (Address);\r
 \r
   if (Breakpoint != NULL) {\r
     return;\r
   }\r
 \r
   // create and fill breakpoint structure\r
-  Breakpoint = AllocatePool(sizeof(ARM_SOFTWARE_BREAKPOINT));\r
+  Breakpoint = AllocatePool (sizeof(ARM_SOFTWARE_BREAKPOINT));\r
 \r
   Breakpoint->Signature   = ARM_SOFTWARE_BREAKPOINT_SIGNATURE;\r
   Breakpoint->Address     = Address;\r
   Breakpoint->Instruction = *(UINT32 *)Address;\r
-  \r
+\r
   // Add it to the list\r
-  InsertTailList(&BreakpointList, &Breakpoint->Link);\r
+  InsertTailList (&BreakpointList, &Breakpoint->Link);\r
 \r
   // Insert the software breakpoint\r
   *(UINT32 *)Address = GDB_ARM_BKPT;\r
-  InvalidateInstructionCacheRange((VOID *)Address, 4);\r
+  InvalidateInstructionCacheRange ((VOID *)Address, 4);\r
 \r
   //DEBUG((EFI_D_ERROR, "SetBreakpoint at 0x%08x (was: 0x%08x is:0x%08x)\n", Address, Breakpoint->Instruction, *(UINT32 *)Address));\r
 }\r
@@ -584,22 +566,22 @@ ClearBreakpoint (
 {\r
   ARM_SOFTWARE_BREAKPOINT *Breakpoint;\r
 \r
-  Breakpoint = SearchBreakpointList(Address);\r
+  Breakpoint = SearchBreakpointList (Address);\r
 \r
   if (Breakpoint == NULL) {\r
     return;\r
   }\r
 \r
   // Add it to the list\r
-  RemoveEntryList(&Breakpoint->Link);\r
+  RemoveEntryList (&Breakpoint->Link);\r
 \r
   // Restore the original instruction\r
   *(UINT32 *)Address = Breakpoint->Instruction;\r
-  InvalidateInstructionCacheRange((VOID *)Address, 4);\r
+  InvalidateInstructionCacheRange ((VOID *)Address, 4);\r
 \r
   //DEBUG((EFI_D_ERROR, "ClearBreakpoint at 0x%08x (was: 0x%08x is:0x%08x)\n", Address, GDB_ARM_BKPT, *(UINT32 *)Address));\r
 \r
-  FreePool(Breakpoint);\r
+  FreePool (Breakpoint);\r
 }\r
 \r
 VOID\r
@@ -614,7 +596,7 @@ InsertBreakPoint (
   UINTN Length;\r
   UINTN ErrorCode;\r
 \r
-  ErrorCode = ParseBreakpointPacket(PacketData, &Type, &Address, &Length);\r
+  ErrorCode = ParseBreakpointPacket (PacketData, &Type, &Address, &Length);\r
   if (ErrorCode > 0) {\r
     SendError ((UINT8)ErrorCode);\r
     return;\r
@@ -630,7 +612,7 @@ InsertBreakPoint (
       return;\r
   }\r
 \r
-  SetBreakpoint(Address);\r
+  SetBreakpoint (Address);\r
 \r
   SendSuccess ();\r
 }\r
@@ -657,13 +639,13 @@ RemoveBreakPoint (
   switch (Type) {\r
     case 0:   //Software breakpoint\r
       break;\r
-    \r
+\r
     default:\r
       SendError (GDB_EINVALIDBRKPOINTTYPE);\r
       return;\r
   }\r
 \r
-  ClearBreakpoint(Address);\r
+  ClearBreakpoint (Address);\r
 \r
   SendSuccess ();\r
 }\r
@@ -674,7 +656,7 @@ InitializeProcessor (
   )\r
 {\r
   // Initialize breakpoint list\r
-  InitializeListHead(&BreakpointList);\r
+  InitializeListHead (&BreakpointList);\r
 }\r
 \r
 BOOLEAN\r
@@ -691,13 +673,13 @@ 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
   UINT32  ExceptionAddress;\r
   UINT32  Instruction;\r
-  \r
+\r
   // Is it a debugger SWI?\r
   ExceptionAddress = SystemContext.SystemContextArm->PC -= 4;\r
   Instruction      = *(UINT32 *)ExceptionAddress;\r