]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmRealViewEbPkg/Library/GdbSerialLib/GdbSerialLib.c
Remove ArmEbPkg and replace with ArmRealViewEbPkg. Ported ArmRealViewEbPkg to have...
[mirror_edk2.git] / ArmRealViewEbPkg / Library / GdbSerialLib / GdbSerialLib.c
diff --git a/ArmRealViewEbPkg/Library/GdbSerialLib/GdbSerialLib.c b/ArmRealViewEbPkg/Library/GdbSerialLib/GdbSerialLib.c
new file mode 100755 (executable)
index 0000000..7a87754
--- /dev/null
@@ -0,0 +1,123 @@
+/** @file
+  Basic serial IO abstaction for GDB
+
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
+  
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD License
+  which accompanies this distribution.  The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include <Uefi.h>
+#include <Library/GdbSerialLib.h>
+#include <Library/PcdLib.h>
+#include <Library/IoLib.h>
+
+#include <ArmEb/ArmEb.h>
+
+RETURN_STATUS
+EFIAPI
+GdbSerialLibConstructor (
+  VOID
+  )
+{
+  return GdbSerialInit (115200, 0, 8, 1);
+}
+
+RETURN_STATUS
+EFIAPI
+GdbSerialInit (
+  IN UINT64     BaudRate, 
+  IN UINT8      Parity, 
+  IN UINT8      DataBits, 
+  IN UINT8      StopBits 
+  )
+{
+  if ((Parity != 0) || (DataBits != 8) || (StopBits != 1)) {
+    return RETURN_UNSUPPORTED;
+  }
+
+  if (BaudRate != 115200) {
+    // Could add support for different Baud rates....
+    return RETURN_UNSUPPORTED;
+  }
+      
+  UINT32  Base = PcdGet32 (PcdGdbUartBase);\r
+  \r
+  // initialize baud rate generator to 115200 based on EB clock REFCLK24MHZ\r
+  MmioWrite32 (Base + UARTIBRD, UART_115200_IDIV);\r
+  MmioWrite32 (Base + UARTFBRD, UART_115200_FDIV);\r
+\r
+  // no parity, 1 stop, no fifo, 8 data bits\r
+  MmioWrite32 (Base + UARTLCR_H, 0x60);\r
+\r
+  // clear any pending errors\r
+  MmioWrite32 (Base + UARTECR, 0);\r
+\r
+  // enable tx, rx, and uart overall\r
+  MmioWrite32 (Base + UARTCR, 0x301);\r
+\r
+  return RETURN_SUCCESS;\r
+}
+
+BOOLEAN
+EFIAPI
+GdbIsCharAvailable (
+  VOID
+  )  
+{
+  UINT32 FR = PcdGet32 (PcdGdbUartBase) + UARTFR;\r
+\r
+  if ((MmioRead32 (FR) & UART_RX_EMPTY_FLAG_MASK) == 0) {\r
+    return TRUE;\r
+  } else {\r
+    return FALSE;\r
+  }\r
+}
+
+CHAR8
+EFIAPI
+GdbGetChar (
+  VOID
+  )
+{
+  UINT32  FR = PcdGet32 (PcdGdbUartBase) + UARTFR;\r
+  UINT32  DR = PcdGet32 (PcdGdbUartBase) + UARTDR;\r
+    \r
+  while ((MmioRead32 (FR) & UART_RX_EMPTY_FLAG_MASK) == 0);\r
+  return MmioRead8 (DR);\r
+}
+
+VOID
+EFIAPI
+GdbPutChar (
+  IN  CHAR8   Char
+  )
+{
+  UINT32 FR = PcdGet32 (PcdGdbUartBase) + UARTFR;\r
+  UINT32 DR = PcdGet32 (PcdGdbUartBase) + UARTDR;\r
+\r
+  while ((MmioRead32 (FR) & UART_TX_EMPTY_FLAG_MASK) != 0);\r
+  MmioWrite8 (DR, Char);\r
+  return;
+}
+
+VOID
+GdbPutString (
+  IN CHAR8  *String
+  )
+{
+  while (*String != '\0') {
+    GdbPutChar (*String);
+    String++;
+  }
+}
+
+
+
+