cleanup
[linux-2.4.21-pre4.git] / arch / ppc64 / kdb / kdba_io.c
1 /*
2  * Kernel Debugger Console I/O handler
3  *
4  * Copyright (C) 1999 Silicon Graphics, Inc.
5  * Copyright (C) Scott Lurndal (slurn@engr.sgi.com)
6  * Copyright (C) Scott Foehner (sfoehner@engr.sgi.com)
7  * Copyright (C) Srinivasa Thirumalachar (sprasad@engr.sgi.com)
8  *
9  * See the file LIA-COPYRIGHT for additional information.
10  *
11  * Written March 1999 by Scott Lurndal at Silicon Graphics, Inc.
12  *
13  * Modifications from:
14  *      Chuck Fleckenstein              1999/07/20
15  *              Move kdb_info struct declaration to this file
16  *              for cases where serial support is not compiled into
17  *              the kernel.
18  *
19  *      Masahiro Adegawa                1999/07/20
20  *              Handle some peculiarities of japanese 86/106
21  *              keyboards.
22  *
23  *      marc@mucom.co.il                1999/07/20
24  *              Catch buffer overflow for serial input.
25  *
26  *      Scott Foehner
27  *              Port to ia64
28  *
29  *      Scott Lurndal                   2000/01/03
30  *              Restructure for v1.0
31  *
32  *      Keith Owens                     2000/05/23
33  *              KDB v1.2
34  *
35  *      Andi Kleen                      2000/03/19
36  *              Support simultaneous input from serial line and keyboard.
37  */
38
39 #include <linux/kernel.h>
40 #include <asm/io.h>
41 #include <linux/wait.h>
42 #include <linux/delay.h>
43 #include <linux/pc_keyb.h>
44 #include <linux/console.h>
45 #include <linux/ctype.h>
46 #include <linux/keyboard.h>
47 #include <linux/serial_reg.h>
48
49 #include <linux/kdb.h>
50 #include <linux/kdbprivate.h>
51 #include <asm/machdep.h>
52 #undef FILE
53
54 int kdb_port;
55 int inchar(void);
56
57 /*
58  * This module contains code to read characters from the keyboard or a serial
59  * port.
60  *
61  * It is used by the kernel debugger, and is polled, not interrupt driven.
62  *
63  */
64 void
65 kdb_resetkeyboard(void)
66 {
67 #if 0
68         kdb_kbdsend(KBD_CMD_ENABLE);
69 #endif
70 }
71
72
73 #if 0
74 /* code that may be resurrected later.. */
75 #if defined(CONFIG_VT)
76 /*
77  * Check if the keyboard controller has a keypress for us.
78  * Some parts (Enter Release, LED change) are still blocking polled here,
79  * but hopefully they are all short.
80  */
81 static int get_kbd_char(void)
82 {
83         int keychar;
84 /*      keychar = inchar(); */
85         keychar = ppc_md.udbg_getc_poll();
86
87         if (keychar == '\n')
88         {
89             kdb_printf("\n");
90         }
91
92         /*
93          * echo the character.
94          */
95         kdb_printf("%c", keychar);
96
97         return keychar ;
98 }
99 #endif /* CONFIG_VT */
100 #endif
101
102 static int get_char_lp(void)
103 {
104     int keychar;
105     keychar = ppc_md.udbg_getc_poll();
106
107     if (keychar == '\n')
108     {
109         kdb_printf("\n");
110     }
111
112 #if 0
113     /* echo the character. */
114     if (keychar != -1)
115         kdb_printf("%c", keychar);
116 #endif
117
118     return keychar ;
119 }
120
121
122 char *
123 kdba_read(char *buffer, size_t bufsize)
124 {
125         char    *cp = buffer;
126         char    *bufend = buffer+bufsize-2;     /* Reserve space for newline and null byte */
127
128         for (;;) {
129             unsigned char key = ppc_md.udbg_getc();
130                 /* Echo is done in the low level functions */
131                 switch (key) {
132                 case '\b': /* backspace */
133                 case '\x7f': /* delete */
134                         if (cp > buffer) {
135                                 udbg_puts("\b \b");
136                                 --cp;
137                         }
138                         break;
139                 case '\n': /* enter */
140                 case '\r': /* - the other enter... */
141                         ppc_md.udbg_putc('\n');
142                         *cp++ = '\n';
143                         *cp++ = '\0';
144                         return buffer;
145                 default:
146                         if (cp < bufend)
147                         ppc_md.udbg_putc(key);
148                                 *cp++ = key;
149                         break;
150                 }
151         }
152 }
153
154
155