os/kernel/cpu/i386/address_spaces.c

22 lines
722 B
C
Raw Normal View History

2019-05-05 13:03:14 -05:00
#include "paging.h"
2019-05-06 08:35:59 -05:00
void address_spaces_copy_data(void* cr3, void* data,uint32_t size,void* virt_addr) {
2019-05-05 13:03:14 -05:00
uint32_t old_cr3;
asm volatile("movl %%cr3, %%eax; movl %%eax, %0;":"=m"(old_cr3)::"%eax");
void* phys_addr=virt_to_phys(data);
load_smap((uint32_t)cr3);
2019-05-06 08:24:30 -05:00
map_pages(virt_addr,phys_addr,(size/4096)+1,1,1);
load_smap(old_cr3);
2019-05-05 13:03:14 -05:00
}
2019-05-23 20:42:00 -05:00
void* address_spaces_put_data(void* cr3, void* data,uint32_t size) {
uint32_t old_cr3;
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=find_free_pages((size/4096)+1);
2019-05-23 20:42:00 -05:00
map_pages(virt_addr,phys_addr,(size/4096)+1,1,1);
load_smap(old_cr3);
2019-05-23 20:42:00 -05:00
return virt_addr;
}