2 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer as
10 * the first lines of this file unmodified.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 * $FreeBSD: src/sys/dev/kbd/kbd.c,v 1.17.2.2 2001/07/30 16:46:43 yokota Exp $
27 * $DragonFly: src/sys/dev/misc/kbd/kbd.c,v 1.7 2003/11/10 06:12:05 dillon Exp $
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/kernel.h>
35 #include <sys/malloc.h>
40 #include <sys/vnode.h>
43 #include <machine/console.h>
47 #define KBD_INDEX(dev) minor(dev)
49 typedef struct genkbd_softc {
50 int gkb_flags; /* flag/status bits */
51 #define KB_ASLEEP (1 << 0)
52 struct clist gkb_q; /* input queue */
53 struct selinfo gkb_rsel;
56 static SLIST_HEAD(, keyboard_driver) keyboard_drivers =
57 SLIST_HEAD_INITIALIZER(keyboard_drivers);
59 SET_DECLARE(kbddriver_set, const keyboard_driver_t);
64 * We need at least one entry each in order to initialize a keyboard
65 * for the kernel console. The arrays will be increased dynamically
69 static int keyboards = 1;
70 static keyboard_t *kbd_ini;
71 static keyboard_t **keyboard = &kbd_ini;
72 static keyboard_switch_t *kbdsw_ini;
73 keyboard_switch_t **kbdsw = &kbdsw_ini;
78 kbd_realloc_array(void)
81 keyboard_switch_t **new_kbdsw;
86 newsize = ((keyboards + ARRAY_DELTA)/ARRAY_DELTA)*ARRAY_DELTA;
87 new_kbd = malloc(sizeof(*new_kbd)*newsize, M_DEVBUF, M_NOWAIT);
88 if (new_kbd == NULL) {
92 new_kbdsw = malloc(sizeof(*new_kbdsw)*newsize, M_DEVBUF, M_NOWAIT);
93 if (new_kbdsw == NULL) {
94 free(new_kbd, M_DEVBUF);
98 bzero(new_kbd, sizeof(*new_kbd)*newsize);
99 bzero(new_kbdsw, sizeof(*new_kbdsw)*newsize);
100 bcopy(keyboard, new_kbd, sizeof(*keyboard)*keyboards);
101 bcopy(kbdsw, new_kbdsw, sizeof(*kbdsw)*keyboards);
103 free(keyboard, M_DEVBUF);
104 free(kbdsw, M_DEVBUF);
112 printf("kbd: new array size %d\n", keyboards);
118 * Low-level keyboard driver functions
119 * Keyboard subdrivers, such as the AT keyboard driver and the USB keyboard
120 * driver, call these functions to initialize the keyboard_t structure
121 * and register it to the virtual keyboard driver `kbd'.
124 /* initialize the keyboard_t structure */
126 kbd_init_struct(keyboard_t *kbd, char *name, int type, int unit, int config,
127 int port, int port_size)
129 kbd->kb_flags = KB_NO_DEVICE; /* device has not been found */
133 kbd->kb_config = config & ~KB_CONF_PROBE_ONLY;
134 kbd->kb_led = 0; /* unknown */
135 kbd->kb_io_base = port;
136 kbd->kb_io_size = port_size;
138 kbd->kb_keymap = NULL;
139 kbd->kb_accentmap = NULL;
140 kbd->kb_fkeytab = NULL;
141 kbd->kb_fkeytab_size = 0;
142 kbd->kb_delay1 = KB_DELAY1; /* these values are advisory only */
143 kbd->kb_delay2 = KB_DELAY2;
145 bzero(kbd->kb_lastact, sizeof(kbd->kb_lastact));
149 kbd_set_maps(keyboard_t *kbd, keymap_t *keymap, accentmap_t *accmap,
150 fkeytab_t *fkeymap, int fkeymap_size)
152 kbd->kb_keymap = keymap;
153 kbd->kb_accentmap = accmap;
154 kbd->kb_fkeytab = fkeymap;
155 kbd->kb_fkeytab_size = fkeymap_size;
158 /* declare a new keyboard driver */
160 kbd_add_driver(keyboard_driver_t *driver)
162 if (SLIST_NEXT(driver, link))
164 SLIST_INSERT_HEAD(&keyboard_drivers, driver, link);
169 kbd_delete_driver(keyboard_driver_t *driver)
171 SLIST_REMOVE(&keyboard_drivers, driver, keyboard_driver, link);
172 SLIST_NEXT(driver, link) = NULL;
176 /* register a keyboard and associate it with a function table */
178 kbd_register(keyboard_t *kbd)
180 const keyboard_driver_t **list;
181 const keyboard_driver_t *p;
184 for (index = 0; index < keyboards; ++index) {
185 if (keyboard[index] == NULL)
188 if (index >= keyboards) {
189 if (kbd_realloc_array())
193 kbd->kb_index = index;
196 kbd->kb_active = 0; /* disabled until someone calls kbd_enable() */
197 kbd->kb_token = NULL;
198 kbd->kb_callback.kc_func = NULL;
199 kbd->kb_callback.kc_arg = NULL;
201 SLIST_FOREACH(p, &keyboard_drivers, link) {
202 if (strcmp(p->name, kbd->kb_name) == 0) {
203 keyboard[index] = kbd;
204 kbdsw[index] = p->kbdsw;
208 SET_FOREACH(list, kbddriver_set) {
210 if (strcmp(p->name, kbd->kb_name) == 0) {
211 keyboard[index] = kbd;
212 kbdsw[index] = p->kbdsw;
221 kbd_unregister(keyboard_t *kbd)
226 if ((kbd->kb_index < 0) || (kbd->kb_index >= keyboards))
228 if (keyboard[kbd->kb_index] != kbd)
232 if (KBD_IS_BUSY(kbd)) {
233 error = (*kbd->kb_callback.kc_func)(kbd, KBDIO_UNLOADING,
234 kbd->kb_callback.kc_arg);
239 if (KBD_IS_BUSY(kbd)) {
245 keyboard[kbd->kb_index] = NULL;
246 kbdsw[kbd->kb_index] = NULL;
252 /* find a funciton table by the driver name */
254 *kbd_get_switch(char *driver)
256 const keyboard_driver_t **list;
257 const keyboard_driver_t *p;
259 SLIST_FOREACH(p, &keyboard_drivers, link) {
260 if (strcmp(p->name, driver) == 0)
263 SET_FOREACH(list, kbddriver_set) {
265 if (strcmp(p->name, driver) == 0)
273 * Keyboard client functions
274 * Keyboard clients, such as the console driver `syscons' and the keyboard
275 * cdev driver, use these functions to claim and release a keyboard for
279 /* find the keyboard specified by a driver name and a unit number */
281 kbd_find_keyboard(char *driver, int unit)
285 for (i = 0; i < keyboards; ++i) {
286 if (keyboard[i] == NULL)
288 if (!KBD_IS_VALID(keyboard[i]))
290 if (strcmp("*", driver) && strcmp(keyboard[i]->kb_name, driver))
292 if ((unit != -1) && (keyboard[i]->kb_unit != unit))
299 /* allocate a keyboard */
301 kbd_allocate(char *driver, int unit, void *id, kbd_callback_func_t *func,
311 index = kbd_find_keyboard(driver, unit);
313 if (KBD_IS_BUSY(keyboard[index])) {
317 keyboard[index]->kb_token = id;
318 KBD_BUSY(keyboard[index]);
319 keyboard[index]->kb_callback.kc_func = func;
320 keyboard[index]->kb_callback.kc_arg = arg;
321 (*kbdsw[index]->clear_state)(keyboard[index]);
328 kbd_release(keyboard_t *kbd, void *id)
334 if (!KBD_IS_VALID(kbd) || !KBD_IS_BUSY(kbd)) {
336 } else if (kbd->kb_token != id) {
339 kbd->kb_token = NULL;
341 kbd->kb_callback.kc_func = NULL;
342 kbd->kb_callback.kc_arg = NULL;
343 (*kbdsw[kbd->kb_index]->clear_state)(kbd);
351 kbd_change_callback(keyboard_t *kbd, void *id, kbd_callback_func_t *func,
358 if (!KBD_IS_VALID(kbd) || !KBD_IS_BUSY(kbd)) {
360 } else if (kbd->kb_token != id) {
362 } else if (func == NULL) {
365 kbd->kb_callback.kc_func = func;
366 kbd->kb_callback.kc_arg = arg;
373 /* get a keyboard structure */
375 *kbd_get_keyboard(int index)
377 if ((index < 0) || (index >= keyboards))
379 if (keyboard[index] == NULL)
381 if (!KBD_IS_VALID(keyboard[index]))
383 return keyboard[index];
387 * The back door for the console driver; configure keyboards
388 * This function is for the kernel console to initialize keyboards
389 * at very early stage.
393 kbd_configure(int flags)
395 const keyboard_driver_t **list;
396 const keyboard_driver_t *p;
398 SLIST_FOREACH(p, &keyboard_drivers, link) {
399 if (p->configure != NULL)
400 (*p->configure)(flags);
402 SET_FOREACH(list, kbddriver_set) {
404 if (p->configure != NULL)
405 (*p->configure)(flags);
411 #ifdef KBD_INSTALL_CDEV
414 * Virtual keyboard cdev driver functions
415 * The virtual keyboard driver dispatches driver functions to
416 * appropriate subdrivers.
419 #define KBD_UNIT(dev) minor(dev)
421 static d_open_t genkbdopen;
422 static d_close_t genkbdclose;
423 static d_read_t genkbdread;
424 static d_write_t genkbdwrite;
425 static d_ioctl_t genkbdioctl;
426 static d_poll_t genkbdpoll;
428 #define CDEV_MAJOR 112
430 static struct cdevsw kbd_cdevsw = {
432 /* maj */ CDEV_MAJOR,
437 /* open */ genkbdopen,
438 /* close */ genkbdclose,
439 /* read */ genkbdread,
440 /* write */ genkbdwrite,
441 /* ioctl */ genkbdioctl,
442 /* poll */ genkbdpoll,
444 /* strategy */ nostrategy,
450 kbd_attach(keyboard_t *kbd)
454 if (kbd->kb_index >= keyboards)
456 if (keyboard[kbd->kb_index] != kbd)
459 dev = make_dev(&kbd_cdevsw, kbd->kb_index, UID_ROOT, GID_WHEEL, 0600,
460 "kbd%r", kbd->kb_index);
461 if (dev->si_drv1 == NULL)
462 dev->si_drv1 = malloc(sizeof(genkbd_softc_t), M_DEVBUF,
464 bzero(dev->si_drv1, sizeof(genkbd_softc_t));
466 printf("kbd%d at %s%d\n", kbd->kb_index, kbd->kb_name, kbd->kb_unit);
471 kbd_detach(keyboard_t *kbd)
475 if (kbd->kb_index >= keyboards)
477 if (keyboard[kbd->kb_index] != kbd)
480 dev = makedev(kbd_cdevsw.d_maj, kbd->kb_index);
482 free(dev->si_drv1, M_DEVBUF);
489 * Generic keyboard cdev driver functions
490 * Keyboard subdrivers may call these functions to implement common
495 #define KB_BUFSIZE 64
497 static kbd_callback_func_t genkbd_event;
500 genkbdopen(dev_t dev, int mode, int flag, d_thread_t *td)
509 kbd = kbd_get_keyboard(KBD_INDEX(dev));
510 if ((sc == NULL) || (kbd == NULL) || !KBD_IS_VALID(kbd)) {
514 i = kbd_allocate(kbd->kb_name, kbd->kb_unit, sc,
515 genkbd_event, (void *)sc);
520 /* assert(i == kbd->kb_index) */
521 /* assert(kbd == kbd_get_keyboard(i)) */
524 * NOTE: even when we have successfully claimed a keyboard,
525 * the device may still be missing (!KBD_HAS_DEVICE(kbd)).
529 bzero(&sc->gkb_q, sizeof(sc->gkb_q));
531 clist_alloc_cblocks(&sc->gkb_q, KB_QSIZE, KB_QSIZE/2); /* XXX */
532 sc->gkb_rsel.si_flags = 0;
533 sc->gkb_rsel.si_pid = 0;
540 genkbdclose(dev_t dev, int mode, int flag, d_thread_t *td)
547 * NOTE: the device may have already become invalid.
548 * kbd == NULL || !KBD_IS_VALID(kbd)
552 kbd = kbd_get_keyboard(KBD_INDEX(dev));
553 if ((sc == NULL) || (kbd == NULL) || !KBD_IS_VALID(kbd)) {
554 /* XXX: we shall be forgiving and don't report error... */
556 kbd_release(kbd, (void *)sc);
558 clist_free_cblocks(&sc->gkb_q);
566 genkbdread(dev_t dev, struct uio *uio, int flag)
570 u_char buffer[KB_BUFSIZE];
578 kbd = kbd_get_keyboard(KBD_INDEX(dev));
579 if ((sc == NULL) || (kbd == NULL) || !KBD_IS_VALID(kbd)) {
583 while (sc->gkb_q.c_cc == 0) {
584 if (flag & IO_NDELAY) {
588 sc->gkb_flags |= KB_ASLEEP;
589 error = tsleep((caddr_t)sc, PCATCH, "kbdrea", 0);
590 kbd = kbd_get_keyboard(KBD_INDEX(dev));
591 if ((kbd == NULL) || !KBD_IS_VALID(kbd)) {
593 return ENXIO; /* our keyboard has gone... */
596 sc->gkb_flags &= ~KB_ASLEEP;
603 /* copy as much input as possible */
605 while (uio->uio_resid > 0) {
606 len = imin(uio->uio_resid, sizeof(buffer));
607 len = q_to_b(&sc->gkb_q, buffer, len);
610 error = uiomove(buffer, len, uio);
619 genkbdwrite(dev_t dev, struct uio *uio, int flag)
623 kbd = kbd_get_keyboard(KBD_INDEX(dev));
624 if ((kbd == NULL) || !KBD_IS_VALID(kbd))
630 genkbdioctl(dev_t dev, u_long cmd, caddr_t arg, int flag, d_thread_t *td)
635 kbd = kbd_get_keyboard(KBD_INDEX(dev));
636 if ((kbd == NULL) || !KBD_IS_VALID(kbd))
638 error = (*kbdsw[kbd->kb_index]->ioctl)(kbd, cmd, arg);
639 if (error == ENOIOCTL)
645 genkbdpoll(dev_t dev, int events, d_thread_t *td)
655 kbd = kbd_get_keyboard(KBD_INDEX(dev));
656 if ((sc == NULL) || (kbd == NULL) || !KBD_IS_VALID(kbd)) {
657 revents = POLLHUP; /* the keyboard has gone */
658 } else if (events & (POLLIN | POLLRDNORM)) {
659 if (sc->gkb_q.c_cc > 0)
660 revents = events & (POLLIN | POLLRDNORM);
662 selrecord(td, &sc->gkb_rsel);
669 genkbd_event(keyboard_t *kbd, int event, void *arg)
677 /* assert(KBD_IS_VALID(kbd)) */
678 sc = (genkbd_softc_t *)arg;
683 case KBDIO_UNLOADING:
684 /* the keyboard is going... */
685 kbd_release(kbd, (void *)sc);
686 if (sc->gkb_flags & KB_ASLEEP) {
687 sc->gkb_flags &= ~KB_ASLEEP;
690 selwakeup(&sc->gkb_rsel);
696 /* obtain the current key input mode */
697 if ((*kbdsw[kbd->kb_index]->ioctl)(kbd, KDGKBMODE, (caddr_t)&mode))
700 /* read all pending input */
701 while ((*kbdsw[kbd->kb_index]->check_char)(kbd)) {
702 c = (*kbdsw[kbd->kb_index]->read_char)(kbd, FALSE);
705 if (c == ERRKEY) /* XXX: ring bell? */
707 if (!KBD_IS_BUSY(kbd))
708 /* the device is not open, discard the input */
711 /* store the byte as is for K_RAW and K_CODE modes */
712 if (mode != K_XLATE) {
713 putc(KEYCHAR(c), &sc->gkb_q);
718 if (c & RELKEY) /* key release is ignored */
721 /* process special keys; most of them are just ignored... */
723 switch (KEYCHAR(c)) {
727 case BTAB: /* a backtab: ESC [ Z */
728 putc(0x1b, &sc->gkb_q);
729 putc('[', &sc->gkb_q);
730 putc('Z', &sc->gkb_q);
735 /* normal chars, normal chars with the META, function keys */
736 switch (KEYFLAGS(c)) {
737 case 0: /* a normal char */
738 putc(KEYCHAR(c), &sc->gkb_q);
740 case MKEY: /* the META flag: prepend ESC */
741 putc(0x1b, &sc->gkb_q);
742 putc(KEYCHAR(c), &sc->gkb_q);
744 case FKEY | SPCLKEY: /* a function key, return string */
745 cp = (*kbdsw[kbd->kb_index]->get_fkeystr)(kbd,
749 putc(*cp++, &sc->gkb_q);
755 /* wake up sleeping/polling processes */
756 if (sc->gkb_q.c_cc > 0) {
757 if (sc->gkb_flags & KB_ASLEEP) {
758 sc->gkb_flags &= ~KB_ASLEEP;
761 selwakeup(&sc->gkb_rsel);
767 #endif /* KBD_INSTALL_CDEV */
770 * Generic low-level keyboard functions
771 * The low-level functions in the keyboard subdriver may use these
776 genkbd_commonioctl(keyboard_t *kbd, u_long cmd, caddr_t arg)
786 case KDGKBINFO: /* get keyboard information */
787 ((keyboard_info_t *)arg)->kb_index = kbd->kb_index;
788 i = imin(strlen(kbd->kb_name) + 1,
789 sizeof(((keyboard_info_t *)arg)->kb_name));
790 bcopy(kbd->kb_name, ((keyboard_info_t *)arg)->kb_name, i);
791 ((keyboard_info_t *)arg)->kb_unit = kbd->kb_unit;
792 ((keyboard_info_t *)arg)->kb_type = kbd->kb_type;
793 ((keyboard_info_t *)arg)->kb_config = kbd->kb_config;
794 ((keyboard_info_t *)arg)->kb_flags = kbd->kb_flags;
797 case KDGKBTYPE: /* get keyboard type */
798 *(int *)arg = kbd->kb_type;
801 case KDGETREPEAT: /* get keyboard repeat rate */
802 ((int *)arg)[0] = kbd->kb_delay1;
803 ((int *)arg)[1] = kbd->kb_delay2;
806 case GIO_KEYMAP: /* get keyboard translation table */
807 bcopy(kbd->kb_keymap, arg, sizeof(*kbd->kb_keymap));
809 case PIO_KEYMAP: /* set keyboard translation table */
810 #ifndef KBD_DISABLE_KEYMAP_LOAD
811 bzero(kbd->kb_accentmap, sizeof(*kbd->kb_accentmap));
812 bcopy(arg, kbd->kb_keymap, sizeof(*kbd->kb_keymap));
819 case GIO_KEYMAPENT: /* get keyboard translation table entry */
820 keyp = (keyarg_t *)arg;
821 if (keyp->keynum >= sizeof(kbd->kb_keymap->key)
822 /sizeof(kbd->kb_keymap->key[0])) {
826 bcopy(&kbd->kb_keymap->key[keyp->keynum], &keyp->key,
829 case PIO_KEYMAPENT: /* set keyboard translation table entry */
830 #ifndef KBD_DISABLE_KEYMAP_LOAD
831 keyp = (keyarg_t *)arg;
832 if (keyp->keynum >= sizeof(kbd->kb_keymap->key)
833 /sizeof(kbd->kb_keymap->key[0])) {
837 bcopy(&keyp->key, &kbd->kb_keymap->key[keyp->keynum],
845 case GIO_DEADKEYMAP: /* get accent key translation table */
846 bcopy(kbd->kb_accentmap, arg, sizeof(*kbd->kb_accentmap));
848 case PIO_DEADKEYMAP: /* set accent key translation table */
849 #ifndef KBD_DISABLE_KEYMAP_LOAD
850 bcopy(arg, kbd->kb_accentmap, sizeof(*kbd->kb_accentmap));
857 case GETFKEY: /* get functionkey string */
858 fkeyp = (fkeyarg_t *)arg;
859 if (fkeyp->keynum >= kbd->kb_fkeytab_size) {
863 bcopy(kbd->kb_fkeytab[fkeyp->keynum].str, fkeyp->keydef,
864 kbd->kb_fkeytab[fkeyp->keynum].len);
865 fkeyp->flen = kbd->kb_fkeytab[fkeyp->keynum].len;
867 case SETFKEY: /* set functionkey string */
868 #ifndef KBD_DISABLE_KEYMAP_LOAD
869 fkeyp = (fkeyarg_t *)arg;
870 if (fkeyp->keynum >= kbd->kb_fkeytab_size) {
874 kbd->kb_fkeytab[fkeyp->keynum].len = imin(fkeyp->flen, MAXFK);
875 bcopy(fkeyp->keydef, kbd->kb_fkeytab[fkeyp->keynum].str,
876 kbd->kb_fkeytab[fkeyp->keynum].len);
892 /* get a pointer to the string associated with the given function key */
894 *genkbd_get_fkeystr(keyboard_t *kbd, int fkey, size_t *len)
899 if (fkey > kbd->kb_fkeytab_size)
901 *len = kbd->kb_fkeytab[fkey].len;
902 return kbd->kb_fkeytab[fkey].str;
905 /* diagnostic dump */
907 *get_kbd_type_name(int type)
914 { KB_101, "AT 101/102" },
915 { KB_OTHER, "generic" },
919 for (i = 0; i < sizeof(name_table)/sizeof(name_table[0]); ++i) {
920 if (type == name_table[i].type)
921 return name_table[i].name;
927 genkbd_diag(keyboard_t *kbd, int level)
930 printf("kbd%d: %s%d, %s (%d), config:0x%x, flags:0x%x",
931 kbd->kb_index, kbd->kb_name, kbd->kb_unit,
932 get_kbd_type_name(kbd->kb_type), kbd->kb_type,
933 kbd->kb_config, kbd->kb_flags);
934 if (kbd->kb_io_base > 0)
935 printf(", port:0x%x-0x%x", kbd->kb_io_base,
936 kbd->kb_io_base + kbd->kb_io_size - 1);
941 #define set_lockkey_state(k, s, l) \
942 if (!((s) & l ## DOWN)) { \
946 i = (s) & LOCK_MASK; \
947 (*kbdsw[(k)->kb_index]->ioctl)((k), KDSETLED, (caddr_t)&i); \
951 save_accent_key(keyboard_t *kbd, u_int key, int *accents)
955 /* make an index into the accent map */
957 if ((i > kbd->kb_accentmap->n_accs)
958 || (kbd->kb_accentmap->acc[i - 1].accchar == 0)) {
959 /* the index is out of range or pointing to an empty entry */
965 * If the same accent key has been hit twice, produce the accent char
969 key = kbd->kb_accentmap->acc[i - 1].accchar;
974 /* remember the index and wait for the next key */
980 make_accent_char(keyboard_t *kbd, u_int ch, int *accents)
985 acc = &kbd->kb_accentmap->acc[*accents - 1];
989 * If the accent key is followed by the space key,
990 * produce the accent char itself.
995 /* scan the accent map */
996 for (i = 0; i < NUM_ACCENTCHARS; ++i) {
997 if (acc->map[i][0] == 0) /* end of table */
999 if (acc->map[i][0] == ch)
1000 return acc->map[i][1];
1002 /* this char cannot be accented... */
1007 genkbd_keyaction(keyboard_t *kbd, int keycode, int up, int *shiftstate,
1010 struct keyent_t *key;
1011 int state = *shiftstate;
1017 f = state & (AGRS | ALKED);
1018 if ((f == AGRS1) || (f == AGRS2) || (f == ALKED))
1020 key = &kbd->kb_keymap->key[i];
1021 i = ((state & SHIFTS) ? 1 : 0)
1022 | ((state & CTLS) ? 2 : 0)
1023 | ((state & ALTS) ? 4 : 0);
1024 if (((key->flgs & FLAG_LOCK_C) && (state & CLKED))
1025 || ((key->flgs & FLAG_LOCK_N) && (state & NLKED)) )
1028 if (up) { /* break: key released */
1029 action = kbd->kb_lastact[keycode];
1030 kbd->kb_lastact[keycode] = NOP;
1033 if (state & SHIFTAON) {
1034 set_lockkey_state(kbd, state, ALK);
1043 if (state & SHIFTAON) {
1044 set_lockkey_state(kbd, state, ALK);
1053 if (state & SHIFTAON) {
1054 set_lockkey_state(kbd, state, ALK);
1063 if (state & SHIFTAON) {
1064 set_lockkey_state(kbd, state, ALK);
1073 if (state & SHIFTAON) {
1074 set_lockkey_state(kbd, state, ALK);
1083 if (state & SHIFTAON) {
1084 set_lockkey_state(kbd, state, ALK);
1106 i = state & LOCK_MASK;
1107 (*kbdsw[kbd->kb_index]->ioctl)(kbd, KDSETLED,
1118 /* release events of regular keys are not reported */
1119 *shiftstate &= ~SHIFTAON;
1122 *shiftstate = state & ~SHIFTAON;
1123 return (SPCLKEY | RELKEY | action);
1124 } else { /* make: key pressed */
1125 action = key->map[i];
1127 if (key->spcl & (0x80 >> i)) {
1129 if (kbd->kb_lastact[keycode] == NOP)
1130 kbd->kb_lastact[keycode] = action;
1131 if (kbd->kb_lastact[keycode] != action)
1136 set_lockkey_state(kbd, state, NLK);
1140 set_lockkey_state(kbd, state, CLK);
1143 i = state & LOCK_MASK;
1144 (*kbdsw[kbd->kb_index]->ioctl)(kbd, KDSETLED,
1149 set_lockkey_state(kbd, state, SLK);
1152 set_lockkey_state(kbd, state, ALK);
1154 /* NON-LOCKING KEYS */
1155 case SPSC: case RBT: case SUSP: case STBY:
1156 case DBG: case NEXT: case PREV: case PNC:
1157 case HALT: case PDWN:
1213 *shiftstate = state;
1216 /* is this an accent (dead) key? */
1217 *shiftstate = state;
1218 if (action >= F_ACC && action <= L_ACC) {
1219 action = save_accent_key(kbd, action,
1227 return (action | MKEY);
1233 /* other special keys */
1238 if (action >= F_FN && action <= L_FN)
1240 /* XXX: return fkey string for the FKEY? */
1241 return (SPCLKEY | action);
1243 *shiftstate = state;
1244 return (SPCLKEY | action);
1247 kbd->kb_lastact[keycode] = NOP;
1248 *shiftstate = state;
1250 /* make an accented char */
1251 action = make_accent_char(kbd, action, accents);
1252 if (action == ERRKEY)