From 3a8b59c39f5efa58205f96d1e9754a39c13c2503 Mon Sep 17 00:00:00 2001 From: Edgaru089 Date: Thu, 28 Oct 2021 18:28:31 +0800 Subject: [PATCH] kernel, driver/ps2: move decoding from kMain to interrupt handler --- driver/irq/pic/ps2/ps2.c | 20 ++++++++++++++++++++ kernel/kmain.c | 19 ------------------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/driver/irq/pic/ps2/ps2.c b/driver/irq/pic/ps2/ps2.c index 1b87612..383bff1 100644 --- a/driver/irq/pic/ps2/ps2.c +++ b/driver/irq/pic/ps2/ps2.c @@ -7,6 +7,7 @@ #include "../../../../runtime/panic_assert.h" #include "../../../../runtime/stdio.h" #include "../../../../graphics/graphics.h" +#include "../../../../driver/input/source.h" bool irq_pic_ps2_HasMouse; @@ -88,4 +89,23 @@ SYSV_ABI void irq_pic_ps2_IRQHandlerK() { SYSV_ABI void irq_pic_ps2_IRQHandlerM() { queue_PushByte(&irq_pic_ps2_QueueMouse, inb(IRQ_PIC_PS2_IOPORT)); + + while (queue_Size(&irq_pic_ps2_QueueMouse) && !(queue_FrontByte(&irq_pic_ps2_QueueMouse) & (1u << 3))) + queue_PopByte(&irq_pic_ps2_QueueMouse); + + while (queue_Size(&irq_pic_ps2_QueueMouse) >= (irq_pic_ps2_Mouse4Bytes ? 4 : 3)) { + unsigned int moveX, moveY, state; + + state = queue_PopByte(&irq_pic_ps2_QueueMouse); + + unsigned int d = queue_PopByte(&irq_pic_ps2_QueueMouse); + moveX = d - ((state << 4) & 0x100); + d = queue_PopByte(&irq_pic_ps2_QueueMouse); + moveY = d - ((state << 3) & 0x100); + + input_source_MoveMouse(moveX, -moveY); + + if (irq_pic_ps2_Mouse4Bytes) + queue_PopByte(&irq_pic_ps2_QueueMouse); + } } diff --git a/kernel/kmain.c b/kernel/kmain.c index 1b2bacb..ce86c3c 100644 --- a/kernel/kmain.c +++ b/kernel/kmain.c @@ -11,7 +11,6 @@ #include "../interrupt/syscall.h" #include "../driver/irq/pic/pic.h" #include "../driver/irq/pic/ps2/ps2.h" -#include "../driver/input/source.h" #include "../execformat/pe/reloc.h" void execformat_pe_ReadSystemHeader(execformat_pe_PortableExecutable *pe); @@ -74,24 +73,6 @@ SYSV_ABI void kMain() { for (;;) { asm volatile("hlt"); - while (queue_Size(&irq_pic_ps2_QueueMouse) >= (irq_pic_ps2_Mouse4Bytes ? 4 : 3)) { - unsigned int moveX, moveY, state; - - do { - state = queue_PopByte(&irq_pic_ps2_QueueMouse); - } while (!(state & (1u << 3))); - - unsigned int d = queue_PopByte(&irq_pic_ps2_QueueMouse); - moveX = d - ((state << 4) & 0x100); - d = queue_PopByte(&irq_pic_ps2_QueueMouse); - moveY = d - ((state << 3) & 0x100); - - input_source_MoveMouse(moveX, -moveY); - - if (irq_pic_ps2_Mouse4Bytes) - queue_PopByte(&irq_pic_ps2_QueueMouse); - } - //io_WriteConsoleASCII("kMain: Interrupt hit\n"); graphics_SwapBuffer(); }