2 * Carsten Langgaard, carstenl@mips.com
3 * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
5 * This program is free software; you can distribute it and/or modify it
6 * under the terms of the GNU General Public License (Version 2) as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
18 * This is the interface to the remote debugger stub.
20 #include <linux/types.h>
21 #include <linux/config.h>
22 #include <linux/serial.h>
23 #include <linux/serialP.h>
24 #include <linux/serial_reg.h>
26 #include <asm/serial.h>
29 static struct serial_state rs_table[RS_TABLE_SIZE] = {
30 SERIAL_PORT_DFNS /* Defined in serial.h */
33 static struct async_struct kdb_port_info = {0};
35 int (*generic_putDebugChar)(char);
36 char (*generic_getDebugChar)(void);
38 static __inline__ unsigned int serial_in(struct async_struct *info, int offset)
40 return inb(info->port + offset);
43 static __inline__ void serial_out(struct async_struct *info, int offset,
46 outb(value, info->port+offset);
49 int rs_kgdb_hook(int tty_no, int speed) {
51 struct serial_state *ser = &rs_table[tty_no];
53 kdb_port_info.state = ser;
54 kdb_port_info.magic = SERIAL_MAGIC;
55 kdb_port_info.port = ser->port;
56 kdb_port_info.flags = ser->flags;
59 * Clear all interrupts
61 serial_in(&kdb_port_info, UART_LSR);
62 serial_in(&kdb_port_info, UART_RX);
63 serial_in(&kdb_port_info, UART_IIR);
64 serial_in(&kdb_port_info, UART_MSR);
67 * Now, initialize the UART
69 serial_out(&kdb_port_info, UART_LCR, UART_LCR_WLEN8); /* reset DLAB */
70 if (kdb_port_info.flags & ASYNC_FOURPORT) {
71 kdb_port_info.MCR = UART_MCR_DTR | UART_MCR_RTS;
72 t = UART_MCR_DTR | UART_MCR_OUT1;
75 = UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2;
76 t = UART_MCR_DTR | UART_MCR_RTS;
79 kdb_port_info.MCR = t; /* no interrupts, please */
80 serial_out(&kdb_port_info, UART_MCR, kdb_port_info.MCR);
83 * and set the speed of the serial port
88 t = kdb_port_info.state->baud_base / speed;
90 serial_out(&kdb_port_info, UART_LCR, UART_LCR_WLEN8 | UART_LCR_DLAB);
91 serial_out(&kdb_port_info, UART_DLL, t & 0xff);/* LS of divisor */
92 serial_out(&kdb_port_info, UART_DLM, t >> 8); /* MS of divisor */
94 serial_out(&kdb_port_info, UART_LCR, UART_LCR_WLEN8);
99 int putDebugChar(char c)
101 return generic_putDebugChar(c);
104 char getDebugChar(void)
106 return generic_getDebugChar();
109 int rs_putDebugChar(char c)
112 if (!kdb_port_info.state) { /* need to init device first */
116 while ((serial_in(&kdb_port_info, UART_LSR) & UART_LSR_THRE) == 0)
119 serial_out(&kdb_port_info, UART_TX, c);
124 char rs_getDebugChar(void)
126 if (!kdb_port_info.state) { /* need to init device first */
130 while (!(serial_in(&kdb_port_info, UART_LSR) & 1))
133 return serial_in(&kdb_port_info, UART_RX);