Thread: hooking my own interrupt without help from dos

  1. #1
    Registered User
    Join Date
    Sep 2001

    hooking my own interrupt without help from dos

    How would I do this?
    Acos is good

  2. #2
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Plano, Texas, United States
    what do you mean? do you mean like calling the interrupts yourself rather than using int86()?

    If that is what u mean....use the asm keyword. ex:

    asm {
    mov ah, 00 //this code will wait for a keypress
    int 16
    My Website

    "Circular logic is good because it is."

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    #define INTR 0x10
    void far (*ISR)()=0;

    unsigned int ISROffset;
    unsigned int ISRSegment;

    void far *GetINTRPointer(void);

    int main(void)
    (void far *)ISR=GetINTRPointer();


    //Test to see if we are pointing at the handler
    //Call the function just like any other C function
    printf("In mode 13h\n");
    return (0);

    void far *GetINTRPointer(void)
    return (void far *)MK_FP(ISRSegment,ISROffset);

    This will work, but will cause major problems. We are hooking into the interrupt chain w/o telling DOS. We have underhandedly hooked into the chain but nobody else will know because we did not notify DOS that we did. DOS does a couple of things when you hook interrupts that allows everyone to get along in the system. W/o using DOS, you are asking for chaos. Turbo C++ 1.01 crashed back to Windows doing this. In the early days your program was not the only one using DOS so you had to follow the rules. Now, since most of those drivers aren't there anymore and DOS is basically vacant - you might get away with this for a little bit longer than before. But, it will come crashing down eventually.

    The problem here is that the interrupt 10 handler assumes it is being invoked via an interrupt. So, instead of doing a RET (return from procedure) it does an IRET (for 16-bit - return from interrupt). But, we haven't invoked the handler by an INT so the IRET will most likely crash the system. We have directly called the handler via a far call, but it has no way of knowing that. The handler and the CPU both are expecting an IRET - after an INT you must do an IRET so as not to cause instability in the system. Actually there is a way it could see the far call, but I guarantee that is not in the handler since it is not good practice to call ISRs, hook INTs, and unhook INTs w/o some intervention from DOS. He should know about everything that's going on - after all he is trying to run the system and keep it stable. Also it is a good chance that the int 10 handler is throwing an EOI to the PIC so the video card stops pulling the INT. If there has been no INT, then this will often times crash the system as well since the PIC never knew about the interrupt so all of it's lines are low instead of high. But, the handler is saying to the PIC - ok, the int is done so you can go low on your lines and stop the INT cuz we are done with it. Shortly thereafter it will issue an IRET to leave the ISR.

    I did get it to work fine in Borland C++, but a lot of it had to be in asm so I could save the system state and attempt to restore it after the call. This method is slower than using an INT, although I still do not know why. Even with all of my precautions the system was still very unstable.

    The pseduocode for an IRET and RET are different. Several things happen in an IRET that do not happen in a RET and vice versa.

    I cannot post the pseudo here as it's very long.

    Intel does say that an IRET will reverse both a CALL and an INT, but there's gotta be a reason for them putting two distinct opcodes for IRET and RET. Either way, the PIC will still be confused even if the CPU isn't.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. really weird behavior, 16 bit asm w/masm
    By BobMcGee123 in forum A Brief History of
    Replies: 7
    Last Post: 12-01-2005, 06:45 PM
  2. TSR to detect video mode
    By surdy in forum C Programming
    Replies: 4
    Last Post: 03-21-2004, 07:31 PM
  3. DOS, Serial, and Touch Screen
    By jon_nc17 in forum A Brief History of
    Replies: 0
    Last Post: 01-08-2003, 04:59 PM
  4. DOS program versus DOS console program
    By scromer in forum A Brief History of
    Replies: 4
    Last Post: 01-10-2002, 01:42 PM
  5. Sound card interrupt problems
    By VirtualAce in forum A Brief History of
    Replies: 3
    Last Post: 12-05-2001, 04:38 AM