中断处理程序将在两台类似的机器上胜出

发布于 2025-02-12 02:13:36 字数 921 浏览 1 评论 0原文

我通过内核模块为键盘注册了一个中断处理程序,该代码在我的VirtualBox Linux Guest Light Ubuntu 20.04 5.13.0-51代基因上效果很好,该中断处理程序按预期工作。但是,当我的主机操作系统上运行相同的代码时,ubuntu 20.04 5.13.0-51总代码init当中断发生时调用。

request_irq(IRQ_NUMBER, keyb_handler, IRQF_SHARED, "irq_keyboard",
                        (void *)keyb_handler);
Light Ubuntu (VM) /proc/interrupts (Entry 1)
// When the module isn't loaded, it's like that
1:         56          0   IO-APIC   1-edge      i8042
// When the module is load, it's like that
1:        272          0   IO-APIC   1-edge      i8042, irq_keyboard

Ubuntu (Host) /proc/interrupts (Entry 1)
// Nothing is shown unless the module is loaded. if the module is loaded, then it's
1:        .. 0  ..  IO-APIC    1-edge      irq_keyboard

有什么问题?我在两个操作系统上多次调试代码,我知道代码很好,因此必须是一个便携性问题。如果需要任何其他信息,LMK。

I register an interrupt handler for my keyboard via a kernel module, the code works well on my virtualbox Linux guest Light Ubuntu 20.04 5.13.0-51-generic, the interrupt handler work as intended. However, when the same code is being run on my host operating system, Ubuntu 20.04 5.13.0-51-generic, the init function ends successfully but the interrupt handler is never called when an interrupt occurs.

request_irq(IRQ_NUMBER, keyb_handler, IRQF_SHARED, "irq_keyboard",
                        (void *)keyb_handler);
Light Ubuntu (VM) /proc/interrupts (Entry 1)
// When the module isn't loaded, it's like that
1:         56          0   IO-APIC   1-edge      i8042
// When the module is load, it's like that
1:        272          0   IO-APIC   1-edge      i8042, irq_keyboard

Ubuntu (Host) /proc/interrupts (Entry 1)
// Nothing is shown unless the module is loaded. if the module is loaded, then it's
1:        .. 0  ..  IO-APIC    1-edge      irq_keyboard

What can be the problem? I debugged the code many times on both operating system, and I know for a fact that the code is fine, hence it must be a portability issue. If any additional information is needed, lmk.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧梦荧光笔 2025-02-19 02:13:36

请注意,“ PC”是1987年的原始IBM PC,及其继任者。当然,原始PC的副本复制了硬件,以便该软件仍然可以正常工作。后来的版本还必须复制硬件,以使软件仍然可以使用。

在这些计算机中,键盘端口连接到Intel 8042计算机芯片,然​​后连接到CPU。 8042芯片负责从键盘和信号之间转换为CPU的信号。因此,例如,当它注意到按下键时,它发出了中断。中断连接到中断控制器的某个销钉。

现代计算机更灵活。一切都通过PCIE或USB等公共汽车连接。如果将其硬连接到键盘控制器芯片到某个中断引脚,那么您只能拥有一个键盘,这将是什么乐趣? USB让我根据需要插入尽可能多的键盘。

您有USB键盘吗?然后,您的键盘连接最有可能通过USB总线到连接连接到处理器的PCIE总线的USB控制器芯片。没有8042芯片。甚至可能没有中断引脚 - 控制器可以使用消息信号的中断。

您的BIOS可能具有“ PS/2仿真”的设置。如果打开此操作,当操作系统试图与该古老的8042芯片交谈时,BIOS会拦截它并模拟8042会做什么。可能会关闭这一点,因为您使用的是20年以上的OS,该操作系统知道如何访问USB端口,并且不需要仿真。

同时,您的VM模拟了8042芯片,因为它方便,与较旧的操作系统兼容。这可能取决于VM的设置方式 - 可能可以选择在8042(PS/2)或USB键盘之间进行选择。请注意,Linux使用的是“ I8042”(Intel 8042)驱动程序。

Note the "PC" is the original IBM PC from 1987, and its successors. Copies of the original PC copied the hardware, of course, so that the software would still work. And later editions also had to copy the hardware, so that the software would still work.

In these computers, the keyboard port was connected to an Intel 8042 computer chip which was then connected to the CPU. The 8042 chip was in charge of converting between the signals from the keyboard, and the signals to the CPU. So for example it sent an interrupt when it noticed a key was pressed. The interrupt was hard-wired to a certain pin of the interrupt controller.

Modern computers are more flexible. Everything is connected through a bus like PCIe or USB. If it was hard-wired to a keyboard controller chip to a certain interrupt pin, you could only have one keyboard, and what would be the fun in that? USB lets me plug in as many keyboards as I want.

Do you have a USB keyboard? Then your keyboard connection is most likely going through a USB bus to a USB controller chip connected to a PCIe bus connected to the processor. There is no 8042 chip involved. There might not even be an interrupt pin - the controller could use Message-Signaled Interrupts instead.

Your BIOS may have a setting for "PS/2 emulation". If this is turned on, when the operating system tries to talk to that ancient 8042 chip, the BIOS intercepts it and simulates what the 8042 would have done. Probably this is turned off, because you are using an OS newer than 20 years, which knows how to access a USB port, and doesn't need the emulation.

Meanwhile your VM simulates the 8042 chip because it's convenient, more compatible with older operating systems, etc. It might depend on how the VM is set up - there might be an option to choose between an 8042 (PS/2) or USB keyboard. Notice that Linux is using the "i8042" (intel 8042) driver.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文