xref: /netbsd/sys/arch/hp300/stand/common/hil.c (revision bf9ec67e)
1 /*	$NetBSD: hil.c,v 1.3 1997/10/04 17:20:19 thorpej Exp $	*/
2 
3 /*-
4  * Copyright (c) 1997 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Jason R. Thorpe.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *	This product includes software developed by the NetBSD
21  *	Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 /*
40  * Copyright (c) 1988 University of Utah.
41  * Copyright (c) 1990, 1993
42  *	The Regents of the University of California.  All rights reserved.
43  *
44  * This code is derived from software contributed to Berkeley by
45  * the Systems Programming Group of the University of Utah Computer
46  * Science Department.
47  *
48  * Redistribution and use in source and binary forms, with or without
49  * modification, are permitted provided that the following conditions
50  * are met:
51  * 1. Redistributions of source code must retain the above copyright
52  *    notice, this list of conditions and the following disclaimer.
53  * 2. Redistributions in binary form must reproduce the above copyright
54  *    notice, this list of conditions and the following disclaimer in the
55  *    documentation and/or other materials provided with the distribution.
56  * 3. All advertising materials mentioning features or use of this software
57  *    must display the following acknowledgement:
58  *	This product includes software developed by the University of
59  *	California, Berkeley and its contributors.
60  * 4. Neither the name of the University nor the names of its contributors
61  *    may be used to endorse or promote products derived from this software
62  *    without specific prior written permission.
63  *
64  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
65  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
66  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
67  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
68  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
69  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
70  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
71  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
72  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
73  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
74  * SUCH DAMAGE.
75  *
76  * from: Utah Hdr: hil.c 1.1 89/08/22
77  *
78  *	@(#)hil.c	8.1 (Berkeley) 6/10/93
79  */
80 
81 /*
82  * HIL keyboard routines for the standalone ITE.
83  */
84 
85 #if defined(ITECONSOLE) && defined(HIL_KEYBOARD)
86 
87 #include <sys/param.h>
88 #include <sys/device.h>			/* XXX */
89 
90 #include <hp300/dev/hilreg.h>
91 #include <hp300/dev/kbdmap.h>
92 #include <hp300/dev/itevar.h>
93 
94 #include <hp300/stand/common/samachdep.h>
95 #include <hp300/stand/common/kbdvar.h>
96 
97 #ifndef SMALL
98 
99 /*
100  * HIL cooked keyboard keymaps.
101  * Supports only unshifted, shifted and control keys.
102  */
103 char hil_us_keymap[] = {
104 	NULL,	'`',	'\\',	ESC,	NULL,	DEL,	NULL,	NULL,
105 	'\n',	'\t',	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,
106 	NULL,	'\n',	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,
107 	NULL,	'\t',	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,
108 	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,
109 	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,	'\b',	NULL,
110 	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,
111 	ESC,	'\r',	NULL,	'\n',	'0',	'.',	',',	'+',
112 	'1',	'2',	'3',	'-',	'4',	'5',	'6',	'*',
113 	'7',	'8',	'9',	'/',	'E',	'(',	')',	'^',
114 	'1',	'2',	'3',	'4',	'5',	'6',	'7',	'8',
115 	'9',	'0',	'-',	'=',	'[',	']',	';',	'\'',
116 	',',	'.',	'/',	'\040',	'o',	'p',	'k',	'l',
117 	'q',	'w',	'e',	'r',	't',	'y',	'u',	'i',
118 	'a',	's',	'd',	'f',	'g',	'h',	'j',	'm',
119 	'z',	'x',	'c',	'v',	'b',	'n',	NULL,	NULL
120 };
121 
122 char hil_us_shiftmap[] = {
123 	NULL,	'~',	'|',	DEL,	NULL,	DEL,	NULL,	NULL,
124 	'\n',	'\t',	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,
125 	NULL,	'\n',	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,
126 	NULL,	'\t',	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,
127 	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,
128 	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,	DEL,	NULL,
129 	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,
130 	ESC,	'\r',	NULL,	'\n',	'0',	'.',	',',	'+',
131 	'1',	'2',	'3',	'-',	'4',	'5',	'6',	'*',
132 	'7',	'8',	'9',	'/',	'`',	'|',	'\\',	'~',
133 	'!',	'@',	'#',	'$',	'%',	'^',	'&',	'*',
134 	'(',	')',	'_',	'+',	'{',	'}',	':',	'\"',
135 	'<',	'>',	'?',	'\040',	'O',	'P',	'K',	'L',
136 	'Q',	'W',	'E',	'R',	'T',	'Y',	'U',	'I',
137 	'A',	'S',	'D',	'F',	'G',	'H',	'J',	'M',
138 	'Z',	'X',	'C',	'V',	'B',	'N',	NULL,	NULL
139 };
140 
141 char hil_us_ctrlmap[] = {
142 	NULL,	'`',	'\034',	ESC,	NULL,	DEL,	NULL,	NULL,
143 	'\n',	'\t',	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,
144 	NULL,	'\n',	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,
145 	NULL,	'\t',	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,
146 	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,
147 	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,	'\b',	NULL,
148 	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,
149 	ESC,	'\r',	NULL,	'\n',	'0',	'.',	',',	'+',
150 	'1',	'2',	'3',	'-',	'4',	'5',	'6',	'*',
151 	'7',	'8',	'9',	'/',	'E',	'(',	')',	'\036',
152 	'1',	'2',	'3',	'4',	'5',	'6',	'7',	'8',
153 	'9',	'0',	'-',	'=',	'\033',	'\035',	';',	'\'',
154 	',',	'.',	'/',	'\040',	'\017',	'\020',	'\013',	'\014',
155 	'\021',	'\027',	'\005',	'\022',	'\024',	'\031',	'\025',	'\011',
156 	'\001',	'\023',	'\004',	'\006',	'\007',	'\010',	'\012',	'\015',
157 	'\032',	'\030',	'\003',	'\026',	'\002',	'\016',	NULL,	NULL
158 };
159 
160 #ifdef UK_KEYBOARD
161 char hil_uk_keymap[] = {
162 	NULL,	'`',	'<',	ESC,	NULL,	DEL,	NULL,	NULL,
163 	'\n',	'\t',	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,
164 	NULL,	'\n',	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,
165 	NULL,	'\t',	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,
166 	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,
167 	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,	'\b',	NULL,
168 	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,
169 	ESC,	'\r',	NULL,	'\n',	'0',	'.',	',',	'+',
170 	'1',	'2',	'3',	'-',	'4',	'5',	'6',	'*',
171 	'7',	'8',	'9',	'/',	'E',	'(',	')',	'^',
172 	'1',	'2',	'3',	'4',	'5',	'6',	'7',	'8',
173 	'9',	'0',	'+',	'\'',	'[',	']',	'*',	'\\',
174 	',',	'.',	'-',	'\040',	'o',	'p',	'k',	'l',
175 	'q',	'w',	'e',	'r',	't',	'y',	'u',	'i',
176 	'a',	's',	'd',	'f',	'g',	'h',	'j',	'm',
177 	'z',	'x',	'c',	'v',	'b',	'n',	NULL,	NULL
178 };
179 
180 char hil_uk_shiftmap[] = {
181 	NULL,	'~',	'>',	DEL,	NULL,	DEL,	NULL,	NULL,
182 	'\n',	'\t',	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,
183 	NULL,	'\n',	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,
184 	NULL,	'\t',	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,
185 	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,
186 	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,	DEL,	NULL,
187 	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,
188 	ESC,	'\r',	NULL,	'\n',	'0',	'.',	',',	'+',
189 	'1',	'2',	'3',	'-',	'4',	'5',	'6',	'*',
190 	'7',	'8',	'9',	'/',	'`',	'|',	'\\',	'~',
191 	'!',	'\"',	'#',	'$',	'%',	'&',	'^',	'(',
192 	')',	'=',	'?',	'/',	'{',	'}',	'@',	'|',
193 	';',	':',	'_',	'\040',	'O',	'P',	'K',	'L',
194 	'Q',	'W',	'E',	'R',	'T',	'Y',	'U',	'I',
195 	'A',	'S',	'D',	'F',	'G',	'H',	'J',	'M',
196 	'Z',	'X',	'C',	'V',	'B',	'N',	NULL,	NULL
197 };
198 
199 char hil_uk_ctrlmap[] = {
200 	NULL,	'`',	'<',	ESC,	NULL,	DEL,	NULL,	NULL,
201 	'\n',	'\t',	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,
202 	NULL,	'\n',	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,
203 	NULL,	'\t',	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,
204 	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,
205 	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,	'\b',	NULL,
206 	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,	NULL,
207 	ESC,	'\r',	NULL,	'\n',	'0',	'.',	',',	'+',
208 	'1',	'2',	'3',	'-',	'4',	'5',	'6',	'*',
209 	'7',	'8',	'9',	'/',	'E',	'(',	')',	'\036',
210 	'1',	'2',	'3',	'4',	'5',	'6',	'7',	'8',
211 	'9',	'0',	'+',	'\'',	'\033',	'\035',	'*',	'\034',
212 	',',	'.',	'/',	'\040',	'\017',	'\020',	'\013',	'\014',
213 	'\021',	'\027',	'\005',	'\022',	'\024',	'\031',	'\025',	'\011',
214 	'\001',	'\023',	'\004',	'\006',	'\007',	'\010',	'\012',	'\015',
215 	'\032',	'\030',	'\003',	'\026',	'\002',	'\016',	NULL,	NULL
216 };
217 #endif
218 
219 /*
220  * The keyboard map table.
221  * Lookup is by hardware returned language code.
222  */
223 struct kbdmap hilkbd_map[] = {
224 	KBD_US,		NULL,
225 	hil_us_keymap,	hil_us_shiftmap, hil_us_ctrlmap, NULL,	NULL,
226 
227 #ifdef UK_KEYBOARD
228 	KBD_UK,		NULL,
229 	hil_uk_keymap,	hil_uk_shiftmap, hil_uk_ctrlmap, NULL,	NULL,
230 #endif
231 
232 	0,		NULL,
233 	NULL,		NULL,		NULL,		NULL,	NULL,
234 };
235 
236 char	*hilkbd_keymap = hil_us_keymap;
237 char	*hilkbd_shiftmap = hil_us_shiftmap;
238 char	*hilkbd_ctrlmap = hil_us_ctrlmap;
239 
240 int
241 hilkbd_getc()
242 {
243 	int status, c;
244 	struct hil_dev *hiladdr = HILADDR;
245 
246 	status = hiladdr->hil_stat;
247 	if ((status & HIL_DATA_RDY) == 0)
248 		return(0);
249 	c = hiladdr->hil_data;
250 	switch ((status>>KBD_SSHIFT) & KBD_SMASK) {
251 	case KBD_SHIFT:
252 		c = hilkbd_shiftmap[c & KBD_CHARMASK];
253 		break;
254 	case KBD_CTRL:
255 		c = hilkbd_ctrlmap[c & KBD_CHARMASK];
256 		break;
257 	case KBD_KEY:
258 		c = hilkbd_keymap[c & KBD_CHARMASK];
259 		break;
260 	default:
261 		c = 0;
262 		break;
263 	}
264 	return(c);
265 }
266 #endif /* SMALL */
267 
268 void
269 hilkbd_nmi()
270 {
271 	struct hil_dev *hiladdr = HILADDR;
272 
273 	HILWAIT(hiladdr);
274 	hiladdr->hil_cmd = HIL_CNMT;
275 	HILWAIT(hiladdr);
276 	hiladdr->hil_cmd = HIL_CNMT;
277 	HILWAIT(hiladdr);
278 }
279 
280 int
281 hilkbd_init()
282 {
283 	struct hil_dev *hiladdr = HILADDR;
284 	struct kbdmap *km;
285 	u_char lang;
286 
287 	/*
288 	 * Determine the existence of a HIL keyboard.
289 	 */
290 	HILWAIT(hiladdr);
291 	hiladdr->hil_cmd = HIL_READKBDSADR;
292 	HILDATAWAIT(hiladdr);
293 	lang = hiladdr->hil_data;
294 	if (lang == 0)
295 		return (0);
296 
297 	HILWAIT(hiladdr);
298 	hiladdr->hil_cmd = HIL_SETARR;
299 	HILWAIT(hiladdr);
300 	hiladdr->hil_data = ar_format(KBD_ARR);
301 	HILWAIT(hiladdr);
302 	hiladdr->hil_cmd = HIL_READKBDLANG;
303 	HILDATAWAIT(hiladdr);
304 	lang = hiladdr->hil_data;
305 	for (km = hilkbd_map; km->kbd_code; km++) {
306 		if (km->kbd_code == lang) {
307 			hilkbd_keymap = km->kbd_keymap;
308 			hilkbd_shiftmap = km->kbd_shiftmap;
309 			hilkbd_ctrlmap = km->kbd_ctrlmap;
310 		}
311 	}
312 	HILWAIT(hiladdr);
313 	hiladdr->hil_cmd = HIL_INTON;
314 }
315 #endif /* ITECONSOLE && HIL_KEYBOARD */
316