2 * Copyright (C) 2008 Stefan Hajnoczi <stefanha@gmail.com>.
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.
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.
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
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.
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
30 #include <ipxe/uart.h>
31 #include <ipxe/gdbstub.h>
32 #include <ipxe/gdbserial.h>
33 #include <config/serial.h>
35 /* UART port number */
37 #define GDBSERIAL_PORT COMCONSOLE
39 #define GDBSERIAL_PORT 0
44 #define GDBSERIAL_BAUD 0
46 #define GDBSERIAL_BAUD COMSPEED
49 /* UART line control register value */
51 #define GDBSERIAL_LCR 0
53 #define GDBSERIAL_LCR UART_LCR_WPS ( COMDATA, COMPARITY, COMSTOP )
56 /** GDB serial UART */
57 static struct uart gdbserial_uart;
59 struct gdb_transport serial_gdb_transport __gdb_transport;
61 static size_t gdbserial_recv ( char *buf, size_t len ) {
64 while ( ! uart_data_ready ( &gdbserial_uart ) ) {}
65 buf[0] = uart_receive ( &gdbserial_uart );
69 static void gdbserial_send ( const char *buf, size_t len ) {
72 uart_transmit ( &gdbserial_uart, *buf++ );
76 static int gdbserial_init ( int argc, char **argv ) {
81 port = GDBSERIAL_PORT;
82 } else if ( argc == 1 ) {
83 port = strtoul ( argv[0], &endp, 10 );
85 printf ( "serial: invalid port\n" );
89 printf ( "serial: syntax <port>\n" );
93 if ( ! gdbserial_configure ( port, GDBSERIAL_BAUD, GDBSERIAL_LCR ) ) {
94 printf ( "serial: unable to configure\n" );
101 struct gdb_transport serial_gdb_transport __gdb_transport = {
103 .init = gdbserial_init,
104 .recv = gdbserial_recv,
105 .send = gdbserial_send,
108 struct gdb_transport * gdbserial_configure ( unsigned int port,
109 unsigned int baud, uint8_t lcr ) {
112 if ( ( rc = uart_select ( &gdbserial_uart, port ) ) != 0 )
115 if ( ( rc = uart_init ( &gdbserial_uart, baud, lcr ) ) != 0 )
118 return &serial_gdb_transport;