Page 1 of 1

an odd problem of my page tables cross 4M

Posted: Sun Apr 13, 2008 8:21 pm
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-

Posted: Mon Apr 14, 2008 1:29 am
by Combuster
A 4M page does *not* require a new table, only a change to one entry in the page directory.

Posted: Mon Apr 14, 2008 1:53 am
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.

Posted: Mon Apr 14, 2008 6:52 am
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?

Posted: Tue Apr 15, 2008 12:28 am
by xyzzy
Page tables and page directories need to be page-aligned (0x1000), so yes, that would be the problem :)