grml...
[seabios.git] / src / mouse.c
index 888d32debf57ad7f1bf594bb39ae3df7bae494fa..e26cf694ca5bcc37791d533c564071f1ee863efd 100644 (file)
@@ -9,7 +9,8 @@
 #include "util.h" // debug_isr
 #include "pic.h" // eoi_pic2
 #include "bregs.h" // struct bregs
-#include "ps2port.h" // aux_command
+#include "ps2port.h" // ps2_mouse_command
+#include "usb-hid.h" // usb_mouse_command
 
 void
 mouse_setup(void)
@@ -21,6 +22,14 @@ mouse_setup(void)
     SETBITS_BDA(equipment_list_flags, 0x04);
 }
 
+static inline int
+mouse_command(int command, u8 *param)
+{
+    if (usb_mouse_active())
+        return usb_mouse_command(command, param);
+    return ps2_mouse_command(command, param);
+}
+
 #define RET_SUCCESS      0x00
 #define RET_EINVFUNCTION 0x01
 #define RET_EINVINPUT    0x02
@@ -28,17 +37,11 @@ mouse_setup(void)
 #define RET_ENEEDRESEND  0x04
 #define RET_ENOHANDLER   0x05
 
-static int
-disable_mouse(void)
-{
-    return aux_command(PSMOUSE_CMD_DISABLE, NULL);
-}
-
 // Disable Mouse
 static void
 mouse_15c20000(struct bregs *regs)
 {
-    int ret = disable_mouse();
+    int ret = mouse_command(PSMOUSE_CMD_DISABLE, NULL);
     if (ret)
         set_code_invalid(regs, RET_ENEEDRESEND);
     else
@@ -55,7 +58,7 @@ mouse_15c20001(struct bregs *regs)
         return;
     }
 
-    int ret = aux_command(PSMOUSE_CMD_ENABLE, NULL);
+    int ret = mouse_command(PSMOUSE_CMD_ENABLE, NULL);
     if (ret)
         set_code_invalid(regs, RET_ENEEDRESEND);
     else
@@ -84,7 +87,7 @@ static void
 mouse_15c201(struct bregs *regs)
 {
     u8 param[2];
-    int ret = aux_command(PSMOUSE_CMD_RESET_BAT, param);
+    int ret = mouse_command(PSMOUSE_CMD_RESET_BAT, param);
     if (ret) {
         set_code_invalid(regs, RET_ENEEDRESEND);
         return;
@@ -104,7 +107,7 @@ mouse_15c202(struct bregs *regs)
         return;
     }
     u8 mouse_data1 = GET_GLOBAL(sample_rates[regs->bh]);
-    int ret = aux_command(PSMOUSE_CMD_SETRATE, &mouse_data1);
+    int ret = mouse_command(PSMOUSE_CMD_SETRATE, &mouse_data1);
     if (ret)
         set_code_invalid(regs, RET_ENEEDRESEND);
     else
@@ -125,7 +128,7 @@ mouse_15c203(struct bregs *regs)
         return;
     }
     u8 param = regs->bh;
-    int ret = aux_command(PSMOUSE_CMD_SETRES, &param);
+    int ret = mouse_command(PSMOUSE_CMD_SETRES, &param);
     if (ret)
         set_code_invalid(regs, RET_ENEEDRESEND);
     else
@@ -137,7 +140,7 @@ static void
 mouse_15c204(struct bregs *regs)
 {
     u8 param[2];
-    int ret = aux_command(PSMOUSE_CMD_GETID, param);
+    int ret = mouse_command(PSMOUSE_CMD_GETID, param);
     if (ret) {
         set_code_invalid(regs, RET_ENEEDRESEND);
         return;
@@ -167,7 +170,7 @@ static void
 mouse_15c20600(struct bregs *regs)
 {
     u8 param[3];
-    int ret = aux_command(PSMOUSE_CMD_GETINFO, param);
+    int ret = mouse_command(PSMOUSE_CMD_GETINFO, param);
     if (ret) {
         set_code_invalid(regs, RET_ENEEDRESEND);
         return;
@@ -182,7 +185,7 @@ mouse_15c20600(struct bregs *regs)
 static void
 mouse_15c20601(struct bregs *regs)
 {
-    int ret = aux_command(PSMOUSE_CMD_SETSCALE11, NULL);
+    int ret = mouse_command(PSMOUSE_CMD_SETSCALE11, NULL);
     if (ret)
         set_code_invalid(regs, RET_ENEEDRESEND);
     else
@@ -193,7 +196,7 @@ mouse_15c20601(struct bregs *regs)
 static void
 mouse_15c20602(struct bregs *regs)
 {
-    int ret = aux_command(PSMOUSE_CMD_SETSCALE21, NULL);
+    int ret = mouse_command(PSMOUSE_CMD_SETSCALE21, NULL);
     if (ret)
         set_code_invalid(regs, RET_ENEEDRESEND);
     else
@@ -229,7 +232,7 @@ mouse_15c207(struct bregs *regs)
         /* remove handler */
         if ((mouse_flags_2 & 0x80) != 0) {
             mouse_flags_2 &= ~0x80;
-            disable_mouse();
+            mouse_command(PSMOUSE_CMD_DISABLE, NULL);
         }
     } else {
         /* install handler */
@@ -269,7 +272,7 @@ handle_15c2(struct bregs *regs)
     }
 }
 
-void
+void noinline
 process_mouse(u8 data)
 {
     if (!CONFIG_MOUSE)
@@ -293,15 +296,17 @@ process_mouse(u8 data)
         return;
     }
 
-    //BX_DEBUG_INT74("int74_function: make_farcall=1\n");
     u16 status = GET_EBDA2(ebda_seg, mouse_data[0]);
     u16 X      = GET_EBDA2(ebda_seg, mouse_data[1]);
     u16 Y      = GET_EBDA2(ebda_seg, mouse_data[2]);
     SET_EBDA2(ebda_seg, mouse_flag1, 0);
 
     struct segoff_s func = GET_EBDA2(ebda_seg, far_call_pointer);
+    dprintf(16, "mouse farcall s=%04x x=%04x y=%04x func=%04x:%04x\n"
+            , status, X, Y, func.seg, func.offset);
 
     asm volatile(
+        "pushl %%ebp\n"
         "sti\n"
 
         "pushl %0\n"
@@ -314,8 +319,8 @@ process_mouse(u8 data)
 
         "cli\n"
         "cld\n"
+        "popl %%ebp"
+        : "+a"(func.segoff), "+c"(status), "+d"(X), "+b"(Y)
         :
-        : "r"(func.segoff), "r"(status), "r"(X), "r"(Y)
-        : "cc"
-        );
+        : "edi", "esi", "cc", "memory");
 }