an odd problem of my page tables cross 4M

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
oohayulin
Posts: 14
Joined: Thu Mar 06, 2008 9:51 pm

an odd problem of my page tables cross 4M

Post by oohayulin »

When my address is less then 0xC0400000(kernel heap start from 0xC0000000, initial_size=0x10000 in a single 4M page table space), everything is ok(Mem info 1). But when i try to allocate the page tabe for the 0xC0400000-0xC0800000, some problem appeared(mem info).

Code: Select all

mem info 1 in qemu(debug mode: info mem)
    00000000-00111000 00111000 ur-
    c0000000-c0400000 00400000 ur-      //0x301 0x0

mem info 2 in qemu(debug mode: info mem)
    00000000-00111000 00111000 ur-
    c0000000-c0400000 00400000 ur-
    c0401000-c0402000 00001000 -r-      //0x301 0x1, where is the hole? <; i have debuged for 4 days, failed.
same in bochs:
    cr3: 000000000010c000
    0x00000000-0x00110fff -> 0x00000000-0x00110fff
    0xc0000000-0xc03fffff -> 0x00111000-0x00510fff
    0xc0401000-0xc0401fff -> 0x00000000-0x00000fff
    0xc0404000-0xc0503fff -> 0x00511000-0x00610fff
from info1 to info2, I just run the following code:

Code: Select all

//page_directory_entry_index=0x301,  for 0xC0400000
dir->tables[page_directory_entry_index]=(page_table_t*)kmalloc_aligned(sizeof(page_table_t), &tmp);
memset(dir->tables[page_directory_entry_index], 0, 1024); // fill 4096 bytes with 0
dir->tablesPhysical[page_directory_entry_index] = tmp | 0x7;	//0x7=0b111
in above code, I confirmed that dir->tables[page_directory_entry_index] can be assigned an address in virtual address space, tmp assigned with an address in pyhsical address. And I tried to manually assign the value in tables to make the c0400000-c0401000 appear in qemu, but failed.

without 0xC0400000-0xC0401000, page-fault will come(cr2=0xC0400000) when i crossed the 4m boundary in test_case of expand.

And when i call get_page with address 0xC0400000+0x1000*i, all map info like that:

Code: Select all

    00000000-00111000 00111000 ur-
    c0000000-c0400000 00400000 ur-
    c0401000-c0402000 00001000 -r-
    c0404000-c0504000 00100000 ur-
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:

Post by Combuster »

A 4M page does *not* require a new table, only a change to one entry in the page directory.
"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 ]
oohayulin
Posts: 14
Joined: Thu Mar 06, 2008 9:51 pm

Post by oohayulin »

Combuster wrote:A 4M page does *not* require a new table, only a change to one entry in the page directory.
You are right. But I think I just changed the physical address of 0x301 Table Page in page directory, with "dir->tablesPhysicals[index]=tmp|0x7;".
Do i misunderstand it?

If I initilized the kernel heap with 16M size at the beginning, it is ok. The problem just appears when I expand the kheap cross the (4*i)M boundary.
oohayulin
Posts: 14
Joined: Thu Mar 06, 2008 9:51 pm

Post by oohayulin »

maybe I found the fault. I did not make the address aligned allocated from the heap, which is used to be a table pointer?
xyzzy
Member
Member
Posts: 391
Joined: Wed Jul 25, 2007 8:45 am
Libera.chat IRC: aejsmith
Location: London, UK
Contact:

Post by xyzzy »

Page tables and page directories need to be page-aligned (0x1000), so yes, that would be the problem :)
Post Reply