Add support for clock syscalls
This commit is contained in:
@@ -294,4 +294,82 @@ ssize_t recvfrom(int sockfd, const void* buf, size_t size, int flags, const void
|
||||
return rtn;
|
||||
}
|
||||
|
||||
|
||||
int clock_settime(clockid_t clockid, const struct timespec *tp) {
|
||||
long int rtn;
|
||||
asm volatile (
|
||||
// Assembly Instructions
|
||||
"mov x8, #112\n" // Syscall number for 'listen' is 201 in AArch64
|
||||
"mov x0, %1\n" // fd
|
||||
"mov x1, %2\n" // backlog
|
||||
"svc #0\n" // Make the syscall
|
||||
"mov %0, x0\n" // save return value
|
||||
// Output operands
|
||||
: "=r" (rtn)
|
||||
// Input operand
|
||||
: "r" ((int64_t)clockid), "r"(tp)
|
||||
// Clobbered registers
|
||||
: "x0", "x1", "x8"
|
||||
);
|
||||
return (int32_t)rtn;
|
||||
}
|
||||
|
||||
int clock_gettime(clockid_t clockid, struct timespec *tp) {
|
||||
long int rtn;
|
||||
asm volatile (
|
||||
// Assembly Instructions
|
||||
"mov x8, #113\n" // Syscall number for 'listen' is 201 in AArch64
|
||||
"mov x0, %1\n" // fd
|
||||
"mov x1, %2\n" // backlog
|
||||
"svc #0\n" // Make the syscall
|
||||
"mov %0, x0\n" // save return value
|
||||
// Output operands
|
||||
: "=r" (rtn)
|
||||
// Input operand
|
||||
: "r" ((int64_t)clockid), "r"(tp)
|
||||
// Clobbered registers
|
||||
: "x0", "x1", "x8", "memory"
|
||||
);
|
||||
return (int32_t)rtn;
|
||||
}
|
||||
|
||||
int clock_getres(clockid_t clockid, struct timespec *res) {
|
||||
long int rtn;
|
||||
asm volatile (
|
||||
// Assembly Instructions
|
||||
"mov x8, #114\n" // Syscall number for 'listen' is 201 in AArch64
|
||||
"mov x0, %1\n" // fd
|
||||
"mov x1, %2\n" // backlog
|
||||
"svc #0\n" // Make the syscall
|
||||
"mov %0, x0\n" // save return value
|
||||
// Output operands
|
||||
: "=r" (rtn)
|
||||
// Input operand
|
||||
: "r" ((int64_t)clockid), "r"(res)
|
||||
// Clobbered registers
|
||||
: "x0", "x1", "x8", "memory"
|
||||
);
|
||||
return (int32_t)rtn;
|
||||
}
|
||||
|
||||
int clock_nanosleep(clockid_t clockid, int flags, const struct timespec *t, struct timespec* remain) {
|
||||
long int rtn;
|
||||
asm volatile (
|
||||
// Assembly Instructions
|
||||
"mov x8, #115\n" // Syscall number for 'listen' is 201 in AArch64
|
||||
"mov x0, %1\n" // fd
|
||||
"mov x1, %2\n" // backlog
|
||||
"mov x2, %3\n" // backlog
|
||||
"svc #0\n" // Make the syscall
|
||||
"mov %0, x0\n" // save return value
|
||||
// Output operands
|
||||
: "=r" (rtn)
|
||||
// Input operand
|
||||
: "r" ((int64_t)clockid), "r"((int64_t)flags), "r"(t), "r"(remain)
|
||||
// Clobbered registers
|
||||
: "x0", "x1", "x8", "memory"
|
||||
);
|
||||
return (int32_t)rtn;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
59
arch/mips.c
59
arch/mips.c
@@ -242,4 +242,63 @@ ssize_t recvfrom(int sockfd, const void* buf, size_t size, int flags, const void
|
||||
return rtn;
|
||||
}
|
||||
|
||||
int clock_settime(clockid_t clockid, const struct timespec *tp){
|
||||
int rtn = 0;
|
||||
asm volatile (
|
||||
"move $a0, %1\n"
|
||||
"move $a1, %2\n"
|
||||
"li $v0, 4262\n"
|
||||
"syscall\n"
|
||||
"move %0, $v0\n"
|
||||
: "=r"(rtn)
|
||||
: "r"(clockid), "r"(tp)
|
||||
: "a0", "a1", "v0"
|
||||
);
|
||||
return rtn;
|
||||
}
|
||||
int clock_gettime(clockid_t clockid, struct timespec *tp){
|
||||
int rtn = 0;
|
||||
asm volatile (
|
||||
"move $a0, %1\n"
|
||||
"move $a1, %2\n"
|
||||
"li $v0, 4263\n"
|
||||
"syscall\n"
|
||||
"move %0, $v0\n"
|
||||
: "=r"(rtn)
|
||||
: "r"(clockid), "r"(tp)
|
||||
: "a0", "a1", "v0", "memory"
|
||||
);
|
||||
return rtn;
|
||||
}
|
||||
int clock_getres(clockid_t clockid, struct timespec *res){
|
||||
int rtn = 0;
|
||||
asm volatile (
|
||||
"move $a0, %1\n"
|
||||
"move $a1, %2\n"
|
||||
"li $v0, 4264\n"
|
||||
"syscall\n"
|
||||
"move %0, $v0\n"
|
||||
: "=r"(rtn)
|
||||
: "r"(clockid), "r"(res)
|
||||
: "a0", "a1", "v0", "memory"
|
||||
);
|
||||
return rtn;
|
||||
}
|
||||
int clock_nanosleep(clockid_t clockid, int flags, const struct timespec *t, struct timespec* remain){
|
||||
int rtn = 0;
|
||||
asm volatile (
|
||||
"move $a0, %1\n"
|
||||
"move $a1, %2\n"
|
||||
"move $a2, %3\n"
|
||||
"move $a3, %4\n"
|
||||
"li $v0, 4265\n"
|
||||
"syscall\n"
|
||||
"move %0, $v0\n"
|
||||
: "=r"(rtn)
|
||||
: "r"(clockid), "r"(flags), "r"(t), "r"(remain)
|
||||
: "a0", "a1", "a2", "a3", "v0", "memory"
|
||||
);
|
||||
return rtn;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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__ */
|
||||
|
||||
Reference in New Issue
Block a user