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.
I have two questions regarding Paging and Physical Frame Allocation.
(1) I see some kernel implementations which set up paging with 4MB page size. However, for physical frame allocation, they use 4KB page size. I'm quite confused how can different page sizes be used.
(2) If I want to enable paging with 4KB page size, I can use the code below to setup page directory. But, How can I setup page table? and How to link page table to page directory:
The paging mechanism consists of a hierarchy of tables. The processor takes top bits of the address and uses that as an index into the table. It then reads the corresponding entry, then considers based upon what's there. In most cases, it'll find it points to another table, it takes the next bits and use those at an index and looks up the entry in the new table. The process is repeated until the table reads that the address is a physical address rather than a table's address. When it sees that, it takes the physical address and adds the remaining bits to that before looking it up in main memory.
the hierarchy has a maximum depth - because there are a limited amount of bits that can used. In standard protected mode you have two levels, in other modes up to four.
4MB paging (or when you get further, 2MB pages and 1GB pages) works simply by stating that an entry is a physical address at a level higher than the lowest. the processor eats the top bytes, finds a physical address, and has a lot more bits left to add to that address (4M combinations), than when the processor has consumed two sets of bits (4k / 4096 combinations)
For the details, I suggest you grab a copy of the intel manuals.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
1) In the 4KiB structure, you have a page table with 1024 entries, each of which points to a 4KiB page frame - you seem to understand this OK. In the 4MiB scheme, your page directory points to a 4MiB range instead of a page table, thus giving you a 4MiB continuous range (with PAE enabled, large pages are actually 2MiB).