How to handle an interrupt?
-
25-10-2019 - |
Question
I have a task to write a program which handles the division by zero exception. I'm having a hard time finding information about that. As I understand, I need to change the 0th entry in interrupt vector table, but how do I do that? I see there is a LIDT instruction, but wouldn't I have to write the whole table then?
Note, I'll be working in 16 bit mode.
Solution
Assuming that you mean "real mode" by 16-bit mode, the interrupt vector table is simply located starting at linear address 0, see the wikipedia entry. So it's a matter of getting the old 4-byte far pointer from [0000:0000]
so it can be restored later (or chained) and overwriting the entry with your own handler.
If you're using DOS you can use INT 21h/AH=25h
to set the interrupt vector and INT 21h/AH=35h
to retrieve the old entry.