os/libc/tasking.c

67 lines
1.3 KiB
C

#include <stdint.h>
#include <tasking.h>
#include <sys/types.h>
#include <sys/syscalls.h>
#define QUAUX(X) #X
#define QU(X) QUAUX(X)
void yield() {
asm volatile(" \
mov $" QU(SYSCALL_YIELD) ", %%eax; \
int $80; \
"::"b"(0));
}
void createTaskCr3(void* task,void* cr3) {
asm volatile(" \
mov $" QU(SYSCALL_CREATEPROC) ", %%eax; \
int $80; \
"::"b"(task),"d"(0),"c"(cr3));
}
void createTaskCr3Param(void* task,void* cr3,uint32_t param1,uint32_t param2) {
asm volatile(" \
mov $" QU(SYSCALL_CREATEPROC) ", %%eax; \
int $80; \
"::"b"(task),"c"(cr3),"d"(1),"S"(param1),"D"(param2));
}
void yieldToPID(uint32_t pid) {
asm volatile(" \
mov $" QU(SYSCALL_YIELD) ", %%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(;;);
}
void blockTask(TaskState state) {
asm volatile(" \
mov $" QU(SYSCALL_BLOCK) ", %%eax; \
int $80; \
"::"b"(state));
}
void unblockTask(pid_t pid,uint32_t tid) {
asm volatile(" \
mov $" QU(SYSCALL_UNBLOCK) ", %%eax; \
int $80; \
"::"b"(pid),"c"(tid));
}
void new_thread(void* start) {
asm volatile(" \
mov $" QU(SYSCALL_NEW_THREAD) ", %%eax; \
int $80; \
"::"b"(start));
}