I am practicing writing a simple keyboard driver in VirtualBox guest Linux. The problem is, my code just register an interrupt handler and print scancode
to the log file. And I don't send those incoming scancode to any upper level codes, like Linux input core
. After insmod
, I can see those captured scancode using dmesg
. But why my terminal still gets correct input? There should not be anything received by the terminal.
My code looks like this:
static int __init init_simple_keyboard_driver(void)
{
free_irq (IRQ_1, NULL);
return request_irq (IRQ_1, my_handler, ...);
}
static irqreturn_t my_handler(int irq, void *dev_id)
{
unsigned char scancode = get_scancode_from_port_0x60();
printk(...scancode...);
}
After insmod
, I can see messages in the kernel log.
- My
free_irq
call causes some messages likeCan't free already freed IRQ
. (I don't know why... It should not be freed already.) atkbd
driver complains that there is someone ask to handleIRQ_1
instead.- Those scancode can be correctly printed.
- [The Most Weird One] The active console still gets correct keyboard input. Thus I can just perform a
rmmod
using this simple driver. - After
rmmod
, the guest Linux just dead because it can't receive any keyboard anymore.
Do you have any idea? Thank you!
cat /proc/interrupts
and sawmy_handler
together with the originali8042
onIRQ 1
. I think that means I failed to free the original interrupt.