Browse Source

[gdb] Use new UART abstraction in GDB serial transport

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 9 years ago
parent
commit
5e622dc085
2 changed files with 45 additions and 17 deletions
  1. 45
    8
      src/core/gdbserial.c
  2. 0
    9
      src/include/ipxe/gdbserial.h

+ 45
- 8
src/core/gdbserial.c View File

23
 
23
 
24
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
24
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25
 
25
 
26
+#include <stddef.h>
26
 #include <assert.h>
27
 #include <assert.h>
27
-#include <ipxe/serial.h>
28
+#include <ipxe/uart.h>
28
 #include <ipxe/gdbstub.h>
29
 #include <ipxe/gdbstub.h>
29
 #include <ipxe/gdbserial.h>
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
 static size_t gdbserial_recv ( char *buf, size_t len ) {
57
 static size_t gdbserial_recv ( char *buf, size_t len ) {
58
+
34
 	assert ( len > 0 );
59
 	assert ( len > 0 );
35
-	buf [ 0 ] = serial_getc();
60
+	while ( ! uart_data_ready ( &gdbserial_uart ) ) {}
61
+	buf[0] = uart_receive ( &gdbserial_uart );
36
 	return 1;
62
 	return 1;
37
 }
63
 }
38
 
64
 
39
 static void gdbserial_send ( const char *buf, size_t len ) {
65
 static void gdbserial_send ( const char *buf, size_t len ) {
66
+
40
 	while ( len-- > 0 ) {
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
 struct gdb_transport serial_gdb_transport __gdb_transport = {
85
 struct gdb_transport serial_gdb_transport __gdb_transport = {
46
 	.name = "serial",
86
 	.name = "serial",
87
+	.init = gdbserial_init,
47
 	.recv = gdbserial_recv,
88
 	.recv = gdbserial_recv,
48
 	.send = gdbserial_send,
89
 	.send = gdbserial_send,
49
 };
90
 };
50
-
51
-struct gdb_transport *gdbserial_configure ( void ) {
52
-	return &serial_gdb_transport;
53
-}

+ 0
- 9
src/include/ipxe/gdbserial.h View File

9
 
9
 
10
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
10
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
 
11
 
12
-struct gdb_transport;
13
-
14
-/**
15
- * Set up the serial transport
16
- *
17
- * @ret transport suitable for starting the GDB stub or NULL on error
18
- */
19
-struct gdb_transport *gdbserial_configure ( void );
20
-
21
 #endif /* _IPXE_GDBSERIAL_H */
12
 #endif /* _IPXE_GDBSERIAL_H */

Loading…
Cancel
Save