# mouse.c

Go to the documentation of this file.

    00001 /*****************************************************************************************
    00002  Copyright (c) 2002 The UbixOS Project
    00003  All rights reserved.
    00004
    00005 Redistribution and use in source and binary forms, with or without modification, are
    00006 permitted provided that the following conditions are met:
    00007
    00008 Redistributions of source code must retain the above copyright notice, this list of
    00009 conditions, the following disclaimer and the list of authors.  Redistributions in binary
    00010 form must reproduce the above copyright notice, this list of conditions, the following
    00011 disclaimer and the list of authors in the documentation and/or other materials provided
    00012 with the distribution. Neither the name of the UbixOS Project nor the names of its
    00013 contributors may be used to endorse or promote products derived from this software
    00014 without specific prior written permission.
    00015
    00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
    00017 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    00018 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
    00019 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    00020 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
    00021 OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    00022 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
    00023 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    00024 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    00025
    00026  $Id: mouse_8c-source.html 88 2016-01-12 00:11:29Z reddawg $
    00027
    00028 *****************************************************************************************/
    00029
    00030 #include <isa/mouse.h>
    00031 #include <isa/8259.h>
    00032 #include <sys/idt.h>
    00033 #include <sys/gdt.h>
    00034 #include <sys/io.h>
    00035 #include <lib/kprintf.h>
    00036 #include <ubixos/types.h>
    00037
    00038 static uInt8 kbdRead() {
    00039   unsigned long Timeout;
    00040   uInt8 Stat, Data;
    00041
    00042   for (Timeout = 50000L; Timeout != 0; Timeout--) {
    00043                 Stat = inportByte(0x64);
    00044
    00045                 /* loop until 8042 output buffer full */
    00046                 if ((Stat & 0x01) != 0)
    00047                 {
    00048                         Data = inportByte(0x60);
    00049
    00050                         /* loop if parity error or receive timeout */
    00051                         if((Stat & 0xC0) == 0)
    00052                                 return Data;
    00053                 }
    00054         }
    00055
    00056         return -1;
    00057 }
    00058
    00059 static void kbdWrite(uInt16 port,uInt8 data) {
    00060         uInt32 timeout;
    00061         uInt8 stat;
    00062
    00063         for (timeout = 500000L; timeout != 0; timeout--)
    00064         {
    00065                 stat = inportByte(0x64);
    00066
    00067                 if ((stat & 0x02) == 0)
    00068                         break;
    00069         }
    00070
    00071         if (timeout != 0)
    00072                 outportByte(port, data);
    00073   }
    00074
    00075 static uInt8 kbdWriteRead(uInt16 port,uInt8 data, const char* expect)
    00076 {
    00077         int RetVal;
    00078
    00079         kbdWrite(port, data);
    00080         for (; *expect; expect++)
    00081         {
    00082                 RetVal = kbdRead();
    00083                 if ((uInt8) *expect != RetVal)
    00084                 {
    00085                         return RetVal;
    00086                 }
    00087         }
    00088
    00089         return 0;
    00090 }
    00091
    00092
    00093
    00094 int mouseInit() {
    00095   static uInt8 s1[] = { 0xF3, 0xC8, 0xF3, 0x64, 0xF3, 0x50, 0 };
    00096   static uInt8 s2[] = { 0xF6, 0xE6, 0xF4, 0xF3, 0x64, 0xE8, 0x03, 0 };
    00097   const  uInt8* ch;
    00098   Int8 cmd = 0x0;
    00099
    00100   kbdWrite(0x64,0xA8);
    00101   for (ch = s1; *ch; ch++) {
    00102     kbdWrite(0x64, 0xD4);
    00103     kbdWriteRead(0x60, *ch,"\xFA");
    00104     }
    00105   for (ch = s2; *ch; ch++) {
    00106     kbdWrite(0x64, 0xD4);
    00107     kbdWriteRead(0x60, *ch,"\xFA");
    00108     }
    00109   kbdWrite(0x64,0xD4);
    00110   if (kbdWriteRead(0x60,0xF2,"\xFA") != 0x0) {
    00111     kprintf("Error With Mouse\n");
    00112     }
    00113   cmd = kbdRead();
    00114   kprintf("CMD: [0x%X]\n",cmd);
    00115   kbdWrite(0x64, 0xD4);
    00116   kbdWriteRead(0x60, 0xF4,"\xFA");
    00117
    00118   setVector(&mouseISR, mVec+12, dPresent + dInt + dDpl3);
    00119
    00120   outportByte(mPic, eoi);
    00121   outportByte(sPic, eoi);
    00122   irqEnable(12);
    00123   outportByte(mPic, eoi);
    00124   outportByte(sPic, eoi);
    00125
    00126   kprintf("psm0 - Address: [0x%X]\n",&mouseISR);
    00127
    00128   /* Return so we know everything went well */
    00129   return(0x0);
    00130   }
    00131
    00132 asm(
    00133   ".globl mouseISR \n"
    00134   "mouseISR:       \n"
    00135   "  pusha         \n" /* Save all registers           */
    00136   "  call mouseHandler \n"
    00137   "  popa          \n"
    00138   "  iret          \n" /* Exit interrupt               */
    00139   );
    00140
    00141 void mouseHandler() {
    00142   kprintf("MOUSE!!!\n");
    00143
    00144   outportByte(mPic, eoi);
    00145   outportByte(sPic, eoi);
    00146   /* Return */
    00147   return;
    00148   }
    00149
    00150 /***
    00151  $Log: mouse_8c-source.html,v $
    00151  Revision 1.7  2006/12/15 17:47:06  reddawg
    00151  Updates
    00151
    00152  Revision 1.1.1.1  2006/06/01 12:46:12  reddawg
    00153  ubix2
    00154
    00155  Revision 1.2  2005/10/12 00:13:37  reddawg
    00156  Removed
    00157
    00158  Revision 1.1.1.1  2005/09/26 17:24:02  reddawg
    00159  no message
    00160
    00161  Revision 1.3  2004/09/07 21:54:38  reddawg
    00162  ok reverted back to old scheduling for now....
    00163
    00164  Revision 1.2  2004/09/06 15:13:25  reddawg
    00165  Last commit before FreeBSD 6.0
    00166
    00167  Revision 1.1  2004/06/04 10:20:53  reddawg
    00168  mouse drive: fixed a few bugs works a bit better now
    00169
    00170  END
    00171  ***/
    00172