TODO list updates.
[seabios.git] / src / kbd.c
index 3af70337abac7026888308a536cd72e1d9e179d1..4c43c317e670a25aa952ee4b48f59ab68f11277f 100644 (file)
--- a/src/kbd.c
+++ b/src/kbd.c
@@ -3,7 +3,7 @@
 // Copyright (C) 2008  Kevin O'Connor <kevin@koconnor.net>
 // Copyright (C) 2002  MandrakeSoft S.A.
 //
-// This file may be distributed under the terms of the GNU GPLv3 license.
+// This file may be distributed under the terms of the GNU LGPLv3 license.
 
 #include "biosvar.h" // GET_BDA
 #include "util.h" // debug_enter
 static void
 keyboard_init()
 {
-    if (CONFIG_COREBOOT)
-        // Coreboot already does low-level keyboard init.
-        goto end;
-
     /* flush incoming keys */
     int ret = i8042_flush();
     if (ret)
@@ -55,7 +51,7 @@ keyboard_init()
     /* ------------------- keyboard side ------------------------*/
     /* reset keyboard and self test  (keyboard side) */
     ret = kbd_command(ATKBD_CMD_RESET_BAT, param);
-    if (ret != 0 && ret != 2)
+    if (ret)
         return;
     if (param[0] != 0xaa) {
         dprintf(1, "keyboard self test failed (got %x not 0xaa)\n", param[0]);
@@ -67,7 +63,12 @@ keyboard_init()
     if (ret)
         return;
 
-end:
+    // Set scancode command (mode 2)
+    param[0] = 0x02;
+    ret = kbd_command(ATKBD_CMD_SSCANSET, param);
+    if (ret)
+        return;
+
     // Keyboard Mode: scan code convert, disable mouse, enable IRQ 1
     SET_EBDA(ps2ctr, I8042_CTR_AUXDIS | I8042_CTR_XLATE | I8042_CTR_KBDINT);
 
@@ -83,7 +84,7 @@ void
 kbd_setup()
 {
     dprintf(3, "init keyboard\n");
-    u16 x = offsetof(struct bios_data_area_s, kbd_buf) - 0x400;
+    u16 x = offsetof(struct bios_data_area_s, kbd_buf);
     SET_BDA(kbd_mode, 0x10);
     SET_BDA(kbd_buf_head, x);
     SET_BDA(kbd_buf_tail, x);
@@ -117,8 +118,8 @@ enqueue_key(u8 scan_code, u8 ascii_code)
     if (buffer_tail == buffer_head)
         return 0;
 
-    SET_FARVAR(SEG_BDA, *(u8*)(temp_tail+0x400+0), ascii_code);
-    SET_FARVAR(SEG_BDA, *(u8*)(temp_tail+0x400+1), scan_code);
+    SET_FARVAR(SEG_BDA, *(u8*)(temp_tail+0), ascii_code);
+    SET_FARVAR(SEG_BDA, *(u8*)(temp_tail+1), scan_code);
     SET_BDA(kbd_buf_tail, buffer_tail);
     return 1;
 }
@@ -141,8 +142,8 @@ dequeue_key(struct bregs *regs, int incr, int extended)
         cpu_relax();
     }
 
-    u8 ascii_code = GET_FARVAR(SEG_BDA, *(u8*)(buffer_head+0x400+0));
-    u8 scan_code  = GET_FARVAR(SEG_BDA, *(u8*)(buffer_head+0x400+1));
+    u8 ascii_code = GET_FARVAR(SEG_BDA, *(u8*)(buffer_head+0));
+    u8 scan_code  = GET_FARVAR(SEG_BDA, *(u8*)(buffer_head+1));
     if ((ascii_code == 0xF0 && scan_code != 0)
         || (ascii_code == 0xE0 && !extended))
         ascii_code = 0;
@@ -551,9 +552,11 @@ process_key(u8 scancode)
         if (scancode & 0x80)
             // toss key releases
             break;
-        if (scancode == 0x53 && (shift_flags & 0x0c) == 0x0c)
+        if (scancode == 0x53 && (shift_flags & 0x0c) == 0x0c) {
             // Ctrl+alt+del - reset machine.
+            SET_BDA(soft_reset_flag, 0x1234);
             reset_vector();
+        }
         if (scancode > MAX_SCAN_CODE) {
             dprintf(1, "KBD: int09h_handler(): unknown scancode read: 0x%02x!\n"
                     , scancode);
@@ -617,8 +620,8 @@ handle_09()
 
     // read key from keyboard controller
     u8 v = inb(PORT_PS2_STATUS);
-    if ((v & 0x21) != 0x01) {
-        dprintf(1, "int09 but no keyboard data.\n");
+    if ((v & (I8042_STR_OBF|I8042_STR_AUXDATA)) != I8042_STR_OBF) {
+        dprintf(1, "keyboard irq but no keyboard data.\n");
         goto done;
     }
     u8 key = inb(PORT_PS2_DATA);