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.10 2004/05/19 22:52:42 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,
89 new_kbdsw = malloc(sizeof(*new_kbdsw) * newsize, M_DEVBUF,
91 bcopy(keyboard, new_kbd, sizeof(*keyboard)*keyboards);
92 bcopy(kbdsw, new_kbdsw, sizeof(*kbdsw)*keyboards);
94 free(keyboard, M_DEVBUF);
95 free(kbdsw, M_DEVBUF);
103 printf("kbd: new array size %d\n", keyboards);
109 * Low-level keyboard driver functions
110 * Keyboard subdrivers, such as the AT keyboard driver and the USB keyboard
111 * driver, call these functions to initialize the keyboard_t structure
112 * and register it to the virtual keyboard driver `kbd'.
115 /* initialize the keyboard_t structure */
117 kbd_init_struct(keyboard_t *kbd, char *name, int type, int unit, int config,
118 int port, int port_size)
120 kbd->kb_flags = KB_NO_DEVICE; /* device has not been found */
124 kbd->kb_config = config & ~KB_CONF_PROBE_ONLY;
125 kbd->kb_led = 0; /* unknown */
126 kbd->kb_io_base = port;
127 kbd->kb_io_size = port_size;
129 kbd->kb_keymap = NULL;
130 kbd->kb_accentmap = NULL;
131 kbd->kb_fkeytab = NULL;
132 kbd->kb_fkeytab_size = 0;
133 kbd->kb_delay1 = KB_DELAY1; /* these values are advisory only */
134 kbd->kb_delay2 = KB_DELAY2;
136 bzero(kbd->kb_lastact, sizeof(kbd->kb_lastact));
140 kbd_set_maps(keyboard_t *kbd, keymap_t *keymap, accentmap_t *accmap,
141 fkeytab_t *fkeymap, int fkeymap_size)
143 kbd->kb_keymap = keymap;
144 kbd->kb_accentmap = accmap;
145 kbd->kb_fkeytab = fkeymap;
146 kbd->kb_fkeytab_size = fkeymap_size;
149 /* declare a new keyboard driver */
151 kbd_add_driver(keyboard_driver_t *driver)
153 if (SLIST_NEXT(driver, link))
155 SLIST_INSERT_HEAD(&keyboard_drivers, driver, link);
160 kbd_delete_driver(keyboard_driver_t *driver)
162 SLIST_REMOVE(&keyboard_drivers, driver, keyboard_driver, link);
163 SLIST_NEXT(driver, link) = NULL;
167 /* register a keyboard and associate it with a function table */
169 kbd_register(keyboard_t *kbd)
171 const keyboard_driver_t **list;
172 const keyboard_driver_t *p;
175 for (index = 0; index < keyboards; ++index) {
176 if (keyboard[index] == NULL)
179 if (index >= keyboards) {
180 if (kbd_realloc_array())
184 kbd->kb_index = index;
187 kbd->kb_active = 0; /* disabled until someone calls kbd_enable() */
188 kbd->kb_token = NULL;
189 kbd->kb_callback.kc_func = NULL;
190 kbd->kb_callback.kc_arg = NULL;
192 SLIST_FOREACH(p, &keyboard_drivers, link) {
193 if (strcmp(p->name, kbd->kb_name) == 0) {
194 keyboard[index] = kbd;
195 kbdsw[index] = p->kbdsw;
199 SET_FOREACH(list, kbddriver_set) {
201 if (strcmp(p->name, kbd->kb_name) == 0) {
202 keyboard[index] = kbd;
203 kbdsw[index] = p->kbdsw;
212 kbd_unregister(keyboard_t *kbd)
217 if ((kbd->kb_index < 0) || (kbd->kb_index >= keyboards))
219 if (keyboard[kbd->kb_index] != kbd)
223 if (KBD_IS_BUSY(kbd)) {
224 error = (*kbd->kb_callback.kc_func)(kbd, KBDIO_UNLOADING,
225 kbd->kb_callback.kc_arg);
230 if (KBD_IS_BUSY(kbd)) {
236 keyboard[kbd->kb_index] = NULL;
237 kbdsw[kbd->kb_index] = NULL;
243 /* find a funciton table by the driver name */
245 *kbd_get_switch(char *driver)
247 const keyboard_driver_t **list;
248 const keyboard_driver_t *p;
250 SLIST_FOREACH(p, &keyboard_drivers, link) {
251 if (strcmp(p->name, driver) == 0)
254 SET_FOREACH(list, kbddriver_set) {
256 if (strcmp(p->name, driver) == 0)
264 * Keyboard client functions
265 * Keyboard clients, such as the console driver `syscons' and the keyboard
266 * cdev driver, use these functions to claim and release a keyboard for
270 /* find the keyboard specified by a driver name and a unit number */
272 kbd_find_keyboard(char *driver, int unit)
276 for (i = 0; i < keyboards; ++i) {
277 if (keyboard[i] == NULL)
279 if (!KBD_IS_VALID(keyboard[i]))
281 if (strcmp("*", driver) && strcmp(keyboard[i]->kb_name, driver))
283 if ((unit != -1) && (keyboard[i]->kb_unit != unit))
290 /* allocate a keyboard */
292 kbd_allocate(char *driver, int unit, void *id, kbd_callback_func_t *func,
302 index = kbd_find_keyboard(driver, unit);
304 if (KBD_IS_BUSY(keyboard[index])) {
308 keyboard[index]->kb_token = id;
309 KBD_BUSY(keyboard[index]);
310 keyboard[index]->kb_callback.kc_func = func;
311 keyboard[index]->kb_callback.kc_arg = arg;
312 (*kbdsw[index]->clear_state)(keyboard[index]);
319 kbd_release(keyboard_t *kbd, void *id)
325 if (!KBD_IS_VALID(kbd) || !KBD_IS_BUSY(kbd)) {
327 } else if (kbd->kb_token != id) {
330 kbd->kb_token = NULL;
332 kbd->kb_callback.kc_func = NULL;
333 kbd->kb_callback.kc_arg = NULL;
334 (*kbdsw[kbd->kb_index]->clear_state)(kbd);
342 kbd_change_callback(keyboard_t *kbd, void *id, kbd_callback_func_t *func,
349 if (!KBD_IS_VALID(kbd) || !KBD_IS_BUSY(kbd)) {
351 } else if (kbd->kb_token != id) {
353 } else if (func == NULL) {
356 kbd->kb_callback.kc_func = func;
357 kbd->kb_callback.kc_arg = arg;
364 /* get a keyboard structure */
366 *kbd_get_keyboard(int index)
368 if ((index < 0) || (index >= keyboards))
370 if (keyboard[index] == NULL)
372 if (!KBD_IS_VALID(keyboard[index]))
374 return keyboard[index];
378 * The back door for the console driver; configure keyboards
379 * This function is for the kernel console to initialize keyboards
380 * at very early stage.
384 kbd_configure(int flags)
386 const keyboard_driver_t **list;
387 const keyboard_driver_t *p;
389 SLIST_FOREACH(p, &keyboard_drivers, link) {
390 if (p->configure != NULL)
391 (*p->configure)(flags);
393 SET_FOREACH(list, kbddriver_set) {
395 if (p->configure != NULL)
396 (*p->configure)(flags);
402 #ifdef KBD_INSTALL_CDEV
405 * Virtual keyboard cdev driver functions
406 * The virtual keyboard driver dispatches driver functions to
407 * appropriate subdrivers.
410 #define KBD_UNIT(dev) minor(dev)
412 static d_open_t genkbdopen;
413 static d_close_t genkbdclose;
414 static d_read_t genkbdread;
415 static d_write_t genkbdwrite;
416 static d_ioctl_t genkbdioctl;
417 static d_poll_t genkbdpoll;
419 #define CDEV_MAJOR 112
421 static struct cdevsw kbd_cdevsw = {
423 /* maj */ CDEV_MAJOR,
428 /* open */ genkbdopen,
429 /* close */ genkbdclose,
430 /* read */ genkbdread,
431 /* write */ genkbdwrite,
432 /* ioctl */ genkbdioctl,
433 /* poll */ genkbdpoll,
435 /* strategy */ nostrategy,
441 kbd_attach(keyboard_t *kbd)
445 if (kbd->kb_index >= keyboards)
447 if (keyboard[kbd->kb_index] != kbd)
450 cdevsw_add(&kbd_cdevsw, -1, kbd->kb_index);
451 dev = make_dev(&kbd_cdevsw, kbd->kb_index, UID_ROOT, GID_WHEEL, 0600,
452 "kbd%r", kbd->kb_index);
453 if (dev->si_drv1 == NULL)
454 dev->si_drv1 = malloc(sizeof(genkbd_softc_t), M_DEVBUF,
456 bzero(dev->si_drv1, sizeof(genkbd_softc_t));
458 printf("kbd%d at %s%d\n", kbd->kb_index, kbd->kb_name, kbd->kb_unit);
463 kbd_detach(keyboard_t *kbd)
467 if (kbd->kb_index >= keyboards)
469 if (keyboard[kbd->kb_index] != kbd)
473 * Deal with refs properly. The KBD driver really ought to have
474 * recorded the dev_t separately.
476 if ((dev = make_adhoc_dev(&kbd_cdevsw, kbd->kb_index)) != NODEV) {
478 free(dev->si_drv1, M_DEVBUF);
482 cdevsw_remove(&kbd_cdevsw, -1, kbd->kb_index);
487 * Generic keyboard cdev driver functions
488 * Keyboard subdrivers may call these functions to implement common
493 #define KB_BUFSIZE 64
495 static kbd_callback_func_t genkbd_event;
498 genkbdopen(dev_t dev, int mode, int flag, d_thread_t *td)
507 kbd = kbd_get_keyboard(KBD_INDEX(dev));
508 if ((sc == NULL) || (kbd == NULL) || !KBD_IS_VALID(kbd)) {
512 i = kbd_allocate(kbd->kb_name, kbd->kb_unit, sc,
513 genkbd_event, (void *)sc);
518 /* assert(i == kbd->kb_index) */
519 /* assert(kbd == kbd_get_keyboard(i)) */
522 * NOTE: even when we have successfully claimed a keyboard,
523 * the device may still be missing (!KBD_HAS_DEVICE(kbd)).
527 bzero(&sc->gkb_q, sizeof(sc->gkb_q));
529 clist_alloc_cblocks(&sc->gkb_q, KB_QSIZE, KB_QSIZE/2); /* XXX */
530 sc->gkb_rsel.si_flags = 0;
531 sc->gkb_rsel.si_pid = 0;
538 genkbdclose(dev_t dev, int mode, int flag, d_thread_t *td)
545 * NOTE: the device may have already become invalid.
546 * kbd == NULL || !KBD_IS_VALID(kbd)
550 kbd = kbd_get_keyboard(KBD_INDEX(dev));
551 if ((sc == NULL) || (kbd == NULL) || !KBD_IS_VALID(kbd)) {
552 /* XXX: we shall be forgiving and don't report error... */
554 kbd_release(kbd, (void *)sc);
556 clist_free_cblocks(&sc->gkb_q);
564 genkbdread(dev_t dev, struct uio *uio, int flag)
568 u_char buffer[KB_BUFSIZE];
576 kbd = kbd_get_keyboard(KBD_INDEX(dev));
577 if ((sc == NULL) || (kbd == NULL) || !KBD_IS_VALID(kbd)) {
581 while (sc->gkb_q.c_cc == 0) {
582 if (flag & IO_NDELAY) {
586 sc->gkb_flags |= KB_ASLEEP;
587 error = tsleep((caddr_t)sc, PCATCH, "kbdrea", 0);
588 kbd = kbd_get_keyboard(KBD_INDEX(dev));
589 if ((kbd == NULL) || !KBD_IS_VALID(kbd)) {
591 return ENXIO; /* our keyboard has gone... */
594 sc->gkb_flags &= ~KB_ASLEEP;
601 /* copy as much input as possible */
603 while (uio->uio_resid > 0) {
604 len = imin(uio->uio_resid, sizeof(buffer));
605 len = q_to_b(&sc->gkb_q, buffer, len);
608 error = uiomove(buffer, len, uio);
617 genkbdwrite(dev_t dev, struct uio *uio, int flag)
621 kbd = kbd_get_keyboard(KBD_INDEX(dev));
622 if ((kbd == NULL) || !KBD_IS_VALID(kbd))
628 genkbdioctl(dev_t dev, u_long cmd, caddr_t arg, int flag, d_thread_t *td)
633 kbd = kbd_get_keyboard(KBD_INDEX(dev));
634 if ((kbd == NULL) || !KBD_IS_VALID(kbd))
636 error = (*kbdsw[kbd->kb_index]->ioctl)(kbd, cmd, arg);
637 if (error == ENOIOCTL)
643 genkbdpoll(dev_t dev, int events, d_thread_t *td)
653 kbd = kbd_get_keyboard(KBD_INDEX(dev));
654 if ((sc == NULL) || (kbd == NULL) || !KBD_IS_VALID(kbd)) {
655 revents = POLLHUP; /* the keyboard has gone */
656 } else if (events & (POLLIN | POLLRDNORM)) {
657 if (sc->gkb_q.c_cc > 0)
658 revents = events & (POLLIN | POLLRDNORM);
660 selrecord(td, &sc->gkb_rsel);
667 genkbd_event(keyboard_t *kbd, int event, void *arg)
675 /* assert(KBD_IS_VALID(kbd)) */
676 sc = (genkbd_softc_t *)arg;
681 case KBDIO_UNLOADING:
682 /* the keyboard is going... */
683 kbd_release(kbd, (void *)sc);
684 if (sc->gkb_flags & KB_ASLEEP) {
685 sc->gkb_flags &= ~KB_ASLEEP;
688 selwakeup(&sc->gkb_rsel);
694 /* obtain the current key input mode */
695 if ((*kbdsw[kbd->kb_index]->ioctl)(kbd, KDGKBMODE, (caddr_t)&mode))
698 /* read all pending input */
699 while ((*kbdsw[kbd->kb_index]->check_char)(kbd)) {
700 c = (*kbdsw[kbd->kb_index]->read_char)(kbd, FALSE);
703 if (c == ERRKEY) /* XXX: ring bell? */
705 if (!KBD_IS_BUSY(kbd))
706 /* the device is not open, discard the input */
709 /* store the byte as is for K_RAW and K_CODE modes */
710 if (mode != K_XLATE) {
711 putc(KEYCHAR(c), &sc->gkb_q);
716 if (c & RELKEY) /* key release is ignored */
719 /* process special keys; most of them are just ignored... */
721 switch (KEYCHAR(c)) {
725 case BTAB: /* a backtab: ESC [ Z */
726 putc(0x1b, &sc->gkb_q);
727 putc('[', &sc->gkb_q);
728 putc('Z', &sc->gkb_q);
733 /* normal chars, normal chars with the META, function keys */
734 switch (KEYFLAGS(c)) {
735 case 0: /* a normal char */
736 putc(KEYCHAR(c), &sc->gkb_q);
738 case MKEY: /* the META flag: prepend ESC */
739 putc(0x1b, &sc->gkb_q);
740 putc(KEYCHAR(c), &sc->gkb_q);
742 case FKEY | SPCLKEY: /* a function key, return string */
743 cp = (*kbdsw[kbd->kb_index]->get_fkeystr)(kbd,
747 putc(*cp++, &sc->gkb_q);
753 /* wake up sleeping/polling processes */
754 if (sc->gkb_q.c_cc > 0) {
755 if (sc->gkb_flags & KB_ASLEEP) {
756 sc->gkb_flags &= ~KB_ASLEEP;
759 selwakeup(&sc->gkb_rsel);
765 #endif /* KBD_INSTALL_CDEV */
768 * Generic low-level keyboard functions
769 * The low-level functions in the keyboard subdriver may use these
774 genkbd_commonioctl(keyboard_t *kbd, u_long cmd, caddr_t arg)
784 case KDGKBINFO: /* get keyboard information */
785 ((keyboard_info_t *)arg)->kb_index = kbd->kb_index;
786 i = imin(strlen(kbd->kb_name) + 1,
787 sizeof(((keyboard_info_t *)arg)->kb_name));
788 bcopy(kbd->kb_name, ((keyboard_info_t *)arg)->kb_name, i);
789 ((keyboard_info_t *)arg)->kb_unit = kbd->kb_unit;
790 ((keyboard_info_t *)arg)->kb_type = kbd->kb_type;
791 ((keyboard_info_t *)arg)->kb_config = kbd->kb_config;
792 ((keyboard_info_t *)arg)->kb_flags = kbd->kb_flags;
795 case KDGKBTYPE: /* get keyboard type */
796 *(int *)arg = kbd->kb_type;
799 case KDGETREPEAT: /* get keyboard repeat rate */
800 ((int *)arg)[0] = kbd->kb_delay1;
801 ((int *)arg)[1] = kbd->kb_delay2;
804 case GIO_KEYMAP: /* get keyboard translation table */
805 bcopy(kbd->kb_keymap, arg, sizeof(*kbd->kb_keymap));
807 case PIO_KEYMAP: /* set keyboard translation table */
808 #ifndef KBD_DISABLE_KEYMAP_LOAD
809 bzero(kbd->kb_accentmap, sizeof(*kbd->kb_accentmap));
810 bcopy(arg, kbd->kb_keymap, sizeof(*kbd->kb_keymap));
817 case GIO_KEYMAPENT: /* get keyboard translation table entry */
818 keyp = (keyarg_t *)arg;
819 if (keyp->keynum >= sizeof(kbd->kb_keymap->key)
820 /sizeof(kbd->kb_keymap->key[0])) {
824 bcopy(&kbd->kb_keymap->key[keyp->keynum], &keyp->key,
827 case PIO_KEYMAPENT: /* set keyboard translation table entry */
828 #ifndef KBD_DISABLE_KEYMAP_LOAD
829 keyp = (keyarg_t *)arg;
830 if (keyp->keynum >= sizeof(kbd->kb_keymap->key)
831 /sizeof(kbd->kb_keymap->key[0])) {
835 bcopy(&keyp->key, &kbd->kb_keymap->key[keyp->keynum],
843 case GIO_DEADKEYMAP: /* get accent key translation table */
844 bcopy(kbd->kb_accentmap, arg, sizeof(*kbd->kb_accentmap));
846 case PIO_DEADKEYMAP: /* set accent key translation table */
847 #ifndef KBD_DISABLE_KEYMAP_LOAD
848 bcopy(arg, kbd->kb_accentmap, sizeof(*kbd->kb_accentmap));
855 case GETFKEY: /* get functionkey string */
856 fkeyp = (fkeyarg_t *)arg;
857 if (fkeyp->keynum >= kbd->kb_fkeytab_size) {
861 bcopy(kbd->kb_fkeytab[fkeyp->keynum].str, fkeyp->keydef,
862 kbd->kb_fkeytab[fkeyp->keynum].len);
863 fkeyp->flen = kbd->kb_fkeytab[fkeyp->keynum].len;
865 case SETFKEY: /* set functionkey string */
866 #ifndef KBD_DISABLE_KEYMAP_LOAD
867 fkeyp = (fkeyarg_t *)arg;
868 if (fkeyp->keynum >= kbd->kb_fkeytab_size) {
872 kbd->kb_fkeytab[fkeyp->keynum].len = imin(fkeyp->flen, MAXFK);
873 bcopy(fkeyp->keydef, kbd->kb_fkeytab[fkeyp->keynum].str,
874 kbd->kb_fkeytab[fkeyp->keynum].len);
890 /* get a pointer to the string associated with the given function key */
892 *genkbd_get_fkeystr(keyboard_t *kbd, int fkey, size_t *len)
897 if (fkey > kbd->kb_fkeytab_size)
899 *len = kbd->kb_fkeytab[fkey].len;
900 return kbd->kb_fkeytab[fkey].str;
903 /* diagnostic dump */
905 *get_kbd_type_name(int type)
912 { KB_101, "AT 101/102" },
913 { KB_OTHER, "generic" },
917 for (i = 0; i < sizeof(name_table)/sizeof(name_table[0]); ++i) {
918 if (type == name_table[i].type)
919 return name_table[i].name;
925 genkbd_diag(keyboard_t *kbd, int level)
928 printf("kbd%d: %s%d, %s (%d), config:0x%x, flags:0x%x",
929 kbd->kb_index, kbd->kb_name, kbd->kb_unit,
930 get_kbd_type_name(kbd->kb_type), kbd->kb_type,
931 kbd->kb_config, kbd->kb_flags);
932 if (kbd->kb_io_base > 0)
933 printf(", port:0x%x-0x%x", kbd->kb_io_base,
934 kbd->kb_io_base + kbd->kb_io_size - 1);
939 #define set_lockkey_state(k, s, l) \
940 if (!((s) & l ## DOWN)) { \
944 i = (s) & LOCK_MASK; \
945 (*kbdsw[(k)->kb_index]->ioctl)((k), KDSETLED, (caddr_t)&i); \
949 save_accent_key(keyboard_t *kbd, u_int key, int *accents)
953 /* make an index into the accent map */
955 if ((i > kbd->kb_accentmap->n_accs)
956 || (kbd->kb_accentmap->acc[i - 1].accchar == 0)) {
957 /* the index is out of range or pointing to an empty entry */
963 * If the same accent key has been hit twice, produce the accent char
967 key = kbd->kb_accentmap->acc[i - 1].accchar;
972 /* remember the index and wait for the next key */
978 make_accent_char(keyboard_t *kbd, u_int ch, int *accents)
983 acc = &kbd->kb_accentmap->acc[*accents - 1];
987 * If the accent key is followed by the space key,
988 * produce the accent char itself.
993 /* scan the accent map */
994 for (i = 0; i < NUM_ACCENTCHARS; ++i) {
995 if (acc->map[i][0] == 0) /* end of table */
997 if (acc->map[i][0] == ch)
998 return acc->map[i][1];
1000 /* this char cannot be accented... */
1005 genkbd_keyaction(keyboard_t *kbd, int keycode, int up, int *shiftstate,
1008 struct keyent_t *key;
1009 int state = *shiftstate;
1015 f = state & (AGRS | ALKED);
1016 if ((f == AGRS1) || (f == AGRS2) || (f == ALKED))
1018 key = &kbd->kb_keymap->key[i];
1019 i = ((state & SHIFTS) ? 1 : 0)
1020 | ((state & CTLS) ? 2 : 0)
1021 | ((state & ALTS) ? 4 : 0);
1022 if (((key->flgs & FLAG_LOCK_C) && (state & CLKED))
1023 || ((key->flgs & FLAG_LOCK_N) && (state & NLKED)) )
1026 if (up) { /* break: key released */
1027 action = kbd->kb_lastact[keycode];
1028 kbd->kb_lastact[keycode] = NOP;
1031 if (state & SHIFTAON) {
1032 set_lockkey_state(kbd, state, ALK);
1041 if (state & SHIFTAON) {
1042 set_lockkey_state(kbd, state, ALK);
1051 if (state & SHIFTAON) {
1052 set_lockkey_state(kbd, state, ALK);
1061 if (state & SHIFTAON) {
1062 set_lockkey_state(kbd, state, ALK);
1071 if (state & SHIFTAON) {
1072 set_lockkey_state(kbd, state, ALK);
1081 if (state & SHIFTAON) {
1082 set_lockkey_state(kbd, state, ALK);
1104 i = state & LOCK_MASK;
1105 (*kbdsw[kbd->kb_index]->ioctl)(kbd, KDSETLED,
1116 /* release events of regular keys are not reported */
1117 *shiftstate &= ~SHIFTAON;
1120 *shiftstate = state & ~SHIFTAON;
1121 return (SPCLKEY | RELKEY | action);
1122 } else { /* make: key pressed */
1123 action = key->map[i];
1125 if (key->spcl & (0x80 >> i)) {
1127 if (kbd->kb_lastact[keycode] == NOP)
1128 kbd->kb_lastact[keycode] = action;
1129 if (kbd->kb_lastact[keycode] != action)
1134 set_lockkey_state(kbd, state, NLK);
1138 set_lockkey_state(kbd, state, CLK);
1141 i = state & LOCK_MASK;
1142 (*kbdsw[kbd->kb_index]->ioctl)(kbd, KDSETLED,
1147 set_lockkey_state(kbd, state, SLK);
1150 set_lockkey_state(kbd, state, ALK);
1152 /* NON-LOCKING KEYS */
1153 case SPSC: case RBT: case SUSP: case STBY:
1154 case DBG: case NEXT: case PREV: case PNC:
1155 case HALT: case PDWN:
1211 *shiftstate = state;
1214 /* is this an accent (dead) key? */
1215 *shiftstate = state;
1216 if (action >= F_ACC && action <= L_ACC) {
1217 action = save_accent_key(kbd, action,
1225 return (action | MKEY);
1231 /* other special keys */
1236 if (action >= F_FN && action <= L_FN)
1238 /* XXX: return fkey string for the FKEY? */
1239 return (SPCLKEY | action);
1241 *shiftstate = state;
1242 return (SPCLKEY | action);
1245 kbd->kb_lastact[keycode] = NOP;
1246 *shiftstate = state;
1248 /* make an accented char */
1249 action = make_accent_char(kbd, action, accents);
1250 if (action == ERRKEY)