ASM interrupt and others
First off. I give credit to the programers of the past. You people are bad ass mofos.
I've been studing(hardcore) on asm for 6 months.
Using dos programs for a study habit.
Now my questions.
How do you add a routine to an interrupt chain?
And secondly (If not first) What is the exact format of a 16/32-bit *.exe
You can do this two ways. You can either directly patch the IVT which starts at 0000:0000 or you can call the DOS int 21h function that will do it for you.
To patch directly:
Place offset of new ISR at IntVector*4
Place segment of new ISR at (IntVector*4)+2
For information on the correct register values to tell DOS to do this for you check the RBIL or Randall Hyde's assembly book (Art of Assembly Language Programming).
DOS should be called to do this
I would have DOS patch the vector for you. This allows DOS to do some vital housekeeping chores in order to ensure system stability. Also in most cases you should call the previous ISR from your ISR just to ensure that everyone has a chance to respond to the interrupt. If you do not do this, you will effectively break the chain. The only time I can think of that it is necessary to break the chain is when patching the keyboard vector or int 09h. You don't want to call the previous vector since it causes that annoying beeping when the key buffer is full. There are ways to physically remove keys from the circular buffer, but personally I think that's a hack and should not be used.
CTRL-BREAK and Critical Error Handler vectors
If you are patching the int 23h or 24h (CTRL-BRK and Critical Error Handler) vectors you must call DOS to do this correctly. DOS will automatically save these vectors for you so you do not have to restore them yourself. As well, if you notify DOS that you are patching these, you and DOS will get along much better. It is possible to patch them w/o using DOS, but I don't recommend it.
Timer vector - for tracking clock ticks and program timing
If you are patching the timer vector, you must patch this indirectly. If you attempt to patch the timer vector directly you could alter the time of day that your computer reports. Each time the timer interrupt is triggered, it also triggers another 'safe' interrupt that you can patch to track clock ticks. Don't mess with the original timer ISR (This vector number and the patchable one are often BIOS dependent - check the RBIL).
Save the current vector prior to patching
Remember to save the current vectors BEFORE you patch with new ones. DOS does not keep track of the vectors you patch (except for 23h and 24h - only on call to DOS int 21h) and if you exit your program (function 04C0h int 21h) the ISR chain for that vector will be broken. Well behaved programs restore the IVT to the condition it was in prior to the program patching it.
I would post the entire header structure of a 16/32 bit exe here, but it is rather long and I've done it before. Don't feel like re-typing that information. You can look it up on www.google.com and you will find loads of links to sites that discuss the EXE structure. Note that this is only for MZ EXEs or DOS EXEs. For information on the PE format (Windows 9x) you can check www.msdn.microsoft.com.
I will tell you that the relocation table for the EXE lies directly after the header. This information is used to produce code that is relocatable into any segment or multiple segments. Unlike their COM counterparts, EXE entry points are not at 0100h, but start at 0000h into the segment.
So, if you write FAT code that loads an EXE from disk, you simply load it into a segment by checking the relocation table and any items in it. Then you translate the addresses(offsets) based on that information, load the CPU registers with the correct data from the EXE header (you will see this when you see the header), and then you can JMP to the code or you can push an address on the stack and do a far return.
Ya. i have no life.
Originally posted by Sean
It took you 6 months?
"Art of Assembly Language Programming"
good book. HIGHLY recommended.
but bubba, what is the "RBIL"?
RBIL : Ralph Brown's Interrupt List
great stuff for all interrupt handling.
search for it on google [i dont remember the link] and dont forget to download the "viewer" made esp for the list.
I mean that was a long time. But then, you probably actually REMEMBERED what you studied didn't you! I should really work on that..... Speaking of which. I was doing that list a while ago, where it teaches you the basics of an instruction, like how to use one etc. then it has just a long list of instructions and all the information you need on each one. I was thinking of doing a similar thing with HTML tags. Who'd be interested?