mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:27:35 +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 IRQ_KEYBOARD 1
|
||||||
#define I8042_BUFFER 0x60
|
#define I8042_BUFFER 0x60
|
||||||
#define I8042_STATUS 0x64
|
#define I8042_STATUS 0x64
|
||||||
#define SET_LEDS 0xED
|
|
||||||
#define DATA_AVAILABLE 0x01
|
|
||||||
#define I8042_ACK 0xFA
|
#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] =
|
static char map[0x80] =
|
||||||
{
|
{
|
||||||
|
@ -110,7 +112,10 @@ void Keyboard::key_state_changed(byte raw, bool pressed)
|
||||||
|
|
||||||
void Keyboard::handle_irq()
|
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 raw = IO::in8(I8042_BUFFER);
|
||||||
byte ch = raw & 0x7f;
|
byte ch = raw & 0x7f;
|
||||||
bool pressed = !(raw & 0x80);
|
bool pressed = !(raw & 0x80);
|
||||||
|
@ -157,7 +162,7 @@ Keyboard::Keyboard()
|
||||||
|
|
||||||
// Empty the buffer of any pending data.
|
// Empty the buffer of any pending data.
|
||||||
// I don't care what you've been pressing until now!
|
// 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);
|
IO::in8(I8042_BUFFER);
|
||||||
|
|
||||||
enable_irq();
|
enable_irq();
|
||||||
|
|
|
@ -1,6 +1,15 @@
|
||||||
#include "PS2MouseDevice.h"
|
#include "PS2MouseDevice.h"
|
||||||
#include "IO.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
|
//#define PS2MOUSE_DEBUG
|
||||||
|
|
||||||
static PS2MouseDevice* s_the;
|
static PS2MouseDevice* s_the;
|
||||||
|
@ -24,33 +33,39 @@ PS2MouseDevice& PS2MouseDevice::the()
|
||||||
|
|
||||||
void PS2MouseDevice::handle_irq()
|
void PS2MouseDevice::handle_irq()
|
||||||
{
|
{
|
||||||
byte data = IO::in8(0x60);
|
for (;;) {
|
||||||
m_data[m_data_state] = data;
|
byte status = IO::in8(I8042_STATUS);
|
||||||
switch (m_data_state) {
|
if (!(((status & I8042_WHICH_BUFFER) == I8042_MOUSE_BUFFER) && (status & I8042_BUFFER_FULL)))
|
||||||
case 0:
|
return;
|
||||||
if (!(data & 0x08)) {
|
|
||||||
dbgprintf("PS2Mouse: Stream out of sync.\n");
|
byte data = IO::in8(I8042_BUFFER);
|
||||||
|
m_data[m_data_state] = data;
|
||||||
|
switch (m_data_state) {
|
||||||
|
case 0:
|
||||||
|
if (!(data & 0x08)) {
|
||||||
|
dbgprintf("PS2Mouse: Stream out of sync.\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
++m_data_state;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
++m_data_state;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
m_data_state = 0;
|
||||||
|
#ifdef PS2MOUSE_DEBUG
|
||||||
|
dbgprintf("PS2Mouse: %d, %d %s %s\n",
|
||||||
|
m_data[1],
|
||||||
|
m_data[2],
|
||||||
|
(m_data[0] & 1) ? "Left" : "",
|
||||||
|
(m_data[0] & 2) ? "Right" : ""
|
||||||
|
);
|
||||||
|
#endif
|
||||||
|
m_queue.enqueue(m_data[0]);
|
||||||
|
m_queue.enqueue(m_data[1]);
|
||||||
|
m_queue.enqueue(m_data[2]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
++m_data_state;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
++m_data_state;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
m_data_state = 0;
|
|
||||||
#ifdef PS2MOUSE_DEBUG
|
|
||||||
dbgprintf("PS2Mouse: %d, %d %s %s\n",
|
|
||||||
m_data[1],
|
|
||||||
m_data[2],
|
|
||||||
(m_data[0] & 1) ? "Left" : "",
|
|
||||||
(m_data[0] & 2) ? "Right" : ""
|
|
||||||
);
|
|
||||||
#endif
|
|
||||||
m_queue.enqueue(m_data[0]);
|
|
||||||
m_queue.enqueue(m_data[1]);
|
|
||||||
m_queue.enqueue(m_data[2]);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,6 +89,8 @@ void PS2MouseDevice::initialize()
|
||||||
// Enable interrupts
|
// Enable interrupts
|
||||||
wait_then_write(0x64, 0x20);
|
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;
|
byte status = wait_then_read(0x60) | 2;
|
||||||
wait_then_write(0x64, 0x60);
|
wait_then_write(0x64, 0x60);
|
||||||
wait_then_write(0x60, status);
|
wait_then_write(0x60, status);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue