os/libc/memory.c

57 lines
1.3 KiB
C
Raw Normal View History

2019-03-17 12:22:00 -05:00
#include <stdint.h>
2020-07-12 16:29:57 -05:00
#include <stdlib.h>
2020-07-22 19:35:23 -05:00
#include <sys/syscalls.h>
#define QUAUX(X) #X
#define QU(X) QUAUX(X)
2019-03-17 12:22:00 -05:00
void* alloc_memory(uint32_t num_pages) {
void* address;
asm volatile(" \
mov $" QU(SYSCALL_ALLOC_MEM) ", %%eax; \
2019-03-17 12:22:00 -05:00
int $80; \
2020-07-12 16:29:57 -05:00
":"=b"(address):"b"(num_pages),"c"(NULL));
2019-03-17 12:22:00 -05:00
return address;
}
void alloc_memory_virt(uint32_t num_pages,void* addr) {
asm volatile(" \
2020-07-12 16:29:57 -05:00
mov $" QU(SYSCALL_ALLOC_MEM) ", %%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 $" QU(SYSCALL_NEW_ADDR_SPACE) ", %%eax; \
2019-05-05 13:14:14 -05:00
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 $" QU(SYSCALL_ADDR_SPACES_COPY_DATA) ", %%eax; \
2019-05-06 08:35:59 -05:00
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(" \
2020-07-12 16:29:57 -05:00
mov $" QU(SYSCALL_ADDR_SPACES_COPY_DATA) ", %%eax; \
2019-05-23 20:42:00 -05:00
int $80; \
2020-07-12 16:29:57 -05:00
":"=b"(virt_addr):"b"(cr3),"c"(data),"d"(size),"S"(NULL));
2019-05-23 20:42:00 -05:00
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 $" QU(SYSCALL_PRIV_MAP_PAGES) ", %%eax; \
2019-05-23 17:08:03 -05:00
int $80; \
":"=b"(virt_addr):"b"(phys_addr),"c"(num_pages));
return virt_addr;
}