Page 1 of 3
page enable problem
Posted: Sat May 16, 2009 2:12 am
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
}
}
Re: page enable problem
Posted: Sat May 16, 2009 12:19 pm
by Combuster
Please read the rules and use code tags.
Your paging structures are most likely not page aligned. use __attribute__ (aligned(4096)).
Re: page enable problem
Posted: Sun May 17, 2009 12:12 am
by kop99
combuster...
thanks for your help...
I'll try it...
Re: page enable problem
Posted: Sun May 17, 2009 12:32 am
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...
Re: page enable problem
Posted: Sun May 17, 2009 4:41 am
by Combuster
Write a memory manager. Or use some linker script magic to force page alignment.
Re: page enable problem
Posted: Sun May 17, 2009 10:01 am
by NickJohnson
Re: page enable problem
Posted: Mon May 18, 2009 2:32 am
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...
Re: page enable problem
Posted: Tue May 19, 2009 4:42 am
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?
Re: page enable problem
Posted: Tue May 19, 2009 4:50 am
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.
Re: page enable problem
Posted: Tue May 19, 2009 5:19 am
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....
Re: page enable problem
Posted: Tue May 19, 2009 5:55 am
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).
Re: page enable problem
Posted: Tue May 19, 2009 6:03 am
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...
Re: page enable problem
Posted: Tue May 19, 2009 6:06 am
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.
Re: page enable problem
Posted: Tue May 19, 2009 6:12 am
by kop99
i've download the bochs and reading how to document...
i'll post the log as soon as posible
Re: page enable problem
Posted: Wed May 20, 2009 4:09 am
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...