page enable problem

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.
User avatar
kop99
Member
Member
Posts: 120
Joined: Fri May 15, 2009 2:58 am

page enable problem

Post by kop99 »

Hi, everybody...

I have some problem in my kernel development.
I just began to os development, and I've aleady finished bootloader and protected mode...

Now I'm gonna enable the paging...
So I've made simple dummy code for paging... But When I boot it, computer is restared...
What problem is it? please help me... thanks for your reguard...

Code: Select all

DWORD	swapper_pg_dir[1024];
DWORD	pg0[1024];

void init_page(void)
{
	init_page_table();
	init_page_directory();
	page_enable((DWORD)swapper_pg_dir);
}

void init_page_table(void)
{
	DWORD i;

	for (i=0; i<PAGE_TABLE_ENTRY; i++) {
		pg0[i] = (DWORD)((i * 0x1000) + 0x7);
	}
}

void init_page_directory(void)
{
	DWORD i;

	for (i=0; i<PAGE_DIRECTORY_ENTRY; i++) {
		swapper_pg_dir[i] = (DWORD)0;
	}

	swapper_pg_dir[0] = (DWORD)((DWORD)pg0 + 0x7);
}

void page_enable(DWORD pdbr)
{
    __asm {
	mov	eax, pdbr
	mov	cr3, eax
	mov	eax, cr0
	or	eax, 0x80000000
	mov	cr0, eax
   }
}
Last edited by kop99 on Tue May 19, 2009 4:55 am, edited 1 time in total.
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: page enable problem

Post by Combuster »

Please read the rules and use code tags.

Your paging structures are most likely not page aligned. use __attribute__ (aligned(4096)).
"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
kop99
Member
Member
Posts: 120
Joined: Fri May 15, 2009 2:58 am

Re: page enable problem

Post by kop99 »

combuster...
thanks for your help...

I'll try it...
User avatar
kop99
Member
Member
Posts: 120
Joined: Fri May 15, 2009 2:58 am

Re: page enable problem

Post by kop99 »

I'm using gcc compiler in windows xp...
but there is warning message from compiler....
"warnign: alignment of pg0 is greater than maximum object file alignment. Using 16..."
So it's still not page aligned....
How can i do that...? I'm trying to solve that problem... but if anybody know about that, just help me.... thank you...
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: page enable problem

Post by Combuster »

Write a memory manager. Or use some linker script magic to force page alignment.
"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
NickJohnson
Member
Member
Posts: 1249
Joined: Tue Mar 24, 2009 8:11 pm
Location: Sunnyvale, California

Re: page enable problem

Post by NickJohnson »

I made the same mistake. Take a look at this thread: http://forum.osdev.org/viewtopic.php?f= ... 29#p152829
User avatar
kop99
Member
Member
Posts: 120
Joined: Fri May 15, 2009 2:58 am

Re: page enable problem

Post by kop99 »

Combuster...
I'm really thank you for your help...
I'm looking hard for gcc option to enable the page alignment...
but I'm still not now... I'll continue to looking for the option...
User avatar
kop99
Member
Member
Posts: 120
Joined: Fri May 15, 2009 2:58 am

Re: page enable problem

Post by kop99 »

I'v made the linker script file....
Here is my kernel.lds file's contents...

Code: Select all

SECTIONS
{
	. = 0x100000;
	.text : { *(.text) }
	.data : { *(.data) }
	.bss : {
		*(.bss)
		. = ALIGN(4096);
		swapper_pg_dir = .;
		. += 0x1000;
		pg0 = .;
		}
}
But It still have the same problem...
Is there anything wrong about that script?
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: page enable problem

Post by pcmattman »

Hi,

First of all, why are you OR-ing with 0x7? That's binary 0111b, which, according to the Intel manuals, means PRESENT | READ/WRITE | USER. It looks to me like you're identity mapping the first 4 MB of the address space, which I assume is your kernel. In that case, you're not going to want to have the USER privilege flag set. That'll make that line OR'd with 0x3 (11b). You can see these for yourself - Volume 3A of the Intel Manuals, section 3.7.6 ("page" 3-29).

EDIT: The above is just me being a bit pedantic, it's most likely not the cause of the problem, but something I think you need to consider.

I assume DWORD is a 32-bit unsigned type? You may want to make those arrays work with bytes rather than DWORDs and cast later.

And finally, what are PAGE_TABLE_ENTRY and PAGE_DIRECTORY_ENTRY defined as?

If you've got a Bochs log or something showing the state before the triple fault, that would help us help you too :)

EDIT 2: And with respect to what Combuster was talking about - it's highly likely that the two arrays are not on a page boundary. There are three ways to get around this (two of which Combuster has already mentioned). You can either somehow align the two variables to a page boundary, or you can use an explicit absolute address for the first page table and page directory. For instance, have the page directory at 0x98000 and the page table at 0x99000. Probably the best solution is to write a page allocator and use that to allocate the paging structures.
User avatar
kop99
Member
Member
Posts: 120
Joined: Fri May 15, 2009 2:58 am

Re: page enable problem

Post by kop99 »

pcmattman, thanks for your reguard...

first, i've already tried OR-ing 0x3 and the result was same...
and also I think DWORD type isn't big problem...

I upload the log file...
I'm using VMware6.0,....
log file is following as
http://pastebin.com/m365a0e27

And I've also aleady aligned the swapper_pg_dir at 0x200000 and pg0 at 0x201000....
but it's still happend the same errors....
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: page enable problem

Post by pcmattman »

Hi,

The reason I wanted to see a Bochs debug log is because the log file actually shows the values of CR0, CR2 and CR3. I would like to see the values of all three for a couple of reasons. Firstly, to see where the page fault is happening (CR2 - the address of the faulting page). And secondly, to ensure that your CR3 value is correct (the address of the page directory).
User avatar
kop99
Member
Member
Posts: 120
Joined: Fri May 15, 2009 2:58 am

Re: page enable problem

Post by kop99 »

pcmattman,
I'm looking forward that register's log...
but i don't find anything about that...

Have you any idea about that?
so, please tell me...
i really appreciate it...
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: page enable problem

Post by pcmattman »

When you run your OS in Bochs, Bochs will output a "bochsout.txt" file. If you could put that up on pastebin and post the link, we can have a look and see what's going on.
User avatar
kop99
Member
Member
Posts: 120
Joined: Fri May 15, 2009 2:58 am

Re: page enable problem

Post by kop99 »

i've download the bochs and reading how to document...
i'll post the log as soon as posible
User avatar
kop99
Member
Member
Posts: 120
Joined: Fri May 15, 2009 2:58 am

Re: page enable problem

Post by kop99 »

pcmattman,
I just successed running my own dummy kernel with bochs emulator....
and following is the bochs's log....
http://pastebin.com/f779d95a2

I'll try to solve that triple fault problem...
but if anyone aleady know about that, help me please...
Post Reply