General Protection Fault

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
User avatar
matthias
Member
Member
Posts: 158
Joined: Fri Oct 22, 2004 11:00 pm
Location: Vlaardingen, Holland
Contact:

General Protection Fault

Post 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
Last edited by matthias on Sun Sep 04, 2005 11:00 pm, edited 1 time in total.
The source of my problems is in the source.
Osbios
Member
Member
Posts: 116
Joined: Fri Jun 10, 2005 11:00 pm

Re: General Protection Fault

Post 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++.
Last edited by Osbios on Sun Sep 04, 2005 11:00 pm, edited 1 time in total.
dw 0xAA55
User avatar
matthias
Member
Member
Posts: 158
Joined: Fri Oct 22, 2004 11:00 pm
Location: Vlaardingen, Holland
Contact:

Re: General Protection Fault

Post 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.
The source of my problems is in the source.
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: General Protection Fault

Post 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...
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Re: General Protection Fault

Post 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
User avatar
matthias
Member
Member
Posts: 158
Joined: Fri Oct 22, 2004 11:00 pm
Location: Vlaardingen, Holland
Contact:

Re: General Protection Fault

Post 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 ;)
The source of my problems is in the source.
User avatar
matthias
Member
Member
Posts: 158
Joined: Fri Oct 22, 2004 11:00 pm
Location: Vlaardingen, Holland
Contact:

Re: General Protection Fault

Post 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");
}
Last edited by matthias on Sun Sep 11, 2005 11:00 pm, edited 2 times in total.
The source of my problems is in the source.
User avatar
matthias
Member
Member
Posts: 158
Joined: Fri Oct 22, 2004 11:00 pm
Location: Vlaardingen, Holland
Contact:

Re: General Protection Fault

Post 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
The source of my problems is in the source.
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: General Protection Fault

Post 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.
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
User avatar
matthias
Member
Member
Posts: 158
Joined: Fri Oct 22, 2004 11:00 pm
Location: Vlaardingen, Holland
Contact:

Re: General Protection Fault

Post 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 ;)
The source of my problems is in the source.
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re: General Protection Fault

Post by bubach »

I would suggest that you insert an EOI before the "iret"....
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
User avatar
matthias
Member
Member
Posts: 158
Joined: Fri Oct 22, 2004 11:00 pm
Location: Vlaardingen, Holland
Contact:

Re: General Protection Fault

Post 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 ??)
The source of my problems is in the source.
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Re: General Protection Fault

Post 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
Post Reply