VOGONS


First post, by nicor

User metadata
Rank Newbie
Rank
Newbie

Hi all. I´m new here.

I use Dosbox to program in Turbo C. Just an old fashion hobby of mine.

Recently, I tried to replace an interrupt vector, eg. divide by zero interrupt (INT 0) using getvect() and setvect() with my own code (a printf() message). The problem is when interrupt function returns, immediately executes again from the beginning. So never returns control to code outside.
By the other hand, calling the backed up vector just before return from my own interrupt everything works nice, but of course both interrupt functions execute (mine and the original).
I tried with INT9 with same results.

In microcontroller architectures one must reset a specific interrupt flag just to avoid re-entering the ISR. I don´t know if PC architecture requires something like that. Can you give me some advice?

Thanks in advance.

Reply 1 of 3, by wd

User metadata
Rank DOSBox Author
Rank
DOSBox Author

problem is when interrupt function returns, immediately executes again from the beginning. So never returns control to code outside.

That's by design, there is an exceptional event, the handler is responsible to clear up the situation. Usually that means for divbyzero to abort the program, if not and (like in your case) you want to skip that instruction you have to care about adjusting the return IP yourself (not that easy).

In microcontroller architectures one must reset a specific interrupt flag just to avoid re-entering the ISR.

This is irrelevant here, ISRs are executed with the interrupt flag disabled unless the ISR changes the flag. On IRET the flags are restored. This all ONLY affects hardware interrupts (PIC triggered) so divbyzero is not affected anyways (though the IF flag is cleared here too).

Reply 2 of 3, by nicor

User metadata
Rank Newbie
Rank
Newbie

Thank you so much, wd for making a time to answer.

That's by design, there is an exceptional event, the handler is responsible to clear up the situation.

I get the interrupt because in a int a/int b, b equals 0. So, adjusting b to 1 before returning from ISR works nice. I´m not doing this in ASM (must study a little more), so I believe this is not the most elegant solution.

if not and (like in your case) you want to skip that instruction you have to care about adjusting the return IP yourself (not that easy).

Sounds very interesting. I don´t want to bother you, just in case you remember some source of information about this, I´ll appreciate that.

Reply 3 of 3, by wd

User metadata
Rank DOSBox Author
Rank
DOSBox Author

I´m not doing this in ASM

You should. Any hardware triggered interrupt can occur in a location that your high level compiler/library/whatever doesn't expect (just think about stack dependence) so you shouldn't do much more than a few plain ASM instructions like what you're doing by adjusting registers to avoid the div by zero.

some source of information about this

intel/amd instruction set references are a good start.
Also check the differentiation in software ints (INT xx instruction), hardware ints (PIC triggered) and exceptions (cpu detected conditions) at
http://en.wikibooks.org/wiki/X86_Assembly/X86_Interrupts
whereas for exceptions almost always the instruction pointer (the one saved on the stack when entering the ISR) points to the start of the faulting instruction.