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/gdb-stub.h>
22 #include <asm/exceptions.h>
23 #include <asm/serial-regs.h>
24 #include <unit/serial.h>
28 * initialise the GDB stub
30 void gdbstub_io_init(void)
34 /* set up the serial port */
35 GDBPORT_SERIAL_LCR
= UART_LCR_WLEN8
; /* 1N8 */
36 GDBPORT_SERIAL_FCR
= (UART_FCR_ENABLE_FIFO
| UART_FCR_CLEAR_RCVR
|
42 gdbstub_io_set_baud(115200);
44 /* we want to get serial receive interrupts */
45 XIRQxICR(GDBPORT_SERIAL_IRQ
) = 0;
46 tmp
= XIRQxICR(GDBPORT_SERIAL_IRQ
);
48 #if CONFIG_GDBSTUB_IRQ_LEVEL == 0
49 IVAR0
= EXCEP_IRQ_LEVEL0
;
50 #elif CONFIG_GDBSTUB_IRQ_LEVEL == 1
51 IVAR1
= EXCEP_IRQ_LEVEL1
;
52 #elif CONFIG_GDBSTUB_IRQ_LEVEL == 2
53 IVAR2
= EXCEP_IRQ_LEVEL2
;
54 #elif CONFIG_GDBSTUB_IRQ_LEVEL == 3
55 IVAR3
= EXCEP_IRQ_LEVEL3
;
56 #elif CONFIG_GDBSTUB_IRQ_LEVEL == 4
57 IVAR4
= EXCEP_IRQ_LEVEL4
;
58 #elif CONFIG_GDBSTUB_IRQ_LEVEL == 5
59 IVAR5
= EXCEP_IRQ_LEVEL5
;
61 #error "Unknown irq level for gdbstub."
64 set_intr_stub(NUM2EXCEP_IRQ_LEVEL(CONFIG_GDBSTUB_IRQ_LEVEL
),
65 gdbstub_io_rx_handler
);
67 XIRQxICR(GDBPORT_SERIAL_IRQ
) &= ~GxICR_REQUEST
;
68 XIRQxICR(GDBPORT_SERIAL_IRQ
) =
69 GxICR_ENABLE
| NUM2GxICR_LEVEL(CONFIG_GDBSTUB_IRQ_LEVEL
);
70 tmp
= XIRQxICR(GDBPORT_SERIAL_IRQ
);
72 GDBPORT_SERIAL_IER
= UART_IER_RDI
| UART_IER_RLSI
;
74 /* permit level 0 IRQs to take place */
75 arch_local_change_intr_mask_level(
76 NUM2EPSW_IM(CONFIG_GDBSTUB_IRQ_LEVEL
+ 1));
80 * set up the GDB stub serial port baud rate timers
82 void gdbstub_io_set_baud(unsigned baud
)
87 value
= 18432000 / 16 / baud
;
89 lcr
= GDBPORT_SERIAL_LCR
;
90 GDBPORT_SERIAL_LCR
|= UART_LCR_DLAB
;
91 GDBPORT_SERIAL_DLL
= value
& 0xff;
92 GDBPORT_SERIAL_DLM
= (value
>> 8) & 0xff;
93 GDBPORT_SERIAL_LCR
= lcr
;
97 * wait for a character to come from the debugger
99 int gdbstub_io_rx_char(unsigned char *_ch
, int nonblock
)
103 #if defined(CONFIG_MN10300_WD_TIMER)
109 if (gdbstub_rx_unget
) {
110 *_ch
= gdbstub_rx_unget
;
111 gdbstub_rx_unget
= 0;
116 /* pull chars out of the buffer */
117 ix
= gdbstub_rx_outp
;
119 if (ix
== gdbstub_rx_inp
) {
122 #ifdef CONFIG_MN10300_WD_TIMER
123 for (cpu
= 0; cpu
< NR_CPUS
; cpu
++)
124 watchdog_alert_counter
[cpu
] = 0;
129 ch
= gdbstub_rx_buffer
[ix
++];
130 st
= gdbstub_rx_buffer
[ix
++];
132 gdbstub_rx_outp
= ix
& 0x00000fff;
134 if (st
& UART_LSR_BI
) {
135 gdbstub_proto("### GDB Rx Break Detected ###\n");
137 } else if (st
& (UART_LSR_FE
| UART_LSR_OE
| UART_LSR_PE
)) {
138 gdbstub_proto("### GDB Rx Error (st=%02x) ###\n", st
);
141 gdbstub_proto("### GDB Rx %02x (st=%02x) ###\n", ch
, st
);
148 * send a character to the debugger
150 void gdbstub_io_tx_char(unsigned char ch
)
154 /* FLOWCTL_WAIT_FOR(CTS); */
157 GDBPORT_SERIAL_TX
= 0x0d;
159 /* FLOWCTL_WAIT_FOR(CTS); */
161 GDBPORT_SERIAL_TX
= ch
;
167 * send a character to the debugger
169 void gdbstub_io_tx_flush(void)