Page 1 of 1

[SOLVED] enabling paging on real processor

Posted: Sun Nov 14, 2010 3:15 pm
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).

Re: enabling paging on real processor

Posted: Sun Nov 14, 2010 3:25 pm
by pcmattman
Try removing the or with 0x8.

Re: enabling paging on real processor

Posted: Sun Nov 14, 2010 4:46 pm
by davidv1992
Isnt that or the whole point of fetching cr0 into eax and then writing (an edited version of) it back again?

Re: enabling paging on real processor

Posted: Sun Nov 14, 2010 4:48 pm
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.

Re: enabling paging on real processor

Posted: Sun Nov 14, 2010 7:50 pm
by TylerH
Oring by 8 in cr3 enables write through.

Re: enabling paging on real processor

Posted: Mon Nov 15, 2010 12:07 am
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?

Re: enabling paging on real processor

Posted: Mon Nov 15, 2010 1:25 am
by xyzzy
You need a $ before 0x80000000. Without the $, you're ORing with the contents of memory at 0x80000000, not the value 0x80000000.

Re: enabling paging on real processor

Posted: Mon Nov 15, 2010 2:40 am
by davidv1992
:shock: I should've seen that.

It works now. Thanks for the tip.