diff --git a/src/userland/pic/main.c b/src/userland/pic/main.c index 7b2880b..fbce3d6 100644 --- a/src/userland/pic/main.c +++ b/src/userland/pic/main.c @@ -30,20 +30,22 @@ void irqMaster(uint32_t intNo) { uint16_t isr = getISR(); - if (isr) { - ioOut(PIC1, 0x20, 1); - } - bool sentPic2EOI = false; + bool sendPic2EOI = false; for (uint8_t i = 0; i < 16; i++) { if (!(isr & (1 << i))) { continue; } - if (i >= 8 && !sentPic2EOI) { - sentPic2EOI = true; - ioOut(PIC2, 0x20, 1); + if (i >= 8) { + sendPic2EOI = true; } fireEvent(eventIds[i], 0); } + if (isr) { + ioOut(PIC1, 0x20, 1); + if (sendPic2EOI) { + ioOut(PIC2, 0x20, 1); + } + } } int32_t main() { diff --git a/src/userland/pic/main.c b/src/userland/pic/main.c index 7b2880b..fbce3d6 100644 --- a/src/userland/pic/main.c +++ b/src/userland/pic/main.c @@ -30,20 +30,22 @@ void irqMaster(uint32_t intNo) { uint16_t isr = getISR(); - if (isr) { - ioOut(PIC1, 0x20, 1); - } - bool sentPic2EOI = false; + bool sendPic2EOI = false; for (uint8_t i = 0; i < 16; i++) { if (!(isr & (1 << i))) { continue; } - if (i >= 8 && !sentPic2EOI) { - sentPic2EOI = true; - ioOut(PIC2, 0x20, 1); + if (i >= 8) { + sendPic2EOI = true; } fireEvent(eventIds[i], 0); } + if (isr) { + ioOut(PIC1, 0x20, 1); + if (sendPic2EOI) { + ioOut(PIC2, 0x20, 1); + } + } } int32_t main() { diff --git a/src/userland/ps2/main.c b/src/userland/ps2/main.c index e16e59d..de689c7 100644 --- a/src/userland/ps2/main.c +++ b/src/userland/ps2/main.c @@ -1,5 +1,4 @@ #include -#include #include "ps2.h" const char* deviceTypeNames[] = { @@ -117,6 +116,7 @@ } REQUEST(registerKeyboard, "ps2kb", "register"); +REQUEST(registerMouse, "ps2mouse", "register"); void initDevice(uint8_t device) { flushOutputBuffer(); @@ -129,7 +129,7 @@ } // send enable command writeController(device == 0 ? 0xAE : 0xA8); - read(device); + read(); flushOutputBuffer(); // send reset command to device writeDevice(device, 0xFF); @@ -149,7 +149,18 @@ uint32_t picService = getService("pic"); uint32_t event = getEvent(picService, device == 0 ? "irq1" : "irq12"); if (deviceType == StandardPS2Mouse || deviceType == StandardPS2MouseWithScrollWheel || deviceType == MouseWith5Buttons) { - // TODO: start mouse listening + writeDevice(device, 0xF6); + // wait for ACK + while (read() != 0xFA); + flushOutputBuffer(); + writeDevice(device, 0xF3); + while (read() != 0xFA); + flushOutputBuffer(); + writeDevice(device, 10); + // wait for ACK + while (read() != 0xFA); + flushOutputBuffer(); + registerMouse(deviceType, event); } else { // get current scancode set flushOutputBuffer(); @@ -171,7 +182,9 @@ int32_t main() { loadFromInitrd("ps2kb"); + loadFromInitrd("ps2mouse"); createFunction("read", (void *)read); + createFunction("flush", (void *)flushOutputBuffer); // disable all devices writeController(0xAD); diff --git a/src/userland/pic/main.c b/src/userland/pic/main.c index 7b2880b..fbce3d6 100644 --- a/src/userland/pic/main.c +++ b/src/userland/pic/main.c @@ -30,20 +30,22 @@ void irqMaster(uint32_t intNo) { uint16_t isr = getISR(); - if (isr) { - ioOut(PIC1, 0x20, 1); - } - bool sentPic2EOI = false; + bool sendPic2EOI = false; for (uint8_t i = 0; i < 16; i++) { if (!(isr & (1 << i))) { continue; } - if (i >= 8 && !sentPic2EOI) { - sentPic2EOI = true; - ioOut(PIC2, 0x20, 1); + if (i >= 8) { + sendPic2EOI = true; } fireEvent(eventIds[i], 0); } + if (isr) { + ioOut(PIC1, 0x20, 1); + if (sendPic2EOI) { + ioOut(PIC2, 0x20, 1); + } + } } int32_t main() { diff --git a/src/userland/ps2/main.c b/src/userland/ps2/main.c index e16e59d..de689c7 100644 --- a/src/userland/ps2/main.c +++ b/src/userland/ps2/main.c @@ -1,5 +1,4 @@ #include -#include #include "ps2.h" const char* deviceTypeNames[] = { @@ -117,6 +116,7 @@ } REQUEST(registerKeyboard, "ps2kb", "register"); +REQUEST(registerMouse, "ps2mouse", "register"); void initDevice(uint8_t device) { flushOutputBuffer(); @@ -129,7 +129,7 @@ } // send enable command writeController(device == 0 ? 0xAE : 0xA8); - read(device); + read(); flushOutputBuffer(); // send reset command to device writeDevice(device, 0xFF); @@ -149,7 +149,18 @@ uint32_t picService = getService("pic"); uint32_t event = getEvent(picService, device == 0 ? "irq1" : "irq12"); if (deviceType == StandardPS2Mouse || deviceType == StandardPS2MouseWithScrollWheel || deviceType == MouseWith5Buttons) { - // TODO: start mouse listening + writeDevice(device, 0xF6); + // wait for ACK + while (read() != 0xFA); + flushOutputBuffer(); + writeDevice(device, 0xF3); + while (read() != 0xFA); + flushOutputBuffer(); + writeDevice(device, 10); + // wait for ACK + while (read() != 0xFA); + flushOutputBuffer(); + registerMouse(deviceType, event); } else { // get current scancode set flushOutputBuffer(); @@ -171,7 +182,9 @@ int32_t main() { loadFromInitrd("ps2kb"); + loadFromInitrd("ps2mouse"); createFunction("read", (void *)read); + createFunction("flush", (void *)flushOutputBuffer); // disable all devices writeController(0xAD); diff --git a/src/userland/ps2/ps2.h b/src/userland/ps2/ps2.h index f5c3471..af87510 100644 --- a/src/userland/ps2/ps2.h +++ b/src/userland/ps2/ps2.h @@ -19,7 +19,7 @@ uint8_t timeoutError: 1; uint8_t parityError: 1; } __attribute__((packed)) data; - } Status; +} Status; typedef union { uint8_t byte; @@ -33,7 +33,7 @@ uint8_t firstPortTranslation: 1; uint8_t zero2: 1; } __attribute__((packed)) data; - } Configuration; +} Configuration; typedef enum { UnknownPS2Device, diff --git a/src/userland/pic/main.c b/src/userland/pic/main.c index 7b2880b..fbce3d6 100644 --- a/src/userland/pic/main.c +++ b/src/userland/pic/main.c @@ -30,20 +30,22 @@ void irqMaster(uint32_t intNo) { uint16_t isr = getISR(); - if (isr) { - ioOut(PIC1, 0x20, 1); - } - bool sentPic2EOI = false; + bool sendPic2EOI = false; for (uint8_t i = 0; i < 16; i++) { if (!(isr & (1 << i))) { continue; } - if (i >= 8 && !sentPic2EOI) { - sentPic2EOI = true; - ioOut(PIC2, 0x20, 1); + if (i >= 8) { + sendPic2EOI = true; } fireEvent(eventIds[i], 0); } + if (isr) { + ioOut(PIC1, 0x20, 1); + if (sendPic2EOI) { + ioOut(PIC2, 0x20, 1); + } + } } int32_t main() { diff --git a/src/userland/ps2/main.c b/src/userland/ps2/main.c index e16e59d..de689c7 100644 --- a/src/userland/ps2/main.c +++ b/src/userland/ps2/main.c @@ -1,5 +1,4 @@ #include -#include #include "ps2.h" const char* deviceTypeNames[] = { @@ -117,6 +116,7 @@ } REQUEST(registerKeyboard, "ps2kb", "register"); +REQUEST(registerMouse, "ps2mouse", "register"); void initDevice(uint8_t device) { flushOutputBuffer(); @@ -129,7 +129,7 @@ } // send enable command writeController(device == 0 ? 0xAE : 0xA8); - read(device); + read(); flushOutputBuffer(); // send reset command to device writeDevice(device, 0xFF); @@ -149,7 +149,18 @@ uint32_t picService = getService("pic"); uint32_t event = getEvent(picService, device == 0 ? "irq1" : "irq12"); if (deviceType == StandardPS2Mouse || deviceType == StandardPS2MouseWithScrollWheel || deviceType == MouseWith5Buttons) { - // TODO: start mouse listening + writeDevice(device, 0xF6); + // wait for ACK + while (read() != 0xFA); + flushOutputBuffer(); + writeDevice(device, 0xF3); + while (read() != 0xFA); + flushOutputBuffer(); + writeDevice(device, 10); + // wait for ACK + while (read() != 0xFA); + flushOutputBuffer(); + registerMouse(deviceType, event); } else { // get current scancode set flushOutputBuffer(); @@ -171,7 +182,9 @@ int32_t main() { loadFromInitrd("ps2kb"); + loadFromInitrd("ps2mouse"); createFunction("read", (void *)read); + createFunction("flush", (void *)flushOutputBuffer); // disable all devices writeController(0xAD); diff --git a/src/userland/ps2/ps2.h b/src/userland/ps2/ps2.h index f5c3471..af87510 100644 --- a/src/userland/ps2/ps2.h +++ b/src/userland/ps2/ps2.h @@ -19,7 +19,7 @@ uint8_t timeoutError: 1; uint8_t parityError: 1; } __attribute__((packed)) data; - } Status; +} Status; typedef union { uint8_t byte; @@ -33,7 +33,7 @@ uint8_t firstPortTranslation: 1; uint8_t zero2: 1; } __attribute__((packed)) data; - } Configuration; +} Configuration; typedef enum { UnknownPS2Device, diff --git a/src/userland/ps2mouse/main.c b/src/userland/ps2mouse/main.c new file mode 100644 index 0000000..1b302c6 --- /dev/null +++ b/src/userland/ps2mouse/main.c @@ -0,0 +1,49 @@ +#include + +REQUEST(read, "ps2", "read"); +REQUEST(flush, "ps2", "flush"); +REQUEST(moveRelative, "mouse", "moveRelative") +REQUEST(updateButton, "mouse", "updateButton") + +uint32_t deviceTypes[16]; +uint8_t deviceBuffer[16][5]; +uint8_t deviceBufferPositions[16]; + +typedef union { + uint8_t byte; + struct { + uint8_t button1: 1; + uint8_t button2: 1; + uint8_t button3: 1; + uint8_t one: 1; + uint8_t xSign: 1; + uint8_t ySign: 1; + uint8_t xOverflow: 1; + uint8_t yOverflow: 1; + } __attribute__((packed)) data; +} Status; + +void onMove(uint8_t device) { + deviceBuffer[device][deviceBufferPositions[device]] = read(0, 0); + deviceBufferPositions[device]++; + if (deviceBufferPositions[device] == 3) { + deviceBufferPositions[device] = 0; + Status status = {.byte = deviceBuffer[device][0]}; + updateButton(1, status.data.button1); + updateButton(2, status.data.button2); + updateButton(3, status.data.button3); + + int32_t dx = (int32_t) deviceBuffer[device][2] - (status.data.xSign << 8); + int32_t dy = (int32_t) deviceBuffer[device][1] - (status.data.ySign << 8); + moveRelative(dx, dy); + } +} + +void doRegister(uint32_t deviceType, uint32_t event) { + subscribeEvent(getService("pic"), event, onMove); + deviceTypes[event] = deviceType; +} + +int32_t main() { + createFunction("register", (void *)doRegister); +}