Virtual memory manager can now create and load address spaces

This commit is contained in:
pjht 2019-03-17 12:37:37 -05:00
parent bfc3964804
commit afcd0b6580
2 changed files with 25 additions and 2 deletions

View File

@ -95,6 +95,28 @@ void alloc_pages_virt(int num_pages,void* addr) {
map_pages(addr,phys_addr,num_pages,1,1);
}
void* new_address_space() {
void* dir=pmem_alloc(1);
smap_page_tables[0]=((uint32_t)dir)|0x3;
for (uint32_t i=0;i<NUM_KERN_DIRS;i++) {
uint32_t entry_virt=(uint32_t)&(kern_page_tables[i*1024]);
smap[i+768]=(entry_virt-0xC0000000)|0x7;
}
for (uint32_t i=0;i<2;i++) {
uint32_t entry_virt=(uint32_t)&(smap_page_tables[i*1024]);
smap[i+1022]=(entry_virt-0xC0000000)|0x3;
}
smap_page_tables[0]=(((uint32_t)&(page_directory))-0xC0000000)|0x3;
return dir;
}
void load_address_space(uint32_t cr3) {
smap_page_tables[0]=cr3|0x3;
for (uint32_t i=1;i<2048;i++) {
smap_page_tables[i]=0;
}
}
void paging_init() {
for (uint32_t i=0;i<NUM_KERN_DIRS*1024;i++) {
kern_page_tables[i]=(i<<12)|0x7;
@ -109,7 +131,7 @@ void paging_init() {
}
for (uint32_t i=0;i<2;i++) {
uint32_t entry_virt=(uint32_t)&(smap_page_tables[i*1024]);
page_directory[i+1022]=(entry_virt-0xC0000000)|0x7;
page_directory[i+1022]=(entry_virt-0xC0000000)|0x3;
}
load_page_directory((uint32_t*)((uint32_t)page_directory-0xC0000000));
}

View File

@ -10,6 +10,7 @@ void map_pages(void* virt_addr_ptr,void* phys_addr_ptr,int num_pages,char usr,ch
void* alloc_pages(int num_pages);
void alloc_pages_virt(int num_pages,void* addr);
void paging_init();
void* new_address_space();
void load_address_space(uint32_t cr3);
#endif