CPU triple faults after divide by zero with ISRs installed
Posted: Mon Sep 26, 2016 9:15 am
I have been stuck with this problem for a few days now and have searched this forum and on Google, but still cannot figure out what is wrong.
I have been following the tutorials at http://www.brokenthorn.com/Resources/OSDevIndex.html and http://www.osdever.net/bkerndev/Docs/intro.htm. I have setup a GDT and IDT that seem to be working correctly. I have also setup all the ISRs and an exception handler function that saves the registers and prints a message to the screen about the interrupt.
The problem is that ISR0 is not being called (or any other ISR) when a DivideByZeroException occurs. Instead of the CPU handling this exception and jumping to and executing the ISR, printing a message that an exception has occured, the CPU just triple faults.
To test the interrupts, I have added the code
and also tried
which, as described above, cause a triple fault.
http://pastebin.com/R2JRVCiT (gdt.asm)
http://pastebin.com/vDZUfRXK (gdt.c)
idt.asm:
http://pastebin.com/R0kFA0tm (idt.c)
http://pastebin.com/hAzX2Y11 (isrs.asm)
http://pastebin.com/9z217v7q (isrs.c)
The fault_handler function and all the ISRs seem to be working correctly. If I put in my kernel, I get the expected error message of 'Exception caught. system halted'. Because of this, I think that it is either my IDT is setup incorrectly and not pointing to the correct ISR to handle the exception or the CPU is not handling the interrupt. Or maybe it's something else?
Sorry that I posted a lot of code, I'm just not sure where the problem is. It's also my first post.
I'm using qemu to test my OS with GRUB legacy and am in protected mode.
I have been following the tutorials at http://www.brokenthorn.com/Resources/OSDevIndex.html and http://www.osdever.net/bkerndev/Docs/intro.htm. I have setup a GDT and IDT that seem to be working correctly. I have also setup all the ISRs and an exception handler function that saves the registers and prints a message to the screen about the interrupt.
The problem is that ISR0 is not being called (or any other ISR) when a DivideByZeroException occurs. Instead of the CPU handling this exception and jumping to and executing the ISR, printing a message that an exception has occured, the CPU just triple faults.
To test the interrupts, I have added the code
Code: Select all
asm("int ")
Code: Select all
printf("%s\n", 4/0)
http://pastebin.com/R2JRVCiT (gdt.asm)
http://pastebin.com/vDZUfRXK (gdt.c)
idt.asm:
Code: Select all
global _idt_install
extern idt_p
_idt_install:
lidt [idt_p]
ret
http://pastebin.com/hAzX2Y11 (isrs.asm)
http://pastebin.com/9z217v7q (isrs.c)
The fault_handler function and all the ISRs seem to be working correctly. If I put
Code: Select all
isr0()
Sorry that I posted a lot of code, I'm just not sure where the problem is. It's also my first post.
I'm using qemu to test my OS with GRUB legacy and am in protected mode.