From 52882f07941983429635b8adc84c52fb8eb74dae Mon Sep 17 00:00:00 2001 From: pjht Date: Mon, 6 May 2019 08:24:30 -0500 Subject: [PATCH] Fix new_address_space and copy_data. --- cpu/i386/address_spaces.c | 2 +- cpu/i386/paging.c | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/cpu/i386/address_spaces.c b/cpu/i386/address_spaces.c index 77d50d7..94b63dc 100644 --- a/cpu/i386/address_spaces.c +++ b/cpu/i386/address_spaces.c @@ -5,6 +5,6 @@ void copy_data(void* cr3, void* data,uint32_t size,void* virt_addr) { asm volatile("movl %%cr3, %%eax; movl %%eax, %0;":"=m"(old_cr3)::"%eax"); void* phys_addr=virt_to_phys(data); load_address_space(cr3); - map_pages((void*)((uint32_t)virt_addr<<12),phys_addr,(size/4096)+1,1,0); + map_pages(virt_addr,phys_addr,(size/4096)+1,1,1); load_address_space(old_cr3); } diff --git a/cpu/i386/paging.c b/cpu/i386/paging.c index f09f0c7..7007f3b 100644 --- a/cpu/i386/paging.c +++ b/cpu/i386/paging.c @@ -114,9 +114,16 @@ void alloc_pages_virt(int num_pages,void* addr) { map_pages(addr,phys_addr,num_pages,1,1); } +void invl_page(void* addr) { + asm volatile("invlpg (%0)"::"r"(addr):"memory"); +} + void* paging_new_address_space() { + uint32_t cr3; + asm volatile("movl %%cr3, %%eax; movl %%eax, %0;":"=m"(cr3)::"%eax"); void* dir=pmem_alloc(1); smap_page_tables[0]=((uint32_t)dir)|0x3; + invl_page(smap); for (uint32_t i=0;i