net: tun.c fix cast
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / mn10300 / kernel / gdb-io-serial.c
blob9a6d4e8ebe7396f058ccc740d48dfc3a0e14f979
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>
15 #include <linux/mm.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)
32 u16 tmp;
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 |
37 UART_FCR_CLEAR_XMIT);
39 FLOWCTL_CLEAR(DTR);
40 FLOWCTL_SET(RTS);
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 */
58 asm volatile(
59 " and %0,epsw \n"
60 " or %1,epsw \n"
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)
71 unsigned value;
72 u8 lcr;
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)
88 unsigned ix;
89 u8 ch, st;
91 *_ch = 0xff;
93 if (gdbstub_rx_unget) {
94 *_ch = gdbstub_rx_unget;
95 gdbstub_rx_unget = 0;
96 return 0;
99 try_again:
100 /* pull chars out of the buffer */
101 ix = gdbstub_rx_outp;
102 if (ix == gdbstub_rx_inp) {
103 if (nonblock)
104 return -EAGAIN;
105 #ifdef CONFIG_MN10300_WD_TIMER
106 watchdog_alert_counter = 0;
107 #endif /* CONFIG_MN10300_WD_TIMER */
108 goto try_again;
111 ch = gdbstub_rx_buffer[ix++];
112 st = gdbstub_rx_buffer[ix++];
113 gdbstub_rx_outp = ix & 0x00000fff;
115 if (st & UART_LSR_BI) {
116 gdbstub_proto("### GDB Rx Break Detected ###\n");
117 return -EINTR;
118 } else if (st & (UART_LSR_FE | UART_LSR_OE | UART_LSR_PE)) {
119 gdbstub_proto("### GDB Rx Error (st=%02x) ###\n", st);
120 return -EIO;
121 } else {
122 gdbstub_proto("### GDB Rx %02x (st=%02x) ###\n", ch, st);
123 *_ch = ch & 0x7f;
124 return 0;
129 * send a character to the debugger
131 void gdbstub_io_tx_char(unsigned char ch)
133 FLOWCTL_SET(DTR);
134 LSR_WAIT_FOR(THRE);
135 /* FLOWCTL_WAIT_FOR(CTS); */
137 if (ch == 0x0a) {
138 GDBPORT_SERIAL_TX = 0x0d;
139 LSR_WAIT_FOR(THRE);
140 /* FLOWCTL_WAIT_FOR(CTS); */
142 GDBPORT_SERIAL_TX = ch;
144 FLOWCTL_CLEAR(DTR);
148 * send a character to the debugger
150 void gdbstub_io_tx_flush(void)
152 LSR_WAIT_FOR(TEMT);
153 LSR_WAIT_FOR(THRE);
154 FLOWCTL_CLEAR(DTR);