summaryrefslogtreecommitdiffstats
path: root/EmbeddedPkg/Library/GdbSerialLib/GdbSerialLib.c
diff options
context:
space:
mode:
Diffstat (limited to 'EmbeddedPkg/Library/GdbSerialLib/GdbSerialLib.c')
-rw-r--r--EmbeddedPkg/Library/GdbSerialLib/GdbSerialLib.c97
1 files changed, 42 insertions, 55 deletions
diff --git a/EmbeddedPkg/Library/GdbSerialLib/GdbSerialLib.c b/EmbeddedPkg/Library/GdbSerialLib/GdbSerialLib.c
index 71452008ec..75e00773ec 100644
--- a/EmbeddedPkg/Library/GdbSerialLib/GdbSerialLib.c
+++ b/EmbeddedPkg/Library/GdbSerialLib/GdbSerialLib.c
@@ -13,38 +13,34 @@
#include <Library/IoLib.h>
#include <Library/DebugLib.h>
-
-//---------------------------------------------
+// ---------------------------------------------
// UART Register Offsets
-//---------------------------------------------
-#define BAUD_LOW_OFFSET 0x00
-#define BAUD_HIGH_OFFSET 0x01
-#define IER_OFFSET 0x01
-#define LCR_SHADOW_OFFSET 0x01
-#define FCR_SHADOW_OFFSET 0x02
-#define IR_CONTROL_OFFSET 0x02
-#define FCR_OFFSET 0x02
-#define EIR_OFFSET 0x02
-#define BSR_OFFSET 0x03
-#define LCR_OFFSET 0x03
-#define MCR_OFFSET 0x04
-#define LSR_OFFSET 0x05
-#define MSR_OFFSET 0x06
-
-//---------------------------------------------
+// ---------------------------------------------
+#define BAUD_LOW_OFFSET 0x00
+#define BAUD_HIGH_OFFSET 0x01
+#define IER_OFFSET 0x01
+#define LCR_SHADOW_OFFSET 0x01
+#define FCR_SHADOW_OFFSET 0x02
+#define IR_CONTROL_OFFSET 0x02
+#define FCR_OFFSET 0x02
+#define EIR_OFFSET 0x02
+#define BSR_OFFSET 0x03
+#define LCR_OFFSET 0x03
+#define MCR_OFFSET 0x04
+#define LSR_OFFSET 0x05
+#define MSR_OFFSET 0x06
+
+// ---------------------------------------------
// UART Register Bit Defines
-//---------------------------------------------
-#define LSR_TXRDY 0x20U
-#define LSR_RXDA 0x01U
-#define DLAB 0x01U
-#define ENABLE_FIFO 0x01U
-#define CLEAR_FIFOS 0x06U
-
-
+// ---------------------------------------------
+#define LSR_TXRDY 0x20U
+#define LSR_RXDA 0x01U
+#define DLAB 0x01U
+#define ENABLE_FIFO 0x01U
+#define CLEAR_FIFOS 0x06U
// IO Port Base for the UART
-UINTN gPort;
-
+UINTN gPort;
/**
The constructor function initializes the UART.
@@ -62,10 +58,10 @@ GdbSerialLibConstructor (
IN EFI_SYSTEM_TABLE *SystemTable
)
{
- UINT64 BaudRate;
- UINT8 DataBits;
- UINT8 Parity;
- UINT8 StopBits;
+ UINT64 BaudRate;
+ UINT8 DataBits;
+ UINT8 Parity;
+ UINT8 StopBits;
gPort = (UINTN)PcdGet32 (PcdGdbUartPort);
@@ -77,8 +73,6 @@ GdbSerialLibConstructor (
return GdbSerialInit (BaudRate, Parity, DataBits, StopBits);
}
-
-
/**
Sets the baud rate, receive FIFO depth, transmit/receive time out, parity,
data buts, and stop bits on a serial device. This call is optional as the serial
@@ -101,16 +95,16 @@ GdbSerialLibConstructor (
RETURN_STATUS
EFIAPI
GdbSerialInit (
- IN UINT64 BaudRate,
- IN UINT8 Parity,
- IN UINT8 DataBits,
- IN UINT8 StopBits
+ IN UINT64 BaudRate,
+ IN UINT8 Parity,
+ IN UINT8 DataBits,
+ IN UINT8 StopBits
)
{
- UINTN Divisor;
- UINT8 OutputData;
- UINT8 Data;
- UINT8 BreakSet = 0;
+ UINTN Divisor;
+ UINT8 OutputData;
+ UINT8 Data;
+ UINT8 BreakSet = 0;
//
// We assume the UART has been turned on to decode gPort address range
@@ -119,7 +113,7 @@ GdbSerialInit (
//
// Map 5..8 to 0..3
//
- Data = (UINT8) (DataBits - (UINT8)5);
+ Data = (UINT8)(DataBits - (UINT8)5);
//
// Calculate divisor for baud generator
@@ -138,7 +132,6 @@ GdbSerialInit (
IoWrite8 (gPort + BAUD_HIGH_OFFSET, (UINT8)(Divisor >> 8));
IoWrite8 (gPort + BAUD_LOW_OFFSET, (UINT8)(Divisor & 0xff));
-
//
// Switch back to bank 0
//
@@ -149,12 +142,10 @@ GdbSerialInit (
// We probably need the FIFO enabled to not drop input
IoWrite8 (gPort + FCR_SHADOW_OFFSET, ENABLE_FIFO);
-
// Configure the UART hardware here
return RETURN_SUCCESS;
}
-
/**
Check to see if a character is available from GDB. Do not read the character as that is
done via GdbGetChar().
@@ -169,14 +160,13 @@ GdbIsCharAvailable (
VOID
)
{
- UINT8 Data;
+ UINT8 Data;
Data = IoRead8 (gPort + LSR_OFFSET);
return ((Data & LSR_RXDA) == LSR_RXDA);
}
-
/**
Get a character from GDB. This function must be able to run in interrupt context.
@@ -189,8 +179,8 @@ GdbGetChar (
VOID
)
{
- UINT8 Data;
- CHAR8 Char;
+ UINT8 Data;
+ CHAR8 Char;
// Wait for the serial port to be ready
do {
@@ -204,7 +194,6 @@ GdbGetChar (
return Char;
}
-
/**
Send a character to GDB. This function must be able to run in interrupt context.
@@ -212,14 +201,13 @@ GdbGetChar (
@param Char Send a character to GDB
**/
-
VOID
EFIAPI
GdbPutChar (
- IN CHAR8 Char
+ IN CHAR8 Char
)
{
- UINT8 Data;
+ UINT8 Data;
// Make this an DEBUG_INFO after we get everything debugged.
DEBUG ((DEBUG_ERROR, ">%c>", Char));
@@ -239,7 +227,6 @@ GdbPutChar (
@param String Send a string to GDB
**/
-
VOID
GdbPutString (
IN CHAR8 *String