Change find_free_pages to return a void*

This commit is contained in:
pjht 2019-09-22 08:25:08 -05:00
parent 9d849a0f23
commit faf3a3aad9
4 changed files with 6 additions and 7 deletions

View File

@ -14,7 +14,7 @@ void* address_spaces_put_data(void* cr3, void* data,uint32_t size) {
asm volatile("movl %%cr3, %%eax; movl %%eax, %0;":"=m"(old_cr3)::"%eax");
void* phys_addr=virt_to_phys(data);
load_smap((uint32_t)cr3);
void* virt_addr=(void*)(find_free_pages((size/4096)+1)<<12);
void* virt_addr=find_free_pages((size/4096)+1);
map_pages(virt_addr,phys_addr,(size/4096)+1,1,1);
load_smap(old_cr3);
return virt_addr;

View File

@ -219,8 +219,7 @@ void isr_handler(registers_t r) {
r.ebx=0;
return;
}
uint32_t page_idx=find_free_pages(r.ecx);
void* virt_addr=(void*)(page_idx<<12);
void* virt_addr=find_free_pages(r.ecx);
map_pages(virt_addr,(void*)r.ebx,r.ecx,1,1);
r.ebx=(uint32_t)virt_addr;
} else if (r.eax==12) {

View File

@ -55,7 +55,7 @@ void map_kstack(uint32_t pid) {
}
}
uint32_t find_free_pages(int num_pages) {
void* find_free_pages(int num_pages) {
uint32_t bmap_index;
uint32_t remaining_blks;
for(uint32_t i=1;i<131072;i++) {
@ -96,12 +96,12 @@ uint32_t find_free_pages(int num_pages) {
if (remaining_blks!=0) {
vga_write_string("[PANIC] Out of memory");
}
return bmap_index;
return (void*)(bmap_index<<12);
}
void* alloc_pages(int num_pages) {
void* phys_addr=pmem_alloc(num_pages);
void* addr=(void*)(find_free_pages(num_pages)<<12);
void* addr=find_free_pages(num_pages);
map_pages(addr,phys_addr,num_pages,1,1);
return addr;
}

View File

@ -15,7 +15,7 @@ void paging_init();
void* paging_new_address_space();
void load_address_space(uint32_t cr3);
void* virt_to_phys(void* virt_addr);
uint32_t find_free_pages(int num_pages);
void* find_free_pages(int num_pages);
void load_smap(uint32_t cr3);
#endif