os/libc/memory.c

57 lines
1.4 KiB
C
Raw Permalink 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
2020-07-23 11:50:23 -05:00
void* alloc_memory(int num_pages) {
2019-03-17 12:22:00 -05:00
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;
}
2020-07-23 11:50:23 -05:00
void alloc_memory_virt(int num_pages,void* addr) {
2019-03-17 12:22:00 -05:00
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* address_space;
2019-05-05 13:14:14 -05:00
asm volatile(" \
mov $" QU(SYSCALL_NEW_ADDR_SPACE) ", %%eax; \
2019-05-05 13:14:14 -05:00
int $80; \
":"=b"(address_space));
return address_space;
2019-05-05 13:14:14 -05:00
}
2019-05-06 08:35:59 -05:00
void copy_data(void* address_space, void* data,size_t size,void* virt_addr) {
2019-05-06 08:35:59 -05:00
asm volatile(" \
mov $" QU(SYSCALL_ADDR_SPACES_COPY_DATA) ", %%eax; \
2019-05-06 08:35:59 -05:00
int $80; \
"::"b"(address_space),"c"(data),"d"(size),"S"(virt_addr));
2019-05-23 20:42:00 -05:00
}
void* put_data(void* address_space, void* data,size_t size) {
2019-05-23 20:42:00 -05:00
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; \
":"=b"(virt_addr):"b"(address_space),"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
2020-07-23 11:50:23 -05:00
void* map_phys(void* phys_addr,size_t num_pages) {
2019-05-23 17:08:03 -05:00
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;
}