Protected mode exception keeps reoccuring

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
helino
Posts: 9
Joined: Mon Jan 16, 2012 8:11 am

Protected mode exception keeps reoccuring

Post 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!
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Protected mode exception keeps reoccuring

Post by Combuster »

If you return to the faulting code without fixing the problem it will obviously reoccur.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Velko
Member
Member
Posts: 153
Joined: Fri Oct 03, 2008 4:13 am
Location: Ogre, Latvia, EU

Re: Protected mode exception keeps reoccuring

Post 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.
If something looks overcomplicated, most likely it is.
helino
Posts: 9
Joined: Mon Jan 16, 2012 8:11 am

Re: Protected mode exception keeps reoccuring

Post by helino »

Aah, now I see, of course!

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