start ps/2 mouse driver

This commit is contained in:
Benji Dial 2025-12-25 16:08:54 -05:00
parent d37fa101f4
commit 0bc7429173
4 changed files with 66 additions and 14 deletions

View file

@ -1,4 +1,4 @@
/* Calcite, kernel/include/keyboard.h /* Calcite, kernel/include/ps2.h
* Copyright 2025 Benji Dial * Copyright 2025 Benji Dial
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -17,4 +17,7 @@
#pragma once #pragma once
void init_ps2();
void on_keyboard_irq(); void on_keyboard_irq();
void on_mouse_irq();

View file

@ -17,12 +17,12 @@
#include <framebuffer.h> #include <framebuffer.h>
#include <interrupts.h> #include <interrupts.h>
#include <keyboard.h>
#include <utility.h> #include <utility.h>
#include <initfs.h> #include <initfs.h>
#include <limine.h> #include <limine.h>
#include <paging.h> #include <paging.h>
#include <panic.h> #include <panic.h>
#include <ps2.h>
LIMINE_BASE_REVISION(3) LIMINE_BASE_REVISION(3)
@ -182,7 +182,9 @@ static uint64_t initfs_length;
//set up interrupts //set up interrupts
init_ps2();
set_irq_handler(0x01, &on_keyboard_irq); set_irq_handler(0x01, &on_keyboard_irq);
set_irq_handler(0x0c, &on_mouse_irq);
enable_interrupts(); enable_interrupts();
//halt repeatedly //halt repeatedly

View file

@ -1,4 +1,4 @@
; Calcite, kernel/src/paging.asm ; Calcite, kernel/src/ps2.asm
; Copyright 2025 Benji Dial ; Copyright 2025 Benji Dial
; ;
; This program is free software: you can redistribute it and/or modify ; This program is free software: you can redistribute it and/or modify
@ -19,11 +19,43 @@ bits 64
section .text 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 ;return type is int
;returns -1 if no byte available ;returns -1 if no byte available
global read_keyboard_byte global read_ps2_byte
read_keyboard_byte: read_ps2_byte:
in al, 0x64 in al, 0x64
test al, 0x01 test al, 0x01

View file

@ -1,4 +1,4 @@
/* Calcite, kernel/src/keyboard.c /* Calcite, kernel/src/ps2.c
* Copyright 2025 Benji Dial * Copyright 2025 Benji Dial
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -16,18 +16,15 @@
*/ */
#include <framebuffer.h> #include <framebuffer.h>
#include <keyboard.h> #include <ps2.h>
//defined in keyboard.asm //defined in ps2.asm
//returns -1 if no byte available //returns -1 if no byte available
int read_keyboard_byte(); int read_ps2_byte();
static uint32_t color = 1; static uint32_t color = 1;
void on_keyboard_irq() { static void change_color() {
while (read_keyboard_byte() != -1)
;
color ^= color << 13; color ^= color << 13;
color ^= color >> 17; color ^= color >> 17;
@ -38,3 +35,21 @@ void on_keyboard_irq() {
*(uint32_t *)&fb_base[y * fb_pitch + x * 4] = color & 0x00ffffff; *(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();
}