source: rtems/c/src/lib/libbsp/i386/pc386/console/keyboard.c @ a4a5624

4.104.114.84.95
Last change on this file since a4a5624 was a4a5624, checked in by Joel Sherrill <joel.sherrill@…>, on 01/04/05 at 23:28:30

2005-01-04 Joel Sherrill <joel@…>

  • console/keyboard.c, console/ps2_mouse.c, console/vt.c: Remove warnings.
  • Property mode set to 100644
File size: 18.9 KB
RevLine 
[3cbb63a]1/*
[a4a5624]2 *   $Id$
[3cbb63a]3 *
[a4a5624]4 *   Rosimildo da Silva:  rdasilva@connecttel.com
[3cbb63a]5 */
6
7#include <sys/types.h>
8#include <rtems/keyboard.h>
9#include "i386kbd.h"
10#include <rtems/kd.h>
11#include <bsp.h>
12
13#define SIZE(x) (sizeof(x)/sizeof((x)[0]))
14
15#ifndef KBD_DEFMODE
16#define KBD_DEFMODE ((1 << VC_REPEAT) | (1 << VC_META))
17#endif
18
19#ifndef KBD_DEFLEDS
20/*
21 * Some laptops take the 789uiojklm,. keys as number pad when NumLock
22 * is on. This seems a good reason to start with NumLock off.
23 */
24#define KBD_DEFLEDS 0
25#endif
26
27#ifndef KBD_DEFLOCK
28#define KBD_DEFLOCK 0
29#endif
30
31extern void add_to_queue( unsigned short );
32extern void rtemsReboot( void );
33
34int set_bit(int nr, unsigned long * addr)
35{
[d57c04e]36        int     mask, retval,level;
[3cbb63a]37
38        addr += nr >> 5;
39        mask = 1 << (nr & 0x1f);
[d57c04e]40        _CPU_ISR_Disable(level)
[3cbb63a]41        retval = (mask & *addr) != 0;
42        *addr |= mask;
[d57c04e]43        _CPU_ISR_Enable (level);
[3cbb63a]44        return retval;
45}
46
47int clear_bit(int nr, unsigned long * addr)
48{
[d57c04e]49        int     mask, retval,level;
[3cbb63a]50
51        addr += nr >> 5;
52        mask = 1 << (nr & 0x1f);
[d57c04e]53        _CPU_ISR_Disable(level)
[3cbb63a]54        retval = (mask & *addr) != 0;
55        *addr &= ~mask;
[d57c04e]56        _CPU_ISR_Enable (level);
[3cbb63a]57        return retval;
58}
59
60int test_bit(int nr, unsigned long * addr)
61{
62        int     mask;
63
64        addr += nr >> 5;
65        mask = 1 << (nr & 0x1f);
66        return ((mask & *addr) != 0);
67}
68
69#define  test_and_set_bit(x,y)      set_bit(x,y)
70#define  test_and_clear_bit(x,y)    clear_bit(x,y)
71
72/*
73 * global state includes the following, and various static variables
74 * in this module: prev_scancode, shift_state, diacr, npadch, dead_key_next.
75 * (last_console is now a global variable)
76 */
77#define  BITS_PER_LONG  32
78
79/* shift state counters.. */
80static unsigned char k_down[NR_SHIFT] = {0, };
81/* keyboard key bitmap */
82static unsigned long key_down[256/BITS_PER_LONG] = { 0, };
83
84static int dead_key_next = 0;
[6128a4a]85/*
[3cbb63a]86 * In order to retrieve the shift_state (for the mouse server), either
[6128a4a]87 * the variable must be global, or a new procedure must be created to
[3cbb63a]88 * return the value. I chose the former way.
89 */
90int shift_state = 0;
91static int npadch = -1;                 /* -1 or number assembled on pad */
92static unsigned char diacr = 0;
93static char rep = 0;                    /* flag telling character repeat */
94
95/* default console for RTEMS */
96static int  fg_console = 0;
97
98struct kbd_struct kbd_table[MAX_NR_CONSOLES];
99static struct kbd_struct * kbd = kbd_table;
100
101void compute_shiftstate(void);
102
103typedef void (*k_hand)(unsigned char value, char up_flag);
104typedef void (k_handfn)(unsigned char value, char up_flag);
105
106static k_handfn
107        do_self, do_fn, do_spec, do_pad, do_dead, do_cons, do_cur, do_shift,
108        do_meta, do_ascii, do_lock, do_lowercase, do_slock, do_dead2,
109        do_ignore;
110
111static k_hand key_handler[16] = {
112        do_self, do_fn, do_spec, do_pad, do_dead, do_cons, do_cur, do_shift,
113        do_meta, do_ascii, do_lock, do_lowercase, do_slock, do_dead2,
114        do_ignore, do_ignore
115};
116
117/* Key types processed even in raw modes */
118
119#define TYPES_ALLOWED_IN_RAW_MODE ((1 << KT_SPEC) | (1 << KT_SHIFT))
120
121typedef void (*void_fnp)(void);
122typedef void (void_fn)(void);
123
124static void show_mem(void)
125{
126}
127static void show_state(void)
128{
129}
130
131static void_fn do_null, enter, show_ptregs, send_intr, lastcons, caps_toggle,
132        num, hold, scroll_forw, scroll_back, boot_it, caps_on, compose,
133        SAK, decr_console, incr_console, spawn_console, bare_num;
134
135static void_fnp spec_fn_table[] = {
136        do_null,        enter,          show_ptregs,    show_mem,
137        show_state,     send_intr,      lastcons,       caps_toggle,
138        num,            hold,           scroll_forw,    scroll_back,
139        boot_it,        caps_on,        compose,        SAK,
140        decr_console,   incr_console,   spawn_console,  bare_num
141};
142
143#define SPECIALS_ALLOWED_IN_RAW_MODE (1 << KVAL(K_SAK))
144
145/* maximum values each key_handler can handle */
146const int max_vals[] = {
147        255, SIZE(func_table) - 1, SIZE(spec_fn_table) - 1, NR_PAD - 1,
148        NR_DEAD - 1, 255, 3, NR_SHIFT - 1,
149        255, NR_ASCII - 1, NR_LOCK - 1, 255,
150        NR_LOCK - 1, 255
151};
152
153const int NR_TYPES = SIZE(max_vals);
154
155/* N.B. drivers/macintosh/mac_keyb.c needs to call put_queue */
156static void put_queue(int);
157static unsigned char handle_diacr(unsigned char);
158
159#ifdef CONFIG_MAGIC_SYSRQ
160static int sysrq_pressed;
161#endif
162
163/*
164 * Many other routines do put_queue, but I think either
165 * they produce ASCII, or they produce some user-assigned
166 * string, and in both cases we might assume that it is
167 * in utf-8 already.
168 */
169void to_utf8(ushort c) {
170    if (c < 0x80)
171        put_queue(c);                   /*  0*******  */
172    else if (c < 0x800) {
173        put_queue(0xc0 | (c >> 6));     /*  110***** 10******  */
174        put_queue(0x80 | (c & 0x3f));
175    } else {
176        put_queue(0xe0 | (c >> 12));    /*  1110**** 10****** 10******  */
177        put_queue(0x80 | ((c >> 6) & 0x3f));
178        put_queue(0x80 | (c & 0x3f));
179    }
180    /* UTF-8 is defined for words of up to 31 bits,
181       but we need only 16 bits here */
182}
183
184/*
185 * Translation of escaped scancodes to keycodes.
186 * This is now user-settable (for machines were it makes sense).
187 */
188
189int setkeycode(unsigned int scancode, unsigned int keycode)
190{
191    return kbd_setkeycode(scancode, keycode);
192}
193
194int getkeycode(unsigned int scancode)
195{
196    return kbd_getkeycode(scancode);
197}
198
199void handle_scancode(unsigned char scancode, int down)
200{
201        unsigned char keycode;
202        char up_flag = down ? 0 : 0200;
203        char raw_mode;
204
205        mark_bh(CONSOLE_BH);
206
207#if 0
208        tty = ttytab? ttytab[fg_console]: NULL;
209        if (tty && (!tty->driver_data)) {
210                /*
211                 * We touch the tty structure via the the ttytab array
212                 * without knowing whether or not tty is open, which
213                 * is inherently dangerous.  We currently rely on that
214                 * fact that console_open sets tty->driver_data when
215                 * it opens it, and clears it when it closes it.
216                 */
217                tty = NULL;
218        }
219#endif
220
221        kbd = kbd_table + fg_console;
222        if ((raw_mode = (kbd->kbdmode == VC_RAW))) {
223                put_queue(scancode | up_flag);
224                /* we do not return yet, because we want to maintain
225                   the key_down array, so that we have the correct
226                   values when finishing RAW mode or when changing VT's */
227        }
228
229        /*
230         *  Convert scancode to keycode
231         */
232        if (!kbd_translate(scancode, &keycode, raw_mode))
233            return;
234
235        /*
236         * At this point the variable `keycode' contains the keycode.
237         * Note: the keycode must not be 0 (++Geert: on m68k 0 is valid).
238         * We keep track of the up/down status of the key, and
239         * return the keycode if in MEDIUMRAW mode.
240         */
241
242        if (up_flag) {
243                rep = 0;
244                if(!test_and_clear_bit(keycode, key_down))
245                    up_flag = kbd_unexpected_up(keycode);
246        } else
247                rep = test_and_set_bit(keycode, key_down);
248
249#ifdef CONFIG_MAGIC_SYSRQ               /* Handle the SysRq Hack */
250        if (keycode == SYSRQ_KEY) {
251                sysrq_pressed = !up_flag;
252                return;
253        } else if (sysrq_pressed) {
254                if (!up_flag && sysrq_enabled)
255                        handle_sysrq(kbd_sysrq_xlate[keycode], kbd_pt_regs, kbd, tty);
256                return;
257        }
258#endif
259
260        if (kbd->kbdmode == VC_MEDIUMRAW) {
261                /* soon keycodes will require more than one byte */
262                put_queue(keycode + up_flag);
263                raw_mode = 1;   /* Most key classes will be ignored */
264        }
265        /*
266         * Small change in philosophy: earlier we defined repetition by
267         *       rep = keycode == prev_keycode;
268         *       prev_keycode = keycode;
269         * but now by the fact that the depressed key was down already.
270         * Does this ever make a difference? Yes.
271         */
272
273        /*
274         *  Repeat a key only if the input buffers are empty or the
275         *  characters get echoed locally. This makes key repeat usable
276         *  with slow applications and under heavy loads.
277         */
278        if (!rep || vc_kbd_mode(kbd,VC_REPEAT) ) {
279/*
280        ||  (vc_kbd_mode(kbd,VC_REPEAT) && tty &&
281             (L_ECHO(tty) || (tty->driver.chars_in_buffer(tty) == 0)))) {
282*/
283                u_short keysym;
284                u_char type;
285
286                /* the XOR below used to be an OR */
287                int shift_final = shift_state ^ kbd->lockstate ^ kbd->slockstate;
288                ushort *key_map = key_maps[shift_final];
289
290                if (key_map != NULL) {
291                        keysym = key_map[keycode];
292                        type = KTYP(keysym);
293
294                        if (type >= 0xf0) {
295                            type -= 0xf0;
296                            if (raw_mode && ! (TYPES_ALLOWED_IN_RAW_MODE & (1 << type)))
297                                return;
298                    if (type == KT_LETTER) {
299                                type = KT_LATIN;
300                                if (vc_kbd_led(kbd, VC_CAPSLOCK)) {
301                                    key_map = key_maps[shift_final ^ (1<<KG_SHIFT)];
302                                    if (key_map)
303                                      keysym = key_map[keycode];
304                                }
305                            }
306
307                            (*key_handler[type])(keysym & 0xff, up_flag);
308
309                            if (type != KT_SLOCK)
310                              kbd->slockstate = 0;
311
312                        } else {
313                            /* maybe only if (kbd->kbdmode == VC_UNICODE) ? */
314                            if (!up_flag && !raw_mode)
315                              to_utf8(keysym);
316                        }
317                } else {
318                        /* maybe beep? */
319                        /* we have at least to update shift_state */
320#if 1                   /* how? two almost equivalent choices follow */
321                        compute_shiftstate();
322#else
323                        keysym = U(plain_map[keycode]);
324                        type = KTYP(keysym);
325                        if (type == KT_SHIFT)
326                          (*key_handler[type])(keysym & 0xff, up_flag);
327#endif
328                }
329        }
330}
331
332static void ( *driver_input_handler_kbd )( void *, unsigned short, unsigned long ) = 0;
333/*
334 */
335void kbd_set_driver_handler( void ( *handler )( void *, unsigned short, unsigned long ) )
336{
337  driver_input_handler_kbd = handler;
338}
339
340static void put_queue(int ch)
341{
342  if( driver_input_handler_kbd )
343  {
344     driver_input_handler_kbd(  ( void *)kbd, (unsigned short)ch,  0 );
345  }
346  else
347  {
348     add_to_queue( ch );
349  }
350}
351
352static void puts_queue(char *cp)
353{
354        while (*cp) {
355     put_queue( *cp );
356                cp++;
357        }
358}
359
360static void applkey(int key, char mode)
361{
362        static char buf[] = { 0x1b, 'O', 0x00, 0x00 };
363
364        buf[1] = (mode ? 'O' : '[');
365        buf[2] = key;
366        puts_queue(buf);
367}
368
369static void enter(void)
370{
371        if (diacr) {
372                put_queue(diacr);
373                diacr = 0;
374        }
375        put_queue(13);
376
377        if (vc_kbd_mode(kbd,VC_CRLF))
378                put_queue(10);
379
380}
381
382static void caps_toggle(void)
383{
384        if (rep)
385                return;
386        chg_vc_kbd_led(kbd, VC_CAPSLOCK);
387}
388
389static void caps_on(void)
390{
391        if (rep)
392                return;
393        set_vc_kbd_led(kbd, VC_CAPSLOCK);
394}
395
396static void show_ptregs(void)
397{
398}
399
400static void hold(void)
401{
402        if (rep )
403                return;
404   chg_vc_kbd_led(kbd, VC_SCROLLOCK );
405
406}
407
408static void num(void)
409{
410
411        if (vc_kbd_mode(kbd,VC_APPLIC))
412                applkey('P', 1);
413        else
414                bare_num();
415}
416
417/*
418 * Bind this to Shift-NumLock if you work in application keypad mode
419 * but want to be able to change the NumLock flag.
420 * Bind this to NumLock if you prefer that the NumLock key always
421 * changes the NumLock flag.
422 */
423static void bare_num(void)
424{
425        if (!rep)
426                chg_vc_kbd_led(kbd,VC_NUMLOCK);
427}
428
429static void lastcons(void)
430{
431}
432
433static void decr_console(void)
434{
435}
436
437static void incr_console(void)
438{
439}
440
441static void send_intr(void)
442{
443}
444
445static void scroll_forw(void)
446{
447}
448
449static void scroll_back(void)
450{
451}
452
453static void boot_it(void)
454{
455   printk( "boot_it() " );
456   rtemsReboot();
457}
458
459static void compose(void)
460{
461        dead_key_next = 1;
462}
463
464int spawnpid, spawnsig;
465
466static void spawn_console(void)
467{
468}
469
470static void SAK(void)
471{
472}
473
474static void do_ignore(unsigned char value, char up_flag)
475{
476}
477
478static void do_null()
479{
480        compute_shiftstate();
481}
482
483static void do_spec(unsigned char value, char up_flag)
484{
485        if (up_flag)
486                return;
487        if (value >= SIZE(spec_fn_table))
488                return;
489
490        if ((kbd->kbdmode == VC_RAW || kbd->kbdmode == VC_MEDIUMRAW) &&
491            !(SPECIALS_ALLOWED_IN_RAW_MODE & (1 << value)))
492                return;
493
494        spec_fn_table[value]();
495}
496
497static void do_lowercase(unsigned char value, char up_flag)
498{
499}
500
501static void do_self(unsigned char value, char up_flag)
502{
503        if (up_flag)
504                return;         /* no action, if this is a key release */
505
506        if (diacr)
507                value = handle_diacr(value);
508
509        if (dead_key_next) {
510                dead_key_next = 0;
511                diacr = value;
512                return;
513        }
514        put_queue(value);
515}
516
517#define A_GRAVE  '`'
518#define A_ACUTE  '\''
519#define A_CFLEX  '^'
520#define A_TILDE  '~'
521#define A_DIAER  '"'
522#define A_CEDIL  ','
523static unsigned char ret_diacr[NR_DEAD] =
524        {A_GRAVE, A_ACUTE, A_CFLEX, A_TILDE, A_DIAER, A_CEDIL };
525
526/* Obsolete - for backwards compatibility only */
527static void do_dead(unsigned char value, char up_flag)
528{
529        value = ret_diacr[value];
530   printk( " do_dead( %X ) ", value );
531        do_dead2(value,up_flag);
532}
533
534/*
535 * Handle dead key. Note that we now may have several
536 * dead keys modifying the same character. Very useful
537 * for Vietnamese.
538 */
539static void do_dead2(unsigned char value, char up_flag)
540{
541        if (up_flag)
542                return;
543        diacr = (diacr ? handle_diacr(value) : value);
544}
545
546/*
547 * We have a combining character DIACR here, followed by the character CH.
548 * If the combination occurs in the table, return the corresponding value.
549 * Otherwise, if CH is a space or equals DIACR, return DIACR.
550 * Otherwise, conclude that DIACR was not combining after all,
551 * queue it and return CH.
552 */
553unsigned char handle_diacr(unsigned char ch)
554{
555        int d = diacr;
556        int i;
557
558        diacr = 0;
559
560        for (i = 0; i < accent_table_size; i++) {
561                if (accent_table[i].diacr == d && accent_table[i].base == ch)
562                        return accent_table[i].result;
563        }
564        if (ch == ' ' || ch == d)
565                return d;
566
567        put_queue(d);
568        return ch;
569}
570
571static void do_cons(unsigned char value, char up_flag)
572{
573        if (up_flag)
574                return;
575}
576
577static void do_fn(unsigned char value, char up_flag)
578{
579        if (up_flag)
580                return;
581
582        if (value < SIZE(func_table)) {
583                if (func_table[value])
584                        puts_queue(func_table[value]);
585        } else
586                printk( "do_fn called with value=%d\n", value);
587}
588
589static void do_pad(unsigned char value, char up_flag)
590{
591        static const char *pad_chars = "0123456789+-*/\015,.?()";
592        static const char *app_map = "pqrstuvwxylSRQMnnmPQ";
593
594        if (up_flag)
595                return;         /* no action, if this is a key release */
596
597        /* kludge... shift forces cursor/number keys */
598        if (vc_kbd_mode(kbd,VC_APPLIC) && !k_down[KG_SHIFT]) {
599                applkey(app_map[value], 1);
600                return;
601        }
602        if (!vc_kbd_led(kbd,VC_NUMLOCK))
603                switch (value) {
604                        case KVAL(K_PCOMMA):
605                        case KVAL(K_PDOT):
606                                do_fn(KVAL(K_REMOVE), 0);
607                                return;
608                        case KVAL(K_P0):
609                                do_fn(KVAL(K_INSERT), 0);
610                                return;
611                        case KVAL(K_P1):
612                                do_fn(KVAL(K_SELECT), 0);
613                                return;
614                        case KVAL(K_P2):
615                                do_cur(KVAL(K_DOWN), 0);
616                                return;
617                        case KVAL(K_P3):
618                                do_fn(KVAL(K_PGDN), 0);
619                                return;
620                        case KVAL(K_P4):
621                                do_cur(KVAL(K_LEFT), 0);
622                                return;
623                        case KVAL(K_P6):
624                                do_cur(KVAL(K_RIGHT), 0);
625                                return;
626                        case KVAL(K_P7):
627                                do_fn(KVAL(K_FIND), 0);
628                                return;
629                        case KVAL(K_P8):
630                                do_cur(KVAL(K_UP), 0);
631                                return;
632                        case KVAL(K_P9):
633                                do_fn(KVAL(K_PGUP), 0);
634                                return;
635                        case KVAL(K_P5):
636                                applkey('G', vc_kbd_mode(kbd, VC_APPLIC));
637                                return;
638                }
639
640        put_queue(pad_chars[value]);
641
642        if (value == KVAL(K_PENTER) && vc_kbd_mode(kbd, VC_CRLF))
643                put_queue(10);
644
645}
646
647static void do_cur(unsigned char value, char up_flag)
648{
649        static const char *cur_chars = "BDCA";
650        if (up_flag)
651                return;
652
653  applkey(cur_chars[value], vc_kbd_mode(kbd,VC_CKMODE));
654}
655
656static void do_shift(unsigned char value, char up_flag)
657{
658        int old_state = shift_state;
659
660        if (rep)
661                return;
662
663        /* Mimic typewriter:
664           a CapsShift key acts like Shift but undoes CapsLock */
665        if (value == KVAL(K_CAPSSHIFT)) {
666                value = KVAL(K_SHIFT);
667                if (!up_flag)
668                        clr_vc_kbd_led(kbd, VC_CAPSLOCK);
669        }
670
671        if (up_flag) {
672                /* handle the case that two shift or control
673                   keys are depressed simultaneously */
674                if (k_down[value])
675                        k_down[value]--;
676        } else
677                k_down[value]++;
678
679        if (k_down[value])
680                shift_state |= (1 << value);
681        else
682                shift_state &= ~ (1 << value);
683
684        /* kludge */
685        if (up_flag && shift_state != old_state && npadch != -1) {
686                if (kbd->kbdmode == VC_UNICODE)
687                  to_utf8(npadch & 0xffff);
688                else
689           put_queue(npadch & 0xff);
690                npadch = -1;
691        }
692}
693
694/* called after returning from RAW mode or when changing consoles -
695   recompute k_down[] and shift_state from key_down[] */
696/* maybe called when keymap is undefined, so that shiftkey release is seen */
697void compute_shiftstate(void)
698{
699        int i, j, k, sym, val;
700
701        shift_state = 0;
702        for(i=0; i < SIZE(k_down); i++)
703          k_down[i] = 0;
704
705        for(i=0; i < SIZE(key_down); i++)
706          if(key_down[i]) {     /* skip this word if not a single bit on */
707            k = i*BITS_PER_LONG;
708            for(j=0; j<BITS_PER_LONG; j++,k++)
709              if(test_bit(k, key_down)) {
710                sym = U(plain_map[k]);
711                if(KTYP(sym) == KT_SHIFT) {
712                  val = KVAL(sym);
713                  if (val == KVAL(K_CAPSSHIFT))
714                    val = KVAL(K_SHIFT);
715                  k_down[val]++;
716                  shift_state |= (1<<val);
717                }
718              }
719          }
720}
721
722static void do_meta(unsigned char value, char up_flag)
723{
724        if (up_flag)
725                return;
726
727        if (vc_kbd_mode(kbd, VC_META)) {
728                put_queue('\033');
729                put_queue(value);
730        } else
731                put_queue(value | 0x80);
732}
733
734static void do_ascii(unsigned char value, char up_flag)
735{
736        int base;
737
738        if (up_flag)
739                return;
740
741        if (value < 10)    /* decimal input of code, while Alt depressed */
742            base = 10;
743        else {       /* hexadecimal input of code, while AltGr depressed */
744            value -= 10;
745            base = 16;
746        }
747
748        if (npadch == -1)
749          npadch = value;
750        else
751          npadch = npadch * base + value;
752}
753
754static void do_lock(unsigned char value, char up_flag)
755{
756        if (up_flag || rep)
757                return;
758        chg_vc_kbd_lock(kbd, value);
759}
760
761static void do_slock(unsigned char value, char up_flag)
762{
763        if (up_flag || rep)
764                return;
765
766  chg_vc_kbd_slock(kbd, value);
767}
768
769/*
770 * The leds display either (i) the status of NumLock, CapsLock, ScrollLock,
771 * or (ii) whatever pattern of lights people want to show using KDSETLED,
772 * or (iii) specified bits of specified words in kernel memory.
773 */
774
775static unsigned char ledstate = 0xff; /* undefined */
776static unsigned char ledioctl;
777
778unsigned char getledstate(void) {
779    return ledstate;
780}
781
782void setledstate(struct kbd_struct *kbd, unsigned int led) {
783    if (!(led & ~7)) {
784        ledioctl = led;
785         kbd->ledmode = LED_SHOW_IOCTL;
786    } else
787    ;
788         kbd->ledmode = LED_SHOW_FLAGS;
789    set_leds();
790}
791
792static struct ledptr {
793    unsigned int *addr;
794    unsigned int mask;
795    unsigned char valid:1;
796} ledptrs[3];
797
798void register_leds(int console, unsigned int led,
799                   unsigned int *addr, unsigned int mask) {
800    struct kbd_struct *kbd = kbd_table + console;
801
802   if (led < 3) {
803        ledptrs[led].addr = addr;
804        ledptrs[led].mask = mask;
805        ledptrs[led].valid = 1;
806        kbd->ledmode = LED_SHOW_MEM;
807    } else
808        kbd->ledmode = LED_SHOW_FLAGS;
809}
810
811static inline unsigned char getleds(void){
812
813    struct kbd_struct *kbd = kbd_table + fg_console;
814
815    unsigned char leds;
816
817    if (kbd->ledmode == LED_SHOW_IOCTL)
818      return ledioctl;
819    leds = kbd->ledflagstate;
820    if (kbd->ledmode == LED_SHOW_MEM) {
821        if (ledptrs[0].valid) {
822            if (*ledptrs[0].addr & ledptrs[0].mask)
823              leds |= 1;
824            else
825              leds &= ~1;
826        }
827        if (ledptrs[1].valid) {
828            if (*ledptrs[1].addr & ledptrs[1].mask)
829              leds |= 2;
830            else
831              leds &= ~2;
832        }
833        if (ledptrs[2].valid) {
834            if (*ledptrs[2].addr & ledptrs[2].mask)
835              leds |= 4;
836            else
837              leds &= ~4;
838        }
839    }
840   return leds;
841}
842
843/*
844 * This routine is the bottom half of the keyboard interrupt
845 * routine, and runs with all interrupts enabled. It does
846 * console changing, led setting and copy_to_cooked, which can
847 * take a reasonably long time.
848 *
849 * Aside from timing (which isn't really that important for
850 * keyboard interrupts as they happen often), using the software
851 * interrupt routines for this thing allows us to easily mask
852 * this when we don't want any of the above to happen. Not yet
853 * used, but this allows for easy and efficient race-condition
854 * prevention later on.
855 */
856static void kbd_bh(void)
857{
858        unsigned char leds = getleds();
859        if (leds != ledstate) {
860                ledstate = leds;
861                kbd_leds(leds);
862        }
863}
864
865void set_leds(void)
866{
867  kbd_bh();
868}
869
870int kbd_init(void)
871{
872
873        int i;
874        struct kbd_struct kbd0;
875        kbd0.ledflagstate = kbd0.default_ledflagstate = KBD_DEFLEDS;
876   kbd0.ledmode = LED_SHOW_MEM;
877        kbd0.lockstate = KBD_DEFLOCK;
878        kbd0.slockstate = 0;
879        kbd0.modeflags = KBD_DEFMODE;
880        kbd0.kbdmode = VC_XLATE;
881
882        for (i = 0 ; i < MAX_NR_CONSOLES ; i++)
883                kbd_table[i] = kbd0;
884
885        kbd_init_hw();
886        mark_bh(KEYBOARD_BH);
887        return 0;
888}
Note: See TracBrowser for help on using the repository browser.