[Solved] C++ - Only divide by zero is caught
Posted: Fri Apr 11, 2014 11:36 am
The divide by zero is caught correctly (at least it appears so) and reports error "0" but when I try to call
It returns error code 4026595393 (it is consistent through a complete rebuild, as well as if I were to use random letters instead of INT3) instead of 2. The assembly for both exceptions are the same with the difference only being in the name
and this is my C function:
I'm guess there is an error in my idt set gate function but I'm lost as to what it could be:
In case you want to read through the rest of the source here is a link to it and you can ask question if you want - not that I'd stop you XD
Any help is appreciated, include how to create other exception, I followed a tutorial on osdever.net on how to setup the GPT, etc and peeked at the source of this tutorial: http://www.websofia.com/writing-your-own-toy-operating-system/ (there is source code in C for a kernel in the complete source he gives - which looks similar to how the tutorial osdev.net has implemented it), the tutorial on osdev.net was also C based and I have tried to convert it to C++ as much as I can
Code: Select all
__asm__ __volatile__ ("INT3")
Code: Select all
isr<number>:
cli
push 0x0
push 0x<Hex value of number>
call isr_handler
isr_handler:
pusha
push %ds
push %es
push %fs
push %gs
mov %ax, 0x10
mov %ds, %ax
mov %es, %ax
mov %fs, %ax
mov %gs, %ax
call <C function>
pop %gs
pop %fs
pop %es
pop %ds
popa
add %esp, 8
iret
Code: Select all
struct regs {
unsigned int gs, fs, es, ds;
unsigned int edi, esi, edp, esp, ebx, edx, ecx, eax;
unsigned int int_no, err_code;
unsigned int eip, cs, eflags, usersp, ss;
};
extern "C" {
void fault_handler(struct regs* r) {
Terminal::print("Error: ");
Terminal::println(Functions::intToChar(r->int_no));
if(r->int_no < 32) {
Terminal::println(exceptionMessage[r->int_no]);
}
for(;;);
}
}
Code: Select all
struct IDT::idt_entry {
uint16_t base_low;
uint16_t sel;
uint8_t always0;
uint8_t flags;
uint16_t base_hi;
} __attribute__((packed));
void IDT::idtSetGate(unsigned char num, unsigned long base, unsigned short sel, unsigned char flags) {
idt[num].base_low = (base & 0xFFFF);
idt[num].base_hi = (base >> 16) & 0xFFFF;
idt[num].sel = sel;
idt[num].always0 = 0;
idt[num].flags = flags;
}
Any help is appreciated, include how to create other exception, I followed a tutorial on osdever.net on how to setup the GPT, etc and peeked at the source of this tutorial: http://www.websofia.com/writing-your-own-toy-operating-system/ (there is source code in C for a kernel in the complete source he gives - which looks similar to how the tutorial osdev.net has implemented it), the tutorial on osdev.net was also C based and I have tried to convert it to C++ as much as I can