os/libc/tasking.c

60 lines
1.2 KiB
C
Raw Normal View History

2019-05-04 10:41:42 -05:00
#include <stdint.h>
2020-07-12 14:28:58 -05:00
#include <tasking.h>
#include <sys/types.h>
#include <sys/syscalls.h>
#define QUAUX(X) #X
#define QU(X) QUAUX(X)
2019-05-04 10:41:42 -05:00
void yield() {
asm volatile(" \
mov $" QU(SYSCALL_YIELD) ", %eax; \
int $80; \
");
}
2019-05-05 13:30:01 -05:00
void createTaskCr3(void* task,void* cr3) {
asm volatile(" \
mov $" QU(SYSCALL_CREATEPROC_GIVEN_ADDR_SPACE) ", %%eax; \
2019-05-05 13:30:01 -05:00
int $80; \
"::"b"(task),"c"(cr3));
}
2019-05-23 20:41:33 -05:00
void createTaskCr3Param(void* task,void* cr3,uint32_t param1,uint32_t param2) {
asm volatile(" \
mov $" QU(SYSCALL_CREATEPROC_GIVEN_ADDR_SPACE_W_ARGS) ", %%eax; \
2019-05-23 20:41:33 -05:00
int $80; \
"::"b"(task),"c"(cr3),"d"(param1),"S"(param2));
}
void yieldToPID(uint32_t pid) {
asm volatile(" \
mov $" QU(SYSCALL_YIELD_TO_PID) ", %%eax; \
int $80; \
"::"b"(pid));
}
__attribute__((noreturn)) void exit(int code) {
code=code&0xff;
asm volatile(" \
mov $" QU(SYSCALL_EXIT) ", %%eax; \
int $80; \
"::"b"(code));
for(;;);
}
2020-07-12 14:28:58 -05:00
void blockTask(TaskState state) {
asm volatile(" \
mov $" QU(SYSCALL_BLOCK) ", %%eax; \
2020-07-12 14:28:58 -05:00
int $80; \
"::"b"(state));
}
void unblockTask(pid_t pid) {
asm volatile(" \
mov $" QU(SYSCALL_UNBLOCK) ", %%eax; \
2020-07-12 14:28:58 -05:00
int $80; \
"::"b"(pid));
}