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.
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>
45 #include <dev/kbd/kbdreg.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);
62 * We need at least one entry each in order to initialize a keyboard
63 * for the kernel console. The arrays will be increased dynamically
67 static int keyboards = 1;
68 static keyboard_t *kbd_ini;
69 static keyboard_t **keyboard = &kbd_ini;
70 static keyboard_switch_t *kbdsw_ini;
71 keyboard_switch_t **kbdsw = &kbdsw_ini;
76 kbd_realloc_array(void)
79 keyboard_switch_t **new_kbdsw;
84 newsize = ((keyboards + ARRAY_DELTA)/ARRAY_DELTA)*ARRAY_DELTA;
85 new_kbd = malloc(sizeof(*new_kbd)*newsize, M_DEVBUF, M_NOWAIT);
86 if (new_kbd == NULL) {
90 new_kbdsw = malloc(sizeof(*new_kbdsw)*newsize, M_DEVBUF, M_NOWAIT);
91 if (new_kbdsw == NULL) {
92 free(new_kbd, M_DEVBUF);
96 bzero(new_kbd, sizeof(*new_kbd)*newsize);
97 bzero(new_kbdsw, sizeof(*new_kbdsw)*newsize);
98 bcopy(keyboard, new_kbd, sizeof(*keyboard)*keyboards);
99 bcopy(kbdsw, new_kbdsw, sizeof(*kbdsw)*keyboards);
101 free(keyboard, M_DEVBUF);
102 free(kbdsw, M_DEVBUF);
110 printf("kbd: new array size %d\n", keyboards);
116 * Low-level keyboard driver functions
117 * Keyboard subdrivers, such as the AT keyboard driver and the USB keyboard
118 * driver, call these functions to initialize the keyboard_t structure
119 * and register it to the virtual keyboard driver `kbd'.
122 /* initialize the keyboard_t structure */
124 kbd_init_struct(keyboard_t *kbd, char *name, int type, int unit, int config,
125 int port, int port_size)
127 kbd->kb_flags = KB_NO_DEVICE; /* device has not been found */
131 kbd->kb_config = config & ~KB_CONF_PROBE_ONLY;
132 kbd->kb_led = 0; /* unknown */
133 kbd->kb_io_base = port;
134 kbd->kb_io_size = port_size;
136 kbd->kb_keymap = NULL;
137 kbd->kb_accentmap = NULL;
138 kbd->kb_fkeytab = NULL;
139 kbd->kb_fkeytab_size = 0;
140 kbd->kb_delay1 = KB_DELAY1; /* these values are advisory only */
141 kbd->kb_delay2 = KB_DELAY2;
146 kbd_set_maps(keyboard_t *kbd, keymap_t *keymap, accentmap_t *accmap,
147 fkeytab_t *fkeymap, int fkeymap_size)
149 kbd->kb_keymap = keymap;
150 kbd->kb_accentmap = accmap;
151 kbd->kb_fkeytab = fkeymap;
152 kbd->kb_fkeytab_size = fkeymap_size;
155 /* declare a new keyboard driver */
157 kbd_add_driver(keyboard_driver_t *driver)
159 if (SLIST_NEXT(driver, link))
161 SLIST_INSERT_HEAD(&keyboard_drivers, driver, link);
166 kbd_delete_driver(keyboard_driver_t *driver)
168 SLIST_REMOVE(&keyboard_drivers, driver, keyboard_driver, link);
169 SLIST_NEXT(driver, link) = NULL;
173 /* register a keyboard and associate it with a function table */
175 kbd_register(keyboard_t *kbd)
177 const keyboard_driver_t **list;
178 const keyboard_driver_t *p;
181 for (index = 0; index < keyboards; ++index) {
182 if (keyboard[index] == NULL)
185 if (index >= keyboards) {
186 if (kbd_realloc_array())
190 kbd->kb_index = index;
193 kbd->kb_active = 0; /* disabled until someone calls kbd_enable() */
194 kbd->kb_token = NULL;
195 kbd->kb_callback.kc_func = NULL;
196 kbd->kb_callback.kc_arg = NULL;
198 SLIST_FOREACH(p, &keyboard_drivers, link) {
199 if (strcmp(p->name, kbd->kb_name) == 0) {
200 keyboard[index] = kbd;
201 kbdsw[index] = p->kbdsw;
205 list = (const keyboard_driver_t **)kbddriver_set.ls_items;
206 while ((p = *list++) != NULL) {
207 if (strcmp(p->name, kbd->kb_name) == 0) {
208 keyboard[index] = kbd;
209 kbdsw[index] = p->kbdsw;
218 kbd_unregister(keyboard_t *kbd)
223 if ((kbd->kb_index < 0) || (kbd->kb_index >= keyboards))
225 if (keyboard[kbd->kb_index] != kbd)
229 if (KBD_IS_BUSY(kbd)) {
230 error = (*kbd->kb_callback.kc_func)(kbd, KBDIO_UNLOADING,
231 kbd->kb_callback.kc_arg);
236 if (KBD_IS_BUSY(kbd)) {
242 keyboard[kbd->kb_index] = NULL;
243 kbdsw[kbd->kb_index] = NULL;
249 /* find a funciton table by the driver name */
251 *kbd_get_switch(char *driver)
253 const keyboard_driver_t **list;
254 const keyboard_driver_t *p;
256 SLIST_FOREACH(p, &keyboard_drivers, link) {
257 if (strcmp(p->name, driver) == 0)
260 list = (const keyboard_driver_t **)kbddriver_set.ls_items;
261 while ((p = *list++) != NULL) {
262 if (strcmp(p->name, driver) == 0)
270 * Keyboard client functions
271 * Keyboard clients, such as the console driver `syscons' and the keyboard
272 * cdev driver, use these functions to claim and release a keyboard for
276 /* find the keyboard specified by a driver name and a unit number */
278 kbd_find_keyboard(char *driver, int unit)
282 for (i = 0; i < keyboards; ++i) {
283 if (keyboard[i] == NULL)
285 if (!KBD_IS_VALID(keyboard[i]))
287 if (strcmp("*", driver) && strcmp(keyboard[i]->kb_name, driver))
289 if ((unit != -1) && (keyboard[i]->kb_unit != unit))
296 /* allocate a keyboard */
298 kbd_allocate(char *driver, int unit, void *id, kbd_callback_func_t *func,
308 index = kbd_find_keyboard(driver, unit);
310 if (KBD_IS_BUSY(keyboard[index])) {
314 keyboard[index]->kb_token = id;
315 KBD_BUSY(keyboard[index]);
316 keyboard[index]->kb_callback.kc_func = func;
317 keyboard[index]->kb_callback.kc_arg = arg;
318 (*kbdsw[index]->clear_state)(keyboard[index]);
325 kbd_release(keyboard_t *kbd, void *id)
331 if (!KBD_IS_VALID(kbd) || !KBD_IS_BUSY(kbd)) {
333 } else if (kbd->kb_token != id) {
336 kbd->kb_token = NULL;
338 kbd->kb_callback.kc_func = NULL;
339 kbd->kb_callback.kc_arg = NULL;
340 (*kbdsw[kbd->kb_index]->clear_state)(kbd);
348 kbd_change_callback(keyboard_t *kbd, void *id, kbd_callback_func_t *func,
355 if (!KBD_IS_VALID(kbd) || !KBD_IS_BUSY(kbd)) {
357 } else if (kbd->kb_token != id) {
359 } else if (func == NULL) {
362 kbd->kb_callback.kc_func = func;
363 kbd->kb_callback.kc_arg = arg;
370 /* get a keyboard structure */
372 *kbd_get_keyboard(int index)
374 if ((index < 0) || (index >= keyboards))
376 if (keyboard[index] == NULL)
378 if (!KBD_IS_VALID(keyboard[index]))
380 return keyboard[index];
384 * The back door for the console driver; configure keyboards
385 * This function is for the kernel console to initialize keyboards
386 * at very early stage.
390 kbd_configure(int flags)
392 const keyboard_driver_t **list;
393 const keyboard_driver_t *p;
395 SLIST_FOREACH(p, &keyboard_drivers, link) {
396 if (p->configure != NULL)
397 (*p->configure)(flags);
399 list = (const keyboard_driver_t **)kbddriver_set.ls_items;
400 while ((p = *list++) != NULL) {
401 if (p->configure != NULL)
402 (*p->configure)(flags);
408 #ifdef KBD_INSTALL_CDEV
411 * Virtual keyboard cdev driver functions
412 * The virtual keyboard driver dispatches driver functions to
413 * appropriate subdrivers.
416 #define KBD_UNIT(dev) minor(dev)
418 static d_open_t genkbdopen;
419 static d_close_t genkbdclose;
420 static d_read_t genkbdread;
421 static d_write_t genkbdwrite;
422 static d_ioctl_t genkbdioctl;
423 static d_poll_t genkbdpoll;
425 #define CDEV_MAJOR 112
427 static struct cdevsw kbd_cdevsw = {
428 /* open */ genkbdopen,
429 /* close */ genkbdclose,
430 /* read */ genkbdread,
431 /* write */ genkbdwrite,
432 /* ioctl */ genkbdioctl,
433 /* poll */ genkbdpoll,
435 /* strategy */ nostrategy,
437 /* maj */ CDEV_MAJOR,
445 kbd_attach(keyboard_t *kbd)
449 if (kbd->kb_index >= keyboards)
451 if (keyboard[kbd->kb_index] != kbd)
454 dev = make_dev(&kbd_cdevsw, kbd->kb_index, UID_ROOT, GID_WHEEL, 0600,
455 "kbd%r", kbd->kb_index);
456 if (dev->si_drv1 == NULL)
457 dev->si_drv1 = malloc(sizeof(genkbd_softc_t), M_DEVBUF,
459 bzero(dev->si_drv1, sizeof(genkbd_softc_t));
461 printf("kbd%d at %s%d\n", kbd->kb_index, kbd->kb_name, kbd->kb_unit);
466 kbd_detach(keyboard_t *kbd)
470 if (kbd->kb_index >= keyboards)
472 if (keyboard[kbd->kb_index] != kbd)
475 dev = makedev(kbd_cdevsw.d_maj, kbd->kb_index);
477 free(dev->si_drv1, M_DEVBUF);
484 * Generic keyboard cdev driver functions
485 * Keyboard subdrivers may call these functions to implement common
490 #define KB_BUFSIZE 64
492 static kbd_callback_func_t genkbd_event;
495 genkbdopen(dev_t dev, int mode, int flag, struct proc *p)
504 kbd = kbd_get_keyboard(KBD_INDEX(dev));
505 if ((sc == NULL) || (kbd == NULL) || !KBD_IS_VALID(kbd)) {
509 i = kbd_allocate(kbd->kb_name, kbd->kb_unit, sc,
510 genkbd_event, (void *)sc);
515 /* assert(i == kbd->kb_index) */
516 /* assert(kbd == kbd_get_keyboard(i)) */
519 * NOTE: even when we have successfully claimed a keyboard,
520 * the device may still be missing (!KBD_HAS_DEVICE(kbd)).
524 bzero(&sc->gkb_q, sizeof(sc->gkb_q));
526 clist_alloc_cblocks(&sc->gkb_q, KB_QSIZE, KB_QSIZE/2); /* XXX */
527 sc->gkb_rsel.si_flags = 0;
528 sc->gkb_rsel.si_pid = 0;
535 genkbdclose(dev_t dev, int mode, int flag, struct proc *p)
542 * NOTE: the device may have already become invalid.
543 * kbd == NULL || !KBD_IS_VALID(kbd)
547 kbd = kbd_get_keyboard(KBD_INDEX(dev));
548 if ((sc == NULL) || (kbd == NULL) || !KBD_IS_VALID(kbd)) {
549 /* XXX: we shall be forgiving and don't report error... */
551 kbd_release(kbd, (void *)sc);
553 clist_free_cblocks(&sc->gkb_q);
561 genkbdread(dev_t dev, struct uio *uio, int flag)
565 u_char buffer[KB_BUFSIZE];
573 kbd = kbd_get_keyboard(KBD_INDEX(dev));
574 if ((sc == NULL) || (kbd == NULL) || !KBD_IS_VALID(kbd)) {
578 while (sc->gkb_q.c_cc == 0) {
579 if (flag & IO_NDELAY) {
583 sc->gkb_flags |= KB_ASLEEP;
584 error = tsleep((caddr_t)sc, PZERO | PCATCH, "kbdrea", 0);
585 kbd = kbd_get_keyboard(KBD_INDEX(dev));
586 if ((kbd == NULL) || !KBD_IS_VALID(kbd)) {
588 return ENXIO; /* our keyboard has gone... */
591 sc->gkb_flags &= ~KB_ASLEEP;
598 /* copy as much input as possible */
600 while (uio->uio_resid > 0) {
601 len = imin(uio->uio_resid, sizeof(buffer));
602 len = q_to_b(&sc->gkb_q, buffer, len);
605 error = uiomove(buffer, len, uio);
614 genkbdwrite(dev_t dev, struct uio *uio, int flag)
618 kbd = kbd_get_keyboard(KBD_INDEX(dev));
619 if ((kbd == NULL) || !KBD_IS_VALID(kbd))
625 genkbdioctl(dev_t dev, u_long cmd, caddr_t arg, int flag, struct proc *p)
630 kbd = kbd_get_keyboard(KBD_INDEX(dev));
631 if ((kbd == NULL) || !KBD_IS_VALID(kbd))
633 error = (*kbdsw[kbd->kb_index]->ioctl)(kbd, cmd, arg);
634 if (error == ENOIOCTL)
640 genkbdpoll(dev_t dev, int events, struct proc *p)
650 kbd = kbd_get_keyboard(KBD_INDEX(dev));
651 if ((sc == NULL) || (kbd == NULL) || !KBD_IS_VALID(kbd)) {
652 revents = POLLHUP; /* the keyboard has gone */
653 } else if (events & (POLLIN | POLLRDNORM)) {
654 if (sc->gkb_q.c_cc > 0)
655 revents = events & (POLLIN | POLLRDNORM);
657 selrecord(p, &sc->gkb_rsel);
664 genkbd_event(keyboard_t *kbd, int event, void *arg)
672 /* assert(KBD_IS_VALID(kbd)) */
673 sc = (genkbd_softc_t *)arg;
678 case KBDIO_UNLOADING:
679 /* the keyboard is going... */
680 kbd_release(kbd, (void *)sc);
681 if (sc->gkb_flags & KB_ASLEEP) {
682 sc->gkb_flags &= ~KB_ASLEEP;
685 selwakeup(&sc->gkb_rsel);
691 /* obtain the current key input mode */
692 if ((*kbdsw[kbd->kb_index]->ioctl)(kbd, KDGKBMODE, (caddr_t)&mode))
695 /* read all pending input */
696 while ((*kbdsw[kbd->kb_index]->check_char)(kbd)) {
697 c = (*kbdsw[kbd->kb_index]->read_char)(kbd, FALSE);
700 if (c == ERRKEY) /* XXX: ring bell? */
702 if (!KBD_IS_BUSY(kbd))
703 /* the device is not open, discard the input */
706 /* store the byte as is for K_RAW and K_CODE modes */
707 if (mode != K_XLATE) {
708 putc(KEYCHAR(c), &sc->gkb_q);
713 if (c & RELKEY) /* key release is ignored */
716 /* process special keys; most of them are just ignored... */
718 switch (KEYCHAR(c)) {
722 case BTAB: /* a backtab: ESC [ Z */
723 putc(0x1b, &sc->gkb_q);
724 putc('[', &sc->gkb_q);
725 putc('Z', &sc->gkb_q);
730 /* normal chars, normal chars with the META, function keys */
731 switch (KEYFLAGS(c)) {
732 case 0: /* a normal char */
733 putc(KEYCHAR(c), &sc->gkb_q);
735 case MKEY: /* the META flag: prepend ESC */
736 putc(0x1b, &sc->gkb_q);
737 putc(KEYCHAR(c), &sc->gkb_q);
739 case FKEY | SPCLKEY: /* a function key, return string */
740 cp = (*kbdsw[kbd->kb_index]->get_fkeystr)(kbd,
744 putc(*cp++, &sc->gkb_q);
750 /* wake up sleeping/polling processes */
751 if (sc->gkb_q.c_cc > 0) {
752 if (sc->gkb_flags & KB_ASLEEP) {
753 sc->gkb_flags &= ~KB_ASLEEP;
756 selwakeup(&sc->gkb_rsel);
762 #endif /* KBD_INSTALL_CDEV */
765 * Generic low-level keyboard functions
766 * The low-level functions in the keyboard subdriver may use these
771 genkbd_commonioctl(keyboard_t *kbd, u_long cmd, caddr_t arg)
781 case KDGKBINFO: /* get keyboard information */
782 ((keyboard_info_t *)arg)->kb_index = kbd->kb_index;
783 i = imin(strlen(kbd->kb_name) + 1,
784 sizeof(((keyboard_info_t *)arg)->kb_name));
785 bcopy(kbd->kb_name, ((keyboard_info_t *)arg)->kb_name, i);
786 ((keyboard_info_t *)arg)->kb_unit = kbd->kb_unit;
787 ((keyboard_info_t *)arg)->kb_type = kbd->kb_type;
788 ((keyboard_info_t *)arg)->kb_config = kbd->kb_config;
789 ((keyboard_info_t *)arg)->kb_flags = kbd->kb_flags;
792 case KDGKBTYPE: /* get keyboard type */
793 *(int *)arg = kbd->kb_type;
796 case KDGETREPEAT: /* get keyboard repeat rate */
797 ((int *)arg)[0] = kbd->kb_delay1;
798 ((int *)arg)[1] = kbd->kb_delay2;
801 case GIO_KEYMAP: /* get keyboard translation table */
802 bcopy(kbd->kb_keymap, arg, sizeof(*kbd->kb_keymap));
804 case PIO_KEYMAP: /* set keyboard translation table */
805 #ifndef KBD_DISABLE_KEYMAP_LOAD
806 bzero(kbd->kb_accentmap, sizeof(*kbd->kb_accentmap));
807 bcopy(arg, kbd->kb_keymap, sizeof(*kbd->kb_keymap));
814 case GIO_KEYMAPENT: /* get keyboard translation table entry */
815 keyp = (keyarg_t *)arg;
816 if (keyp->keynum >= sizeof(kbd->kb_keymap->key)
817 /sizeof(kbd->kb_keymap->key[0])) {
821 bcopy(&kbd->kb_keymap->key[keyp->keynum], &keyp->key,
824 case PIO_KEYMAPENT: /* set keyboard translation table entry */
825 #ifndef KBD_DISABLE_KEYMAP_LOAD
826 keyp = (keyarg_t *)arg;
827 if (keyp->keynum >= sizeof(kbd->kb_keymap->key)
828 /sizeof(kbd->kb_keymap->key[0])) {
832 bcopy(&keyp->key, &kbd->kb_keymap->key[keyp->keynum],
840 case GIO_DEADKEYMAP: /* get accent key translation table */
841 bcopy(kbd->kb_accentmap, arg, sizeof(*kbd->kb_accentmap));
843 case PIO_DEADKEYMAP: /* set accent key translation table */
844 #ifndef KBD_DISABLE_KEYMAP_LOAD
845 bcopy(arg, kbd->kb_accentmap, sizeof(*kbd->kb_accentmap));
852 case GETFKEY: /* get functionkey string */
853 fkeyp = (fkeyarg_t *)arg;
854 if (fkeyp->keynum >= kbd->kb_fkeytab_size) {
858 bcopy(kbd->kb_fkeytab[fkeyp->keynum].str, fkeyp->keydef,
859 kbd->kb_fkeytab[fkeyp->keynum].len);
860 fkeyp->flen = kbd->kb_fkeytab[fkeyp->keynum].len;
862 case SETFKEY: /* set functionkey string */
863 #ifndef KBD_DISABLE_KEYMAP_LOAD
864 fkeyp = (fkeyarg_t *)arg;
865 if (fkeyp->keynum >= kbd->kb_fkeytab_size) {
869 kbd->kb_fkeytab[fkeyp->keynum].len = imin(fkeyp->flen, MAXFK);
870 bcopy(fkeyp->keydef, kbd->kb_fkeytab[fkeyp->keynum].str,
871 kbd->kb_fkeytab[fkeyp->keynum].len);
887 /* get a pointer to the string associated with the given function key */
889 *genkbd_get_fkeystr(keyboard_t *kbd, int fkey, size_t *len)
894 if (fkey > kbd->kb_fkeytab_size)
896 *len = kbd->kb_fkeytab[fkey].len;
897 return kbd->kb_fkeytab[fkey].str;
900 /* diagnostic dump */
902 *get_kbd_type_name(int type)
909 { KB_101, "AT 101/102" },
910 { KB_OTHER, "generic" },
914 for (i = 0; i < sizeof(name_table)/sizeof(name_table[0]); ++i) {
915 if (type == name_table[i].type)
916 return name_table[i].name;
922 genkbd_diag(keyboard_t *kbd, int level)
925 printf("kbd%d: %s%d, %s (%d), config:0x%x, flags:0x%x",
926 kbd->kb_index, kbd->kb_name, kbd->kb_unit,
927 get_kbd_type_name(kbd->kb_type), kbd->kb_type,
928 kbd->kb_config, kbd->kb_flags);
929 if (kbd->kb_io_base > 0)
930 printf(", port:0x%x-0x%x", kbd->kb_io_base,
931 kbd->kb_io_base + kbd->kb_io_size - 1);
936 #define set_lockkey_state(k, s, l) \
937 if (!((s) & l ## DOWN)) { \
941 i = (s) & LOCK_MASK; \
942 (*kbdsw[(k)->kb_index]->ioctl)((k), KDSETLED, (caddr_t)&i); \
946 save_accent_key(keyboard_t *kbd, u_int key, int *accents)
950 /* make an index into the accent map */
952 if ((i > kbd->kb_accentmap->n_accs)
953 || (kbd->kb_accentmap->acc[i - 1].accchar == 0)) {
954 /* the index is out of range or pointing to an empty entry */
960 * If the same accent key has been hit twice, produce the accent char
964 key = kbd->kb_accentmap->acc[i - 1].accchar;
969 /* remember the index and wait for the next key */
975 make_accent_char(keyboard_t *kbd, u_int ch, int *accents)
980 acc = &kbd->kb_accentmap->acc[*accents - 1];
984 * If the accent key is followed by the space key,
985 * produce the accent char itself.
990 /* scan the accent map */
991 for (i = 0; i < NUM_ACCENTCHARS; ++i) {
992 if (acc->map[i][0] == 0) /* end of table */
994 if (acc->map[i][0] == ch)
995 return acc->map[i][1];
997 /* this char cannot be accented... */
1002 genkbd_keyaction(keyboard_t *kbd, int keycode, int up, int *shiftstate,
1005 struct keyent_t *key;
1006 int state = *shiftstate;
1012 f = state & (AGRS | ALKED);
1013 if ((f == AGRS1) || (f == AGRS2) || (f == ALKED))
1015 key = &kbd->kb_keymap->key[i];
1016 i = ((state & SHIFTS) ? 1 : 0)
1017 | ((state & CTLS) ? 2 : 0)
1018 | ((state & ALTS) ? 4 : 0);
1019 if (((key->flgs & FLAG_LOCK_C) && (state & CLKED))
1020 || ((key->flgs & FLAG_LOCK_N) && (state & NLKED)) )
1023 action = key->map[i];
1024 if (up) { /* break: key released */
1025 if (key->spcl & (0x80 >> i)) {
1029 if (state & SHIFTAON) {
1030 set_lockkey_state(kbd, state, ALK);
1039 if (state & SHIFTAON) {
1040 set_lockkey_state(kbd, state, ALK);
1049 if (state & SHIFTAON) {
1050 set_lockkey_state(kbd, state, ALK);
1059 if (state & SHIFTAON) {
1060 set_lockkey_state(kbd, state, ALK);
1069 if (state & SHIFTAON) {
1070 set_lockkey_state(kbd, state, ALK);
1079 if (state & SHIFTAON) {
1080 set_lockkey_state(kbd, state, ALK);
1102 i = state & LOCK_MASK;
1103 (*kbdsw[kbd->kb_index]->ioctl)(kbd, KDSETLED,
1114 *shiftstate = state & ~SHIFTAON;
1115 return (SPCLKEY | RELKEY | action);
1117 /* release events of regular keys are not reported */
1118 *shiftstate &= ~SHIFTAON;
1120 } else { /* make: key pressed */
1122 if (key->spcl & (0x80 >> i)) {
1127 set_lockkey_state(kbd, state, NLK);
1131 set_lockkey_state(kbd, state, CLK);
1134 i = state & LOCK_MASK;
1135 (*kbdsw[kbd->kb_index]->ioctl)(kbd, KDSETLED,
1140 set_lockkey_state(kbd, state, SLK);
1143 set_lockkey_state(kbd, state, ALK);
1145 /* NON-LOCKING KEYS */
1146 case SPSC: case RBT: case SUSP: case STBY:
1147 case DBG: case NEXT: case PREV: case PNC:
1203 /* is this an accent (dead) key? */
1204 *shiftstate = state;
1205 if (action >= F_ACC && action <= L_ACC) {
1206 action = save_accent_key(kbd, action,
1214 return (action | MKEY);
1220 /* other special keys */
1225 if (action >= F_FN && action <= L_FN)
1227 /* XXX: return fkey string for the FKEY? */
1228 return (SPCLKEY | action);
1230 *shiftstate = state;
1231 return (SPCLKEY | action);
1234 *shiftstate = state;
1236 /* make an accented char */
1237 action = make_accent_char(kbd, action, accents);
1238 if (action == ERRKEY)