os/libc/tasking.c

54 lines
1.1 KiB
C
Raw Normal View History

#include <sys/syscalls.h>
2020-07-22 19:35:23 -05:00
#include <sys/types.h>
#include <tasking.h>
#define QUAUX(X) #X
#define QU(X) QUAUX(X)
2019-05-04 10:41:42 -05:00
void yield() {
asm volatile(" \
2020-07-12 16:29:57 -05:00
mov $" QU(SYSCALL_YIELD) ", %%eax; \
int $80; \
2020-07-12 16:29:57 -05:00
"::"b"(0));
}
void create_proc(void* start,void* address_space,void* param1,void* param2) {
2019-05-05 13:30:01 -05:00
asm volatile(" \
2020-07-12 16:29:57 -05:00
mov $" QU(SYSCALL_CREATEPROC) ", %%eax; \
2019-05-05 13:30:01 -05:00
int $80; \
"::"b"(start),"c"(address_space),"d"(param1),"S"(param2));
2019-05-23 20:41:33 -05:00
}
__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
2020-07-29 08:09:53 -05:00
void block_thread(thread_state state) {
2020-07-12 14:28:58 -05:00
asm volatile(" \
mov $" QU(SYSCALL_BLOCK) ", %%eax; \
2020-07-12 14:28:58 -05:00
int $80; \
"::"b"(state));
}
2020-07-29 08:09:53 -05:00
void unblock_thread(pid_t pid,pid_t tid) {
2020-07-12 14:28:58 -05:00
asm volatile(" \
mov $" QU(SYSCALL_UNBLOCK) ", %%eax; \
2020-07-12 14:28:58 -05:00
int $80; \
2020-07-20 09:51:30 -05:00
"::"b"(pid),"c"(tid));
}
2020-08-02 14:37:23 -05:00
char check_proc_exists(pid_t pid) {
char exists;
asm volatile(" \
mov $" QU(SYSCALL_CHECK_PROC_EXISTS) ", %%eax; \
int $80; \
":"=c"(exists):"b"(pid));
return exists;
}