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/system.h>
23 #include <asm/irc-regs.h>
24 #include <asm/timer-regs.h>
25 #include <asm/gdb-stub.h>
28 #ifdef CONFIG_GDBSTUB_UART0
29 #define __UART(X) (*(volatile uint8_t *)(UART0_BASE + (UART_##X)))
30 #define __UART_IRR_NMI 0xff0f0000
31 #else /* CONFIG_GDBSTUB_UART1 */
32 #define __UART(X) (*(volatile uint8_t *)(UART1_BASE + (UART_##X)))
33 #define __UART_IRR_NMI 0xfff00000
36 #define LSR_WAIT_FOR(STATE) \
39 } while (!(__UART(LSR) & UART_LSR_##STATE))
41 #define FLOWCTL_QUERY(LINE) ({ __UART(MSR) & UART_MSR_##LINE; })
42 #define FLOWCTL_CLEAR(LINE) do { __UART(MCR) &= ~UART_MCR_##LINE; mb(); } while (0)
43 #define FLOWCTL_SET(LINE) do { __UART(MCR) |= UART_MCR_##LINE; mb(); } while (0)
45 #define FLOWCTL_WAIT_FOR(LINE) \
48 } while(!FLOWCTL_QUERY(LINE))
50 /*****************************************************************************/
52 * initialise the GDB stub
53 * - called with PSR.ET==0, so can't incur external interrupts
55 void gdbstub_io_init(void)
57 /* set up the serial port */
58 __UART(LCR) = UART_LCR_WLEN8; /* 1N8 */
60 UART_FCR_ENABLE_FIFO |
68 // gdbstub_set_baud(115200);
70 /* we want to get serial receive interrupts */
71 __UART(IER) = UART_IER_RDI | UART_IER_RLSI;
74 __set_IRR(6, __UART_IRR_NMI); /* map ERRs and UARTx to NMI */
76 } /* end gdbstub_io_init() */
78 /*****************************************************************************/
80 * set up the GDB stub serial port baud rate timers
82 void gdbstub_set_baud(unsigned baud)
84 unsigned value, high, low;
87 /* work out the divisor to give us the nearest higher baud rate */
88 value = __serial_clock_speed_HZ / 16 / baud;
90 /* determine the baud rate range */
91 high = __serial_clock_speed_HZ / 16 / value;
92 low = __serial_clock_speed_HZ / 16 / (value + 1);
94 /* pick the nearest bound */
95 if (low + (high - low) / 2 > baud)
99 __UART(LCR) |= UART_LCR_DLAB;
101 __UART(DLL) = value & 0xff;
102 __UART(DLM) = (value >> 8) & 0xff;
107 } /* end gdbstub_set_baud() */
109 /*****************************************************************************/
111 * receive characters into the receive FIFO
113 void gdbstub_do_rx(void)
119 while (__UART(LSR) & UART_LSR_DR) {
120 nix = (ix + 2) & 0xfff;
121 if (nix == gdbstub_rx_outp)
124 gdbstub_rx_buffer[ix++] = __UART(LSR);
125 gdbstub_rx_buffer[ix++] = __UART(RX);
134 } /* end gdbstub_do_rx() */
136 /*****************************************************************************/
138 * wait for a character to come from the debugger
140 int gdbstub_rx_char(unsigned char *_ch, int nonblock)
147 if (gdbstub_rx_unget) {
148 *_ch = gdbstub_rx_unget;
149 gdbstub_rx_unget = 0;
156 /* pull chars out of the buffer */
157 ix = gdbstub_rx_outp;
158 if (ix == gdbstub_rx_inp) {
161 //watchdog_alert_counter = 0;
165 st = gdbstub_rx_buffer[ix++];
166 ch = gdbstub_rx_buffer[ix++];
167 gdbstub_rx_outp = ix & 0x00000fff;
169 if (st & UART_LSR_BI) {
170 gdbstub_proto("### GDB Rx Break Detected ###\n");
173 else if (st & (UART_LSR_FE|UART_LSR_OE|UART_LSR_PE)) {
174 gdbstub_proto("### GDB Rx Error (st=%02x) ###\n",st);
178 gdbstub_proto("### GDB Rx %02x (st=%02x) ###\n",ch,st);
183 } /* end gdbstub_rx_char() */
185 /*****************************************************************************/
187 * send a character to the debugger
189 void gdbstub_tx_char(unsigned char ch)
193 // FLOWCTL_WAIT_FOR(CTS);
199 // FLOWCTL_WAIT_FOR(CTS);
205 } /* end gdbstub_tx_char() */
207 /*****************************************************************************/
209 * send a character to the debugger
211 void gdbstub_tx_flush(void)
216 } /* end gdbstub_tx_flush() */