interrupt handling in protected mode.

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
Utku DEMIR

interrupt handling in protected mode.

Post by Utku DEMIR »

I want to handle interrupts in protected mode but I think I couldnt manage to do so. I wrote my own gdt, idt and interrupt handler functions. For ins. I handle int 0(division by zero). To be simple, I just give a message and returned from function. My function work fine whenever I wrote "int 0" in my code. It printed the message and returned successfully, but when I try to create interrupt internally, I mean when I code like this (mov bx, 0; div bx;) it prints the message and crashes. I mean the function works fine but cant return. just crashes after executing function. Even, I tried to send EOI to pics. But didnt work. Where did I wrong?Does anyone have idea?? ???
slacker

Re:interrupt handling in protected mode.

Post by slacker »

i dont know what your trying to say. try rewording your question so that people can understand and help you.
Curufir

Re:interrupt handling in protected mode.

Post by Curufir »

Divide by zero is a fault, it pushes the CS/EIP of the faulting instruction onto the stack when it causes the exception. It does this because the processor expects the OS to handle the fault, and decide whether or not to kill the application or fix the problem.

Now if you just call INT 0 in your code this isn't a problem. The reason for this is that by calling it in your code you are using a software interrupt, therefore the CS/EIP pushed onto the stack will point to the next instruction, not the INT 0 instruction.

What happens when you force the exception is that the CS/EIP of your DIV BX instruction are pushed onto the stack, you happily print out a message, then IRET straight back into the same DIV BX instruction which is executed again. The DIV BX instruction will cause another divide by zero exception and you have an infinite loop. Needless to say this isn't a good thing.

Now if you have your message being printed at the same place each time (Eg by manipulating video memory) this is going to look like your machine has crashed when in actual fact it's just printing the message a few hundred time per second.

Hope that help.
Utku DEMIR

Re:interrupt handling in protected mode.

Post by Utku DEMIR »

Yes, that is the problem, thanks.

But how can I understand the interrupt caused by software or hardware and how can I solve this problem?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:interrupt handling in protected mode.

Post by Pype.Clicker »

Just make sure the software can't call INT 0 by setting the DPL field at 0 in the first IDT descriptor :) this way, only the kernel can issue an INT 0 instruction -- and it will never do it because kernel programmers are nice guy that will know they shouldn't do it -- and when the CPU will encouter a division by zero, it will call exception 0 (regardless of the CPL and the DPL, which doesn't apply in that case :)
Post Reply