Page 1 of 1

Page Fault in Recursive Page Directory

Posted: Tue Jul 26, 2016 5:17 am
by TheBugEater
So I setup recursive page directory in my hobby kernel and it works fine. But when I try to add a new Page Mapping I get a page fault. It seems to store the new physical address of page table in the page directory.

I have been following this tutorial. http://www.rohitab.com/discuss/topic/31 ... directory/

This is my implementation of the Paging : https://github.com/TheBugEater/FluxOS/b ... l/paging.c

The Page Fault Occurs on Line Number 103, when I try to add a new mapping. I was trying to figure out this for the past 2 days. I think I'm missing something small but couldn't figure out.

Thanks in Advance.

Re: Page Fault in Recursive Page Directory

Posted: Tue Jul 26, 2016 8:40 am
by Combuster
Two things that I noticed:
- Using recursive paging, one would set a new page table via a write to 0xfffff000-0xffffffff
- page_directory was never set in this code.
My preliminary guess is that the page table was added to the wrong page directory.


In addition, I see a number of print statements, the output of which would be very nice information for us to have.

Re: Page Fault in Recursive Page Directory

Posted: Tue Jul 26, 2016 8:13 pm
by TheBugEater
I have defined the Page Directory in the header file
https://github.com/TheBugEater/FluxOS/b ... l/paging.h

Here is a screenshot of the Output.
Image

As you can see the physical frame 10F000 is allocated for the new page table, With Write Present and Writable flags set it's 10F003... After the Page Fault happens, I'm also extracting the value of physical address in the page directory entry for the table. It returns the same value, but not reading or writing to it.

Re: Page Fault in Recursive Page Directory

Posted: Wed Jul 27, 2016 3:25 am
by sleephacker

Code: Select all

    v_page_directory[1023] = ((unsigned long)recursive_page_table & 0xFFFFF000) | 3; 

    /***************************************************
     * This Block Sets the Last Index of the Page Table to Map to Page
     * Directory*/
    for(unsigned int i = 0; i < 1023; i++)
    {
        // Set the Address and Make it Present and Writable
        v_recursive_page_table[i] = 2;
    }
    v_recursive_page_table[1023] = ((unsigned long)page_directory_phys_addr & 0xFFFFF000) | 3;
    v_recursive_page_table[768] = ((unsigned long)kernel_page_table & 0xFFFFF000) | 3;
You mapped the virtual address 0xFFFFF000 to the page directory, and 0xFFF00000 to your kernel page table, but all other pages above 0xFFC00000 (including 0xFFEBF000) are set to nonpresent, causing the page fault (error code 2 means you tried to write to an address on a nonpresent page).

What you probably want to do is to map

Code: Select all

page_directory[1023] = page_directory
so that the page directory itself looks like a page table to the system, that's the idea behind recursive mapping.

Re: Page Fault in Recursive Page Directory

Posted: Wed Jul 27, 2016 4:01 am
by TheBugEater
Doesn't this line map 0xFFFFF000 to the page directory itself ?

v_recursive_page_table[1023] = ((unsigned long)page_directory_phys_addr & 0xFFFFF000) | 3;

v_recursive_page_table is the virtual address of the page table since I have a higher half kernel enabled at this point of time. So it writes the physical address of page directory to index 1023, which is 0xFFFFF000. Is this wrong ? I'm still kinda confused about the recursive page directory. Everytime I think of it deeply, my mind starts to think recursively on it and doesn't stop (I'm not joking)

Re: Page Fault in Recursive Page Directory

Posted: Wed Jul 27, 2016 4:07 am
by TheBugEater
Yes You're right man, It took me so long Thanks allot. It was my mistake. I created a seperate page to handle the recursive page directory. Instead of mapping itself to it. Now it works Thanks.