How do I modify page directory when paging is enabled?
In wiki there is a paragraph "Manipulation", but it is very brief. Can some one explain it in detail?
Modifying page directory
Re: Modifying page directory
Hi,
I'm unable to determine how you feel like doing it for your OS; which makes it hard to explain how you feel like doing it for your OS in further detail.
However; a lot of people use a trick where you pretend that the physical page containing the page directory is also a physical page containing a page table. You need to understand how paging works before you can really understand how this trick works.
The paging hardware splits a virtual address into 3 parts:
In addition; if the highest page directory entry points to the physical address of the page directory (instead of pointing to the physical address of a page table), then:
Cheers,
Brendan
When paging is enabled; software can only modify physical pages that are mapped into the virtual address space that is currently being used. The page directory is a physical page; therefore software can only modify a page directory if it is mapped into the virtual address space that is currently being used. How you map page directory/ies into virtual address space/s depends on how you feel like doing it for your OS.lrod wrote:How do I modify page directory when paging is enabled?
In wiki there is a paragraph "Manipulation", but it is very brief. Can some one explain it in detail?
I'm unable to determine how you feel like doing it for your OS; which makes it hard to explain how you feel like doing it for your OS in further detail.
However; a lot of people use a trick where you pretend that the physical page containing the page directory is also a physical page containing a page table. You need to understand how paging works before you can really understand how this trick works.
The paging hardware splits a virtual address into 3 parts:
- an index into the page directory that selects which page table to use
- an index into the page table that selects which physical page to use
- an offset into a physical page (where "physical address of selected page + offset within that page = physical address that corresponds to the original virtual address")
- an index into the page directory that selects which page table to use; where the selected page table may be the page directory itself
- an index into the page table that selects which physical page to use; where the selected physical page may actually be a page table (and may be the page directory pretending to be a page table)
- an offset into the physical page; which may actually be an offset into a page table (and may be an offset into the page directory pretending to be a page table)
- for virtual addresses from 0xFFC00000 to 0xFFFFFFFF, the index into the page directory would be 0x3FF, which is the highest page directory entry that points to the physical address of the "page directory pretending to be a page table"
- for virtual addresses from 0xFFC00000 to 0xFFFFFFFF, the index into the page table would be an index into the "page directory pretending to be a page table"
- for virtual addresses from 0xFFC00000 to 0xFFFFFFFF, the offset in the physical page would be an offset into a page table.
In addition; if the highest page directory entry points to the physical address of the page directory (instead of pointing to the physical address of a page table), then:
- for virtual addresses from 0xFFFFFF000 to 0xFFFFFFFF, the index into the page directory would be 0x3FF, which is the highest page directory entry that points to the physical address of the "page directory pretending to be a page table"
- for virtual addresses from 0xFFFFF000 to 0xFFFFFFFF, the index into the "page directory pretending to be a page table" would be 0x3FF, which is the highest page directory entry that points to the physical address of the "page directory pretending to be a page table" again
- for virtual addresses from 0xFFFFF000 to 0xFFFFFFFF, the offset in the physical page would actually be an offset into the page directory itself.
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Re: Modifying page directory
Note that after you update the Page Directory you need to invalidate the TLB buffer for that entry, otherwise the change won't take effect. You can either do this on a page basis, with the INVLPG instruction, or you can reload cr3 and so invalidate the whole TLB (with certain exceptions).
Re: Modifying page directory
Thanks for answer!Brendan wrote:Hi,
...
Cheers,
Brendan
I think I almost got it, but one thing I don't understand. From 0xffc00000 to 0xffffffff there is 4Mb, right? And 1024 page directory entres takes exactly 4Mb, so where does additional 4Kb comes from to map page directory?
Re: Modifying page directory
Last 4-kb page table and page directory are the same page.
If you have seen bad English in my words, tell me what's wrong, please.