Identity Paging: Difference between revisions

From OSDev.wiki
Jump to navigation Jump to search
[unchecked revision][unchecked revision]
Content added Content deleted
No edit summary
 
No edit summary
Line 1: Line 1:
{{Convert}}
{{Convert}}


Identity Paging, Identity Mapped paging and 1:1 paging are terms often used on the forum to describe a design choice where a portion of [virtual addresses|Physical, Virtual, Paging, help?!?] are mapped to physical addresses that have the same value.
Identity Paging, Identity Mapped paging and 1:1 paging are terms often used on the forum to describe a design choice where a portion of virtual addresses are mapped to physical addresses that have the same value.


For instance you may decide to use IdentityPaging in the lowest 1MB, in which case vaddr =00000000..00000fff= are mapped to frame #00000, vaddr =00001000..00001fff= are mapped to frame #00001, and so on (vaddr =000ff000..000fffff= are mapped to frame #000ff)
For instance you may decide to use Identity Paging in the lowest 1MB, in which case vaddr <tt>00000000</tt>..<tt>00000fff</tt> are mapped to frame #00000, vaddr <tt>00001000</tt>..<tt>00001fff</tt> are mapped to frame #00001, and so on (vaddr <tt>000ff000</tt>..<tt>000fffff</tt> are mapped to frame #000ff)


You can easily do this with a loop filling the page table:
You can easily do this with a loop filling the page table:
<pre>
<verbatim>
void idpaging(dword *first_pte, vaddr from, int size)
void idpaging(dword *first_pte, vaddr from, int size){
{
from = from & 0xfffff000; // discard bits we don't want
from = from & 0xfffff000; // discard bits we don't want
for(;size;from+=4096,first_pte++) {
for(;size;from+=4096,first_pte++){
*first_pte=from|1; // mark page present.
*first_pte=from|1; // mark page present.
}
}
}
}
</verbatim>
</pre>

!What's the advantage of 1:1 paging


==Advantages of Identity Paging==
When switching to paged protected mode, your 1:1 mapping region doesn't care of whether paging is enabled or disabled. Placing your switching code and important data such as the core page directory and a few system page tables in this region gives you an easier way to set up paging without headaches.
When switching to paged protected mode, your 1:1 mapping region doesn't care of whether paging is enabled or disabled. Placing your switching code and important data such as the core page directory and a few system page tables in this region gives you an easier way to set up paging without headaches.

[[Category:Memory management]]

Revision as of 08:05, 4 April 2007

Template:Convert

Identity Paging, Identity Mapped paging and 1:1 paging are terms often used on the forum to describe a design choice where a portion of virtual addresses are mapped to physical addresses that have the same value.

For instance you may decide to use Identity Paging in the lowest 1MB, in which case vaddr 00000000..00000fff are mapped to frame #00000, vaddr 00001000..00001fff are mapped to frame #00001, and so on (vaddr 000ff000..000fffff are mapped to frame #000ff)

You can easily do this with a loop filling the page table:

void idpaging(dword *first_pte, vaddr from, int size){
   from = from & 0xfffff000; // discard bits we don't want
   for(;size;from+=4096,first_pte++){
      *first_pte=from|1;     // mark page present.
   }
}

Advantages of Identity Paging

When switching to paged protected mode, your 1:1 mapping region doesn't care of whether paging is enabled or disabled. Placing your switching code and important data such as the core page directory and a few system page tables in this region gives you an easier way to set up paging without headaches.