Custom keyboard interrupt handler

别来无恙 提交于 2019-12-23 13:09:51

问题


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?


回答1:


  1. You need to save DS on the stack and set it to the proper value for your program, then restore it before the iret.

  2. This part:

    mov al,20h
    out 20h,al
    

    acknowledges the interrupt. If you call the BIOS interrupt handler then you should not also do this, as the BIOS handler will do it.




回答2:


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.

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]


来源:https://stackoverflow.com/questions/10480576/custom-keyboard-interrupt-handler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!