vjain20 wrote:Thanks for replying!
What I have understood is that since page tables contain physical address we have no option but to use physical address.
But isn't every address in the kernel directory identity-mapped ? I am wondering if the physical address can be used as virtual address.
Not all pages in the so-called kernel directory are identity-mapped and identity mapping are not necessary after you set up an initial page directory. The identity mapping in JamesM's tutorial contains the first 1MB of the physical memory (reserved for I/O, e.g, VGA), the kernel image, a 4KB page for kernel page directory and a few page tables. Then he
Code: Select all
int i = 0;
for (i = KHEAP_START; i < KHEAP_START+KHEAP_INITIAL_SIZE; i += 0x1000)
get_page(i, 1, kernel_directory);
-- by get_page from KHEAP_START to KHEAP_START+KHEAP_INITIAL_SIZE, he fill the PTEs with linear addresses of kernel heap pages, and allocate their corresponding page tables (e.g, PTE 0xC0000000 needs table 768, but it is not created when initializing paging) by moving the placement pointer (these tables are identity-mapped, for there's not a heap). However, these pages are not actually allocated until alloc_frame is called.
If you read the routine alloc_frame, you should realize that it grabs the first available page for a request. That's why JamesM get the identity mapping done before he *allocates* pages for kernel heap - It *happens* that the identity-mapped area is identity-mapped because of the policy of alloc_frame.