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/serial.h>
22 #include <linux/serialP.h>
23 #include <linux/serial_reg.h>
25 #include <asm/serial.h>
28 static struct serial_state rs_table
[] = {
29 SERIAL_PORT_DFNS
/* Defined in serial.h */
32 static struct async_struct kdb_port_info
= {0};
34 int (*generic_putDebugChar
)(char);
35 char (*generic_getDebugChar
)(void);
37 static __inline__
unsigned int serial_in(struct async_struct
*info
, int offset
)
39 return inb(info
->port
+ offset
);
42 static __inline__
void serial_out(struct async_struct
*info
, int offset
,
45 outb(value
, info
->port
+offset
);
48 int rs_kgdb_hook(int tty_no
, int speed
) {
50 struct serial_state
*ser
= &rs_table
[tty_no
];
52 kdb_port_info
.state
= ser
;
53 kdb_port_info
.magic
= SERIAL_MAGIC
;
54 kdb_port_info
.port
= ser
->port
;
55 kdb_port_info
.flags
= ser
->flags
;
58 * Clear all interrupts
60 serial_in(&kdb_port_info
, UART_LSR
);
61 serial_in(&kdb_port_info
, UART_RX
);
62 serial_in(&kdb_port_info
, UART_IIR
);
63 serial_in(&kdb_port_info
, UART_MSR
);
66 * Now, initialize the UART
68 serial_out(&kdb_port_info
, UART_LCR
, UART_LCR_WLEN8
); /* reset DLAB */
69 if (kdb_port_info
.flags
& ASYNC_FOURPORT
) {
70 kdb_port_info
.MCR
= UART_MCR_DTR
| UART_MCR_RTS
;
71 t
= UART_MCR_DTR
| UART_MCR_OUT1
;
74 = UART_MCR_DTR
| UART_MCR_RTS
| UART_MCR_OUT2
;
75 t
= UART_MCR_DTR
| UART_MCR_RTS
;
78 kdb_port_info
.MCR
= t
; /* no interrupts, please */
79 serial_out(&kdb_port_info
, UART_MCR
, kdb_port_info
.MCR
);
82 * and set the speed of the serial port
87 t
= kdb_port_info
.state
->baud_base
/ speed
;
89 serial_out(&kdb_port_info
, UART_LCR
, UART_LCR_WLEN8
| UART_LCR_DLAB
);
90 serial_out(&kdb_port_info
, UART_DLL
, t
& 0xff);/* LS of divisor */
91 serial_out(&kdb_port_info
, UART_DLM
, t
>> 8); /* MS of divisor */
93 serial_out(&kdb_port_info
, UART_LCR
, UART_LCR_WLEN8
);
98 int putDebugChar(char c
)
100 return generic_putDebugChar(c
);
103 char getDebugChar(void)
105 return generic_getDebugChar();
108 int rs_putDebugChar(char c
)
111 if (!kdb_port_info
.state
) { /* need to init device first */
115 while ((serial_in(&kdb_port_info
, UART_LSR
) & UART_LSR_THRE
) == 0)
118 serial_out(&kdb_port_info
, UART_TX
, c
);
123 char rs_getDebugChar(void)
125 if (!kdb_port_info
.state
) { /* need to init device first */
129 while (!(serial_in(&kdb_port_info
, UART_LSR
) & 1))
132 return serial_in(&kdb_port_info
, UART_RX
);