diff --git a/cpu/i386/address_spaces.c b/cpu/i386/address_spaces.c index 8b4f420..cc087b9 100644 --- a/cpu/i386/address_spaces.c +++ b/cpu/i386/address_spaces.c @@ -8,3 +8,14 @@ void address_spaces_copy_data(void* cr3, void* data,uint32_t size,void* virt_add map_pages(virt_addr,phys_addr,(size/4096)+1,1,1); load_address_space(old_cr3); } + +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_address_space((uint32_t)cr3); + void* virt_addr=find_free_pages((size/4096)+1)<<12; + map_pages(virt_addr,phys_addr,(size/4096)+1,1,1); + load_address_space(old_cr3); + return virt_addr; +} diff --git a/cpu/i386/address_spaces.h b/cpu/i386/address_spaces.h index 3876137..d27158a 100644 --- a/cpu/i386/address_spaces.h +++ b/cpu/i386/address_spaces.h @@ -4,5 +4,5 @@ #include void address_spaces_copy_data(void* cr3, void* data,uint32_t size,void* virt_addr); - +void* address_spaces_put_data(void* cr3, void* data,uint32_t size); #endif diff --git a/cpu/i386/isr.c b/cpu/i386/isr.c index 57818a6..acf066c 100644 --- a/cpu/i386/isr.c +++ b/cpu/i386/isr.c @@ -206,6 +206,8 @@ void isr_handler(registers_t r) { r.ebx=virt_addr; } else if (r.eax=12) { tasking_createTaskCr3KmodeParam((void*)r.ebx,(void*)r.ecx,0,1,r.edx,1,r.esi); + } else if (r.eax=13) { + r.ebx=(uint32_t)address_spaces_put_data((void*)r.ebx,(void*)r.ecx,r.edx); } break; } diff --git a/libc/memory.c b/libc/memory.c index c5eb917..8ebdc8e 100644 --- a/libc/memory.c +++ b/libc/memory.c @@ -30,12 +30,15 @@ void copy_data(void* cr3, void* data,uint32_t size,void* virt_addr) { mov $10, %%eax; \ int $80; \ "::"b"(cr3),"c"(data),"d"(size),"S"(virt_addr)); - // uint32_t old_cr3; - // 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(virt_addr,phys_addr,(size/4096)+1,1,1); - // load_address_space(old_cr3); +} + +void* put_data(void* cr3, void* data,uint32_t size) { + void* virt_addr; + asm volatile(" \ + mov $10, %%eax; \ + int $80; \ + ":"=b"(virt_addr):"b"(cr3),"c"(data),"d"(size)); + return virt_addr; } void* map_phys(void* phys_addr,uint32_t num_pages) { diff --git a/libc/memory.h b/libc/memory.h index 8499d01..02e6594 100644 --- a/libc/memory.h +++ b/libc/memory.h @@ -9,6 +9,7 @@ void* alloc_memory(uint32_t num_pages); void alloc_memory_virt(uint32_t num_pages,void* addr); void* new_address_space(); void copy_data(void* cr3, void* data,uint32_t size,void* virt_addr); +void* put_data(void* cr3, void* data,uint32_t size); void* map_phys(void* phys_addr,uint32_t num_pages); #endif