iPXE
Macros | Functions | Variables
gdbserial.c File Reference
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <ipxe/uart.h>
#include <ipxe/gdbstub.h>
#include <ipxe/gdbserial.h>
#include <config/serial.h>

Go to the source code of this file.

Macros

#define GDBSERIAL_PORT   COMCONSOLE
 
#define GDBSERIAL_BAUD   COMSPEED
 
#define GDBSERIAL_LCR   UART_LCR_WPS ( COMDATA, COMPARITY, COMSTOP )
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static size_t gdbserial_recv (char *buf, size_t len)
 
static void gdbserial_send (const char *buf, size_t len)
 
static int gdbserial_init (int argc, char **argv)
 
struct gdb_transportgdbserial_configure (unsigned int port, unsigned int baud, uint8_t lcr)
 

Variables

static struct uart gdbserial_uart
 GDB serial UART. More...
 
struct gdb_transport serial_gdb_transport __gdb_transport
 

Macro Definition Documentation

◆ GDBSERIAL_PORT

#define GDBSERIAL_PORT   COMCONSOLE

Definition at line 37 of file gdbserial.c.

◆ GDBSERIAL_BAUD

#define GDBSERIAL_BAUD   COMSPEED

Definition at line 46 of file gdbserial.c.

◆ GDBSERIAL_LCR

#define GDBSERIAL_LCR   UART_LCR_WPS ( COMDATA, COMPARITY, COMSTOP )

Definition at line 53 of file gdbserial.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ gdbserial_recv()

static size_t gdbserial_recv ( char *  buf,
size_t  len 
)
static

Definition at line 61 of file gdbserial.c.

61  {
62 
63  assert ( len > 0 );
64  while ( ! uart_data_ready ( &gdbserial_uart ) ) {}
65  buf[0] = uart_receive ( &gdbserial_uart );
66  return 1;
67 }
static int uart_data_ready(struct uart *uart)
Check if received data is ready.
Definition: uart.h:109
static struct uart gdbserial_uart
GDB serial UART.
Definition: gdbserial.c:57
static uint8_t uart_receive(struct uart *uart)
Receive data.
Definition: uart.h:122
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
uint32_t len
Length.
Definition: ena.h:14

References assert(), gdbserial_uart, len, uart_data_ready(), and uart_receive().

◆ gdbserial_send()

static void gdbserial_send ( const char *  buf,
size_t  len 
)
static

Definition at line 69 of file gdbserial.c.

69  {
70 
71  while ( len-- > 0 ) {
72  uart_transmit ( &gdbserial_uart, *buf++ );
73  }
74 }
void uart_transmit(struct uart *uart, uint8_t data)
Transmit data.
Definition: uart.c:48
static struct uart gdbserial_uart
GDB serial UART.
Definition: gdbserial.c:57
uint32_t len
Length.
Definition: ena.h:14

References gdbserial_uart, len, and uart_transmit().

◆ gdbserial_init()

static int gdbserial_init ( int  argc,
char **  argv 
)
static

Definition at line 76 of file gdbserial.c.

76  {
77  unsigned int port;
78  char *endp;
79 
80  if ( argc == 0 ) {
82  } else if ( argc == 1 ) {
83  port = strtoul ( argv[0], &endp, 10 );
84  if ( *endp ) {
85  printf ( "serial: invalid port\n" );
86  return 1;
87  }
88  } else {
89  printf ( "serial: syntax <port>\n" );
90  return 1;
91  }
92 
94  printf ( "serial: unable to configure\n" );
95  return 1;
96  }
97 
98  return 0;
99 }
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
unsigned long strtoul(const char *string, char **endp, int base)
Convert string to numeric value.
Definition: string.c:484
#define GDBSERIAL_BAUD
Definition: gdbserial.c:46
#define GDBSERIAL_PORT
Definition: gdbserial.c:37
u8 port
Port number.
Definition: CIB_PRM.h:31
struct gdb_transport * gdbserial_configure(unsigned int port, unsigned int baud, uint8_t lcr)
Definition: gdbserial.c:108
#define GDBSERIAL_LCR
Definition: gdbserial.c:53

References GDBSERIAL_BAUD, gdbserial_configure(), GDBSERIAL_LCR, GDBSERIAL_PORT, port, printf(), and strtoul().

◆ gdbserial_configure()

struct gdb_transport* gdbserial_configure ( unsigned int  port,
unsigned int  baud,
uint8_t  lcr 
)

Definition at line 108 of file gdbserial.c.

109  {
110  int rc;
111 
112  if ( ( rc = uart_select ( &gdbserial_uart, port ) ) != 0 )
113  return NULL;
114 
115  if ( ( rc = uart_init ( &gdbserial_uart, baud, lcr ) ) != 0 )
116  return NULL;
117 
118  return &serial_gdb_transport;
119 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static struct uart gdbserial_uart
GDB serial UART.
Definition: gdbserial.c:57
int uart_init(struct uart *uart, unsigned int baud, uint8_t lcr)
Initialise UART.
Definition: uart.c:113
u8 port
Port number.
Definition: CIB_PRM.h:31
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
int uart_select(struct uart *uart, unsigned int port)
Select UART port.
Definition: x86_uart.c:50

References gdbserial_uart, NULL, port, rc, uart_init(), and uart_select().

Referenced by gdbserial_init().

Variable Documentation

◆ gdbserial_uart

struct uart gdbserial_uart
static

GDB serial UART.

Definition at line 57 of file gdbserial.c.

Referenced by gdbserial_configure(), gdbserial_recv(), and gdbserial_send().

◆ __gdb_transport

struct gdb_transport serial_gdb_transport __gdb_transport
Initial value:
= {
.name = "serial",
.init = gdbserial_init,
.recv = gdbserial_recv,
.send = gdbserial_send,
}
static void gdbserial_send(const char *buf, size_t len)
Definition: gdbserial.c:69
static int gdbserial_init(int argc, char **argv)
Definition: gdbserial.c:76
static size_t gdbserial_recv(char *buf, size_t len)
Definition: gdbserial.c:61

Definition at line 59 of file gdbserial.c.