Ps/2 Compatible Mouse Driver May 2026

// Send EOI to PIC outb(0x20, 0x20); In real mode or protected mode, you must set up the IDT (Interrupt Descriptor Table) for IRQ12 (vector 0x2C if PIC is in standard remap). Example for 32-bit protected mode:

uint8_t data = inb(0x60);

Your main loop can now poll mouse_x , mouse_y , and mouse_buttons . Here’s a simple console debug: ps/2 compatible mouse driver

Enabling Scroll Wheel (IntelliMouse) Send this sequence to switch to 4-byte packets:

The PS/2 mouse might seem like a relic of the 1990s, but it remains the gold standard for low-level OS development. Unlike USB, which relies on complex host controllers and descriptor parsing, the PS/2 interface is simple, memory-mapped, and interrupt-driven. In this article, we’ll build a bare-bones PS/2 mouse driver from scratch, covering initialization, packet decoding, and integration with a simple GUI. 1. Understanding the PS/2 Interface The PS/2 port uses two bidirectional lines: Clock (usually IRQ 12 for the mouse) and Data . Communication is synchronous, with the device sending 11-bit packets (1 start bit, 8 data bits, 1 parity bit, 1 stop bit) when the host pulls the clock low. // Send EOI to PIC outb(0x20, 0x20); In

// Set controller configuration byte outb(0x64, 0x20); // Read command byte uint8_t config = inb(0x60); config |= 0x02; // Enable mouse IRQ12 (bit 1) config &= ~0x10; // Enable standard translation (optional) outb(0x64, 0x60); // Write command byte outb(0x60, config);

int old_buttons = 0; while (1) mouse_y) printf("Mouse moved: %d, %d\n", mouse_x, mouse_y); mouse_x = 0; mouse_y = 0; sleep(10); Unlike USB, which relies on complex host controllers

void install_mouse_handler() set_idt_gate(0x2C, (uint32_t)mouse_isr, 0x08, 0x8E); outb(0x21, inb(0x21) & ~0x20); // Unmask IRQ12 on slave PIC outb(0xA1, inb(0xA1) & ~0x20);

// Send EOI to PIC outb(0x20, 0x20); In real mode or protected mode, you must set up the IDT (Interrupt Descriptor Table) for IRQ12 (vector 0x2C if PIC is in standard remap). Example for 32-bit protected mode:

uint8_t data = inb(0x60);

Your main loop can now poll mouse_x , mouse_y , and mouse_buttons . Here’s a simple console debug:

Enabling Scroll Wheel (IntelliMouse) Send this sequence to switch to 4-byte packets:

The PS/2 mouse might seem like a relic of the 1990s, but it remains the gold standard for low-level OS development. Unlike USB, which relies on complex host controllers and descriptor parsing, the PS/2 interface is simple, memory-mapped, and interrupt-driven. In this article, we’ll build a bare-bones PS/2 mouse driver from scratch, covering initialization, packet decoding, and integration with a simple GUI. 1. Understanding the PS/2 Interface The PS/2 port uses two bidirectional lines: Clock (usually IRQ 12 for the mouse) and Data . Communication is synchronous, with the device sending 11-bit packets (1 start bit, 8 data bits, 1 parity bit, 1 stop bit) when the host pulls the clock low.

// Set controller configuration byte outb(0x64, 0x20); // Read command byte uint8_t config = inb(0x60); config |= 0x02; // Enable mouse IRQ12 (bit 1) config &= ~0x10; // Enable standard translation (optional) outb(0x64, 0x60); // Write command byte outb(0x60, config);

int old_buttons = 0; while (1) mouse_y) printf("Mouse moved: %d, %d\n", mouse_x, mouse_y); mouse_x = 0; mouse_y = 0; sleep(10);

void install_mouse_handler() set_idt_gate(0x2C, (uint32_t)mouse_isr, 0x08, 0x8E); outb(0x21, inb(0x21) & ~0x20); // Unmask IRQ12 on slave PIC outb(0xA1, inb(0xA1) & ~0x20);