Page Fault in Recursive Page Directory

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
TheBugEater
Posts: 4
Joined: Tue Jul 26, 2016 5:03 am
Libera.chat IRC: TheBugEater

Page Fault in Recursive Page Directory

Post 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.
Last edited by TheBugEater on Tue Jul 26, 2016 10:35 pm, 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 Fault in Recursive Page Directory

Post 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.
"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 ]
TheBugEater
Posts: 4
Joined: Tue Jul 26, 2016 5:03 am
Libera.chat IRC: TheBugEater

Re: Page Fault in Recursive Page Directory

Post 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.
User avatar
sleephacker
Member
Member
Posts: 97
Joined: Thu Aug 06, 2015 6:41 am
Location: Netherlands

Re: Page Fault in Recursive Page Directory

Post 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.
TheBugEater
Posts: 4
Joined: Tue Jul 26, 2016 5:03 am
Libera.chat IRC: TheBugEater

Re: Page Fault in Recursive Page Directory

Post 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)
TheBugEater
Posts: 4
Joined: Tue Jul 26, 2016 5:03 am
Libera.chat IRC: TheBugEater

Re: Page Fault in Recursive Page Directory

Post 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.
Post Reply