Flush TLB after editing paging

This commit is contained in:
Baptiste Wicht 2014-01-10 20:07:03 +01:00
parent 7c61a533eb
commit 871e1f2775
2 changed files with 16 additions and 4 deletions

View File

@ -36,6 +36,10 @@ uintptr_t init_new_page(){
return new_page;
}
inline void flush_tlb(void* page){
asm volatile("invlpg [%0]" :: "r" (reinterpret_cast<uintptr_t>(page)) : "memory");
}
} //end of anonymous namespace
//TODO Update to support offsets at the end of virt
@ -142,6 +146,9 @@ bool paging::map(void* virt, void* physical){
//Map to the physical address
pt[table] = reinterpret_cast<page_entry>(reinterpret_cast<uintptr_t>(physical) | (PRESENT | WRITEABLE));
//Flush TLB
flush_tlb(virt);
return true;
}
@ -213,6 +220,9 @@ bool paging::unmap(void* virt){
//Unmap the virtual address
pt[table] = 0x0;
//Flush TLB
flush_tlb(virt);
return true;
}

View File

@ -786,6 +786,9 @@ void exec_command(const std::vector<std::string>& params){
break;
}
//Save it to be able to free it later
allocated_segments[p] = memory;
//3. Find a start of a page inside the physical memory
auto aligned_memory = paging::page_aligned(memory) ? memory :
@ -799,9 +802,6 @@ void exec_command(const std::vector<std::string>& params){
break;
}
//Save it to be able to free it later
allocated_segments[p] = memory;
//5. Copy memory
auto memory_start = reinterpret_cast<uintptr_t>(aligned_memory) + left_padding;
@ -834,7 +834,9 @@ void exec_command(const std::vector<std::string>& params){
auto bytes = left_padding + paging::PAGE_SIZE + p_header.p_memsz;
auto pages = (bytes / paging::PAGE_SIZE) + 1;
paging::unmap(reinterpret_cast<void*>(first_page), pages);
if(!paging::unmap(reinterpret_cast<void*>(first_page), pages)){
k_print_line("Unmap failed, memory could be in invalid state");
}
}
}
}