Fractal Page Mapping

From OSDev Wiki
Jump to navigation Jump to search

This article is a stub! This page or section is a stub. You can help the wiki by accurately contributing to it.

This article is written like a tutorial. Please edit it to have more information and documentation instead of example code and step by step instructions.

A common problem related to paging is "How do you access the paging structures to change mappings?"

Fractal mapping uses the orthogonality of page tables on most architectures (notably x86 and x86_64) to make a region of memory automatically map the paging structures

How to do it

On 32-bit x86, all you need to do is set an entry in the page table to the address of the page table (with appropriate access bits). In examples, the last entry is typically used, but in practice any can be used

page_directory[1024 - 1] = get_phys_addr(&page_directory[0]) | PAGE_PRESENT | PAGE_WRITABLE;

Now, when you access the last 4MB of the physical address space, the CPU will use the page directory as a page table. This leads to the last 4KB of memory being the page directory.