1 /* gdb-io.c: FR403 GDB stub I/O
3 * Copyright (C) 2003 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 License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
12 #include <linux/string.h>
13 #include <linux/kernel.h>
14 #include <linux/signal.h>
15 #include <linux/sched.h>
17 #include <linux/console.h>
18 #include <linux/init.h>
19 #include <linux/serial_reg.h>
21 #include <asm/pgtable.h>
22 #include <asm/irc-regs.h>
23 #include <asm/timer-regs.h>
24 #include <asm/gdb-stub.h>
27 #ifdef CONFIG_GDBSTUB_UART0
28 #define __UART(X) (*(volatile uint8_t *)(UART0_BASE + (UART_##X)))
29 #define __UART_IRR_NMI 0xff0f0000
30 #else /* CONFIG_GDBSTUB_UART1 */
31 #define __UART(X) (*(volatile uint8_t *)(UART1_BASE + (UART_##X)))
32 #define __UART_IRR_NMI 0xfff00000
35 #define LSR_WAIT_FOR(STATE) \
38 } while (!(__UART(LSR) & UART_LSR_##STATE))
40 #define FLOWCTL_QUERY(LINE) ({ __UART(MSR) & UART_MSR_##LINE; })
41 #define FLOWCTL_CLEAR(LINE) do { __UART(MCR) &= ~UART_MCR_##LINE; mb(); } while (0)
42 #define FLOWCTL_SET(LINE) do { __UART(MCR) |= UART_MCR_##LINE; mb(); } while (0)
44 #define FLOWCTL_WAIT_FOR(LINE) \
47 } while(!FLOWCTL_QUERY(LINE))
49 /*****************************************************************************/
51 * initialise the GDB stub
52 * - called with PSR.ET==0, so can't incur external interrupts
54 void gdbstub_io_init(void)
56 /* set up the serial port */
57 __UART(LCR
) = UART_LCR_WLEN8
; /* 1N8 */
59 UART_FCR_ENABLE_FIFO
|
67 // gdbstub_set_baud(115200);
69 /* we want to get serial receive interrupts */
70 __UART(IER
) = UART_IER_RDI
| UART_IER_RLSI
;
73 __set_IRR(6, __UART_IRR_NMI
); /* map ERRs and UARTx to NMI */
75 } /* end gdbstub_io_init() */
77 /*****************************************************************************/
79 * set up the GDB stub serial port baud rate timers
81 void gdbstub_set_baud(unsigned baud
)
83 unsigned value
, high
, low
;
86 /* work out the divisor to give us the nearest higher baud rate */
87 value
= __serial_clock_speed_HZ
/ 16 / baud
;
89 /* determine the baud rate range */
90 high
= __serial_clock_speed_HZ
/ 16 / value
;
91 low
= __serial_clock_speed_HZ
/ 16 / (value
+ 1);
93 /* pick the nearest bound */
94 if (low
+ (high
- low
) / 2 > baud
)
98 __UART(LCR
) |= UART_LCR_DLAB
;
100 __UART(DLL
) = value
& 0xff;
101 __UART(DLM
) = (value
>> 8) & 0xff;
106 } /* end gdbstub_set_baud() */
108 /*****************************************************************************/
110 * receive characters into the receive FIFO
112 void gdbstub_do_rx(void)
118 while (__UART(LSR
) & UART_LSR_DR
) {
119 nix
= (ix
+ 2) & 0xfff;
120 if (nix
== gdbstub_rx_outp
)
123 gdbstub_rx_buffer
[ix
++] = __UART(LSR
);
124 gdbstub_rx_buffer
[ix
++] = __UART(RX
);
133 } /* end gdbstub_do_rx() */
135 /*****************************************************************************/
137 * wait for a character to come from the debugger
139 int gdbstub_rx_char(unsigned char *_ch
, int nonblock
)
146 if (gdbstub_rx_unget
) {
147 *_ch
= gdbstub_rx_unget
;
148 gdbstub_rx_unget
= 0;
155 /* pull chars out of the buffer */
156 ix
= gdbstub_rx_outp
;
157 if (ix
== gdbstub_rx_inp
) {
160 //watchdog_alert_counter = 0;
164 st
= gdbstub_rx_buffer
[ix
++];
165 ch
= gdbstub_rx_buffer
[ix
++];
166 gdbstub_rx_outp
= ix
& 0x00000fff;
168 if (st
& UART_LSR_BI
) {
169 gdbstub_proto("### GDB Rx Break Detected ###\n");
172 else if (st
& (UART_LSR_FE
|UART_LSR_OE
|UART_LSR_PE
)) {
173 gdbstub_io("### GDB Rx Error (st=%02x) ###\n",st
);
177 gdbstub_io("### GDB Rx %02x (st=%02x) ###\n",ch
,st
);
182 } /* end gdbstub_rx_char() */
184 /*****************************************************************************/
186 * send a character to the debugger
188 void gdbstub_tx_char(unsigned char ch
)
192 // FLOWCTL_WAIT_FOR(CTS);
198 // FLOWCTL_WAIT_FOR(CTS);
204 } /* end gdbstub_tx_char() */
206 /*****************************************************************************/
208 * send a character to the debugger
210 void gdbstub_tx_flush(void)
215 } /* end gdbstub_tx_flush() */