iPXE
gdbserial.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008 Stefan Hajnoczi <stefanha@gmail.com>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  *
19  * You can also choose to distribute this program under the terms of
20  * the Unmodified Binary Distribution Licence (as given in the file
21  * COPYING.UBDL), provided that you have satisfied its requirements.
22  */
23 
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 
26 #include <stddef.h>
27 #include <stdio.h>
28 #include <assert.h>
29 #include <ipxe/uart.h>
30 #include <ipxe/gdbstub.h>
31 #include <ipxe/gdbserial.h>
32 #include <config/serial.h>
33 
34 /* UART baud rate */
35 #ifdef COMPRESERVE
36 #define GDBSERIAL_BAUD 0
37 #else
38 #define GDBSERIAL_BAUD COMSPEED
39 #endif
40 
41 /** GDB serial UART */
42 static struct uart *gdbserial_uart;
43 
44 struct gdb_transport serial_gdb_transport __gdb_transport;
45 
46 static size_t gdbserial_recv ( char *buf, size_t len ) {
47 
48  assert ( len > 0 );
49  while ( ! uart_data_ready ( gdbserial_uart ) ) {}
50  buf[0] = uart_receive ( gdbserial_uart );
51  return 1;
52 }
53 
54 static void gdbserial_send ( const char *buf, size_t len ) {
55 
56  while ( len-- > 0 ) {
57  uart_transmit ( gdbserial_uart, *buf++ );
58  }
59 }
60 
61 static int gdbserial_init ( int argc, char **argv ) {
62  const char *port;
63 
64  if ( argc == 1 ) {
65  port = argv[0];
66  } else {
67  printf ( "serial: syntax <port>\n" );
68  return 1;
69  }
70 
72  printf ( "serial: unable to configure\n" );
73  return 1;
74  }
75 
76  return 0;
77 }
78 
79 struct gdb_transport serial_gdb_transport __gdb_transport = {
80  .name = "serial",
81  .init = gdbserial_init,
82  .recv = gdbserial_recv,
83  .send = gdbserial_send,
84 };
85 
86 struct gdb_transport * gdbserial_configure ( const char *name,
87  unsigned int baud ) {
88  int rc;
89 
90  uart_put ( gdbserial_uart );
92 
94  if ( ! gdbserial_uart )
95  return NULL;
96  uart_get ( gdbserial_uart );
97 
98  gdbserial_uart->baud = baud;
99 
100  if ( ( rc = uart_init ( gdbserial_uart ) ) != 0 )
101  return NULL;
102 
103  return &serial_gdb_transport;
104 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Definition: ath9k_hw.c:1984
Generic UART.
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
static void gdbserial_send(const char *buf, size_t len)
Definition: gdbserial.c:54
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
static int gdbserial_init(int argc, char **argv)
Definition: gdbserial.c:61
A generic UART.
Definition: uart.h:17
const char * name
Transport name.
Definition: gdbstub.h:22
struct gdb_transport serial_gdb_transport __gdb_transport
Definition: gdbserial.c:44
#define GDBSERIAL_BAUD
Definition: gdbserial.c:38
static struct uart * gdbserial_uart
GDB serial UART.
Definition: gdbserial.c:42
unsigned int baud
Baud rate (if specified)
Definition: uart.h:26
struct gdb_transport * gdbserial_configure(const char *name, unsigned int baud)
Definition: gdbserial.c:86
u8 port
Port number.
Definition: CIB_PRM.h:31
Assertions.
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
ring len
Length.
Definition: dwmac.h:231
GDB remote debugging over serial.
Serial port configuration.
struct uart * uart_find(const char *name)
Find named UART.
Definition: uart.c:130
static size_t gdbserial_recv(char *buf, size_t len)
Definition: gdbserial.c:46
GDB remote debugging.
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
A transport mechanism for the GDB protocol.
Definition: gdbstub.h:20