Page 1 of 1

General Protection Fault

Posted: Sun Sep 04, 2005 11:00 pm
by matthias
Hi everyone,

When I enable interrupts, I get a general protection fault (0x0D). GDT, IDT code is ok. I used the same code as my c++ kernel but, now I get a GPF :S

Code: Select all


init_gdt(); // goes well.. debuging didn't point any bugs
init_idt(); // the same for this one.. 

asm("sti"); // after this a GPF happens :@(6)
for(;;); // go and do infinitly nothing :p
I really have no idea why this happened.. A GPF when I'm just looping :S
I hope someone can help.

Here is also some source:
http://www.telebyte.nl/~vdvlies/source.rar

Thanks in advance,

Matthias

Re: General Protection Fault

Posted: Sun Sep 04, 2005 11:00 pm
by Osbios
GDT, IDT code is ok. I used the same code as my c++ kernel
Oo ?
I really have no idea why this happened.. A GPF when I'm just looping :S
hmm... you dont know timer ints?
http://www.clipx.net/ng/hardware/ng256d3.php

And btw, i cant C or C++.

Re: General Protection Fault

Posted: Sun Sep 04, 2005 11:00 pm
by matthias
Sorry, but this has nothing to do with timer ints.. This should work since it worked for me before.. I only stripped the code out of my classes and converted it to normal C code.

Re: General Protection Fault

Posted: Mon Sep 05, 2005 11:00 pm
by xenos
I just looked at your code. What happens, when the timer interrupt fires? There doesn't seem to be an interrupt handler for that case, resulting in a GPF...

Re: General Protection Fault

Posted: Sat Sep 10, 2005 11:00 pm
by earlz
hmm i bet thats why my os gets a gpf after enabling interrupts and then going into an infinite loop

you also need to remap the pic because by default it starts at 8 which is also reserved for exceptions so it would be like everytime your timer rings it has an 8th exception

Re: General Protection Fault

Posted: Sat Sep 10, 2005 11:00 pm
by matthias
hckr83 wrote: you also need to remap the pic because by default it starts at 8 which is also reserved for exceptions so it would be like everytime your timer rings it has an 8th exception
If you've read my source code carefully I already did that ;)

Re: General Protection Fault

Posted: Sun Sep 11, 2005 11:00 pm
by matthias
XenOS wrote:I just looked at your code. What happens, when the timer interrupt fires? There doesn't seem to be an interrupt handler for that case, resulting in a GPF...
Though there is.. The interrupt is handled by the default handler int_unknown() which does only an iret (just lookup in my idt_init() function).. Shouldn't give a problem. Worked before.

Code: Select all

void int_unknown()
{
	asm("iret");
}

Re: General Protection Fault

Posted: Wed Sep 14, 2005 11:00 pm
by matthias
After some debugging I found out that the GPF occured after the asm("iret"); So IDT is ok.. Maybe it's of any use.. I wonder what causes this :S

Re: General Protection Fault

Posted: Wed Sep 14, 2005 11:00 pm
by xenos
Have you checked whether the compiler creates a stack frame for int_unknown? If so, the raw asm("iret"); causes a return to the pushed EBP register instead of the return address, resulting in a GPF.

Re: General Protection Fault

Posted: Thu Sep 15, 2005 11:00 pm
by matthias
XenOS wrote:Have you checked whether the compiler creates a stack frame for int_unknown? If so, the raw asm("iret"); causes a return to the pushed EBP register instead of the return address, resulting in a GPF.
That could be the cause of my problem.. Thanks.. I'll put it in a .asm file.. and test if it works ;)

Re: General Protection Fault

Posted: Sat Sep 17, 2005 11:00 pm
by bubach
I would suggest that you insert an EOI before the "iret"....

Re: General Protection Fault

Posted: Tue Sep 20, 2005 11:00 pm
by matthias
EOI wasn't needed to solve the problem.. I've put the function in a assembly file and assebled it with nasm.. linked it in my kernel.. and it works... But Now I've got another question (not a problem :p).. Is there an option in GCC to disable the creation of a stack-frame? (Was it the -fomit-frame-pointer option ??)

Re: General Protection Fault

Posted: Thu Sep 22, 2005 11:00 pm
by earlz
in my kernel i had to pop 3 dwords to trash(edx) for it to iret to the interrupt pushed stuff

also you mght not get a gpf for it but you should send an end of interrupt signal to the pic

such as here is my timer interrupt function

Code: Select all

#define irqm_return __asm("pop %edx");__asm("pop %edx");__asm("pop %edx");outportb(0x20, 0x20);__asm("iret")
void irq0(){ /*overflow causes invalid opcode error, although that dont quite make sense*/
	/*timer*/
	if (timer_ticks>0xFFFFFFF5){timer_ticks=0;}
	timer_ticks++;
	irqm_return;
}
as i stated, for some reason UNDER BOCHS an overflow causes an invalid opcode error although i got no error with microsoft vpc and i got no error on my real pc