|  | @@ -23,31 +23,68 @@
 | 
		
	
		
			
			| 23 | 23 |  
 | 
		
	
		
			
			| 24 | 24 |  FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 | 
		
	
		
			
			| 25 | 25 |  
 | 
		
	
		
			
			|  | 26 | +#include <stddef.h>
 | 
		
	
		
			
			| 26 | 27 |  #include <assert.h>
 | 
		
	
		
			
			| 27 |  | -#include <ipxe/serial.h>
 | 
		
	
		
			
			|  | 28 | +#include <ipxe/uart.h>
 | 
		
	
		
			
			| 28 | 29 |  #include <ipxe/gdbstub.h>
 | 
		
	
		
			
			| 29 | 30 |  #include <ipxe/gdbserial.h>
 | 
		
	
		
			
			|  | 31 | +#include <config/serial.h>
 | 
		
	
		
			
			| 30 | 32 |  
 | 
		
	
		
			
			| 31 |  | -struct gdb_transport serial_gdb_transport __gdb_transport;
 | 
		
	
		
			
			|  | 33 | +/* UART port number */
 | 
		
	
		
			
			|  | 34 | +#ifdef COMCONSOLE
 | 
		
	
		
			
			|  | 35 | +#define GDBSERIAL_PORT COMCONSOLE
 | 
		
	
		
			
			|  | 36 | +#else
 | 
		
	
		
			
			|  | 37 | +#define GDBSERIAL_PORT 0
 | 
		
	
		
			
			|  | 38 | +#endif
 | 
		
	
		
			
			|  | 39 | +
 | 
		
	
		
			
			|  | 40 | +/* UART baud rate */
 | 
		
	
		
			
			|  | 41 | +#ifdef COMPRESERVE
 | 
		
	
		
			
			|  | 42 | +#define GDBSERIAL_BAUD 0
 | 
		
	
		
			
			|  | 43 | +#else
 | 
		
	
		
			
			|  | 44 | +#define GDBSERIAL_BAUD COMSPEED
 | 
		
	
		
			
			|  | 45 | +#endif
 | 
		
	
		
			
			|  | 46 | +
 | 
		
	
		
			
			|  | 47 | +/* UART line control register value */
 | 
		
	
		
			
			|  | 48 | +#ifdef COMPRESERVE
 | 
		
	
		
			
			|  | 49 | +#define GDBSERIAL_LCR 0
 | 
		
	
		
			
			|  | 50 | +#else
 | 
		
	
		
			
			|  | 51 | +#define GDBSERIAL_LCR UART_LCR_WPS ( COMDATA, COMPARITY, COMSTOP )
 | 
		
	
		
			
			|  | 52 | +#endif
 | 
		
	
		
			
			|  | 53 | +
 | 
		
	
		
			
			|  | 54 | +/** GDB serial UART */
 | 
		
	
		
			
			|  | 55 | +static struct uart gdbserial_uart;
 | 
		
	
		
			
			| 32 | 56 |  
 | 
		
	
		
			
			| 33 | 57 |  static size_t gdbserial_recv ( char *buf, size_t len ) {
 | 
		
	
		
			
			|  | 58 | +
 | 
		
	
		
			
			| 34 | 59 |  	assert ( len > 0 );
 | 
		
	
		
			
			| 35 |  | -	buf [ 0 ] = serial_getc();
 | 
		
	
		
			
			|  | 60 | +	while ( ! uart_data_ready ( &gdbserial_uart ) ) {}
 | 
		
	
		
			
			|  | 61 | +	buf[0] = uart_receive ( &gdbserial_uart );
 | 
		
	
		
			
			| 36 | 62 |  	return 1;
 | 
		
	
		
			
			| 37 | 63 |  }
 | 
		
	
		
			
			| 38 | 64 |  
 | 
		
	
		
			
			| 39 | 65 |  static void gdbserial_send ( const char *buf, size_t len ) {
 | 
		
	
		
			
			|  | 66 | +
 | 
		
	
		
			
			| 40 | 67 |  	while ( len-- > 0 ) {
 | 
		
	
		
			
			| 41 |  | -		serial_putc ( *buf++ );
 | 
		
	
		
			
			|  | 68 | +		uart_transmit ( &gdbserial_uart, *buf++ );
 | 
		
	
		
			
			| 42 | 69 |  	}
 | 
		
	
		
			
			| 43 | 70 |  }
 | 
		
	
		
			
			| 44 | 71 |  
 | 
		
	
		
			
			|  | 72 | +static int gdbserial_init ( int argc __unused, char **argv __unused ) {
 | 
		
	
		
			
			|  | 73 | +	int rc;
 | 
		
	
		
			
			|  | 74 | +
 | 
		
	
		
			
			|  | 75 | +	if ( ( rc = uart_select ( &gdbserial_uart, GDBSERIAL_PORT ) ) != 0 )
 | 
		
	
		
			
			|  | 76 | +		return rc;
 | 
		
	
		
			
			|  | 77 | +
 | 
		
	
		
			
			|  | 78 | +	if ( ( rc = uart_init ( &gdbserial_uart, GDBSERIAL_BAUD,
 | 
		
	
		
			
			|  | 79 | +				GDBSERIAL_LCR ) ) != 0 )
 | 
		
	
		
			
			|  | 80 | +		return rc;
 | 
		
	
		
			
			|  | 81 | +
 | 
		
	
		
			
			|  | 82 | +	return 0;
 | 
		
	
		
			
			|  | 83 | +}
 | 
		
	
		
			
			|  | 84 | +
 | 
		
	
		
			
			| 45 | 85 |  struct gdb_transport serial_gdb_transport __gdb_transport = {
 | 
		
	
		
			
			| 46 | 86 |  	.name = "serial",
 | 
		
	
		
			
			|  | 87 | +	.init = gdbserial_init,
 | 
		
	
		
			
			| 47 | 88 |  	.recv = gdbserial_recv,
 | 
		
	
		
			
			| 48 | 89 |  	.send = gdbserial_send,
 | 
		
	
		
			
			| 49 | 90 |  };
 | 
		
	
		
			
			| 50 |  | -
 | 
		
	
		
			
			| 51 |  | -struct gdb_transport *gdbserial_configure ( void ) {
 | 
		
	
		
			
			| 52 |  | -	return &serial_gdb_transport;
 | 
		
	
		
			
			| 53 |  | -}
 |