1 /* 16550 serial driver for gdbstub I/O
3 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public Licence
8 * as published by the Free Software Foundation; either version
9 * 2 of the Licence, or (at your option) any later version.
11 #include <linux/string.h>
12 #include <linux/kernel.h>
13 #include <linux/signal.h>
14 #include <linux/sched.h>
16 #include <linux/console.h>
17 #include <linux/init.h>
18 #include <linux/nmi.h>
20 #include <asm/pgtable.h>
21 #include <asm/system.h>
22 #include <asm/gdb-stub.h>
23 #include <asm/exceptions.h>
24 #include <asm/serial-regs.h>
25 #include <unit/serial.h>
29 * initialise the GDB stub
31 void gdbstub_io_init(void)
35 /* set up the serial port */
36 GDBPORT_SERIAL_LCR
= UART_LCR_WLEN8
; /* 1N8 */
37 GDBPORT_SERIAL_FCR
= (UART_FCR_ENABLE_FIFO
| UART_FCR_CLEAR_RCVR
|
43 gdbstub_io_set_baud(115200);
45 /* we want to get serial receive interrupts */
46 XIRQxICR(GDBPORT_SERIAL_IRQ
) = 0;
47 tmp
= XIRQxICR(GDBPORT_SERIAL_IRQ
);
49 #if CONFIG_GDBSTUB_IRQ_LEVEL == 0
50 IVAR0
= EXCEP_IRQ_LEVEL0
;
51 #elif CONFIG_GDBSTUB_IRQ_LEVEL == 1
52 IVAR1
= EXCEP_IRQ_LEVEL1
;
53 #elif CONFIG_GDBSTUB_IRQ_LEVEL == 2
54 IVAR2
= EXCEP_IRQ_LEVEL2
;
55 #elif CONFIG_GDBSTUB_IRQ_LEVEL == 3
56 IVAR3
= EXCEP_IRQ_LEVEL3
;
57 #elif CONFIG_GDBSTUB_IRQ_LEVEL == 4
58 IVAR4
= EXCEP_IRQ_LEVEL4
;
59 #elif CONFIG_GDBSTUB_IRQ_LEVEL == 5
60 IVAR5
= EXCEP_IRQ_LEVEL5
;
62 #error "Unknown irq level for gdbstub."
65 set_intr_stub(NUM2EXCEP_IRQ_LEVEL(CONFIG_GDBSTUB_IRQ_LEVEL
),
66 gdbstub_io_rx_handler
);
68 XIRQxICR(GDBPORT_SERIAL_IRQ
) &= ~GxICR_REQUEST
;
69 XIRQxICR(GDBPORT_SERIAL_IRQ
) =
70 GxICR_ENABLE
| NUM2GxICR_LEVEL(CONFIG_GDBSTUB_IRQ_LEVEL
);
71 tmp
= XIRQxICR(GDBPORT_SERIAL_IRQ
);
73 GDBPORT_SERIAL_IER
= UART_IER_RDI
| UART_IER_RLSI
;
75 /* permit level 0 IRQs to take place */
76 arch_local_change_intr_mask_level(
77 NUM2EPSW_IM(CONFIG_GDBSTUB_IRQ_LEVEL
+ 1));
81 * set up the GDB stub serial port baud rate timers
83 void gdbstub_io_set_baud(unsigned baud
)
88 value
= 18432000 / 16 / baud
;
90 lcr
= GDBPORT_SERIAL_LCR
;
91 GDBPORT_SERIAL_LCR
|= UART_LCR_DLAB
;
92 GDBPORT_SERIAL_DLL
= value
& 0xff;
93 GDBPORT_SERIAL_DLM
= (value
>> 8) & 0xff;
94 GDBPORT_SERIAL_LCR
= lcr
;
98 * wait for a character to come from the debugger
100 int gdbstub_io_rx_char(unsigned char *_ch
, int nonblock
)
104 #if defined(CONFIG_MN10300_WD_TIMER)
110 if (gdbstub_rx_unget
) {
111 *_ch
= gdbstub_rx_unget
;
112 gdbstub_rx_unget
= 0;
117 /* pull chars out of the buffer */
118 ix
= gdbstub_rx_outp
;
120 if (ix
== gdbstub_rx_inp
) {
123 #ifdef CONFIG_MN10300_WD_TIMER
124 for (cpu
= 0; cpu
< NR_CPUS
; cpu
++)
125 watchdog_alert_counter
[cpu
] = 0;
130 ch
= gdbstub_rx_buffer
[ix
++];
131 st
= gdbstub_rx_buffer
[ix
++];
133 gdbstub_rx_outp
= ix
& 0x00000fff;
135 if (st
& UART_LSR_BI
) {
136 gdbstub_proto("### GDB Rx Break Detected ###\n");
138 } else if (st
& (UART_LSR_FE
| UART_LSR_OE
| UART_LSR_PE
)) {
139 gdbstub_proto("### GDB Rx Error (st=%02x) ###\n", st
);
142 gdbstub_proto("### GDB Rx %02x (st=%02x) ###\n", ch
, st
);
149 * send a character to the debugger
151 void gdbstub_io_tx_char(unsigned char ch
)
155 /* FLOWCTL_WAIT_FOR(CTS); */
158 GDBPORT_SERIAL_TX
= 0x0d;
160 /* FLOWCTL_WAIT_FOR(CTS); */
162 GDBPORT_SERIAL_TX
= ch
;
168 * send a character to the debugger
170 void gdbstub_io_tx_flush(void)