linux-kernel - 编写基本的键盘中断处理程序,抛出 "Unknown key released"

标签 linux-kernel

我写了一个基本的键盘中断处理程序。它使用共享中断并用于打印到/var/log/messages 哪个键被按下。但是当我尝试使用箭头键时出现以下错误,其余键工作正常。

8 月 19 日 18:59:06 vim 内核:[112.485102] atkbd serio0:释放未知 key (翻译集 2,isa0060/serio0 上的代码 0xe0)。
8 月 19 日 18:59:06 vim 内核:[112.485108] atkbd serio0:使用 'setkeycodes e060' 让它知道。


粘贴代码。

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/interrupt.h>
#include <asm/io.h>

/* This function services keyboard interrupts */
irq_handler_t irq_handler (int irq, void *dev_id, struct pt_regs *regs) {
  static unsigned char scancode;

  /*
    Read keyboard status
  */
  scancode = inb (0x60);

  if ((scancode == 0x01) || (scancode == 0x81))
    {
      printk ("You pressed Esc !\n");
    }
  }

  return (irq_handler_t) IRQ_HANDLED;
}

/* Initialize the module and Register the IRQ handler */
static int __init keybrd_int_register(void)
{
  int result;
  /* Request IRQ 1, the keyboard IRQ */    
  result = request_irq (1, (irq_handler_t) irq_handler, IRQF_SHARED, "keyboard_stats_irq", (void *)(irq_handler));

  if (result)
    printk(KERN_INFO "can't get shared interrupt for keyboard\n");

  return result;
}

/* Remove the interrupt handler */
static void __exit keybrd_int_unregister(void) {
  free_irq(1, (void *)(irq_handler)); /* i can't pass NULL, this is a shared interrupt handler! */
}

MODULE_LICENSE ("GPL");
module_init(keybrd_int_register);
module_exit(keybrd_int_unregister);

谁能给我一些线索,说明为什么当我插入模块并开始工作时,为什么这个箭头键会停止工作,因为我删除了它们?

我在虚拟机上运行我的代码。

最佳答案

原因是由于一些VM搞砸了。它在基本的 linux 主机上运行良好。可以看到代码的完整实现(naive)@https://github.com/vigith/Linux-Device-Drivers/tree/master/keyboard

关于linux-kernel - 编写基本的键盘中断处理程序,抛出 "Unknown key released",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7122392/

相关文章:

assembly - x86 中的 IN 和 OUT 指令有何用途?

Ubuntu一次又一次地询问密码

linux - Unbound workqueue 的 kthreads CPU affinity

c - 进程在用户空间和内核空间执行

linux-kernel - linux/module.h : No such file or directory

c++ - sem_timedwait 与 CLOCK_MONOTONIC_RAW/CLOCK_MONOTONIC

linux-kernel - 为什么驱动程序编程更喜欢kzalloc而不是kmalloc

Linux 内核页表的 copy_to_user 失败

c - Linux 内核中的工作队列实现

x86 - Linux/SMP 自旋锁不必要地慢吗?