自定义键盘中断处理程序 [英] Custom keyboard interrupt handler

查看:247
本文介绍了自定义键盘中断处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个简单的程序,该程序将用减少变量的自定义中断替换标准键盘中断.但是,如果不调用旧处理程序,它将无法正常工作.这是我的中断处理程序:

I'm trying to write a simple program that will replace standard keyboard interrupt with a custom one that will decrement a variable. However, it won't work without a call to the old handler. Here is my interrupt handler:

handler proc
  push ax
  push di
  dec EF
  ;pushf      ;when these to instructions commented keyboard interrupts handling hangs
  ;call [OLD]
  mov al,20h
  out 20h,al
  pop di
  pop ax
  iret
handler endp

我还应该在处理程序中执行哪些操作以使其在不调用旧处理程序的情况下起作用?

What actions I should also execute in my handler to make it works without calling the old handler?

推荐答案

在从键盘缓冲区读取当前数据之前,您不会从键盘上收到任何其他数据.在将EOI发送给PIC之前,先使用

You will not receive any further data from the keyboard until you read the current data from the keyboard buffer. Before sending the EOI to the PIC use

in al,60h

读取当前等待处理的扫描代码.调用旧的中断处理程序的原因是因为它确实从键盘读取等待的数据.

to read the scancode that is currently waiting to be processed. The reason calling the old interrupt handler works is because it does read the data waiting from the keyboard.

正如迈克尔·斯拉德(Michael Slade)所指出的,您需要关心以下事实:相对于 DS 寄存器,访问标签EFOLD.到达中断处理程序时,不能依赖 DS 中的值.唯一保证可用的段寄存器是 CS ,因为它是根据中断向量表(IVT)中中断向量的段值设置的.如果您设计其余代码,以使变量EFOLD与中断处理程序位于同一段中,则可以通过以下方式覆盖内存操作数上的段:

As was noted by Michael Slade, you need to concern yourself with the fact that the labels EF and OLD are accessed relative to the DS register. The value in DS can't be relied upon when reaching your interrupt handler. The only segment register guaranteed to be usable is CS since it is set based on the segment value of the interrupt vector in the Interrupt Vector Table (IVT). If you design the rest of your code so that the variables EF and OLD are in the same segment as the interrupt handler then you can override the segments on the memory operands this way:

dec cs:[EF]
pushf
call cs:[OLD]

这篇关于自定义键盘中断处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆