[Paging] General Protection Fault when setting paging bit

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
samuelagm
Posts: 7
Joined: Thu Jun 17, 2010 6:33 pm
Location: Nigeria

[Paging] General Protection Fault when setting paging bit

Post 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
 :(
Last edited by samuelagm on Thu Jan 13, 2011 10:43 am, edited 2 times in total.
And there shall be nothing impossible to those who believe
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

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

Post 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.
If a trainstation is where trains stop, what is a workstation ?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

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

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
samuelagm
Posts: 7
Joined: Thu Jun 17, 2010 6:33 pm
Location: Nigeria

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

Post 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.
And there shall be nothing impossible to those who believe
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

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

Post 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)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Dario
Member
Member
Posts: 117
Joined: Sun Aug 31, 2008 12:39 pm

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

Post 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?
____
Dario
User avatar
samuelagm
Posts: 7
Joined: Thu Jun 17, 2010 6:33 pm
Location: Nigeria

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

Post 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
And there shall be nothing impossible to those who believe
User avatar
samuelagm
Posts: 7
Joined: Thu Jun 17, 2010 6:33 pm
Location: Nigeria

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

Post 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?
And there shall be nothing impossible to those who believe
Dario
Member
Member
Posts: 117
Joined: Sun Aug 31, 2008 12:39 pm

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

Post 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/
____
Dario
Post Reply