Page 1 of 1

[Paging] General Protection Fault when setting paging bit

Posted: Wed Dec 22, 2010 9:59 am
by samuelagm
Please can anyone help me, my kernel works fine until i try to initialize paging by setting the paging bit in the cr0 register.
My directory and page table are okay and the address of my page directory gets into the cr3 register fine(from BOCHS register info screen), but when i try to set the paging bit BOCHS resets and generates this message

add byte ptr ds:[eax],al:0000.
exception 13 (which is General Protection Fault)


This is the code that sets the paging bit

Code: Select all

__asm__ __volatile__ (            "movl %cr0, %eax            \n"
                                  "orl $0x80000000,  %eax   \n"
                                  "movl %eax, %cr0           \n");


I even tried placing the page directory at 100000 and page table at 101000 to no avail
 :(

Re: [Paging] General Protection Fault when setting paging bi

Posted: Wed Dec 22, 2010 12:16 pm
by gerryg400
Are you using inline assembler with no 'constraints' ? Trashing eax in the middle of a c function is not usually a good idea.

Re: [Paging] General Protection Fault when setting paging bi

Posted: Wed Dec 22, 2010 1:36 pm
by Combuster
Do not use colours (red is indiscernable from the background in my theme) , fix your page tables as they point into nothingness, and browse the front page of this forum and look for the half dozen others that reported this exact error message.

Re: [Paging] General Protection Fault when setting paging bi

Posted: Thu Jan 13, 2011 10:41 am
by samuelagm
Thanks alot Guys, moving the page directry and page table to 0x109c00 and 0x109d00 respectively and re-writing the code in pure assembly language (no more inline assembly) solved the problem :D , as for the colours in my post; forgive me I didn't bother to read the forum rules :oops: , it would'nt happen again.

Re: [Paging] General Protection Fault when setting paging bi

Posted: Thu Jan 13, 2011 11:12 am
by Combuster
moving the page directry and page table to 0x109c00 and 0x109d00
Paging structures need to be aligned to 4K or the processor will either complain or silently align them for you (so they both end up at 0x109000)

Re: [Paging] General Protection Fault when setting paging bi

Posted: Thu Jan 13, 2011 1:12 pm
by Dario
samuelagm wrote:moving the page directry and page table to 0x109c00 and 0x109d00 respectively
You shouldn't care too much about exact addresses as long as they are in predicted region in memory with correct alignments.
samuelagm wrote: and re-writing the code in pure assembly language (no more inline assembly)
Will that make your coding more efficient?

Re: [Paging] General Protection Fault when setting paging bi

Posted: Mon Jan 17, 2011 11:01 am
by samuelagm
Combuster wrote:Paging structures need to be aligned to 4K or the processor will either complain or silently align them for you (so they both end up at 0x109000)
Yea, you're right, after a while I started getting "page not present exceptions" after enabling paging, after seeing your post I change both the page directory and page table addresses to 0x109000 and 0x10a000 respectively and it worked!

The cause of the initial problem I posted was because the page table address was 0x10100
instead of 0x101000, thats why I was getting the "eax" message. I'm loving OS deving its just like a soap opera :D

Re: [Paging] General Protection Fault when setting paging bi

Posted: Mon Jan 17, 2011 11:17 am
by samuelagm
Dario wrote:
samuelagm wrote: and re-writing the code in pure assembly language (no more inline assembly)
Will that make your coding more efficient?
I wouldn't say yes, but I now prefer all my assembly codes in one or two asm files rather than being scattered in my c files, is there any drawback to this technique?

Re: [Paging] General Protection Fault when setting paging bi

Posted: Mon Jan 17, 2011 11:38 am
by Dario
samuelagm wrote:is there any drawback to this technique?
No...it's just that you have more work to do (assembling and linking), calling your asm code, more files...It's much more easier to just put asm snippet in your C code stream...and all is well...just make sure you know your tools.
That is especially true for very short streams of code like enabling paging, etc.

EDIT: 100 post! \:D/