Hi,
I have a query about the
vmmngr_map_page function.
Following is the implementation
Code: Select all
void vmmngr_map_page (void* phys, void* virt) {
//! get page directory
pdirectory* pageDirectory = vmmngr_get_directory ();
//! get page table
pd_entry* e = &pageDirectory->m_entries [PAGE_DIRECTORY_INDEX ((uint32_t) virt) ];
if ( (*e & I86_PTE_PRESENT) != I86_PTE_PRESENT) {
//! page table not present, allocate it
ptable* table = (ptable*) pmmngr_alloc_block ();
if (!table)
return;
//! clear page table
memset (table, 0, sizeof(ptable));
//! create a new entry
pd_entry* entry =
&pageDirectory->m_entries [PAGE_DIRECTORY_INDEX ( (uint32_t) virt) ];
//! map in the table (Can also just do *entry |= 3) to enable these bits
pd_entry_add_attrib (entry, I86_PDE_PRESENT);
pd_entry_add_attrib (entry, I86_PDE_WRITABLE);
pd_entry_set_frame (entry, (physical_addr)table);
}
//! get table*****************************
ptable* table = (ptable*) PAGE_GET_PHYSICAL_ADDRESS ( e );
//! get page******************************
pt_entry* page = &table->m_entries [ PAGE_TABLE_INDEX ( (uint32_t) virt) ];
//! map it in (Can also do (*page |= 3 to enable..)
pt_entry_set_frame ( page, (physical_addr) phys);
pt_entry_add_attrib ( page, I86_PTE_PRESENT);
}
In the above code the lines (marked by **)
//! get table
ptable* table = (ptable*) PAGE_GET_PHYSICAL_ADDRESS ( e );
//! get page
pt_entry* page = &table->m_entries [ PAGE_TABLE_INDEX ( (uint32_t) virt) ];
are using the physical address of page table as its virtual address. I guess this is under the assumption that
memory area occupied by the page table is identity-mapped. Am I right ?
Also, I am wondering if this can cause problem at some point of time because not all the memory is identity-mapped.