os/libc/memory.c

52 lines
1.0 KiB
C
Raw Normal View History

2019-03-17 12:22:00 -05:00
#include <stdint.h>
void* alloc_memory(uint32_t num_pages) {
void* address;
asm volatile(" \
mov $3, %%eax; \
int $80; \
":"=b"(address):"b"(num_pages));
return address;
}
void alloc_memory_virt(uint32_t num_pages,void* addr) {
asm volatile(" \
2019-03-17 18:04:06 -05:00
mov $4, %%eax; \
2019-03-17 12:22:00 -05:00
int $80; \
"::"b"(num_pages),"c"(addr));
}
2019-05-05 13:14:14 -05:00
void* new_address_space() {
void* cr3;
asm volatile(" \
mov $8, %%eax; \
int $80; \
":"=b"(cr3));
return cr3;
}
2019-05-06 08:35:59 -05:00
void copy_data(void* cr3, void* data,uint32_t size,void* virt_addr) {
asm volatile(" \
mov $10, %%eax; \
int $80; \
"::"b"(cr3),"c"(data),"d"(size),"S"(virt_addr));
2019-05-23 20:42:00 -05:00
}
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;
2019-05-06 08:35:59 -05:00
}
2019-05-23 17:08:03 -05:00
void* map_phys(void* phys_addr,uint32_t num_pages) {
void* virt_addr;
asm volatile(" \
mov $11, %%eax; \
int $80; \
":"=b"(virt_addr):"b"(phys_addr),"c"(num_pages));
return virt_addr;
}