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
24FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25FILE_SECBOOT ( FORBIDDEN );
26
27#include <stddef.h>
28#include <stdio.h>
29#include <assert.h>
30#include <ipxe/uart.h>
31#include <ipxe/gdbstub.h>
32#include <ipxe/gdbserial.h>
33#include <config/serial.h>
34
35/* UART baud rate */
36#ifdef COMPRESERVE
37#define GDBSERIAL_BAUD 0
38#else
39#define GDBSERIAL_BAUD COMSPEED
40#endif
41
42/** GDB serial UART */
43static struct uart *gdbserial_uart;
44
45struct gdb_transport serial_gdb_transport __gdb_transport;
46
47static size_t gdbserial_recv ( char *buf, size_t len ) {
48
49 assert ( len > 0 );
50 while ( ! uart_data_ready ( gdbserial_uart ) ) {}
51 buf[0] = uart_receive ( gdbserial_uart );
52 return 1;
53}
54
55static void gdbserial_send ( const char *buf, size_t len ) {
56
57 while ( len-- > 0 ) {
58 uart_transmit ( gdbserial_uart, *buf++ );
59 }
60}
61
62static int gdbserial_init ( int argc, char **argv ) {
63 const char *port;
64
65 if ( argc == 1 ) {
66 port = argv[0];
67 } else {
68 printf ( "serial: syntax <port>\n" );
69 return 1;
70 }
71
73 printf ( "serial: unable to configure\n" );
74 return 1;
75 }
76
77 return 0;
78}
79
80struct gdb_transport serial_gdb_transport __gdb_transport = {
81 .name = "serial",
82 .init = gdbserial_init,
83 .recv = gdbserial_recv,
84 .send = gdbserial_send,
85};
86
87struct gdb_transport * gdbserial_configure ( const char *name,
88 unsigned int baud ) {
89 int rc;
90
91 uart_put ( gdbserial_uart );
93
95 if ( ! gdbserial_uart )
96 return NULL;
97 uart_get ( gdbserial_uart );
98
99 gdbserial_uart->baud = baud;
100
101 if ( ( rc = uart_init ( gdbserial_uart ) ) != 0 )
102 return NULL;
103
104 return &serial_gdb_transport;
105}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
u8 port
Port number.
Definition CIB_PRM.h:3
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
Assertions.
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
const char * name
Definition ath9k_hw.c:1986
Serial port configuration.
ring len
Length.
Definition dwmac.h:226
static void gdbserial_send(const char *buf, size_t len)
Definition gdbserial.c:55
#define GDBSERIAL_BAUD
Definition gdbserial.c:39
struct gdb_transport * gdbserial_configure(const char *name, unsigned int baud)
Definition gdbserial.c:87
static int gdbserial_init(int argc, char **argv)
Definition gdbserial.c:62
static size_t gdbserial_recv(char *buf, size_t len)
Definition gdbserial.c:47
static struct uart * gdbserial_uart
GDB serial UART.
Definition gdbserial.c:43
GDB remote debugging over serial.
GDB remote debugging.
#define __gdb_transport
Definition gdbstub.h:53
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:926
A transport mechanism for the GDB protocol.
Definition gdbstub.h:21
A generic UART.
Definition uart.h:17
struct uart * uart_find(const char *name)
Find named UART.
Definition uart.c:130
Generic UART.
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition vsprintf.c:465