add put_data function

This commit is contained in:
pjht 2019-05-23 20:42:00 -05:00
parent eebf2b97fb
commit 57e5d55c36
5 changed files with 24 additions and 7 deletions

View File

@ -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;
}

View File

@ -4,5 +4,5 @@
#include <stdint.h>
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

View File

@ -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;
}

View File

@ -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) {

View File

@ -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