summary refs log blame commit diff stats
path: root/Makefile
blob: fd525721cb6e85c11dd692ea3efa3d4da6f321ad (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15














                                                                       
             
                                                      
                                                                                   


                                                                            
                                       
                   
            
               


                                                
"> int32 mouse_read(File *file, uint32 size, uint8 *buffer) { FifoBuffer* fifo = (FifoBuffer*)file->privateData; while (FifoBuffer_getSize(fifo) < MOUSE_PACKET_SIZE) { file->thread->state = TS_WAITIO; file->thread->state_privateData = mouse_read; enableInterrupts(); halt(); } disableInterrupts(); uint32 available = FifoBuffer_getSize(fifo); uint32 smaller = MIN(available, size); FifoBuffer_dequeue(fifo, buffer, smaller); return smaller; } static void prepareForRead() { //https://wiki.osdev.org/Mouse_Input //Bytes cannot be read from port 0x60 until bit 0 (value=1) of port 0x64 is set int32 tryCount = 1000; uint8 data = 0; do { data = inb(0x64); } while (((data & 0x01) == 0) && --tryCount > 0); } static void prepareForWrite() { //https://wiki.osdev.org/Mouse_Input //All output to port 0x60 or 0x64 must be preceded by waiting for bit 1 (value=2) of port 0x64 to become clear int32 tryCount = 1000; uint8 data = 0; do { data = inb(0x64); } while (((data & 0x02) != 0) && --tryCount > 0); } static void writeMouse(uint8 data) { prepareForWrite(); outb(0x64, 0xD4); prepareForWrite(); outb(0x60, data); } static void handleMouseInterrupt(Registers *regs) { uint8 status = 0; //0x20 (5th bit is mouse bit) //read from 0x64, if its mouse bit is 1 then data is available at 0x60! int32 tryCount = 1000; do { status = inb(0x64); } while (((status & 0x20) == 0) && --tryCount > 0); uint8 data = inb(0x60); gMousePacket[gMouseByteCounter] = data; gMouseByteCounter += 1; if (gMouseByteCounter == MOUSE_PACKET_SIZE) { gMouseByteCounter = 0; Spinlock_Lock(&gReadersLock); //Wake readers List_Foreach(n, gReaders) { File* file = n->data; FifoBuffer* fifo = (FifoBuffer*)file->privateData; FifoBuffer_enqueue(fifo, gMousePacket, MOUSE_PACKET_SIZE); if (file->thread->state == TS_WAITIO) { if (file->thread->state_privateData == mouse_read) { file->thread->state = TS_RUN; file->thread->state_privateData = NULL; } } } Spinlock_Unlock(&gReadersLock); } //printkf("mouse:%d\n", data); }