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 <asm/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 IVAR0 = EXCEP_IRQ_LEVEL0;
49 set_intr_stub(EXCEP_IRQ_LEVEL0, gdbstub_io_rx_handler);
51 XIRQxICR(GDBPORT_SERIAL_IRQ) &= ~GxICR_REQUEST;
52 XIRQxICR(GDBPORT_SERIAL_IRQ) = GxICR_ENABLE | GxICR_LEVEL_0;
53 tmp = XIRQxICR(GDBPORT_SERIAL_IRQ);
55 GDBPORT_SERIAL_IER = UART_IER_RDI | UART_IER_RLSI;
57 /* permit level 0 IRQs to take place */
62 : "i"(~EPSW_IM), "i"(EPSW_IE | EPSW_IM_1)
67 * set up the GDB stub serial port baud rate timers
69 void gdbstub_io_set_baud(unsigned baud)
74 value = 18432000 / 16 / baud;
76 lcr = GDBPORT_SERIAL_LCR;
77 GDBPORT_SERIAL_LCR |= UART_LCR_DLAB;
78 GDBPORT_SERIAL_DLL = value & 0xff;
79 GDBPORT_SERIAL_DLM = (value >> 8) & 0xff;
80 GDBPORT_SERIAL_LCR = lcr;
84 * wait for a character to come from the debugger
86 int gdbstub_io_rx_char(unsigned char *_ch, int nonblock)
93 if (gdbstub_rx_unget) {
94 *_ch = gdbstub_rx_unget;
100 /* pull chars out of the buffer */
101 ix = gdbstub_rx_outp;
103 if (ix == gdbstub_rx_inp) {
106 #ifdef CONFIG_MN10300_WD_TIMER
107 watchdog_alert_counter = 0;
108 #endif /* CONFIG_MN10300_WD_TIMER */
112 ch = gdbstub_rx_buffer[ix++];
113 st = gdbstub_rx_buffer[ix++];
115 gdbstub_rx_outp = ix & 0x00000fff;
117 if (st & UART_LSR_BI) {
118 gdbstub_proto("### GDB Rx Break Detected ###\n");
120 } else if (st & (UART_LSR_FE | UART_LSR_OE | UART_LSR_PE)) {
121 gdbstub_proto("### GDB Rx Error (st=%02x) ###\n", st);
124 gdbstub_proto("### GDB Rx %02x (st=%02x) ###\n", ch, st);
131 * send a character to the debugger
133 void gdbstub_io_tx_char(unsigned char ch)
137 /* FLOWCTL_WAIT_FOR(CTS); */
140 GDBPORT_SERIAL_TX = 0x0d;
142 /* FLOWCTL_WAIT_FOR(CTS); */
144 GDBPORT_SERIAL_TX = ch;
150 * send a character to the debugger
152 void gdbstub_io_tx_flush(void)