[SOLVED] enabling paging on real processor

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
davidv1992
Member
Member
Posts: 223
Joined: Thu Jul 05, 2007 8:58 am

[SOLVED] enabling paging on real processor

Post by davidv1992 »

After adding multitasking to my kernel and getting everything working again wanted to try something fun and run the kernel on actual hardware (instead of bochs).

However, after a lot of debugging figured out that on my processor (some AMD 64 bit dual core: "AMD Turion(tm) 64 X2 Mobile Technology TL-58" according to linux /proc/cpuinfo) something went awry on turning on paging (or so I believe). For this i am using the following code:

Code: Select all

asm("mov %0, %%cr3\n" : : "r" (main_map));
	asm("mov %%cr0, %%eax\n"
		"or 0x80000000, %%eax\n"
		"mov %%eax, %%cr0" : : : "eax");
main_map is the address of the pagedirectory anded with 0xFFFFF000 and ored with 0x8.

(figured this out by removing my identity mapping frrom pagedir, which caused pagefault (as expected) in bochs but did nothing on the real deal)

Has anyone seen something like this before or has an explanation.

For reference, on bochs i use grub 0.97 to boot (grub legacy), on the real hardware grub 1.96beta4 (the default for ubuntu 9.10).
Last edited by davidv1992 on Mon Nov 15, 2010 2:41 am, edited 1 time in total.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Re: enabling paging on real processor

Post by pcmattman »

Try removing the or with 0x8.
davidv1992
Member
Member
Posts: 223
Joined: Thu Jul 05, 2007 8:58 am

Re: enabling paging on real processor

Post by davidv1992 »

Isnt that or the whole point of fetching cr0 into eax and then writing (an edited version of) it back again?
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Re: enabling paging on real processor

Post by pcmattman »

No, that's an OR with 0x80000000.

I was referring to:
main_map is the address of the pagedirectory anded with 0xFFFFF000 and ored with 0x8.
TylerH
Member
Member
Posts: 285
Joined: Tue Apr 13, 2010 8:00 pm
Contact:

Re: enabling paging on real processor

Post by TylerH »

Oring by 8 in cr3 enables write through.
davidv1992
Member
Member
Posts: 223
Joined: Thu Jul 05, 2007 8:58 am

Re: enabling paging on real processor

Post by davidv1992 »

Manual says that too. Tried change nontheless, but it didn't do anything.

Starting to think this might be some hardware issue (wouldnt be a surprise really, 3 year old laptop that has overheated quite a bit more often than i think is good for it, only surprise would be that ubuntu still works) so does anyone have some real barebones code that just tests paging?
xyzzy
Member
Member
Posts: 391
Joined: Wed Jul 25, 2007 8:45 am
Libera.chat IRC: aejsmith
Location: London, UK
Contact:

Re: enabling paging on real processor

Post by xyzzy »

You need a $ before 0x80000000. Without the $, you're ORing with the contents of memory at 0x80000000, not the value 0x80000000.
davidv1992
Member
Member
Posts: 223
Joined: Thu Jul 05, 2007 8:58 am

Re: enabling paging on real processor

Post by davidv1992 »

:shock: I should've seen that.

It works now. Thanks for the tip.
Post Reply