From 3fda97332f5af01b26ecee8c1112dc0f0daf367d Mon Sep 17 00:00:00 2001 From: Matheus Date: Tue, 12 May 2026 22:18:42 -0300 Subject: [PATCH] ps2: don't wait forever on machines with no controller --- kernel-src/arch/x86-64/ps2.c | 8 +++++++- kernel-src/include/x86-64/arch/ps2.h | 15 +++++++++++++++ recipes/astral | 2 +- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/kernel-src/arch/x86-64/ps2.c b/kernel-src/arch/x86-64/ps2.c index 1c605279..0ebc87d7 100644 --- a/kernel-src/arch/x86-64/ps2.c +++ b/kernel-src/arch/x86-64/ps2.c @@ -132,7 +132,13 @@ bool ps2_init_device(int port, bool *mouse) { void arch_ps2_init() { // XXX actually check if the controller is there - ps2_write_command(PS2_CTLR_CMD_DISABLEP1); + bool t; + ps2_write_command_timeout(PS2_CTLR_CMD_DISABLEP1, 10, &t); + if (t) { + printf("ps2: no controller on this machine\n"); + return; + } + ps2_write_command(PS2_CTLR_CMD_DISABLEP2); // just to make sure diff --git a/kernel-src/include/x86-64/arch/ps2.h b/kernel-src/include/x86-64/arch/ps2.h index 4e19f964..ba6cce58 100644 --- a/kernel-src/include/x86-64/arch/ps2.h +++ b/kernel-src/include/x86-64/arch/ps2.h @@ -63,6 +63,21 @@ static inline void ps2_write_command(uint8_t cmd) { outb(PS2_PORT_COMMAND, cmd); } +static inline void ps2_write_command_timeout(uint8_t cmd, int ms, bool *timeout) { + timespec_t initial = timekeeper_timefromboot(); + + while (ps2_inbuffer_full()) { + timespec_t current = timekeeper_timefromboot(); + if (timespec_diffms(initial, current) >= ms) { + *timeout = true; + return; + } + } + + *timeout = false; + outb(PS2_PORT_COMMAND, cmd); +} + static inline void ps2_write_data(uint8_t cmd) { while (ps2_inbuffer_full()); outb(PS2_PORT_DATA, cmd); diff --git a/recipes/astral b/recipes/astral index ec616893..28fe005d 100644 --- a/recipes/astral +++ b/recipes/astral @@ -1,5 +1,5 @@ name=astral -revision=1 +revision=2 from_source=astral imagedeps="build-essential nasm" hostdeps="xgcc xbinutils limine"