~ubuntu-branches/ubuntu/jaunty/grub2/jaunty-proposed

« back to all changes in this revision

Viewing changes to term/i386/pc/at_keyboard.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Millan
  • Date: 2008-01-28 00:01:11 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20080128000111-qolpe0u4qkf0xccc
Tags: 1.95+20080128-1
* New CVS snapshot.
  - Fixes bogus CLAIM problems on Apple firmware.  (Closes: #449135, #422729)
  - grub-probe performs sanity checks to make sure our filesystem drivers
    are usable.  (Closes: #462449)
  - patches/disable_ata.diff: Remove.  ATA module isn't auto-loaded in
    rescue floppies now.
  - patches/disable_xfs.diff: Remove.  See above (about grub-probe).
* Bring back grub-emu; it can help a lot with debugging feedback.
  - control
  - rules

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 *  GRUB  --  GRand Unified Bootloader
3
 
 *  Copyright (C) 2007  Free Software Foundation, Inc.
 
3
 *  Copyright (C) 2007,2008  Free Software Foundation, Inc.
4
4
 *
5
5
 *  GRUB is free software: you can redistribute it and/or modify
6
6
 *  it under the terms of the GNU General Public License as published by
37
37
#define KEYBOARD_REG_DATA       0x60
38
38
#define KEYBOARD_REG_STATUS     0x64
39
39
 
 
40
/* Used for sending commands to the controller.  */
 
41
#define KEYBOARD_COMMAND_ISREADY(x)     !((x) & 0x02)
 
42
#define KEYBOARD_COMMAND_READ           0x20
 
43
#define KEYBOARD_COMMAND_WRITE          0x60
 
44
 
 
45
#define KEYBOARD_SCANCODE_SET1          0x40
 
46
 
40
47
#define KEYBOARD_ISMAKE(x)      !((x) & 0x80)
41
48
#define KEYBOARD_ISREADY(x)     (((x) & 0x01) == 0)
42
49
#define KEYBOARD_SCANCODE(x)    ((x) & 0x7f)
73
80
  '2', '3',
74
81
};
75
82
 
 
83
static void
 
84
grub_keyboard_controller_write (grub_uint8_t c)
 
85
{
 
86
  while (! KEYBOARD_COMMAND_ISREADY (grub_inb (KEYBOARD_REG_STATUS)));
 
87
  grub_outb (KEYBOARD_COMMAND_WRITE, KEYBOARD_REG_STATUS);
 
88
  grub_outb (c, KEYBOARD_REG_DATA);
 
89
}
 
90
 
 
91
static grub_uint8_t
 
92
grub_keyboard_controller_read (void)
 
93
{
 
94
  while (! KEYBOARD_COMMAND_ISREADY (grub_inb (KEYBOARD_REG_STATUS)));
 
95
  grub_outb (KEYBOARD_COMMAND_READ, KEYBOARD_REG_STATUS);
 
96
  return grub_inb (KEYBOARD_REG_DATA);
 
97
}
 
98
 
 
99
void
 
100
grub_keyboard_controller_init (void)
 
101
{
 
102
  grub_keyboard_controller_write (grub_keyboard_controller_read () | KEYBOARD_SCANCODE_SET1);
 
103
}
 
104
 
76
105
/* FIXME: This should become an interrupt service routine.  For now
77
106
   it's just used to catch events from control keys.  */
78
107
static void
118
147
          /* Skip grub_dprintf.  */
119
148
          return;
120
149
      }
 
150
#ifdef DEBUG_AT_KEYBOARD
121
151
  grub_dprintf ("atkeyb", "Control key 0x%0x was %s\n", key, is_make ? "pressed" : "unpressed");
 
152
#endif
122
153
}
123
154
 
124
155
/* If there is a raw key pending, return it; otherwise return -1.  */
125
156
static int
126
 
grub_keyboard_getkey ()
 
157
grub_keyboard_getkey (void)
127
158
{
128
159
  grub_uint8_t key;
129
160
  if (KEYBOARD_ISREADY (grub_inb (KEYBOARD_REG_STATUS)))
137
168
 
138
169
/* If there is a character pending, return it; otherwise return -1.  */
139
170
int
140
 
grub_console_checkkey ()
 
171
grub_console_checkkey (void)
141
172
{
142
173
  int key;
143
174
  key = grub_keyboard_getkey ();
144
175
  if (key == -1)
145
176
    return -1;
 
177
#ifdef DEBUG_AT_KEYBOARD
146
178
  grub_dprintf ("atkeyb", "Detected key 0x%x\n", key);
 
179
#endif
147
180
  switch (key)
148
181
    {
149
182
      case CAPS_LOCK:
151
184
          at_keyboard_status &= ~KEYBOARD_STATUS_CAPS_LOCK;
152
185
        else
153
186
          at_keyboard_status |= KEYBOARD_STATUS_CAPS_LOCK;
 
187
#ifdef DEBUG_AT_KEYBOARD
154
188
        grub_dprintf ("atkeyb", "caps_lock = %d\n", !!(at_keyboard_status & KEYBOARD_STATUS_CAPS_LOCK));
 
189
#endif
155
190
        key = -1;
156
191
        break;
157
192
      default:
171
206
}
172
207
 
173
208
int
174
 
grub_console_getkey ()
 
209
grub_console_getkey (void)
175
210
{
176
211
  int key;
177
212
  do