1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:18:11 +00:00

Kernel: Drivers for PS/2 mouse and keyboard kept stealing from each other.

We need to look at the i8042 status register to see if the packets in the
PS/2 controller's output buffer are mouse or keyboard packets.

This fixes occasionally surprising inputs while using both devices.
This commit is contained in:
Andreas Kling 2019-02-07 07:55:53 +01:00
parent 26f4301521
commit a537d78ac0
2 changed files with 51 additions and 29 deletions

View file

@ -11,9 +11,11 @@
#define IRQ_KEYBOARD 1
#define I8042_BUFFER 0x60
#define I8042_STATUS 0x64
#define SET_LEDS 0xED
#define DATA_AVAILABLE 0x01
#define I8042_ACK 0xFA
#define I8042_BUFFER_FULL 0x01
#define I8042_WHICH_BUFFER 0x20
#define I8042_MOUSE_BUFFER 0x20
#define I8042_KEYBOARD_BUFFER 0x00
static char map[0x80] =
{
@ -110,7 +112,10 @@ void Keyboard::key_state_changed(byte raw, bool pressed)
void Keyboard::handle_irq()
{
while (IO::in8(I8042_STATUS) & DATA_AVAILABLE) {
for (;;) {
byte status = IO::in8(I8042_STATUS);
if (!(((status & I8042_WHICH_BUFFER) == I8042_KEYBOARD_BUFFER) && (status & I8042_BUFFER_FULL)))
return;
byte raw = IO::in8(I8042_BUFFER);
byte ch = raw & 0x7f;
bool pressed = !(raw & 0x80);
@ -157,7 +162,7 @@ Keyboard::Keyboard()
// Empty the buffer of any pending data.
// I don't care what you've been pressing until now!
while (IO::in8(I8042_STATUS ) & DATA_AVAILABLE)
while (IO::in8(I8042_STATUS) & I8042_BUFFER_FULL)
IO::in8(I8042_BUFFER);
enable_irq();