I have a problem with my paging initializer code. There is no problem when I idty. map all my kernel or when I map it to any address. But recently I tried to identity-map only the first megabyte of physical memory, and I had an unresolved problem. First i used this very simple code to see if it works(and it does perfectly):
Code: Select all
ptable_t *first_page_table = epalloc(sizeof(ptable_t));
printf("Mapping pages to first table %x\n", first_page_table);
for (address_t i = 0; i < PAGING_MAX_ENTRIES; i++)
{
//first_page_table= (i*0x1000)|PAGE_READ_WRITE|PAGE_PRESENT;
first_page_table->pages[i] = (i * 0x1000) | PAGE_READ_WRITE | PAGE_PRESENT;
}
kdir.tables[0] = ((address_t)first_page_table) | PAGE_READ_WRITE | PAGE_PRESENT;
Code: Select all
void identity_paging(phys_t start, size_t end, uint8 flags, pdir_t * dir)
{
address_t address;
pindex_t pdiridx, ptabidx;
ptable_t * table;
ppage_t page;
for(address = start; address < end; address+=0x1000){
//check direntry is present
pdiridx = get_direntry_index(address);
table = dir->tables[pdiridx];
if(!((address_t) table & TABLE_PRESENT)){
//table = create_table_from_address(dir, address, flags);
table = epalloc(sizeof(ptable_t));
clear_page_table(table);
dir->tables[pdiridx] = ((address_t)table) | TABLE_READ_WRITE | TABLE_PRESENT;
}else{
table = (address_t)table & TABLE_FRAME;
}
//now we have the table, we need to set the page
ptabidx = get_tabentry_index(address);
//page = table->pages[ptabidx];
page = ((address_t) address & PAGE_FRAME) | (flags & PAGING_ENTRY_FLAGS);
table->pages[ptabidx] = page;
printf("Address: %x-Table: %x-Page: %x-Val: %x\n",address, table, ptabidx, page);
}
}
Code: Select all
identity_paging(0, 0x100000, (PAGE_PRESENT | PAGE_READ_WRITE), &kdir);
Thank you very much, in advance.