mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:57:45 +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:
parent
26f4301521
commit
a537d78ac0
2 changed files with 51 additions and 29 deletions
|
@ -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();
|
||||
|
|
|
@ -1,6 +1,15 @@
|
|||
#include "PS2MouseDevice.h"
|
||||
#include "IO.h"
|
||||
|
||||
#define IRQ_MOUSE 1
|
||||
#define I8042_BUFFER 0x60
|
||||
#define I8042_STATUS 0x64
|
||||
#define I8042_ACK 0xFA
|
||||
#define I8042_BUFFER_FULL 0x01
|
||||
#define I8042_WHICH_BUFFER 0x20
|
||||
#define I8042_MOUSE_BUFFER 0x20
|
||||
#define I8042_KEYBOARD_BUFFER 0x00
|
||||
|
||||
//#define PS2MOUSE_DEBUG
|
||||
|
||||
static PS2MouseDevice* s_the;
|
||||
|
@ -24,7 +33,12 @@ PS2MouseDevice& PS2MouseDevice::the()
|
|||
|
||||
void PS2MouseDevice::handle_irq()
|
||||
{
|
||||
byte data = IO::in8(0x60);
|
||||
for (;;) {
|
||||
byte status = IO::in8(I8042_STATUS);
|
||||
if (!(((status & I8042_WHICH_BUFFER) == I8042_MOUSE_BUFFER) && (status & I8042_BUFFER_FULL)))
|
||||
return;
|
||||
|
||||
byte data = IO::in8(I8042_BUFFER);
|
||||
m_data[m_data_state] = data;
|
||||
switch (m_data_state) {
|
||||
case 0:
|
||||
|
@ -53,6 +67,7 @@ void PS2MouseDevice::handle_irq()
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PS2MouseDevice::wait_then_write(byte port, byte data)
|
||||
{
|
||||
|
@ -74,6 +89,8 @@ void PS2MouseDevice::initialize()
|
|||
// Enable interrupts
|
||||
wait_then_write(0x64, 0x20);
|
||||
|
||||
// Enable the PS/2 mouse IRQ (12).
|
||||
// NOTE: The keyboard uses IRQ 1 (and is enabled by bit 0 in this register).
|
||||
byte status = wait_then_read(0x60) | 2;
|
||||
wait_then_write(0x64, 0x60);
|
||||
wait_then_write(0x60, status);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue