diff --git a/kernel/address_spaces.c b/kernel/address_spaces.c index 8a2dafb..721ee30 100644 --- a/kernel/address_spaces.c +++ b/kernel/address_spaces.c @@ -4,17 +4,17 @@ void address_spaces_copy_data(void* cr3, void* data,uint32_t size,void* virt_addr) { void* old_cr3=get_cr3(); void* phys_addr=virt_to_phys(data); - load_smap(cr3); + load_address_space(cr3); map_pages(virt_addr,phys_addr,(size/PAGE_SZ)+1,1,1); - load_smap(old_cr3); + load_address_space(old_cr3); } void* address_spaces_put_data(void* cr3, void* data,uint32_t size) { void* old_cr3=get_cr3(); void* phys_addr=virt_to_phys(data); - load_smap(cr3); + load_address_space(cr3); void* virt_addr=find_free_pages((size/PAGE_SZ)+1); map_pages(virt_addr,phys_addr,(size/PAGE_SZ)+1,1,1); - load_smap(old_cr3); + load_address_space(old_cr3); return virt_addr; } diff --git a/kernel/cpu/i386/paging.c b/kernel/cpu/i386/paging.c index 72ad3ac..e6bede9 100644 --- a/kernel/cpu/i386/paging.c +++ b/kernel/cpu/i386/paging.c @@ -179,11 +179,6 @@ void* paging_new_address_space() { return dir; } -void load_address_space(void* cr3) { - load_smap(cr3); - load_page_directory((uint32_t*)cr3); -} - void load_smap(void* cr3) { smap_page_tables[0]=(uint32_t)cr3|0x3; invl_page(&smap[0]); @@ -193,6 +188,12 @@ void load_smap(void* cr3) { } } + +void load_address_space(void* cr3) { + load_smap(cr3); + load_page_directory((uint32_t*)cr3); +} + void unmap_pages(void* start_virt,uint32_t num_pages) { uint32_t virt_addr=(uint32_t)start_virt; int dir_entry=(virt_addr&0xFFC00000)>>22; diff --git a/kernel/cpu/i386/tasking_helpers.asm b/kernel/cpu/i386/tasking_helpers.asm index cb9ad10..b15b930 100644 --- a/kernel/cpu/i386/tasking_helpers.asm +++ b/kernel/cpu/i386/tasking_helpers.asm @@ -1,5 +1,6 @@ section .text global switch_to_thread_asm +extern load_address_space extern currentThread extern tss ;WARNING: Caller is expected to disable IRQs before calling, and enable IRQs again after function returns @@ -35,9 +36,11 @@ switch_to_thread_asm: cmp eax,ecx ;Does the virtual address space need to being changed? je .doneVAS ; no, virtual address space is the same, so don't reload it and cause TLB flushes - mov cr3,eax ; yes, load the next thread's virtual address space + ; yes, load the next thread's virtual address space + push eax + call load_address_space + add esp,4 .doneVAS: - pop ebp pop edi pop esi diff --git a/kernel/cpu/paging.h b/kernel/cpu/paging.h index 0bc35d2..2a7f90c 100644 --- a/kernel/cpu/paging.h +++ b/kernel/cpu/paging.h @@ -14,7 +14,6 @@ void* paging_new_address_space(); void load_address_space(void* cr3); void* virt_to_phys(void* virt_addr); void* find_free_pages(int num_pages); -void load_smap(void* cr3); void* get_cr3(); #endif diff --git a/kernel/tasking.c b/kernel/tasking.c index 87dceac..b34b5cb 100644 --- a/kernel/tasking.c +++ b/kernel/tasking.c @@ -201,7 +201,6 @@ void switch_to_thread(Thread* thread) { mark_proc_scheduled(currentThread->process->pid); } serial_printf("Switching to PID %d TID %d.\n",thread->process->pid,thread->tid); - load_smap(thread->cr3); switch_to_thread_asm(thread); }