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