Compare commits

..

No commits in common. "df9d4e1a269721b30c02a2ce789bc6dd732793d3" and "766fc0f052c2050b13fee6b39e79d82b8a3b8988" have entirely different histories.

2 changed files with 18 additions and 39 deletions

View file

@ -1,5 +1,3 @@
set timeout=2
menuentry "ps2 kbtest" { menuentry "ps2 kbtest" {
multiboot /boot/ps2-kbtest.kernel multiboot /boot/ps2-kbtest.kernel
} }

View file

@ -178,18 +178,14 @@ void write_config_8042(uint8_t config) {
write_8042(config); write_8042(config);
} }
void flush_buffer() {
while (status_8042() & (1<<0))
(void) read_8042();
}
void init_8042(void) { void init_8042(void) {
// Disable devices // Disable devices
command_8042(0xad); command_8042(0xad);
command_8042(0xa7); command_8042(0xa7);
// Flush output buffer // Flush output buffer
flush_buffer(); while (status_8042() & (1<<0))
(void) read_8042();
// Read configuration // Read configuration
uint8_t config = read_config_8042(); uint8_t config = read_config_8042();
@ -266,30 +262,31 @@ uint8_t read_keyboard(void) {
} }
void enable_scanning(void) { void enable_scanning(void) {
flush_buffer();
write_8042(0xf4); write_8042(0xf4);
if (read_keyboard() != 0xfa) if (read_keyboard() != 0xfa)
terminal_writestring("Enabling scanning failed\n"); terminal_writestring("Enabling scanning failed\n");
while (status_8042() & (1<<0))
(void) read_8042();
} }
void disable_scanning(void) { void disable_scanning(void) {
flush_buffer();
write_8042(0xf5); write_8042(0xf5);
if (read_keyboard() != 0xfa) if (read_keyboard() != 0xfa)
terminal_writestring("Disabling scanning failed\n"); terminal_writestring("Disabling scanning failed\n");
while (status_8042() & (1<<0))
(void) read_8042();
} }
void set_scancode_set(uint8_t set) { void set_scancode_set(uint8_t set) {
flush_buffer();
write_8042(0xf0); write_8042(0xf0);
write_8042(set); write_8042(set);
if (read_keyboard() != 0xfa) if (read_keyboard() != 0xfa)
terminal_writestring("Setting scancode set failed\n"); terminal_writestring("Setting scancode set failed\n");
flush_buffer(); while (status_8042() & (1<<0))
(void) read_8042();
} }
uint8_t get_scancode_set(void) { uint8_t get_scancode_set(void) {
flush_buffer();
write_8042(0xf0); write_8042(0xf0);
write_8042(0); write_8042(0);
if (read_keyboard() != 0xfa) if (read_keyboard() != 0xfa)
@ -307,7 +304,7 @@ void print_key(uint8_t code) {
switch (code) { switch (code) {
case KEY_A_SET1: terminal_writestring("Set 1 A"); break; case KEY_A_SET1: terminal_writestring("Set 1 A"); break;
case KEY_A_SET2: terminal_writestring("Set 2 A"); break; case KEY_A_SET2: terminal_writestring("Set 2 A"); break;
case KEY_A_MISINTERPRET: terminal_writestring("Set 1 A misinterpreted as set 2 2"); break; case KEY_A_MISINTERPRET: terminal_writestring("Set 1 A misinterpreted as set 2 A"); break;
default: default:
terminal_writestring("Unknown byte "); terminal_writestring("Unknown byte ");
terminal_writehex(code); terminal_writehex(code);
@ -318,7 +315,6 @@ void print_key(uint8_t code) {
void key_prompt(uint8_t expect) { void key_prompt(uint8_t expect) {
enable_scanning(); enable_scanning();
terminal_writestring("Press A... "); terminal_writestring("Press A... ");
flush_buffer();
uint8_t code = read_keyboard(); uint8_t code = read_keyboard();
if ( code == expect ) if ( code == expect )
terminal_setcolor(vga_entry_color(VGA_COLOR_GREEN, VGA_COLOR_BLACK)); terminal_setcolor(vga_entry_color(VGA_COLOR_GREEN, VGA_COLOR_BLACK));
@ -342,54 +338,39 @@ void kernel_main(void)
init_8042(); init_8042();
terminal_writestring("Assuming keyboard is channel 1\n"); terminal_writestring("Assuming keyboard is channel 1\n");
terminal_setcolor(vga_entry_color(VGA_COLOR_BROWN, VGA_COLOR_BLACK));
terminal_writestring("\nNOTE: ");
terminal_setcolor(vga_entry_color(VGA_COLOR_LIGHT_GREY, VGA_COLOR_BLACK));
terminal_writestring("If getting scancode set seems to hang, tap the 'A' key.\n");
terminal_writestring("\nTranslation initially "); terminal_writestring("\nTranslation initially ");
if (translation_initially) if (translation_initially)
terminal_writestring("on, scancode set initially set to... "); terminal_writestring("on\n");
else else
terminal_writestring("off, scancode set initially set to... "); terminal_writestring("off\n");
terminal_writehex(get_scancode_set());
terminal_writestring("\n");
key_prompt(translation_initially ? KEY_A_SET1 : KEY_A_SET2); key_prompt(translation_initially ? KEY_A_SET1 : KEY_A_SET2);
disable_translation(); disable_translation();
terminal_writestring("\nTranslation off, scancode set initially set to... "); terminal_writestring("\nTranslation off, scancode set initially ");
uint8_t initial_scancode = get_scancode_set(); uint8_t initial_scancode = get_scancode_set();
terminal_writehex(initial_scancode); terminal_writehex(initial_scancode);
terminal_writestring("\n"); terminal_writestring("\n");
key_prompt(initial_scancode == 1 ? KEY_A_SET1 : KEY_A_SET2); key_prompt(initial_scancode == 1 ? KEY_A_SET1 : KEY_A_SET2);
terminal_writestring("Translation off, trying set 1... ");
set_scancode_set(1); set_scancode_set(1);
terminal_writestring("scancode set set to... "); terminal_writestring("Translation off, trying set 1... scancode set set to ");
terminal_writehex(get_scancode_set()); terminal_writehex(get_scancode_set());
terminal_writestring("\n"); terminal_writestring("\n");
key_prompt(KEY_A_SET1); key_prompt(KEY_A_SET1);
terminal_writestring("Translation off, trying set 2... ");
set_scancode_set(2); set_scancode_set(2);
terminal_writestring("scancode set set to... "); terminal_writestring("Translation off, trying set 2... scancode set set to ");
terminal_writehex(get_scancode_set()); terminal_writehex(get_scancode_set());
terminal_writestring("\n"); terminal_writestring("\n");
key_prompt(KEY_A_SET2); key_prompt(KEY_A_SET2);
enable_translation();
terminal_writestring("\nTranslation on, trying set 1... ");
set_scancode_set(1); set_scancode_set(1);
terminal_writestring("scancode set set to... "); enable_translation();
terminal_writehex(get_scancode_set()); terminal_writestring("\nTranslation on, trying set 1\n");
terminal_writestring("\n");
key_prompt(KEY_A_MISINTERPRET); key_prompt(KEY_A_MISINTERPRET);
terminal_writestring("Translation on, trying set 2... ");
set_scancode_set(2); set_scancode_set(2);
terminal_writestring("scancode set set to... "); terminal_writestring("Translation on, trying set 2\n");
terminal_writehex(get_scancode_set());
terminal_writestring("\n");
key_prompt(KEY_A_SET1); key_prompt(KEY_A_SET1);
terminal_writestring("\nHanging\n"); terminal_writestring("\nHanging\n");