From 0bc7429173bf79000fb4b37a66b9987055a702bf Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Thu, 25 Dec 2025 16:08:54 -0500 Subject: [PATCH] start ps/2 mouse driver --- kernel/include/{keyboard.h => ps2.h} | 5 +++- kernel/src/entry.c | 4 ++- kernel/src/{keyboard.asm => ps2.asm} | 40 +++++++++++++++++++++++++--- kernel/src/{keyboard.c => ps2.c} | 31 +++++++++++++++------ 4 files changed, 66 insertions(+), 14 deletions(-) rename kernel/include/{keyboard.h => ps2.h} (90%) rename kernel/src/{keyboard.asm => ps2.asm} (65%) rename kernel/src/{keyboard.c => ps2.c} (80%) diff --git a/kernel/include/keyboard.h b/kernel/include/ps2.h similarity index 90% rename from kernel/include/keyboard.h rename to kernel/include/ps2.h index e8a909b..53364fb 100644 --- a/kernel/include/keyboard.h +++ b/kernel/include/ps2.h @@ -1,4 +1,4 @@ -/* Calcite, kernel/include/keyboard.h +/* Calcite, kernel/include/ps2.h * Copyright 2025 Benji Dial * * This program is free software: you can redistribute it and/or modify @@ -17,4 +17,7 @@ #pragma once +void init_ps2(); + void on_keyboard_irq(); +void on_mouse_irq(); diff --git a/kernel/src/entry.c b/kernel/src/entry.c index fb8d2d1..952dba9 100644 --- a/kernel/src/entry.c +++ b/kernel/src/entry.c @@ -17,12 +17,12 @@ #include #include -#include #include #include #include #include #include +#include LIMINE_BASE_REVISION(3) @@ -182,7 +182,9 @@ static uint64_t initfs_length; //set up interrupts + init_ps2(); set_irq_handler(0x01, &on_keyboard_irq); + set_irq_handler(0x0c, &on_mouse_irq); enable_interrupts(); //halt repeatedly diff --git a/kernel/src/keyboard.asm b/kernel/src/ps2.asm similarity index 65% rename from kernel/src/keyboard.asm rename to kernel/src/ps2.asm index 275250b..b91ec81 100644 --- a/kernel/src/keyboard.asm +++ b/kernel/src/ps2.asm @@ -1,4 +1,4 @@ - ; Calcite, kernel/src/paging.asm + ; Calcite, kernel/src/ps2.asm ; Copyright 2025 Benji Dial ; ; This program is free software: you can redistribute it and/or modify @@ -19,11 +19,43 @@ bits 64 section .text -;referenced in keyboard.c +global init_ps2 +init_ps2: + mov al, 0x60 + out 0x64, al + +.wait_ready: + in al, 0x64 + test al, 0x02 + jnz .wait_ready + + mov al, 0x07 + out 0x60, al + + mov al, 0xd4 + out 0x64, al + +.wait_ready_2: + in al, 0x64 + test al, 0x02 + jnz .wait_ready_2 + + mov al, 0xf4 + out 0x60, al + +.wait_ready_3: + in al, 0x64 + test al, 0x01 + jz .wait_ready_3 + + in al, 0x60 + ret + +;referenced in ps2.c ;return type is int ;returns -1 if no byte available -global read_keyboard_byte -read_keyboard_byte: +global read_ps2_byte +read_ps2_byte: in al, 0x64 test al, 0x01 diff --git a/kernel/src/keyboard.c b/kernel/src/ps2.c similarity index 80% rename from kernel/src/keyboard.c rename to kernel/src/ps2.c index 33a7f6a..1c54e68 100644 --- a/kernel/src/keyboard.c +++ b/kernel/src/ps2.c @@ -1,4 +1,4 @@ -/* Calcite, kernel/src/keyboard.c +/* Calcite, kernel/src/ps2.c * Copyright 2025 Benji Dial * * This program is free software: you can redistribute it and/or modify @@ -16,18 +16,15 @@ */ #include -#include +#include -//defined in keyboard.asm +//defined in ps2.asm //returns -1 if no byte available -int read_keyboard_byte(); +int read_ps2_byte(); static uint32_t color = 1; -void on_keyboard_irq() { - - while (read_keyboard_byte() != -1) - ; +static void change_color() { color ^= color << 13; color ^= color >> 17; @@ -38,3 +35,21 @@ void on_keyboard_irq() { *(uint32_t *)&fb_base[y * fb_pitch + x * 4] = color & 0x00ffffff; } + +void on_keyboard_irq() { + + while (read_ps2_byte() != -1) + ; + + change_color(); + +} + +void on_mouse_irq() { + + while (read_ps2_byte() != -1) + ; + + change_color(); + +}