diff --git a/src/sys/include/isa/mouse.h b/src/sys/include/isa/mouse.h new file mode 100644 index 0000000..3dfc3a0 --- /dev/null +++ b/src/sys/include/isa/mouse.h @@ -0,0 +1,42 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _MOUE_H +#define _MOUSE_H + +int mouseInit(); +void mouseISR(); +void mouseHandler(); + +#endif + +/*** + $Log$ + END + ***/ diff --git a/src/sys/isa/mouse.c b/src/sys/isa/mouse.c new file mode 100644 index 0000000..a26b4c1 --- /dev/null +++ b/src/sys/isa/mouse.c @@ -0,0 +1,154 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project nor the names of its +contributors may be used to endorse or promote products derived from this software +without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT +OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +static uInt8 kbdRead() { + unsigned long Timeout; + uInt8 Stat, Data; + + for (Timeout = 50000L; Timeout != 0; Timeout--) { + Stat = inportByte(0x64); + + /* loop until 8042 output buffer full */ + if ((Stat & 0x01) != 0) + { + Data = inportByte(0x60); + + /* loop if parity error or receive timeout */ + if((Stat & 0xC0) == 0) + return Data; + } + } + + return -1; +} + +static void kbdWrite(uInt16 port,uInt8 data) { + uInt32 timeout; + uInt8 stat; + + for (timeout = 500000L; timeout != 0; timeout--) + { + stat = inportByte(0x64); + + if ((stat & 0x02) == 0) + break; + } + + if (timeout != 0) + outportByte(port, data); + } + +static uInt8 kbdWriteRead(uInt16 port,uInt8 data, const char* expect) +{ + int RetVal; + + kbdWrite(port, data); + for (; *expect; expect++) + { + RetVal = kbdRead(); + if ((uInt8) *expect != RetVal) + { + return RetVal; + } + } + + return 0; +} + + + +int mouseInit() { + static uInt8 s1[] = { 0xF3, 0xC8, 0xF3, 0x64, 0xF3, 0x50, 0 }; + static uInt8 s2[] = { 0xF6, 0xE6, 0xF4, 0xF3, 0x64, 0xE8, 0x03, 0 }; + const uInt8* ch; + Int8 cmd = 0x0; + + kbdWrite(0x64,0xA8); + for (ch = s1; *ch; ch++) { + kbdWrite(0x64, 0xD4); + kbdWriteRead(0x60, *ch,"\xFA"); + } + for (ch = s2; *ch; ch++) { + kbdWrite(0x64, 0xD4); + kbdWriteRead(0x60, *ch,"\xFA"); + } + kbdWrite(0x64,0xD4); + if (kbdWriteRead(0x60,0xF2,"\xFA") != 0x0) { + kprintf("Error With Mouse\n"); + } + cmd = kbdRead(); + kprintf("CMD: [0x%X]\n",cmd); + kbdWrite(0x64, 0xD4); + kbdWriteRead(0x60, 0xF4,"\xFA"); + + setVector(&mouseISR, mVec+12, dPresent + dInt + dDpl3); + + outportByte(mPic, eoi); + outportByte(sPic, eoi); + irqEnable(12); + outportByte(mPic, eoi); + outportByte(sPic, eoi); + + kprintf("psm0 - Address: [0x%X]\n",&mouseISR); + + /* Return so we know everything went well */ + return(0x0); + } + +asm( + ".globl mouseISR \n" + "mouseISR: \n" + " pusha \n" /* Save all registers */ + " call mouseHandler \n" + " popa \n" + " iret \n" /* Exit interrupt */ + ); + +void mouseHandler() { + kprintf("MOUSE!!!\n"); + + outportByte(mPic, eoi); + outportByte(sPic, eoi); + /* Return */ + return; + } + +/*** + $Log$ + END + ***/ +