Page 1 of 1

Protected mode exception keeps reoccuring

Posted: Thu Jan 19, 2012 7:57 am
by helino
Hi,

I've just started to get my IDT working (works great for IRQ and INT instructions).
However, in order to test that it was working for protected mode exceptions, I wrote the following assembly code:

Code: Select all

mov edx, 0
div edx
in order to generate a divide error (#DE).

My interrupt handler gets called, but the problem is, it gets called multiple times.
I'm using a trap gate in the IDT and I don't disable interrupts in my handler, therefore other interrupts can happen at the same time.

Should protected mode exceptions keep reoccurring, or have I done something wrong (most likely :D)?
Do I need to acknowledge that I've handled the exception somehow?

Thanks!

Re: Protected mode exception keeps reoccuring

Posted: Thu Jan 19, 2012 9:04 am
by Combuster
If you return to the faulting code without fixing the problem it will obviously reoccur.

Re: Protected mode exception keeps reoccuring

Posted: Thu Jan 19, 2012 9:14 am
by Velko
If you simply "return" from exception handler, it is perfectly normal.
  • Instruction generates #DE
  • Exception handler is called
  • Exception handler returns
  • CPU tries to execute the same instruction again
  • Instruction generates #DE again
  • ...
In real system you should do something else, like sending a signal to process, killing it, or something like that, but return to same instruction.

When handling #PF it may be acceptable, though. If you adjust Page Tables accordingly before returning.

Re: Protected mode exception keeps reoccuring

Posted: Thu Jan 19, 2012 9:27 am
by helino
Aah, now I see, of course!

Thanks for your great answers, Combuster and Velko, I really appreciate it!