Paging question

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
Jarek

Paging question

Post by Jarek »

Hi !

How to handle simple paging for OS. I saw in Linux 0.0.1 that for each process there is created page dir. It is allocated in kernel page table. But how is it handled that there are 3 levels of page dictionary and how is it loaded.
Thanks for info.

Best regards
Jarek Pelczar
Keith

RE:Paging question

Post by Keith »

You don't have three levels of a page directory.  You have a directory, and a page group, which then points to the physical page.  When the PG bit is enabled (32nd bit of cr0), the processor looks at the page directory base (physical addres of course), located in cr3.  This *MUST* begin on a page boundary.  Pages on the 386+ are either 4k or 4MB...most people juse use 4k.  With 36-bit addressing, there is also another page size of 2mb (I believe) available, but you probably wouldn't use that as you'll break quite a number of things in the process.

When paging is enabled, the processor translates what is in these tables to correctly establish what is going on...each address is "intercepted" if you will.  The processor views the address as follows.

10 bits = Page Directory
10 bits = Page Group
12 bits = offset within page.

The first 12 bits of an address map exactly from both virtual and physical arenas, only the top 20-bits really matter.  Reviewing the above, you can see that...you have 1024 entries in your Page Directory and 1024 entries per page group within that page directory.

Each of these entries are not 20-bits, however, they're 32-bits, but the lower 12-bits are not used to store the addresses only to store information such as Present (bit 0), or other information, such as read/write, supervisor/user, etc.

When performing paging, be concerned with using even page boundaries, that is, any address that can be evenly divided by 4096 (without a remainder) is an even page boundary.

In the Page Directory, the top 20-bits points to the first entry of the page group, then, that points to the page of the physical address to use.  Each of these act as an "index."

To enable paging, you would performing the following:

a) Create the page directory and page groups as necessary (you can map virtual addresses to physical addresses).
b) Point cr3 to the page directory base address (remember, the page directory must be on an even page boundary)
c) Enable paging by turning on bit 31 (32nd bit) in cr0.
d) Load an address onto the stack and perform a ret instruction, or perform an indirect jmp.  You'll need to do this to make sure that eip is reloaded from physical land over into virtual land correctly.

I hope this answers some of your questions,

Cheers!
Post Reply