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

4.115
Last change on this file since 1c0b8d7 was 1fef02ca, checked in by Joel Sherrill <joel.sherrill@…>, on 03/14/11 at 14:57:00

2011-03-14 Joel Sherrill <joel.sherrill@…>

PR 1762/cpukit

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