Installing a software interrupt handler under x86 DOS

This isn’t for anything remotely serious, merely for my own edification. I know that I’m requesting knowledge that has been obsolete for a good while, and only appertains to a rather crappy OS in the first place. :wink:

What I want to do is establish my own software interrupt handler under a generic DOS-a-like running on x86 hardware (either IA-16 (8086 and upwards) or IA-32 (80386 and upwards)). I wish to create what would be something like an OS extension without having to modify the OS source code.

To further clarify, I’ll give an example: When you execute the int 21h opcode under most DOS clones, you send the CPU to look at a specifc offset in a jump table. The jump opcode stored at that offset sends it into RAM claimed by the OS so the OS can service the interrupt and then return control to the program. I wish to load my own jump opcode into that table (if I can) and then load my own interrupt-servicing code into RAM, hooking up (say) interrupt 13h to some piece of code I wrote that would do what I choose.

I’m well-versed in both 8086 and 80386 assembly, and I create assembly programs for both dosemu and i686-Linux (I run an AMD Pentium clone). I prefer NASM syntax, as that is the assembler I use, but I’ll be able to work my way through MASM or TASM if I get some help about directives and such. (I doubt GAS will be much used. ;)) If there’s a way to do it in a language that’s not assembly, I’m all ears. Oh, and I have Ralf Brown’s Interrupt List, so I’ll be able to choose an interrupt that isn’t claimed by anything else (with 256 to choose from, it shouldn’t be hard to find a gap).

If you’re running DOS, you can call interrupt function 25H to change the interrupt vector for a given interrupt. You’ll pass it in the segment and offset of your handler.

If you aren’t running DOS then you’ll probably have to modify the vector table manually. Disable interrupts, change the segment and offset in the table to match your routine, then re-enable interrupts (depending on what you are doing, do a pushf, cli, then popf when you are done, rather than just a cli/sti).

Most C compilers will let you install an interrupt handler, but the syntax varies. You usually have to define the function as an interrupt handler, then call a function to install it to the vector table. I’ve never dis-assembled the code they produce, but I suspect that the DOS compilers will simply call the DOS function to do it rather than modifying the table directly.

Thanks. I didn’t think it would be so easy. :slight_smile:

(Another indication I should do more than skim the Interrupt List, methinks.)

Here’s an example in C:
http://www.coding-zone.co.uk/cpp/howtos/200401interrupt.shtml

In my very brief search I wasn’t able to find a good example in assembly. “Advanced Assembly Language” by Allen L. Wyatt, Sr. has some decent examples in it, if you can find a copy of the book.

Have a look at this site - http://webster.cs.ucr.edu/Page_asm/ArtofAssembly/0_ArtofAsm.html

Especially chapters 17 & 18.