Add support for clock syscalls

This commit is contained in:
2025-04-30 12:52:49 -04:00
parent 74cfa5f949
commit ab5dd8d9fb
6 changed files with 214 additions and 0 deletions

View File

@@ -192,4 +192,53 @@ ssize_t recvfrom(int fd, const void* buf, size_t size, int flags, const void* so
return nrecv;
}
#define SYS_CLOCK_SETTIME 227
int clock_settime(clockid_t clockid, const struct timespec *tp) {
int rtn;
asm volatile(
"syscall\n"
: "=a"(rtn)
: "a"(SYS_CLOCK_SETTIME), "D"(clockid), "S"(tp)
: "rcx", "r11"
);
return rtn;
}
#define SYS_CLOCK_GETTIME 228
int clock_gettime(clockid_t clockid, struct timespec *tp) {
int rtn;
asm volatile(
"syscall\n"
: "=a"(rtn)
: "a"(SYS_CLOCK_GETTIME), "D"(clockid), "S"(tp)
: "rcx", "r11", "memory"
);
return rtn;
}
#define SYS_CLOCK_GETRES 229
int clock_getres(clockid_t clockid, struct timespec *res){
int rtn;
asm volatile(
"syscall\n"
: "=a"(rtn)
: "a"(SYS_CLOCK_GETRES), "D"(clockid), "S"(res)
: "rcx", "r11", "memory"
);
return rtn;
}
#define SYS_CLOCK_NANOSLEEP 230
int clock_nanosleep(clockid_t clockid, int flags, const struct timespec *t, struct timespec* remain){
int rtn;
asm volatile(
"mov %5, %%r10\n"
"syscall\n"
: "=a"(rtn)
: "a"(SYS_CLOCK_NANOSLEEP), "D"(clockid), "S"(flags), "d"(t), "r"(remain)
: "rcx", "r11", "memory"
);
return rtn;
}
#endif /* ifdef __x86_64__ */