Remove load_smap from paging.h

This commit is contained in:
pjht 2020-07-22 21:28:00 -05:00
parent ce0cfb2e11
commit af4233e968
5 changed files with 15 additions and 13 deletions

View File

@ -4,17 +4,17 @@
void address_spaces_copy_data(void* cr3, void* data,uint32_t size,void* virt_addr) { void address_spaces_copy_data(void* cr3, void* data,uint32_t size,void* virt_addr) {
void* old_cr3=get_cr3(); void* old_cr3=get_cr3();
void* phys_addr=virt_to_phys(data); 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); 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* address_spaces_put_data(void* cr3, void* data,uint32_t size) {
void* old_cr3=get_cr3(); void* old_cr3=get_cr3();
void* phys_addr=virt_to_phys(data); void* phys_addr=virt_to_phys(data);
load_smap(cr3); load_address_space(cr3);
void* virt_addr=find_free_pages((size/PAGE_SZ)+1); void* virt_addr=find_free_pages((size/PAGE_SZ)+1);
map_pages(virt_addr,phys_addr,(size/PAGE_SZ)+1,1,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; return virt_addr;
} }

View File

@ -179,11 +179,6 @@ void* paging_new_address_space() {
return dir; return dir;
} }
void load_address_space(void* cr3) {
load_smap(cr3);
load_page_directory((uint32_t*)cr3);
}
void load_smap(void* cr3) { void load_smap(void* cr3) {
smap_page_tables[0]=(uint32_t)cr3|0x3; smap_page_tables[0]=(uint32_t)cr3|0x3;
invl_page(&smap[0]); 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) { void unmap_pages(void* start_virt,uint32_t num_pages) {
uint32_t virt_addr=(uint32_t)start_virt; uint32_t virt_addr=(uint32_t)start_virt;
int dir_entry=(virt_addr&0xFFC00000)>>22; int dir_entry=(virt_addr&0xFFC00000)>>22;

View File

@ -1,5 +1,6 @@
section .text section .text
global switch_to_thread_asm global switch_to_thread_asm
extern load_address_space
extern currentThread extern currentThread
extern tss extern tss
;WARNING: Caller is expected to disable IRQs before calling, and enable IRQs again after function returns ;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? 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 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: .doneVAS:
pop ebp pop ebp
pop edi pop edi
pop esi pop esi

View File

@ -14,7 +14,6 @@ void* paging_new_address_space();
void load_address_space(void* cr3); void load_address_space(void* cr3);
void* virt_to_phys(void* virt_addr); void* virt_to_phys(void* virt_addr);
void* find_free_pages(int num_pages); void* find_free_pages(int num_pages);
void load_smap(void* cr3);
void* get_cr3(); void* get_cr3();
#endif #endif

View File

@ -201,7 +201,6 @@ void switch_to_thread(Thread* thread) {
mark_proc_scheduled(currentThread->process->pid); mark_proc_scheduled(currentThread->process->pid);
} }
serial_printf("Switching to PID %d TID %d.\n",thread->process->pid,thread->tid); serial_printf("Switching to PID %d TID %d.\n",thread->process->pid,thread->tid);
load_smap(thread->cr3);
switch_to_thread_asm(thread); switch_to_thread_asm(thread);
} }