diff --git a/kernel/cpu/i386/address_spaces.c b/kernel/cpu/i386/address_spaces.c index 3e43c8f..e81498f 100644 --- a/kernel/cpu/i386/address_spaces.c +++ b/kernel/cpu/i386/address_spaces.c @@ -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; diff --git a/kernel/cpu/i386/isr.c b/kernel/cpu/i386/isr.c index cc6ad75..7484740 100644 --- a/kernel/cpu/i386/isr.c +++ b/kernel/cpu/i386/isr.c @@ -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) { diff --git a/kernel/cpu/i386/paging.c b/kernel/cpu/i386/paging.c index b9d0d01..648eee4 100644 --- a/kernel/cpu/i386/paging.c +++ b/kernel/cpu/i386/paging.c @@ -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; } diff --git a/kernel/cpu/i386/paging.h b/kernel/cpu/i386/paging.h index ec01d81..2a7d759 100644 --- a/kernel/cpu/i386/paging.h +++ b/kernel/cpu/i386/paging.h @@ -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