/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2007,2008,2009 Free Software Foundation, Inc.
*
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/at_keyboard.h>
#include <grub/keyboard_layouts.h>
GRUB_MOD_LICENSE ("GPLv3+");
static short at_keyboard_status = 0;
static int e0_received = 0;
static int f0_received = 0;
{
/* 0x54 */ 0, 0,
/* 0x58 */ GRUB_KEYBOARD_KEY_F12, 0,
/* 0x5a */ 0, 0,
/* 0x5c */ 0, 0,
/* 0x5e */ 0, 0,
/* 0x60 */ 0, 0,
/* 0x62 */ 0, 0,
/* OLPC keys. Just mapped to normal keys. */
/* 0x64 */ 0, GRUB_KEYBOARD_KEY_UP,
/* 0x68 */ GRUB_KEYBOARD_KEY_RIGHT
};
static const struct
{
} set1_e0_mapping[] =
{
{0x1c, GRUB_KEYBOARD_KEY_NUMENTER},
{0x1d, GRUB_KEYBOARD_KEY_RIGHT_CTRL},
{0x35, GRUB_KEYBOARD_KEY_NUMSLASH },
{0x38, GRUB_KEYBOARD_KEY_RIGHT_ALT},
{0x47, GRUB_KEYBOARD_KEY_HOME},
{0x48, GRUB_KEYBOARD_KEY_UP},
{0x49, GRUB_KEYBOARD_KEY_PPAGE},
{0x4b, GRUB_KEYBOARD_KEY_LEFT},
{0x4d, GRUB_KEYBOARD_KEY_RIGHT},
{0x4f, GRUB_KEYBOARD_KEY_END},
{0x50, GRUB_KEYBOARD_KEY_DOWN},
{0x51, GRUB_KEYBOARD_KEY_NPAGE},
{0x52, GRUB_KEYBOARD_KEY_INSERT},
{0x53, GRUB_KEYBOARD_KEY_DELETE},
};
{
/* 0x00 */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UB_KEYBOARD_KEY_SCROLL_LOCK, 0,
/* 0x80 */ 0, 0,
/* 0x82 */ 0, GRUB_KEYBOARD_KEY_F7,
};
static const struct
{
} set2_e0_mapping[] =
{
{0x11, GRUB_KEYBOARD_KEY_RIGHT_ALT},
{0x14, GRUB_KEYBOARD_KEY_RIGHT_CTRL},
{0x4a, GRUB_KEYBOARD_KEY_NUMSLASH},
{0x5a, GRUB_KEYBOARD_KEY_NUMENTER},
{0x69, GRUB_KEYBOARD_KEY_END},
{0x6b, GRUB_KEYBOARD_KEY_LEFT},
{0x6c, GRUB_KEYBOARD_KEY_HOME},
{0x70, GRUB_KEYBOARD_KEY_INSERT},
{0x71, GRUB_KEYBOARD_KEY_DELETE},
{0x72, GRUB_KEYBOARD_KEY_DOWN},
{0x74, GRUB_KEYBOARD_KEY_RIGHT},
{0x75, GRUB_KEYBOARD_KEY_UP},
{0x7a, GRUB_KEYBOARD_KEY_NPAGE},
{0x7d, GRUB_KEYBOARD_KEY_PPAGE},
};
static void
{
}
static grub_uint8_t
wait_ack (void)
{
do
&& grub_get_time_ms () < endtime);
return ack;
}
static int
{
unsigned i;
for (i = 0; i < GRUB_AT_TRIES; i++)
{
if (ack == GRUB_AT_NACK)
continue;
if (ack == GRUB_AT_ACK)
break;
return 0;
}
return (i != GRUB_AT_TRIES);
}
static void
{
grub_outb (c, KEYBOARD_REG_DATA);
}
#if !defined (GRUB_MACHINE_MIPS_LOONGSON) && !defined (GRUB_MACHINE_QEMU) && !defined (GRUB_MACHINE_MIPS_QEMU_MIPS)
static grub_uint8_t
{
return grub_inb (KEYBOARD_REG_DATA);
}
#endif
static int
{
unsigned i;
for (i = 0; i < GRUB_AT_TRIES; i++)
{
if (ack == GRUB_AT_NACK)
continue;
if (ack == GRUB_AT_ACK)
break;
return 0;
}
return (i != GRUB_AT_TRIES);
}
static int
query_mode (void)
{
int e;
e = write_mode (0);
if (!e)
return 0;
do
while (ret == GRUB_AT_ACK);
/* QEMU translates the set even in no-translate mode. */
return 1;
return 2;
return 3;
return 0;
}
static void
set_scancodes (void)
{
/* You must have visited computer museum. Keyboard without scancode set
knowledge. Assume XT. */
if (!grub_keyboard_orig_set)
{
current_set = 1;
return;
}
#if !(defined (GRUB_MACHINE_MIPS_LOONGSON) || defined (GRUB_MACHINE_QEMU) || defined (GRUB_MACHINE_MIPS_QEMU_MIPS))
current_set = 1;
return;
#else
write_mode (2);
current_set = query_mode ();
if (current_set == 2)
return;
write_mode (1);
current_set = query_mode ();
if (current_set == 1)
return;
grub_printf ("No supported scancode set found\n");
#endif
}
static void
{
}
static int
{
int was_ext = 0;
int ret = 0;
return -1;
if (at_key == 0xe0)
{
e0_received = 1;
return -1;
}
{
f0_received = 1;
return -1;
}
/* Setting LEDs may generate ACKs. */
if (at_key == GRUB_AT_ACK)
return -1;
e0_received = 0;
switch (current_set)
{
case 1:
if (!was_ext)
else
{
unsigned i;
for (i = 0; i < ARRAY_SIZE (set1_e0_mapping); i++)
{
break;
}
}
break;
case 2:
*is_break = f0_received;
f0_received = 0;
if (!was_ext)
else
{
unsigned i;
for (i = 0; i < ARRAY_SIZE (set2_e0_mapping); i++)
{
break;
}
}
break;
default:
return -1;
}
if (!ret)
{
if (was_ext)
else
return -1;
}
return ret;
}
/* FIXME: This should become an interrupt service routine. For now
it's just used to catch events from control keys. */
static int
{
if (!is_break)
switch (key)
{
return 1;
return 1;
return 1;
return 1;
return 1;
return 1;
default:
return 0;
}
else
switch (key)
{
return 1;
return 1;
return 1;
return 1;
return 1;
return 1;
default:
return 0;
}
}
/* If there is a raw key pending, return it; otherwise return -1. */
static int
grub_keyboard_getkey (void)
{
int key;
int is_break = 0;
if (key == -1)
return -1;
return -1;
if (is_break)
return -1;
return key;
}
/* If there is a character pending, return it;
otherwise return GRUB_TERM_NO_KEY. */
static int
{
int code;
code = grub_keyboard_getkey ();
if (code == -1)
return GRUB_TERM_NO_KEY;
#ifdef DEBUG_AT_KEYBOARD
#endif
switch (code)
{
#ifdef DEBUG_AT_KEYBOARD
#endif
return GRUB_TERM_NO_KEY;
#ifdef DEBUG_AT_KEYBOARD
#endif
return GRUB_TERM_NO_KEY;
return GRUB_TERM_NO_KEY;
default:
}
}
static grub_err_t
{
at_keyboard_status = 0;
/* Drain input buffer. */
while (1)
{
break;
}
#if defined (GRUB_MACHINE_MIPS_LOONGSON) || defined (GRUB_MACHINE_QEMU) || defined (GRUB_MACHINE_MIPS_QEMU_MIPS)
#else
#endif
set_scancodes ();
return GRUB_ERR_NONE;
}
static grub_err_t
{
return GRUB_ERR_NONE;
}
static grub_err_t
{
return grub_keyboard_controller_fini (NULL);
}
static grub_err_t
grub_at_restore_hw (void)
{
/* Drain input buffer. */
while (1)
{
break;
}
set_scancodes ();
return GRUB_ERR_NONE;
}
{
.name = "at_keyboard",
};
{
}
{
}