Paging
Posted: Thu Oct 15, 2009 3:06 am
Hi, I've been working on getting paging correct and dynamic. Almost there, but I have a few questions
Let me get this right: we have a page directory, with page directory entries. Each page directory entry points to the physical location of a page table, which has page (table) entries. Each page (table) entry points to the physical location of a piece of memory. The virtual location is determined by the Nth location the page table entry has in the directory (so for 4 MB pages, the 3rd entry covers the virtual addresses from 8 MB to 12 MB).
Is it right that we only ever have (or need) one page directory? So I only ever set cr3 once?
When using 4 MB sized pages, 1024 page table entries is enough to cover the whole memory, then why the need for more page tables? Is this because also 4 KB sized pages are supported, or does it have other advantages? Such as, each process uses a different page table?
As I can see it now, to make code not dependent on the physical address the data is at, we use pages, but this makes the code dependent on the virtual address, unless each process uses a different page table...what if 2 processes have in their code that all data is at 3GB, and they use the same page table, they both get mapped to the same physical address, isn't it?
Then, another point. I've been following this wiki 'tutorial': http://wiki.osdev.org/Higher_Half_bare_bones, in ASM it sets up a page directory, but nowhere I see it setting up a page table. In fact, it looks like the page directory defines 2 page tables, both at offset 0 of the physical memory location? I have no tables at offset 0 :S, have I?
Also, if I dynamically want to add and subtract pages, I will have to map the page directory and page tables themselves too I suppose? Else I can't write to or read from the page description.
Thanks!
Let me get this right: we have a page directory, with page directory entries. Each page directory entry points to the physical location of a page table, which has page (table) entries. Each page (table) entry points to the physical location of a piece of memory. The virtual location is determined by the Nth location the page table entry has in the directory (so for 4 MB pages, the 3rd entry covers the virtual addresses from 8 MB to 12 MB).
Is it right that we only ever have (or need) one page directory? So I only ever set cr3 once?
When using 4 MB sized pages, 1024 page table entries is enough to cover the whole memory, then why the need for more page tables? Is this because also 4 KB sized pages are supported, or does it have other advantages? Such as, each process uses a different page table?
As I can see it now, to make code not dependent on the physical address the data is at, we use pages, but this makes the code dependent on the virtual address, unless each process uses a different page table...what if 2 processes have in their code that all data is at 3GB, and they use the same page table, they both get mapped to the same physical address, isn't it?
Then, another point. I've been following this wiki 'tutorial': http://wiki.osdev.org/Higher_Half_bare_bones, in ASM it sets up a page directory, but nowhere I see it setting up a page table. In fact, it looks like the page directory defines 2 page tables, both at offset 0 of the physical memory location? I have no tables at offset 0 :S, have I?
Also, if I dynamically want to add and subtract pages, I will have to map the page directory and page tables themselves too I suppose? Else I can't write to or read from the page description.
Thanks!